Page MenuHome

File Browser: select files and directories after renaming
Needs ReviewPublic

Authored by Pieter Schiettecatte (Schiette) on Jan 5 2021, 2:35 AM.
Tokens
"Love" token, awarded by intracube."Love" token, awarded by pablovazquez."Love" token, awarded by gilberto_rodrigues."Love" token, awarded by manitwo.

Details

Summary

This is my first patch so please go easy on me :)

Currently, when a new directory is created, the newly created directory is not selected. Similarly, when renaming an existing file or directory, it does not remain active/highlighted blue after renaming.

This patch proposes to keep the file or directory selected after (re)naming it, even when the rename is cancelled (for example when you create a new directory and accept the default name, the rename is canceled).

This has some usability advantages:

  • open the newly created directory without having to select it (ENTER)
  • if you make a naming mistake, you can immediately fix that without having to re-select (F2)
  • if you create a directory and forget to name it, you can fix that without having to select it (F2)
  • consistent with windows file browser (not sure about Linux and Mac?)

One downside I could think of is that when you have multiple files/directories selected, and then rename one of them, the selection will be reset to that renamed file.

There also seems to be weird bug that I could use some help on. If you rename a file (F2), move your mouse away from that row, and then cancel the rename (ESC) the row only turns blue after moving your mouse over one of the files. I have run into similar bugs in the current master, so I don't think this commit causes it, but rather makes it more obvious by adding this new use-case.

Diff Detail

Repository
rB Blender

Event Timeline

Pieter Schiettecatte (Schiette) requested review of this revision.Jan 5 2021, 2:35 AM
Pieter Schiettecatte (Schiette) created this revision.
Pieter Schiettecatte (Schiette) retitled this revision from Select files and directories after renaming them in the file browser to File Browser: select files and directories after renaming.Jan 5 2021, 5:00 PM

Great improvement! It's consistent with selection elsewhere in Blender that newly created items are selected. (There are places that break this, but that's the convention anyway AFAIK).

One comment on the code, but don't read into it much, I don't have much experience with this area of the code.

One usability thing I ran into when testing this: If you add a new folder with a name that's already taken the folder won't be selected. I don't consider that a blocking problem, but if you have an idea of how to resolve it, that might be nice.

One downside I could think of is that when you have multiple files/directories selected, and then rename one of them, the selection will be reset to that renamed file.

This seems to be a bit buggy right now anyway, so I wouldn't worry about that.

If you rename a file (F2), move your mouse away from that row, and then cancel the rename (ESC) the row only turns blue after moving your mouse over one of the files.

I ran into this testing current master before your patch, so it's definitely not caused by this.

source/blender/editors/space_file/filesel.c
1074

It's a little suspicious to have two calls to filelist_entry_select_set with one right after the first in this case. Maybe it's fine though.

Generally I like the idea of this.

I can think of a number of ways how this could behave exactly. E.g. in the current implementation, it seems whatever is selected and only changes selection to the item when the renaming was successful?
Personally I'd prefer if the item I renamed always ends up being selected, that makes it feel predictable.

The macOS file browser (Finder) selects items when renaming (not when right-clicking, only when renaming). This makes sense to me, and would also work when renaming is cancelled or the same name is entered.
How do other File Browsers behave?

source/blender/editors/space_file/filesel.c
1074

The second one enables editing by setting the FILE_SEL_EDITING flag. It's just confusing that this is done through a function saying it just deals with selection.

I digged a bit deeper since we want this functionality in for D11119: Assets: Keep assets active after renaming, ensure they are scrolled into view (important for the pose library workflow which we need to get into master). I figured we need a different approach to make sure the file is always reliably selected after renaming, even if that failed (e.g. because the file name exists already) or was cancelled. So I ended up with rB6b0869039a40.

Sorry for screwing up the party on your first patch. The code/design here is quite tricky, it took me a while to come up with something that works and isn't too hacky. So don't feel beaten, the game was rigged from the beginning!

Oh also, regarding this:

One downside I could think of is that when you have multiple files/directories selected, and then rename one of them, the selection will be reset to that renamed file.

My patch entirely deselects other files so it applies there as well. But we could simply leave the selection untouched if the file was selected before. That would be a trivial further improvement to make, if wanted.

I digged a bit deeper since we want this functionality in for D11119: Assets: Keep assets active after renaming, ensure they are scrolled into view (important for the pose library workflow which we need to get into master). I figured we need a different approach to make sure the file is always reliably selected after renaming, even if that failed (e.g. because the file name exists already) or was cancelled. So I ended up with rB6b0869039a40.

Sorry for screwing up the party on your first patch. The code/design here is quite tricky, it took me a while to come up with something that works and isn't too hacky. So don't feel beaten, the game was rigged from the beginning!

Thank you Julian for working on this! As you noted, the code was trickier than I anticipated and I wasn't sure how to properly implement this. I'm glad you found the time to do it!