Command IsSet deselects folders

A few days ago in one of my commands, there was a strange behavior, discovered by @fkast. Right after executing the command, the selected folders were deselected. At first I thought it was something inherent to the command, something in its configuration (partly it is), but I have found a way to reproduce it.

  1. Have checked Deselect files used in functions in Preferences / File Operations / Options
  2. If the script makes use of Command.IsSet method (e.g. Set EXPANDABLEFOLDERS=off), the folders are deselected.
function OnClick(clickData) {
	var cmd = clickData.func.command;
	//var cmd = DOpus.Create.Command(); same if you use this instead
	cmd.SetModifier("nodeselect"); //doesn't have effect
	if (cmd.IsSet('Set EXPANDABLEFOLDERS=off')) {
		DOpus.Output('Expandable Folders is currently disabled. Enable it before using this command.');
	}
	var items = clickData.func.sourcetab.selected;
	DOpus.Output("dirs selected : " + clickData.func.sourcetab.selected_dirs.count);
	DOpus.Output("files selected : " + clickData.func.sourcetab.selected_files.count);
	if (items.count == 0) {
		DOpus.Output("  (none)");
	}
	else {
		for (var i = 0; i < items.count; i++) {
			DOpus.Output((i+1) + ": " + items(i));
		}
	}
	return;
}

Test isSet.dcf (1.5 KB)

Works fine here. Did I follow your instructions correctly?

First :

Then using that button:

If you comment this lines, folders keeps selected.

I also had Preferences / File Operations / Options / Postpone file deselection until end of function checked.

With this unchecked, the folders do get deselected.

This is what I normally use:
var cmd = cmdData.func.command; cmd.deselect = false;
works great.

Ok. But in this context, adding cmd.deselect = false doesn't make any effect.
What I was trying to point out (and it seems I failed), is that when you have Preferences / File Operations / Options / Deselect files used in functions checked (and the one below unchecked as lxp rightly pointed out), it happens that :

  • If a command uses IsSet(), no matter what it queries, the selected folders are deselected.
  • @nodeselect or cmd.deselect = false, have no effect on override that option, as indicated in the manual.
1 Like

I had a similar problem, where I had to refresh the lister but didn't want to lose the selection. Maybe as a temporary workaround, something like this?

// somewhere at the top
var orig_selected_items = scriptCmdData.func.sourcetab.selected;
// do stuff
for (var e2 = new Enumerator(orig_selected_items); !e2.atEnd(); e2.moveNext()) {
  cmd.AddFile(e2.item());
}
cmd.runCommand('Select FROMSCRIPT');

Visually not nice, but might help temporarily

-- 2 mins later --

I tested out your code in a new button and selection is not lost for me and my inline expandable folders are off:

function OnClick(clickData)
{
        var cmd = DOpus.create().command();
        cmd.deselect = false;
        if (cmd.isSet('Set EXPANDABLEFOLDERS=off')) {
            DOpus.output('Expandable Folders is currently disabled. Enable it before using this command.');
        }
        var items = clickData.func.sourcetab.selected;
        DOpus.output('dirs selected : ' + clickData.func.sourceTab.selected_dirs.count);
        DOpus.output('files selected : ' + clickData.func.sourceTab.selected_files.count);
        if (items.count == 0) {
            DOpus.output('  (none)');
        }
        else {
            for (var i = 0; i < items.count; i++) {
                DOpus.output((i+1) + ': ' + items(i));
            }
        }
}

Have you checked the state for Preferences / File Operations / Options / Deselect files used in functions and Preferences / File Operations / Options / Postpone file deselection until end of function first?
Set EXPANDABLEFOLDERS=off was just an example, can be anything, e.g. Set DUAL=off. The result doesn't matter.

Based on my test, prob isSet() is not the culprit alone. These are my settings and the code for the 8-ball button:

in action:

Uncheck Preferences / File Operations / Options / Postpone file deselection until end of function and see how it goes now.

my bad, deselect active, postpone inactive => loses the dir.

EDIT: it seems the culprit is the postpone option alone, I'd say.

Using your code:

and :

  • Preferences / File Operations / Options / Deselect files used in functions checked :ballot_box_with_check:
  • Preferences / File Operations / Options / Postpone file deselection until end of function unchecked

I'm still seeing the same. (folders get deselected).
So if you're not seeing the same thing, I'm guessing there's something else going on so l and fkast (and probably lxp?) see it but you don't.

No, maybe I wasn't clear, if "postpone" is inactive/unchecked, then I lose the dir selection as well, so I can reproduce your problem. And if I disable cmd.isset() block it retains the selection.

But I suspect the problem is not with cmd.isset but the postpone option, because isset() works if postpone is active; probably it takes only the files into account as the option text suggests, not dirs.

Yep, sorry I didn't read your response before my last post.

Try commenting that whole part.

Yeah I deleted the whole block even. I still suspect it is the postpone option, but from this point on, I think what the root cause is, is a question Leo/Jon can answer.