Help with creating a context menu [Solved]

Discuss and share scripts and script files...
Post Reply
John_C
Posts: 336
Joined: 16 May 2018 20:04

Help with creating a context menu [Solved]

Post by John_C »

This is a script for a custom "Right-Click on White in File List" menu.

Code: Select all

"Right-Click on White in File List"
  $newFlags = "ru";
  $cntIndent = 6;

  $newItems = "";
  $folders = listfolder("<xydata>\NewItems",, 2);
  $files = listfolder("<xydata>\NewItems",, 1);

  foreach($item, $folders . "|" . $files,, "e") {
    $caption = gpc($item, "file");
    $captionTrimmed = regexreplace($caption, "^New ", "");
    $data = 'new("' . $caption . '"' . ((exists($item) == 2) ? ', "dir"' : ", ") . ",'" . $item . "'," . (($newFlags) ? ' "' . $newFlags . '")' : ")");
    $icon = $item;
    $newItems .= strrepeat(" ", $cntIndent) . $captionTrimmed . ";" . $data . ";" . $icon . <crlf>;
  }
  $menu =
  <<<MENU
    New Folder;#231
    New Text File;#234
    -
    Refresh;#1001
    -
    Paste;#202
    -
    New
$newItems
  MENU;
  $selected = popupnested($menu);
  if (strpos($selected, "#") != -1) { eval("""$selected"""); }
  else { eval($selected); }
The items in the NewItems folder are assumed to be named as follows: New Markdown File, New InDesign File, and so on.

Is it possible to have the items from the NewItems folder as a part of the main pop-up menu? Like this:

Code: Select all

New Folder
New Text File
New Markdown File
New InDesign File
-----------
Refresh
-----------
Paste
I tried to replace popupnested() with popupmenu(), but then separators (that is, horizontal gray lines) were replaced to hyphens (each line to one hyphen). So it was something wrong...
Last edited by John_C on 22 Mar 2022 15:59, edited 1 time in total.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Help with creating a context menu

Post by highend »

Code: Select all

"Right-Click on White in File List"
  $newFlags = "ru";
  $cntIndent = 4;

  $newItems = "";
  $folders  = listfolder("<xydata>\NewItems",, 2);
  $files    = listfolder("<xydata>\NewItems",, 1);

  foreach($item, $folders . "|" . $files,, "e") {
    $caption = gpc($item, "file");
    if ($caption LikeI "New") { continue; }
    $data      = 'new("' . $caption . '"' . ((exists($item) == 2) ? ', "dir"' : ", ") . ",'" . $item . "'," . (($newFlags) ? ' "' . $newFlags . '")' : ")");
    $icon      = $item;
    $newItems .= strrepeat(" ", $cntIndent) . $caption . ";" . $data . ";" . $icon . <crlf>;
  }

  $menu =
  <<<MENU
    New Folder;#231
    New Text File;#234
$newItems
    -
    Refresh;#1001
    -
    Paste;#202
  MENU;

  $selected = popupnested($menu);
  if (strpos($selected, "#") != -1) { eval("""$selected"""); }
  else                              { eval($selected);       }
One of my scripts helped you out? Please donate via Paypal

John_C
Posts: 336
Joined: 16 May 2018 20:04

Re: Help with creating a context menu

Post by John_C »

Thanks. I see you still use popupnested(), even though the menu is not really nested now. Is it by intent, a necessary workaround?

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Help with creating a context menu [Solved]

Post by highend »

You are free to use popupmenu() if you remove all indentation (and the scripting part of it^^)
One of my scripts helped you out? Please donate via Paypal

Post Reply