Page 5 of 6

Re: Add sub-menu support for scripts

Posted: 03 Nov 2016 22:09
by yusef88
thanks highend

Re: Add sub-menu support for scripts

Posted: 10 Nov 2016 13:23
by FluxTorpedoe
Hi’
Still wondering how to avoid this, any idea?

 • An extra separator is added to menus for each "_hidden" entry, e.g. (here, one before and two after):

Code: Select all

"_Initialize"
"Top"
"Sub|||1"
  sub "_routine";
"_routine"
  msg 1;
"_otherroutine"
Thanks,
Flux

Re: Add sub-menu support for scripts

Posted: 10 Nov 2016 17:30
by admin
Whoops, that one slipped my attention. Fix comes... :whistle:

Re: Add sub-menu support for scripts

Posted: 10 Nov 2016 17:47
by TheQwerty
admin wrote:Whoops, that one slipped my attention. Fix comes... :whistle:
Similarly take a look at this:

Code: Select all

"_Initialize|||99"
  echo 'hi';
"Top|||0"
  echo 'top';
"Sub|||1"
  sub "_routine";
"_routine|||-1"
  msg 1;
"_otherroutine|||-1"
  msg 2;
I was playing with menu levels in an attempt to remove the separators and while this is successful it breaks things. Selecting Top > Sub results in the following error:
The list of labels did not match any script in Script resource.
sub
_routine

Re: Add sub-menu support for scripts

Posted: 10 Nov 2016 18:57
by admin
Okay, fix comes. (No mention in change log)

Re: Add sub-menu support for scripts

Posted: 14 Nov 2016 18:17
by FluxTorpedoe
Hi’

First of all, thanks a lot for the ultra-fast separator fix! :appl:
Working very well, and it was quite easy to convert previous scripted menus—well, the regular embedded ones.

Now… there’s only one piece missing in the "submenus" feature. :whistle:

———————————————————————————

• Wish:
Have the same "popup >" effect for the parent of submenus created with SC load, e.g.
 "Menu|||>"
    load $Menu, , "s";

This would enable dynamic and externalized menus.

• Case:
I’ve a "System" button which opens a menu, listing:
 – standard entries (e.g. run command line)
 – simple submenus (via |||1),
 – but also full-featured submenus (Archive, Report…)

These are loaded from dedicated script files since they’re quite comprehensive (Archive > Rar: each item| Rar: each subfolders|…|7Zip…|Zip:…; Report > Folders up to 1/2/3 levels|Folders+Files up to…)

So, trying to embed such scripts gets really messy real quick (even if just the headers with a switch).
(I know, I tried… Hence my delay in replying.) :oops:

• Risk:
Longer delay before main menu is displayed (since you’re currently preprocessing it), in case the "load…" is not optimized. But that’s a fair price to pay, IMHO…

Well, an example might be clearer (even if you’ll probably have a better idea of how to implement this).

• Mockup:

Code: Select all

"1. Top|||>"
  load "Menu.xys";

"2. Top|||>"
  load self("file"), "_menu";

"3. Top|||>"
  sub "_menu";

"4. Top|||>"
  $menu = '"Sub"'.<crlf><tab>.'msg 1;'.<crlf>.'"Sub"'.<crlf><tab>.'msg 2;';
  load $menu, , "s";

"_menu"
  $menu = <<<MENU
"Sub"
  msg 1;
"Sub"
  msg 2;
MENU;
  load $menu, , "s";
Thanks, 8)
Flux

Re: Add sub-menu support for scripts

Posted: 15 Nov 2016 12:00
by admin
That's not easy at all.

Here is another idea. I did not try it but what if you'd use the include statement instead of load()?

Re: Add sub-menu support for scripts

Posted: 15 Nov 2016 12:25
by FluxTorpedoe
Well, I guess include could work just fine!

Hmmm—ok, I know I push my luck a lot but—since load/function won’t work here in combination, I seem to remember that you were planning some include, [labels] now, weren’t you? :mrgreen:

Anyway, thanks for the quick feedback! :)

Re: Add sub-menu support for scripts

Posted: 15 Nov 2016 12:30
by admin
FluxTorpedoe wrote:Hmmm—ok, I know I push my luck a lot but—since load/function won’t work here in combination, I seem to remember that you were planning some include, [labels] now, weren’t you?
Oh really, did I? :mrgreen: So that would include just a labeled part of a file or what? Hmmm, that needs rules and stuff. You are really pushing it...

Re: Add sub-menu support for scripts

Posted: 15 Nov 2016 14:48
by FluxTorpedoe
Well, that was probably a dumb as :om: idea, since it would mean much work for you, only to get something pretty similar to load, [labels]… :roll:

———————————————————————————

Now, regarding external scripts, I suppose include could work—you meant something like that?

Code: Select all

"Archive"
  include "Archive.inc"

// Archive.inc content:
"_Initialize"
  ...
"Menu 1"
  ...
"Menu 2"
  ...
But, for dynamic menus, that would quickly become unusable with lots of small inc…

Say, in the case of this simplified example (currently working but without the "popup >"):

Code: Select all

"Show Items"
// ---------<> Show Hidden
  if get("#493") {
    $Menu = <<<#>>>
"Show Hidden Files and Folders||2"
  #493;
#>>>;
  } else {
    $Menu = <<<#>>>
"Show Hidden Files and Folders"
  #493;
#>>>;
  }
// ---------<> Show Protected
    $Menu = $Menu.<<<#>>>
"..."
#>>>;
  load $Menu, , "s";

"..."
Hence the idea of flagging parent menus as a "popable" menus…

Well, not sure if that would make things easier for you, but "parent menus" could just display the extra ">" without pre-processing their submenu, which would only be loaded after the regular mouseover delay.

Re: Add sub-menu support for scripts

Posted: 15 Nov 2016 15:02
by admin
Well, dynamic menus (submenus that are created only on mouseover), that's not supported at all at the moment.

I think you will have to do with Include for a while.

There is this suggestion of relative levels by zhaowu that might come in handy here (and is something I can do with an okay effort): viewtopic.php?p=143536#p143536

Re: Add sub-menu support for scripts

Posted: 15 Nov 2016 20:46
by FluxTorpedoe
admin wrote:Well, dynamic menus (submenus that are created only on mouseover), that's not supported at all at the moment.
I guessed as much. Definitely not important and not really regular anyway (that’s why I was previously talking about "pre-" dynamic menus that would be preloaded along with all other entries, before the main menu is displayed).
admin wrote:There is this suggestion of relative levels by zhaowu that might come in handy here (and is something I can do with an okay effort): viewtopic.php?p=143536#p143536
Hmmm, :oops: I fear I don’t understand the benefits (except readability) if menus can’t be externalized…
Well, except for the new include suggestion (but then a non-relative would work too I suppose). :veryconfused:
admin wrote:I think you will have to do with Include for a while.
Fine by me already, thanks!

But ohhh, now I get it! [Return of the dumb :om: ]
You’re also talking about that time when you mentioned including local resources, as in include $Menu, "s"? :mrgreen: :twisted:

Re: Add sub-menu support for scripts

Posted: 16 Nov 2016 09:37
by admin
If we have a file "IncludedMenu.xys" in the Scripts folder:

Code: Select all

"C:|*||1"
"Go to C:\|||2"
  goto "C:\";
"Select Calculator|||2" goto "%winsysdir%";
  selectitems "calc.exe";
"D:|*||1"
"Go to D:\|||2"
  goto "D:\";
... then in this script:

Code: Select all

"Top A"
include "IncludedMenu.xys";
"Top B"
"Sub B|||1"
include "IncludedMenu.xys";
... only the first include would work as desired. The second include would not create the included menu under "Sub B" but under "Top B". With relative levels this could be handled.

Re: Add sub-menu support for scripts

Posted: 16 Nov 2016 10:15
by FluxTorpedoe
Oh OK, I thought the counter would somehow be reset, thanks for explaining.
So yes, that would make sense for complex external multi-level submenus (as rare as they might be, so probably not a priority…).

But that definitely wouldn’t be as simply useful as an include $Menu now, would it… :twisted:

OK, OK, I stop! :biggrin:

Have a nice day, 8)
Flux

Re: Add sub-menu support for scripts

Posted: 16 Nov 2016 10:19
by admin
I just added it. Works nicely. Here's a preview of the change log:

Code: Select all

    + Scripting: Now multi-script nesting can be defined with relative levels. 
      This can be useful when building menus from local resources by use of the 
      Include statement.
      Syntax: A relative level is marked by a prefixed "+" character. The 
      number following "+" is added to the last defined absolute level.
      For example, the following two code samples create identical nested 
      multi-scripts:
      ------------------------------------------------------------------------
      "A" echo "A";
      "B|||1" echo "B";
      "C|||2" echo "C";
      "D|||1" echo "D";
      "B|||2" echo "B";
      "C|||3" echo "C";
      ------------------------------------------------------------------------
      "A" echo "A";
      "B|||+1" echo "B";
      "C|||+2" echo "C";
      "D|||1" echo "D";
      "B|||+1" echo "B";
      "C|||+2" echo "C";
      ------------------------------------------------------------------------
      However, the second sample uses relative levels which allows it to re-use 
      the same part of code twice:
        "B|||+1" echo "B";
        "C|||+2" echo "C";
      So this part of code could be outsourced to a file say 
      "IncludedMenuBC.xys" and then be included like this:
      ------------------------------------------------------------------------
      "A" echo "A";
      include "IncludedMenuBC.xys"
      "D|||1" echo "D";
      include "IncludedMenuBC.xys"
      ------------------------------------------------------------------------