Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

One Level file '- Copy' pattern - #313

Merged
malxau-msft merged 8 commits into
microsoft:masterfrom
schinagl:one_level_-_copy_behaviour
May 9, 2022
Merged

One Level file '- Copy' pattern#313
malxau-msft merged 8 commits into
microsoft:masterfrom
schinagl:one_level_-_copy_behaviour

Conversation

@schinagl

@schinagl schinagl commented Mar 20, 2022

Copy link
Copy Markdown
Contributor

Motivation

One wants to create a copy of a file/directory in the very same directory.
Dragging a file/directory onto the empty space in the file-pane does nothing currently.

Improvements

With this change one can drag an already existing file/directory into the empty space of the file pane and an item with the ' - Copy' is created.
E.g. File.txt -> 'File - Copy.txt'
FileCopyPattern

Lets have a live look

Comments on the Code

I starts in wfdirsr.c: 1049, where normally a drop on the same directory was blocked.
Enabling this only for 'copy' (fShowSourceBitmaps == TRUE) brings us to wfcopy.c, which is extended once for files and once for directories.

Known Limitations

This PR intentionally only works in the same directory.
There is no Copy (n) algorithm implemented if applied multiple times on the same file.

Dependencies

This one lives on its own, but if the Symlink/Hardlink one #312 will make it to the maintrunk, I will update this PR with a ' - Hardlink', '- Symlink' one.
I already have an aggregated version of all my changes under the _hermann branch.

@schinagl
schinagl force-pushed the one_level_-_copy_behaviour branch from 26a1b63 to 7993f66 Compare April 11, 2022 20:22
@schinagl

Copy link
Copy Markdown
Contributor Author

Let me give you a use-case:
One wants to make a temporary copy of a file easily, because you would like to try out things and be able to revert quickly.

Then simply drag the file onto the empty space, or on the directory itself in the left pane, and have a file with the ' - Copy' Prefix.

Comment thread src/wfcopy.c Outdated
Comment thread src/wfcopy.c Outdated
Comment thread src/wfcopy.c Outdated
Comment thread src/wfcopy.c Outdated
lstrcpy(szDest, szDestAlt);
} else {
// If one already used this '- Copy' postfix, bail out. Just one level.
ret = DE_SAMEFILE;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this happens for two cases, the one I don't understand above ( ! FUNC_COPY ), or where the file name has been changed so it's not the same file but the file name is in use. Would DE_RENAMREPLACE be better here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the -copy Postfix didn't exist (GetFileAttributes() ...) we create it
If it already exists we bail out, as we did before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It bails out, telling the user that it's the same file - but it's not the same file. It's attempting to copy "foo" to "foo - Copy", finds "foo - Copy", and bails out. The question is what to tell the user.

@schinagl schinagl May 5, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct it says the file is the same, but instead the file with '- copy' postfix is there.
We could create a new message, but for me it was good enough to see the current message

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look at the message for DE_RENAMREPLACE? See

"A file or directory by this name already exists. Within a directory, file and directory names must be unique." )
. We could have a new message, but this one seems to say the right thing already.

Comment thread src/wfcopy.c Outdated
Comment thread src/wfdirsrc.c
Comment thread src/wfdirsrc.c Outdated
Comment thread src/wfdirsrc.c Outdated
if (hwndHolder == lpds->hwndSource) {
if ((dwSelSink == (DWORD)-1) || SendMessage(hwndLB, LB_GETSEL, dwSelSink, 0L))
return TRUE;
if ((dwSelSink == (DWORD)-1) || SendMessage(hwndLB, LB_GETSEL, dwSelSink, 0L)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part of this test means that if a user Ctrl+drags a file over itself, it will be copied; but Ctrl+drag over any other file will do nothing. Is this intended?

Note that because this is checking the list box hwnd, dragging between two windows to the same directory have different behavior here: Ctrl+drag to a different file in the same directory but a second window will copy (adding the new suffix.)

It looks like this section can't interpret dragging over other files as copies without breaking the code below which is attempting to launch a program with a file as an argument.

I think this check used to be at the top to just short circuit logic. Note the "NormalMoveCopy" case comments that it's checking for the same directory, but really doesn't - it's checking for the same window, so the previous code would attempt the operation when crossing windows and fail later.

I'm wondering if this check should really look at fShowSourceBitmaps to no-op moves, but allow copies to continue; and the "NormalMoveCopy" case should also look at fShowSourceBitmaps to avoid the same-window check for copies, which this PR is aiming to support.

@schinagl schinagl May 5, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Investigating ....
<I set the other comments where I thought it is fine to 'resolved'. Hope this is fine. I am not sure what the policy is. So feel free to reopen>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try this or just guessed from the code?

I just tried this.
If I drag a file over an .exe it does start the .exe with the file as command line argument, regardless if it is in the same window or in a different one.
If I drag a file on the empty space it does a copy with the '- Copy' postfix.

Does this resolve your concern?
Do you have a use-case where you observed that it did not work?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it. I saw the same behavior for both cases you listed. The issue is what happens when files are dragged over each other (ie., not the empty space.) The case that seemed interesting to me is Ctrl+drag a file over a different file, which is a no-op in the same window, but will generate a copy if dragged to a different window. The behavior difference is really an artifact though of having slightly different pieces of code processing what is effectively the same case (by checking the window for equality), and I think removing the duplication will result in a more consistent experience.

@schinagl schinagl May 6, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current summary on this thread so far is

Copy files over 'ops' (.exe/.bat/...)

  • Works as before

Copy no-op over no-ops

  • Code of this PR
    same pane: nothing happens
    different pane: copy is created with '- Copy' postfix
New_NoOp2NoOp.mp4
  • Previous Code
    same pane: nothing happens
    different pane: Box pops up that files are the same <the video grabber didn't capture this>
Old_NoOp2NoOp.mp4

messagebox

So I don't see a change of behaviour, except for the '- copy' postfix.
I don't want to change the same-window check in this PR. I just wanted to create postfixes.

Did I miss something? Any breaking behaviour change?

@malxau-msft

Copy link
Copy Markdown
Contributor

I pushed a commit of suggestions: malxau@66759bb

(Obviously I'm no more familiar with this code than you, so please review and let me know if I'm making a horrible mistake.)

The "major" thing here is in wfdirsrc.c. In this PR, it seemed like there was code duplication, and I wanted to explore a bit more about how we could have a single path. I think the changes in this suggestion are cleaner and more consistent, but note they introduce one behavior change: in this PR, copying to the same window short-circuits the confirmation dialog. In my suggested change, copying to the same directory follows the same path as everything else, which results in a confirmation dialog. I think this is the right thing to do (if a user didn't want confirmations, they can turn them off), but it's worth calling out.

For wfcopy.c, I'm a bit frustrated at having two paths to add "- Copy" but after digging into it I understand why this happened. I tried to handle the directory case in the same way as the file case, but it didn't really seem "better" - it has to reconstruct the target path (one component) in OPER_MKDIR, so it felt like both approaches end up duplicating logic. Note these suggestions change the error message, check if the path is valid after adding "- Copy", and more explicitly check for FUNC_COPY when doing these appends.

Please let me know what you think.

@schinagl

schinagl commented May 8, 2022

Copy link
Copy Markdown
Contributor Author

Thx for the input. I am taking things piece by piece from your branch in an extra commit and comment it there.
Some things are easy, somethings need some time to think. Will mark he last commit , so that you know I am done

In my next version for sym/hardlinks Winfile also supports '-hardlink' and '-symlink' postfixes.
So as soon as hard/sylinks come in, I will have to revert things, because there will be FUNC_HARD, FUNC_LINK, FUNC_JUNC, and then the switch statement ist back
This was the reason why in all those places the odd looking switch() was there

Anyhow for now lets take it.
@schinagl

schinagl commented May 8, 2022

Copy link
Copy Markdown
Contributor Author

This was an easy one. The code is shorter, but .. :-)
In my next version for sym/hardlinks Winfile also supports '-hardlink' and '-symlink' postfixes.
So as soon as hard/sylinks come in, I will have to revert things, because there will be FUNC_HARD, FUNC_LINK, FUNC_JUNC, and then the switch statement ist back
This was the reason why in all those places the odd looking switch() was there

Anyhow for now lets take it.

Variable declaration in C style, needed for branch targeting W2K & WXP
Change message to more a appropriate
@schinagl

schinagl commented May 8, 2022

Copy link
Copy Markdown
Contributor Author

Also an easy one
Variable declaration in C style, needed for branch targeting W2K & WXP
Change message to more a appropriate

The intention to reach DirMoveCopy: is the same
Fine, thx
@schinagl

schinagl commented May 8, 2022

Copy link
Copy Markdown
Contributor Author

The flow of lines is untwisted much better.
The intention to reach DirMoveCopy: is the same
Fine, thx

bDoMoveRename is really used that late, and since we have the check for FUNC_COPY this is more logical. // if (bSameFile && pCopyInfo->dwFunc == FUNC_COPY
Checking the path is also good for all pathes // IsInvalidPath ...

I was a bit struggling with the removal of the switch, because as mentiond earlier there might be FUNC_HARD, FUNC_LINK ... and so on
Anyhow the 'switch' will then return, also the 'if (bSameFile ....' will become a little more clumsy, because all affected FUNC_ are mentioned

I guess this was the last commit. Thx for digging into and providing leaner sections!
@schinagl

schinagl commented May 8, 2022

Copy link
Copy Markdown
Contributor Author

Took over this one too. Took me the longest to check.
bDoMoveRename is really used that late, and since we have the check for FUNC_COPY this is more logical. // if (bSameFile && pCopyInfo->dwFunc == FUNC_COPY
Checking the path is also good for all pathes // IsInvalidPath ...

I was a bit struggling with the removal of the switch, because as mentiond earlier there might be FUNC_HARD, FUNC_LINK ... and so on
Anyhow the 'switch' will then return, also the 'if (bSameFile ....' will become a little more clumsy, because all affected FUNC_ are mentioned

I guess this was the last commit. Thx for digging into and providing leaner sections!

@malxau-msft
malxau-msft merged commit ffa2c97 into microsoft:master May 9, 2022
@schinagl
schinagl deleted the one_level_-_copy_behaviour branch May 9, 2022 05:04
@schinagl

schinagl commented May 9, 2022

Copy link
Copy Markdown
Contributor Author

Something gone wrong with the/my merge. It throws Access denied on -Copy Postfix

@malxau-msft

Copy link
Copy Markdown
Contributor

It's missing the initial population of szDestAlt :(

@schinagl

schinagl commented May 9, 2022

Copy link
Copy Markdown
Contributor Author

Yes. See #322. Found it when preparing

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants