Load the full script, select a few items, go to the upper level, run the command GotoPre, the SELECT ALL command does not select the added items, but the entire list.
Even if I use a new cmd object after going to the new path, it doesn't work. The log outputs the number of items added.
if (Script.Vars.Exists("prePath")) {
var prePath = Script.Vars.Get('prePath');
cmd.RunCommand('Go "' + prePath + '"');
if (selected.count) {
var cmd2 = DOpus.Create.Command;
cmd2.ClearFiles();
for (var e = new Enumerator(selected); !e.atEnd(); e.moveNext())
{
cmd2.AddFile(e.item())
}
}
if (cmd2.filecount) cmd2.AddLine('SELECT ALL')
DOpus.Output("Files count: " + cmd2.filecount)
cmd2.Run;
}
FullScript
// Go to Previous Location
// (c) 2023 Ken
// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "Go to Previous Location";
initData.version = "v1.0(2023.10.12)";
initData.copyright = "(c) 2023 Ken";
// initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
initData.desc = "Jump to the previous location.";
initData.default_enable = true;
initData.min_version = "13.0";
}
// Called to add commands to Opus
function OnAddCommands(addCmdData)
{
var cmd = addCmdData.AddCommand();
cmd.name = "GotoPre";
cmd.method = "OnGotoPre";
cmd.desc = "";
cmd.label = "GotoPre";
cmd.template = "";
cmd.hide = false;
cmd.icon = "script";
}
// Called when a tab is activated
function OnActivateTab(activateTabData)
{
var tab = activateTabData.oldtab;
Script.Vars.Set("preTab", tab);
Script.Vars.Set("prePath", tab.path);
if (tab.format.view)
Script.Vars.Set("selected", tab.selected)
}
// Called before a new folder is read in a tab
function OnBeforeFolderChange(beforeFolderChange)
{
var tab = beforeFolderChange.tab;
Script.Vars.Set("prePath", tab.path);
Script.Vars.Set("selected", tab.selected)
if (Script.Vars.Exists("preTab"))
Script.Vars.Delete("preTab")
}
// Implement the GotoPre command
function OnGotoPre(scriptCmdData)
{
var tab = scriptCmdData.func.sourcetab;
var cmd = scriptCmdData.func.command;
var selected = Script.Vars.Get("selected");
if (selected.count) {
cmd.ClearFiles();
//cmd.SetFiles(selected)
for (var e = new Enumerator(selected); !e.atEnd(); e.moveNext())
{
cmd.AddFile(e.item())
}
}
if (!Script.Vars.Exists("preTab")) {
if (Script.Vars.Exists("prePath")) {
var prePath = Script.Vars.Get('prePath');
cmd.RunCommand('Go "' + prePath + '"');
if (selected.count) {
var cmd2 = DOpus.Create.Command;
cmd2.ClearFiles();
for (var e = new Enumerator(selected); !e.atEnd(); e.moveNext())
{
cmd2.AddFile(e.item())
}
}
if (cmd2.filecount) cmd2.AddLine('SELECT ALL')
DOpus.Output("Files count: " + cmd2.filecount)
cmd2.Run;
}
return
}
var preTab = Number(Script.Vars.Get("preTab"));
var tabs = tab.lister.tabs;
for (var i = 0; i < tabs.count; i++)
{
if (tabs[i] == preTab) {
cmd.RunCommand('Go TABSELECT=' + i);
return
}
}
cmd.RunCommand('Go TABUNDOCLOSE');
}
When the event script runs Script.Vars.Set("preFocusItem", tab.GetFocusItem); in a tab with no items, it crashes. It's a problem with the GetFocusItem object.
To make it work:
if (tab.all.count)
Script.Vars.Set("preFocusItem", tab.GetFocusItem);
else
Script.Vars.Set("preFocusItem", false);
I don't know where the logs are yet, but you can reproduce it, it also happens on another machine with v12.
Summary
// Go to Previous Location
// (c) 2023 Ken
// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "Go to Previous Location";
initData.version = "v1.0(2023.10.12)";
initData.copyright = "(c) 2023 Ken";
// initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
initData.desc = "Jump to the previous location.";
initData.default_enable = true;
initData.min_version = "12.0";
}
// Called to add commands to Opus
function OnAddCommands(addCmdData)
{
var cmd = addCmdData.AddCommand();
cmd.name = "GotoPre";
cmd.method = "OnGotoPre";
cmd.desc = "";
cmd.label = "GotoPre";
cmd.template = "";
cmd.hide = false;
cmd.icon = "script";
}
// Called when a tab is activated
function OnActivateTab(activateTabData)
{
var tab = activateTabData.oldtab;
Script.Vars.Set("preTab", tab);
Script.Vars.Set("prePath", tab.path);
/*
if (tab.all.count)
Script.Vars.Set("preFocusItem", tab.GetFocusItem);
else
Script.Vars.Set("preFocusItem", false);
*/
Script.Vars.Set("preFocusItem", tab.GetFocusItem);
}
// Called before a new folder is read in a tab
function OnBeforeFolderChange(beforeFolderChange)
{
var tab = beforeFolderChange.tab;
Script.Vars.Set("prePath", tab.path);
Script.Vars.Set("selected", tab.selected);
/*
if (tab.all.count)
Script.Vars.Set("preFocusItem", tab.GetFocusItem);
else
Script.Vars.Set("preFocusItem", false);
*/
Script.Vars.Set("preFocusItem", tab.GetFocusItem);
if (Script.Vars.Exists("preTab"))
Script.Vars.Delete("preTab");
}
// Implement the GotoPre command
function OnGotoPre(scriptCmdData)
{
var tab = scriptCmdData.func.sourcetab;
var cmd = scriptCmdData.func.command;
cmd.ClearFiles();
if (!Script.Vars.Exists("preTab")) {
if (Script.Vars.Exists("prePath")) {
var prePath = Script.Vars.Get('prePath');
var selected = Script.Vars.Get("selected");
var preFocusItem = Script.Vars.Get("preFocusItem");
cmd.RunCommand('Go "' + prePath + '"');
var focItemSel = 0, eItem;
if (selected.count) {
//cmd.SetFiles(selected);
for (var e = new Enumerator(selected); !e.atEnd(); e.moveNext())
{
eItem = e.item();
cmd.AddFile(eItem);
if (eItem + "" == preFocusItem) focItemSel = 1
}
}
if (cmd.filecount)
cmd.RunCommand('Select FROMSCRIPT');
if (preFocusItem) {
cmd.ClearFiles();
cmd.AddFile(preFocusItem);
cmd.RunCommand('Select FROMSCRIPT SETFOCUS');
if (!focItemSel)
cmd.RunCommand('Select NONE');
}
}
return
}
var preTab = Number(Script.Vars.Get("preTab"));
var tabs = tab.lister.tabs;
for (var i = 0; i < tabs.count; i++)
{
if (tabs(i) == preTab) {
//cmd.RunCommand('Go TABSELECT=' + i);
cmd.RunCommand("Go TABSELECT=$" + preTab);
return
}
}
cmd.RunCommand('Go TABUNDOCLOSE');
}
It's much better if we have those in case we need them, before we start trying to reproduce the issue, else it will potentially waste time when we get to this. There are a lot of threads to get through right now.