Page 1 of 3

Custom context menu for list's whitespace

Posted: 29 Aug 2018 21:06
by John_C
How does such context menu could be created:

viewtopic.php?f=3&t=18674#p157659

?

Here is what I have currently:

Code: Select all

"Paste" #202
"Undo" #203
"Redo" #204
"Refresh" #1001
"New Shortcut" #241
"New Items (should be expandable. How?)" #240

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 21:18
by highend
By using

Code: Select all

popupnested()
and either manually stored items for "New items" or by parsing them in their location...

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 21:42
by John_C
highend wrote:By using

Code: Select all

popupnested()
and either manually stored items for "New items" or by parsing them in their location...
I have tried different examples from docs, but it works slightly different compared to the linked image. On the image, as you can see, the item on first menu is already expandable. In my case, it doesn't. Here is my current code:

Code: Select all

"Paste" #202
"Undo" #203
"Redo" #204
"Refresh" #1001
"New Shortcut" #241
"New" // #240
    $menu = <<<MENU
        Top;;:paper;1
            Sub;;;4
            Sub
                Sub2;;*.ini
                Sub2
                Sub2;;;2
        Top;;<xy>
    MENU;
    text popupnested($menu);

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 21:47
by highend
Ofc you need to arrange these leading items in the popupnested() menu as well?

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 22:18
by John_C
highend wrote:Ofc you need to arrange these leading items in the popupnested() menu as well?
Well, here is updated version. Much cleaner:

Code: Select all

$menu =
    <<<MENU
        Paste;#202;:paste
        Undo;#203;:undo
        Redo;#204;:redo
        Refresh;#1001;:refresh
        New Items;#240
            Foo
            Bar
    MENU;
    popupnested($menu);
Now I trying to understand how to add "new items" in place of "Foo" and "Bar". Here is what I mean:
menu.png
"Parsing them in their location" as you said - I understand what it mean, but I don't understand how to write it in code :lol:

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 22:22
by Filehero
Examples for SC new().

Code: Select all

new("NewFolder", "dir");
new("file.txt");

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 22:24
by highend
and the only thing necessary to execute the returned menu entry is

Code: Select all

 eval()

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 22:29
by John_C
Filehero wrote:Examples for SC new().

Code: Select all

new("NewFolder", "dir");
new("file.txt");
Could you please show how to use it together with my code?

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 22:33
by highend
Read the docs for

Code: Select all

popupmenu()
. It explains how the necessary parts are put together

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 22:47
by John_C
highend wrote:Read the docs for

Code: Select all

popupmenu()
. It explains how the necessary parts are put together
I already read, but can't understand. :veryconfused:

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 22:49
by highend
What? You're already using the necessary structure in your other items?

Code: Select all

Paste;#202;:paste
caption;DATA;icon
What to use for DATA for an item was posted and how to execute that returned DATA stuff was also posted...

1+1=?

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 22:55
by John_C
highend wrote:What? You're already using the necessary structure in your other items?

Code: Select all

Paste;#202;:paste
caption;DATA;icon
What to use for DATA for an item was posted and how to execute that returned DATA stuff was also posted...

1+1=?
I'm not a programmer. If it's hard to post a working solution? I see your code, but it works for "Paste" button. I already have working "Paste" button. I'm trying to understand how to add "new folder" and "new text file" instead of "Foo" and "Bar".

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 23:09
by John_C
highend wrote:What? You're already using the necessary structure in your other items?

Code: Select all

Paste;#202;:paste
caption;DATA;icon
What to use for DATA for an item was posted and how to execute that returned DATA stuff was also posted...

1+1=?
For example, I tried this:

Code: Select all

$menu =
    <<<MENU
        Paste;#202;:paste
        Undo;#203;:undo
        Redo;#204;:redo
        Refresh;#1001;:refresh
        New Items
            Foo;new("NewFolder", "dir"));
            Bar;new("file.txt")
    MENU;
    popupnested($menu);
    eval($menu);
It doesn't work for me.

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 23:12
by highend
You need to assign popupnested()'s return value to a variable and eval that or do it directly in one go.
Atm the menu is displayed but what it returns isn't stored / nor eval()'d

Code: Select all

eval(popupnested($menu));
or

Code: Select all

$selected = popupnested($menu);
eval($selected);

Re: Custom context menu for list's whitespace

Posted: 29 Aug 2018 23:17
by John_C
highend wrote:...
Thank you very much, it works perfectly! :beer: