Page 1 of 1

popupmenu - Add nested submenus

Posted: 11 Nov 2019 13:24
by Japistos
Hi Guys, first post here.
Thank you for the amazing forums and software.

I'm really new to scripting, as you'll see by my question.

I want a popupmenu that has a top level and then sub levels that get populated by the script iterating through a folder and returning all the subfolders as menus. Then within that sub menu is a copyto command using that same token.

I've tried hacking together copy pasted bits that I can find from the help menu and from here, but my knowledge of the syntax isn't enough.

I'm not sure how to use the popupmenu and foreach loops together.

Thanks in advance.

Re: Foreach into popupmenu

Posted: 11 Nov 2019 19:24
by highend
A while loop makes more sense here to check if an entry has submenus or not...

Code: Select all

    $iconFolder  = ":showfolders";
    $iconCommand = ":copyto";

    $selectedItems = <get SelectedItemsPathNames |>;
    end (!$selectedItems), "No item(s) selected, aborted!";

    $folders = quicksearch("/d /excl=$RECYCLE.BIN;System Volume Information", , , "s");
    $folders = replace($folders, "<curpath>\");

    $menu       = "";
    $indent     = <space 4>;
    $lastFolder = "";

    while ($folders) {
        $folder    = gettoken($folders, 1, <crlf>);
        $folders   = gettoken($folders, 2, <crlf>, , 2);
        $cntIndent = gettoken($folder, "count", "\") - 1;

        if ($folder != $lastFolder) {
            $indentation = strrepeat($indent, $cntIndent);
            $caption     = gpc($folder, "component", -1);
            $menu       .= <crlf> . $indentation . "$caption<:><:>$iconFolder";

        if (strpos($folders, $folder) != 0) {
            $indentation = strrepeat($indent, $cntIndent + 1);
            $data  = "copyto " . quote("<curpath>\$folder") . ", " . quote($selectedItems) . ", , 2, 2;";
            $menu .= <crlf> . $indentation . "Copy <selected items> here...<:>$data<:>$iconCommand";
        $lastFolder = $folder;
    $selection = popupnested($menu, 6:=<crlf>, 7:="<:>");
    if ($selection) { load $selection, , "s"; }

Re: Foreach into popupmenu

Posted: 03 Dec 2019 18:02
by klownboy
Hey highend. You should change the title on this thread so others know what it actually does (e.g., Folder submenu operations or similar). Right now no one would have a clue unless they looked through the thread.

The OP hadn't yet responded so I figured I would. :) The script works nicely. It was easy enough to modify the script to add additional submenus for "Move to" along with the "Copy to" and a couple of fixed folder locations just to provide more flexibility.

Re: popupmenu - Add nested submenus

Posted: 03 Dec 2019 18:40
by highend
Title changed
The OP hadn't yet responded so
Actually he wasn't ever online again. This is more or less an existing user who was (as always) too lazy to achieve something on his own...

Re: popupmenu - Add nested submenus

Posted: 03 Dec 2019 22:56
by Japistos
who was (as always) too lazy to achieve something on his own...
Haha, little harsh?
I agree, I should have said thank you or given feedback a little earlier... but I definitely wasn't too lazy to achieve this on my own.
Truth is, I'm not one to ask to be spoonfed without trying to figure out things on my own first.
Thank you for your reply.
So I got as far as using your code and then getting stuck again and I haven't had time to ask for more help or look at it further.

The example you provided is almost what I need, but I would like it to only go "one level down."
So basically, I point the script to a parent folder, and it just lists the immediate sub folders, not further down than that.
I think I tried to use folder report instead of quicksearch because I couldn't figure out how to limit it to one child level.
Got it to list just the subfolders I wanted, but then got stuck at something else.
Will confirm and provide more info in the morning when it's in front of me.

Thanks for the title name change, better.

Re: popupmenu - Add nested submenus

Posted: 04 Dec 2019 01:47
by klownboy
If you only want to see the immediate subfolders (1 level), change the SC quicksearch line to read as follows:
$folders = quicksearch("/d /maxdepth=0 /excl=$RECYCLE.BIN;System Volume Information", , , "s");
That should do what you want.

Re: popupmenu - Add nested submenus

Posted: 10 Feb 2020 09:43
by Japistos
klownboy, thank you for your response! :beer: