Is it possible to discard current lister's settings (sort, view, filters etc.) to default configured in settings?
I want to have a button that will cancel any settings made to flat/sort/filters settings to defaults, regardless of whether I changed default lister's settings using Set command or settings were applied because I used lister layout with changed sort options.
So if I open layout with sort options specific to that layout and hit a certain button, I want to display current folder with sort:
a) specific to that folder if current folder has saved folder format
b) specific to current location type (collection, custom, flat view, local drives, ftp etc) if specified in Folder Formats -> Default Formats
c) default for all other folders
Currently, I think the best way to do this is to open a new tab for the current folder, then close the old tab:
Go CURRENT NEWTAB=nofocus TABPOS=+1
Go TABSELECT=+1
Go TABSELECT=-1
Go TABCLOSE
The two TABSELECT lines ensure the correct tab is selected when the current tab is closed. This also results in some flashing between the old & new tab.
To avoid all of that, it can be done more elegantly using a script:
@script jscript
function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.RunCommand("Go CURRENT NEWTAB TABPOS=+1");
cmd.RunCommand("Go TABCLOSE=" + clickData.func.sourcetab);
}
In the future, we'll also have an explicit command to reset the folder format to what it would be if the folder had been loaded into a fresh tab. (That way you don't lose the tab's selection, history etc.)
Flashing is not a problem so I chose the first option for now.
Losing current file selection in tab being closed is indeed a problem but I can live with that for now. Hope you will implement the explicit way in the nearest future.
Wow, didn't know this existed. Thanks, great work.
The only problem is that if Preferences -> File Operations -> Options -> Deselect files used in functions is disabled, the script also selects the first item in folder.
How can this be avoided?
I found out that the code below works ok but I don't know if it has some disadvantages over code proposed by you.
Please use the SelectEx version attached, it is work in progress in some parts, but it contains a NOFAIL switch I recently added to prevent the error you get if there is no selection. Did only quick-test with a selection present, sorry. I think DESELECTNOMATCH is good to prevent the first line from being highlighted, though I actually don't understand why it is highlighted. It does happen here with the option disabled you mentioned.
SelectEx TOVAR="TmpSelection" NODESELECT NOFAIL
Go CURRENT NEWTAB=nofocus TABPOS=+1
Go TABSELECT=+1
Go TABSELECT=-1
Go TABCLOSE
SelectEx FROMVAR="TmpSelection" MAKEVISIBLE DESELECTNOMATCH NOFAIL Command.Generic_SelectEx.js.txt (146 KB)
For the way it's used here, I agree, indicating an error is probably too much, though I think I had situations where an empty selection container was indeed some sign of malfunction elsewhere. Anyway, I changed the "E" in line #1414 to be an "I" for now, that should fix the red blinking icon for you as well! o)