Load script (custom menu) at selection?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
sinilill
Posts: 111
Joined: 02 Dec 2013 18:37

Load script (custom menu) at selection?

Post 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?

highend
Posts: 13275
Joined: 06 Feb 2011 00:33

Re: Load script (custom menu) at selection?

Post by highend »

popupmenu() can be invoked with x | y coordinates but not at specific gui elements (list selections or anything like that).
One of my scripts helped you out? Please donate via Paypal

sinilill
Posts: 111
Joined: 02 Dec 2013 18:37

Re: Load script (custom menu) at selection?

Post 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 :D
And then I had the idea to make a seperate menu for file operations :D

Is it possible to load it in the center of XYplorers window?

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Load script (custom menu) at selection?

Post 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. :?

sinilill
Posts: 111
Joined: 02 Dec 2013 18:37

Re: Load script (custom menu) at selection?

Post 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 :D
$row = row(<curitem>);
$column = "name";
sel $row;
$x = cell($row, $column, "x");
$y = cell($row, $column, "b");
popupmenu("TEST", $x, $y+155);
Image

sinilill
Posts: 111
Joined: 02 Dec 2013 18:37

Re: Load script (custom menu) at selection?

Post by sinilill »

Is it supposed to load offset or am I doing something wrong?
Unfortunately my scripting skills are based on trial and error!

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Load script (custom menu) at selection?

Post 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! :oops:

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Load script (custom menu) at selection?

Post by admin »

screen position: yep, I can do that.

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Load script (custom menu) at selection?

Post 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])

sinilill
Posts: 111
Joined: 02 Dec 2013 18:37

Re: Load script (custom menu) at selection?

Post 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);
Image

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Load script (custom menu) at selection?

Post 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.

sinilill
Posts: 111
Joined: 02 Dec 2013 18:37

Re: Load script (custom menu) at selection?

Post by sinilill »

Image

I guess I could live with the 1. scenario, but now my computer makes a BING everytime I run the script :D

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Load script (custom menu) at selection?

Post 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. :?

sinilill
Posts: 111
Joined: 02 Dec 2013 18:37

Re: Load script (custom menu) at selection?

Post by sinilill »

Thanks, now it's working flawlessly, I appreciate your input!

The BING sound was because I didn't had On KeyUp checked :D

Post Reply