Page 1 of 1
Load script (custom menu) at selection?
Posted: 01 Jun 2014 16:54
by sinilill
Hi, I wan't to load a custom menu via keyboard shortcut at the selection, like POM, currently it loads at the mouse pointer.
Is there a way I can specify the position?
Re: Load script (custom menu) at selection?
Posted: 01 Jun 2014 17:27
by highend
popupmenu() can be invoked with x | y coordinates but not at specific gui elements (list selections or anything like that).
Re: Load script (custom menu) at selection?
Posted: 01 Jun 2014 18:10
by sinilill
I'm using load "rename.txt"
the txt file contains:
Code: Select all
"Rename add date+sig" rename , "<date yymm> * - PN";
"Rename after current folder" rename , "<curfolder>";
etc
I wanted to make a seperate menu just for renaming files, because my POM is already too crowded. It's working, but everytime I use it, I have to search for the dialog box

And then I had the idea to make a seperate menu for file operations
Is it possible to load it in the center of XYplorers window?
Re: Load script (custom menu) at selection?
Posted: 01 Jun 2014 18:23
by TheQwerty
There's the undocumented
row and
cell scripting commands which allow you to find a row index by item and then find coordinates for a particular column within that row.
You'll want to read a some of the posts starting here:
http://www.xyplorer.com/xyfc/viewtopic. ... 19#p102919
That should allow you to show popupmenu near the selection, but I don't think you'll be able to easily determine the center of the list pane or window.

Re: Load script (custom menu) at selection?
Posted: 01 Jun 2014 21:06
by sinilill
Managed to get it work, but it's offset, both in x and y direction.
Maybe it has something to do with the new Layout?
With offset correction
$row = row(<curitem>);
$column = "name";
sel $row;
$x = cell($row, $column, "x");
$y = cell($row, $column, "b");
popupmenu("TEST", $x, $y+155);

Re: Load script (custom menu) at selection?
Posted: 03 Jun 2014 00:19
by sinilill
Is it supposed to load offset or am I doing something wrong?
Unfortunately my scripting skills are based on trial and error!
Re: Load script (custom menu) at selection?
Posted: 03 Jun 2014 15:41
by TheQwerty
Eh... forget about my earlier post. It appears cell only returns positions relative to the top,left of the active list pane while popupmenu uses coordinates across the entire screen.
Maybe Don will improve this by adding a flag to cell to get the screen position instead.
Sorry for leading you astray!

Re: Load script (custom menu) at selection?
Posted: 03 Jun 2014 15:50
by admin
screen position: yep, I can do that.
Re: Load script (custom menu) at selection?
Posted: 03 Jun 2014 16:03
by admin
No time to doc this, but pass 1 as flags to convert it to screen position:
Code: Select all
syntax: cell(row, column, coord, [flags])
Re: Load script (custom menu) at selection?
Posted: 03 Jun 2014 21:55
by sinilill
admin wrote:No time to doc this, but pass 1 as flags to convert it to screen position:
Code: Select all
syntax: cell(row, column, coord, [flags])
WOW, thanks, the flag is working as intended.
But I'm stuck again
As everybody can see from the scipt, it's only supposed to work with a single selection.
It would be a lot more useful if it would work with a multiselection. I browsed the scripting commands reference, but couldn't come up with anything good.
Code: Select all
$row = row(<curitem>);
$column = "name";
sel $row;
$x = cell($row, $column, "x", 1);
$y = cell($row, $column, "b", 1);
popupmenu("ALMOST", $x, $y);

Re: Load script (custom menu) at selection?
Posted: 03 Jun 2014 22:04
by TheQwerty
You don't need to call sel $row; in your script at all so removing that line should get you one step closer.
Re: Load script (custom menu) at selection?
Posted: 03 Jun 2014 22:25
by sinilill
I guess I could live with the 1. scenario, but now my computer makes a BING everytime I run the script

Re: Load script (custom menu) at selection?
Posted: 03 Jun 2014 22:40
by TheQwerty
The problem is <curitem> is the selected AND focused item but the dragging selection rectangle selects items without changing the focus.
In one case: hdkanafilee.jpg is focused but not in the selection so <curitem> is nothing and thus row() returns 1.
In the other job.gif is focused and in the selection so it is <curitem> and row(<curitem>) then returns 9.
The question then becomes where should the menu appear when multiple items are selected?
You could do something like this to show the menu after the first item in the selection:
Code: Select all
// Get list of selected items.
$items = Get('SelectedItemsPathNames');
// Default to the focused item if nothing is selected.
if ($items == '') {
$items = "<focitem>";
}
// Get first item from list.
// Replace 1 with -1 to use the last item from the list.
$item = GetToken($items, 1, "<crlf>");
$row = row($item);
$column = "name";
$x = cell($row, $column, "x", 1);
$y = cell($row, $column, "b", 1);
popupmenu("ALMOST", $x, $y);
Not sure why it's making noise for you as it is silent here.

Re: Load script (custom menu) at selection?
Posted: 04 Jun 2014 13:56
by sinilill
Thanks, now it's working flawlessly, I appreciate your input!
The BING sound was because I didn't had On KeyUp checked
