Page 1 of 1

Help with creating a context menu [Solved]

Posted: 22 Mar 2022 15:09
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...

Re: Help with creating a context menu

Posted: 22 Mar 2022 15:24
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);       }

Re: Help with creating a context menu

Posted: 22 Mar 2022 15:58
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?

Re: Help with creating a context menu [Solved]

Posted: 22 Mar 2022 16:42
by highend
You are free to use popupmenu() if you remove all indentation (and the scripting part of it^^)