Page 1 of 1

Executing two commands via Nested Menu

Posted: 21 Apr 2023 19:06
by sl23
I'm trying to add an entry which opens a new tab and goes to the XY script folder, but I've tried so many variations and even tried looking at the manual to see if I could find anything to help. Although the manual has a lot of info about menus and nested menus, I can't find anything about using two commands at once, like in this situation.

This is what I've tried, with a hundred variations in brackets, spacing, punctuation marks, etc!
Script Folder;#340{goto "<xyscripts>"};*.<DIR>

Any help would be appreciated, thank you.

Re: Executing two commands via Nested Menu

Posted: 21 Apr 2023 19:29
by highend
Use a different separator for the entries and ";" between the commands or just lookup the tab() command instead?

Re: Executing two commands via Nested Menu

Posted: 21 Apr 2023 20:36
by sl23
Thank you for your reply highend.

I forgot about the tab() function!
So, I tried this, but it's still not working: Script Folder;tab("new", "<xyscripts>");*.<DIR>

I don't know what you mean by "Use a different separator for the entries".
And, I did try previously to use a ";" between commands, but that didn't work for me. I opened the TryScript window to see if that could shed light on the problem, but that just said "dubious syntax"!

Sorry for my lack of knowledge on these things, but I have no idea of the fundamentals of programming, something I'm still trying to find the time to learn!

Re: Executing two commands via Nested Menu

Posted: 21 Apr 2023 21:21
by highend
What? We are talking about something that is displayed via popupmenu / popupnested?
Why on earth should it work to post such a single line into the try script box then?

Read the help file about those two commands, they have a separator argument or how do you think should any of these commands know what is the caption, data, icon or state if the default separator is ";" and you'd separate multiple script commands via ";"?

And if this is about popupmenu / popupnested you have to load the result as a script resource type. As always the help file knows how^^

Re: Executing two commands via Nested Menu

Posted: 21 Apr 2023 21:33
by sl23
highend wrote: 21 Apr 2023 21:21 What? We are talking about something that is displayed via popupmenu / popupnested?
Why on earth should it work to post such a single line into the try script box then?
:lol: Isn't it obvious? Clearly, I don't have a clue what I'm doing!

Re: Executing two commands via Nested Menu

Posted: 21 Apr 2023 23:00
by sl23
Ok, this is where I'm getting really lost! I don't get it at all. The reason is that there are so many different ways of writing scripts depending where and how they are used, but the manual doesn't say how examples are to be used.

What do I mean? Well, I'll try to explain, please bare with me...

So, I have a nested menu, laid out like this one from the manual:

Code: Select all

     $menu = <<<MENU
               Top;;:paper;1
                 Sub;;;4
                 Sub
                   Sub2;;*.ini
                   Sub2
                   Sub2;;;2
               Top;;<xy>
             MENU;
       text popupnested($menu);
Where is the separator or multiple commands on a single line? All examples are like this, showing only the one command per action. ie, one command per mouse click. I can set a menu item to open a new tab OR I can set it to open the Script folder, but to do both? I really can't see the answer here.

In the first examples for popupmenu, it uses a "|" to mark the next option, but this isn't what you called "multiple script commands." It's dividing menu entries up into single commands. I have been through the manual several times looking at all popupmenu type scripting, and I don't see anywhere where it explains how to use more than one command in a single entry of the menu, such as the one I'm asking about. I have tried separating them with | , ; placing inside different brackets, adding/removing a space in various places I just don't see where I need to look to find what I need in the manual. It's so vast and I'm looking for a needle! :shock:

I realise in your eyes this must seem really dumb, but when you don't know, you just don't know.

Also, does it matter how I 'phrase' the syntax? Sorry, I don't know the correct terminology to explain, so an example:
Putting aside the script is incorrect and not working does it make any difference if I use this: tab("new", "<xyscripts>") or this: #340, #757?

Anyway, I checked popupmenu(), again, and there's nothing in there that uses "multiple script commands," the only reference I can find is: sep_itemlist. But searching for this in the manual returns nothing and it doesn't appear in the Index. So what is it? What does tthis mean? I tried using that character "|" many times before opening this topic, as it didn't help. So I don't understand what you're trying to tell me. Like in the last paragraph, do I use the pipe character as a separator in the tab() script or in the CID script? or can I use either?

I understand you are actually trying to help by giving me breadcrumbs rather than spoon feeding, it's just that I'm not a coder and I really am trying to understand and find a solution, but I just don't see what you're getting at. Could I have a little more of an idea how this works please? My main problem is that I don't know the syntax to start with, like which of the two examples I gave do I need to use. If I had the right starting point, that would be a help. :)

Also, I have no idea what you mean by this:
And if this is about popupmenu / popupnested you have to load the result as a script resource type.
I use the nested menu via a toolbar button, it calls a script saved in the Script Folder. Is that what you're referring to?

Sorry for the long post, I'm just trying to explain in detail, and I do apologise if I seem a bit I come across the wrong way, I have suffered with severe insomnia for 4 years now and it can make me a bit short tempered, mainly with myself, so please don't take it personally! I do appreciate you taking the time to help out. :tup:

Re: Executing two commands via Nested Menu

Posted: 21 Apr 2023 23:29
by sl23
What is also confusing the hell out of me, is that this works perfectly: XY Script Folder|#340; #757;|*.<DIR>
It shows the caption and icon in the menu, and it works exactly how I want it to. My problem is that I don't want XY shortcuts in my favourite folders/bookmarks menu. Yes I could use this, but I'm trying to understand why it works in one menu, but not the other. They are identical, other than the entries of course, except the Bookmarks menu has this at the end:

Code: Select all

            MENU;
       $sel = popupnested($menu, 7:="|");
       if ($sel) { load $sel, , "s"; }
Whereas the MainMenu that I have set up to show a cut down selection of XY tools, simply ends with:

Code: Select all

            MENU;
       popupnested($menu);
Now, looking at the above code, the working script at the top of this post, I'm trying to come across completely neutral here, just in case you think I'm trying to slate the manual, I'm not. I'm only trying to say that it doesn't make any logical sense. Not to me at least. :oops:

In the manual, it says this: (Caption;Data;Icon;State)
Yet the first command is a part of the Caption as it comes BEFORE the first colon that separates Caption from Data, so it currently works like this: (Caption|Data;Data;Icon;State). Data is where the Command normally goes to perform an action. So why is the "New Tab" command appearing in the Caption part of the syntax? I just don't see the logic behind that?! In my mind it should be (Caption;Data|Data;Icon;State). So that the Caption is shown, after which the two data functions are performed in serial upon actioning a mouse click.

Re: Executing two commands via Nested Menu

Posted: 22 Apr 2023 00:01
by highend
I don't have time to write an essay, sorry.

If your script commands inside a menu require e.g. the "|" character, you'd need to choose a different separator in the popupmenu() command (e.g. 7:="<:>")
which would result e.g. in:

Code: Select all

Show quicksearch result<:>text quicksearch("/f", "<curpath>", "|");<:>*.<DIR>

Code: Select all

    $menu = <<<>>>
A single command id, automatically executed when selected|#340;|*.<DIR>
Multiple command ids, must be interpreted as a script|#340; #757;|*.<DIR>
Single script command, must be interpreted as a script|tab("new", "<xyscripts>");|*.<DIR>
Multiple script commands, must be interpreted as a script|$path = "<xyscripts>"; tab("new", $path);|*.<DIR>
    >>>;
    $sel = popupmenu($menu, 6:=<crlf>, 7:="|");
    if ($sel) {
        // Only load $sel if it isn't a single command id!
        if (!regexmatches($sel, "^#\d+?;?$")) {
            load $sel, , "s";
        }
    }

Re: Executing two commands via Nested Menu

Posted: 22 Apr 2023 08:47
by sl23
I understand. Thank you for your time.

I sorta guessed it was something to do with that from the start with one menu working and the other not. But it's good to get clarification, that helps.

Btw highend, sorry we got off on the wrong foot, that was around the time my insomnia started and it was really hard then.