Remeber the focused file/folder as you navigate

Here's a little add-in that should do what you want. Give it a try and let me know what you think.

function OnInit(initData) {
    initData.name = 'SaveSelection';
    initData.version = '2024-08-14';
    initData.url = 'https://resource.dopus.com/t/remeber-the-focused-file-folder-as-you-navigate/52274/6';
    initData.desc = 'Save and restore selected items';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnBeforeFolderChange(beforeFolderChangeData) {
    if (beforeFolderChangeData.initial) return;
    var tab = beforeFolderChangeData.tab;
    var tabID = String(tab.path);
    tab.vars.Set(tabID, tab.selected);
}

function OnAfterFolderChange(afterFolderChangeData) {
    var tab = afterFolderChangeData.tab;
    if (!tab) return;
    if (!tab.path) return;
    var tabID = String(tab.path);
    if (!tab.vars.Exists(tabID)) return;

    var cmd = DOpus.Create().Command();
    cmd.SetSourceTab(tab);
    // cmd.SetFiles(tab.vars.Get(tabID));
    cmd.ClearFiles();
    cmd.AddFiles(tab.vars.Get(tabID));
    cmd.RunCommand('Select NONE');
    cmd.RunCommand('Select FROMSCRIPT SETFOCUS');
    cmd.RunCommand('Select SHOWFOCUS');
}

:one: Save EventSaveSelection.js.txt to   ↓

%appdata%\GPSoftware\Directory Opus\Script AddIns

:two: This button will switch the script on and off

XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>SaveSelection Script is %1</label>
	<tip>Toggle EventSaveSelection.js</tip>
	<icon1>#script</icon1>
	<function type="normal">
		<instruction>@eval:scriptIsOff = IsChecked(&quot;Prefs SCRIPTDISABLE=EventSaveSelection.js*&quot;)</instruction>
		<instruction>@icon:=scriptIsOff ? &quot;setoff&quot; : &quot;setdest&quot;</instruction>
		<instruction>@label:Format(original_label, (scriptIsOff ? &quot;off&quot; : &quot;&lt;b&gt;on&lt;/b&gt;&quot;))</instruction>
		<instruction>@toggle:invert</instruction>
		<instruction />
		<instruction>Prefs SCRIPTDISABLE=EventSaveSelection.js*</instruction>
	</function>
</button>

How to use buttons and scripts from this forum

1 Like