GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Go FROMSEL not working as expected after a rename/re-select

Hello,

i've got a simple task i've put as code for a shortcut key :
1- it creates a new folder based on timestamp and move current selected files/folder to that new folder
2- it forces reselection / refocus on newly created folder
3- it is supposed to enter into that newly created folder

step 3 with GO FROMSEL is not working and i cannot understand what is wrong in this last instruction.

nota : here i've put all the patterns code for step 1 with 'rename' but i'm supposed to use a rename preset in my real code. And also i'm using 'details view mode' maybe it has something specific when reselecting and entering folder with "go fromsel".

any idea ?

function OnClick(clickData)
{
    var cmd = clickData.func.command;

	// 1. move selected items in a new folder
	cmd.RunCommand("Rename PATTERN * TO new_{date|MM-dd}-{time|HH}H{time|mm}\\*");

	// 2. select the newly created folder and force its focus
    cmd.RunCommand("Select TYPE=dirs DATE=created,newest SETFOCUS");

	// 3. entering folder
	cmd.RunCommand("Go FROMSEL");

}

Thanks in advance,
Antoine

Try this.

function OnClick(clickData) {
	var cmd = clickData.func.command;
	var tab = clickData.func.sourcetab;
	cmd.RunCommand('Rename PATTERN * TO new_{date|MM-dd}-{time|HH}H{time|mm}\\*');
	cmd.RunCommand('Select TYPE=dirs DATE=created,newest SETFOCUS');
	tab.Update();
	cmd.RunCommand('Go PATH="' + tab.selected_dirs(0) +'"');
}

(Assuming this is part of a bigger project and you really must use a Select statement. If not, I'd suggest a different approach.)

thanks lxp,

it's working well indeed with this solution.

(seems a bit tricky to me to need updating a tab but it's working that's the thing :wink: )

Well, it was you who started the JScript :wink:

If you just need the functionality from above, the button can be as simple as

@set newFolder=new_{date|MM-dd}-{time|HH}H{time|mm}
Copy MOVE HERE CREATEFOLDER={$newFolder}
Go PATH={$newFolder}
1 Like

The Tab object keeps a snapshot of the state the last time it was created or updated. If it kept changing state as things happened, everything would go haywire and you wouldn't be able to do a stable iteration through the list of files selected at the time the button was clicked. You decide when the snapshot is updated, and it remains consistent between updates. It has to or nothing would work properly.


In general, it's also better not to use the selection in this way. Change the selection if you want to change what is selected in the user interface. But don't (unless there's no alternative) think of the selection as a way for one piece of script code to influence what another command or piece of code runs on.

Most internal commands can be given file paths directly as arguments, and you can also define which files the Command objects work on when those arguments are not specified. (The ClearFiles and AddFile methods on the object are the main ones for that.)

Thanks Lxp for you two answers, i'll keep the last one as the best approach.

And Leo, thanks for this explanation about how things are working.
That's great to understand also all this.

Best to you and the dev team,
Antoine

1 Like