popupmenu - Add nested submenus

Discuss and share scripts and script files...
Post Reply
Japistos
Posts: 2
Joined: 11 Nov 2019 13:08

popupmenu - Add nested submenus

Post by Japistos » 11 Nov 2019 13:24

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.

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

Re: Foreach into popupmenu

Post by highend » 11 Nov 2019 19:24

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"; }
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

klownboy
Posts: 2828
Joined: 28 Feb 2012 19:27

Re: Foreach into popupmenu

Post by klownboy » 03 Dec 2019 18:02

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.

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

Re: popupmenu - Add nested submenus

Post by highend » 03 Dec 2019 18:40

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...
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

Japistos
Posts: 2
Joined: 11 Nov 2019 13:08

Re: popupmenu - Add nested submenus

Post by Japistos » 03 Dec 2019 22:56

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.

klownboy
Posts: 2828
Joined: 28 Feb 2012 19:27

Re: popupmenu - Add nested submenus

Post by klownboy » 04 Dec 2019 01:47

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.

Post Reply