Go EXPANDBRANCH=Collapse on files

ALT+UP to collapse a branch only works with selected folders. I would like to change it, such that it also works with selected file(s) in folders I want to collapse.
Is this possible?

Try modifying the hotkey like this (or add a button):

Go EXPANDBRANCH=collapse PATH={filepath|..}

Thanks, but I can't get that to work for both the folder and the files inside.
{filepath} works for the folder, {filepath|..} works for the file inside the folder. I'd like it to work for both, depending on where my selection is. I think I might need some @if... but I can't find how.

Try

Go EXPANDBRANCH=collapse PATH="{=Right(filepath,1)=="\" ? filepath : Parent(filepath)=}"
4 Likes

Awesome, thanks! Never thought of evals.

Thanks for the function! Although on collapse the focus line (not the selection) jumps from the folder being collapsed to the next item. Is this fixable within maybe another command or is that a behavior that should be fixed by DOpus for the collapse action?

(am using your command just with 'toggle' instead of 'collapse')

Changing the focus/selection would probably require a script. What would you suggest should happen? What should be selected/have focus? Note that the command works on files and folders on several levels simultaneously.

What should happen is that the collapsed folder should get the focus and selection since it's the item the command acts upon, and the manual alternative would be scrolling up to select the folder and executing the regular collapse command (or maybe it should just get the focus without selection, can't answer that without longer actual use)

Sorry, don't get this, that PATH parameter has a single "parent/root" argument, it's "just" that you don't need to go up manually to select that parent item to collapse it, but can use your command to do so, which is why it should behave the same as this manual process

Also I've noticed that if you don't have an active selection (like pressing Esc after navigating into the expanded folder), the script doesn't work, guess
because you don't have filepath and focused but not selected item has a different command to get its path?

Yes, but it runs on every selected item in the file display and will collapse all associated folders regardless of their level.

One solution could be to select all collapsed folders, deselect everything else, and put the focus on the first folder.

In this case, the script could use the focus item to determine the parent folder.

Oh, I see now. Well, in that case the principle is the same - it should replicate manual operation assuming that instead of a file you had the top folder selected. So all the top-level folders for all the different items should be selected just like currently if you select two folders and collapse/expand them you still end up with a selection of two folders.

And if you select 2 folders and 1 file, then collapse/expand them, you still get the same selection, so the script should ideally do the same

Maybe all that is needed is 1 extra command that would simply add selection of the PATH calculated value and then do a regular EXPANDBRANCH operation? It would "naturally" has the same effect as if you manually did the selection

(though I don't see a way for a simple selection of a single path in Select [Directory Opus Manual])