Select SETFOCUS not working as expected

This button works as expected (it selects orphaned video thumbnails), except for setting/showing the focus. It is always on top of the list.

Select NONE
Select grp:Movies
Select SIMILARBASE 
Select INVERT 
Select ~grp:Images DESELECT SETFOCUS
Select SHOWFOCUS

SETFOCUS doesn't seem to work with DESELECT.

Is this similar to this thread: Show first selected file ?

I wouldn't expect deselect and setfocus to work together. What does that mean; set focus to the first file that isn't selected?

You'd probably need to do the setfocus separately.

I thought: set focus to the first file that is still selected

You'd probably need to do the setfocus separately.

Yes. But how?

  • Added it to all commands before (one by one)
  • Added a line Select RESELECT SETFOCUS
  • Added a line Select NOPATTERN SETFOCUS

None worked. Then I found the thread mentioned above. The extra JScript button works just fine.

There aren't that many orphaned thumbnails on my drives, so probably not worth spending much time on it. Guess I was just a bit too curious :wink:

The docs don't make it clear but SETFOCUS will only move focus to the first item selected by the rest of the command. So if the rest of the command only deselects (or doesn't do anything, e.g. Select NOPATTERN) then it won't do anything.

You'd probably need to use scripting to do what you want: Run the select commands up to that point, then call tab.Update to tell the object to update its snapshot of what is selected, then feed the first selection into Select FROMSCRIPT SETFOCUS which I think should work.

This is actually something I had tried. I gave up because the Select commands already behave differently when called from a script without Setfocus. I know from other scripts that what is shown in the file display can be (will quickly be) different from what is in the command object and this time I just didn't feel like digging into the details.

If you have time to have a look - here are the buttons and some test files. No rush, it's more appetite for knowledge than real need :slight_smile:

//@nodeselect 
Select NONE
Select grp:Movies
Select SIMILARBASE 
Select INVERT 
Select ~grp:Images DESELECT 
function OnClick(clickData) {
    var cmd = clickData.func.command;
	var tab = clickData.func.sourcetab;
		
    //cmd.deselect = false; // Prevent automatic deselection
    cmd.RunCommand('Select NONE');
    cmd.RunCommand('Select grp:Movies');
    cmd.RunCommand('Select SIMILARBASE');
    cmd.RunCommand('Select INVERT');
    cmd.RunCommand('Select ~grp:Images DESELECT');
	// tab.Update();
	// cmd.RunCommand('Select FROMSCRIPT MAKEVISIBLE=immediate');
	// cmd.RunCommand('Select FROMSCRIPT SETFOCUS');
}

Select Orphaned Thumbnails JS.dcf (1.2 KB)
Select Orphaned Thumbnails.dcf (525 Bytes)
orphantest.rar (12.3 KB)

You could need to update the cmd object's file list as well. Select FROMSCRIPT will act on the files given to the cmd object, which if it comes from clickdata.func.command will be whatever was selected when the button started, unless something is done to change that.

So you'd need to call cmd.ClearFiles(), then cmd.AddFile(...) with the file you want to give focus, then run the commands on that.

The trick to get this script to work properly was to use cmd.AddLine instead of cmd.RunCommand for the Select commands.

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    
    cmd.Clear;
    cmd.AddLine('Select NONE');
    cmd.AddLine('Select grp:Movies');
    cmd.AddLine('Select SIMILARBASE');
    cmd.AddLine('Select INVERT');
    cmd.AddLine('Select ~grp:Images DESELECT');
    cmd.Run;
    tab.Update();
    cmd.ClearFiles;
    cmd.AddFiles(tab.selected_files);
    cmd.RunCommand('Select FROMSCRIPT MAKEVISIBLE=immediate');
}