Code: Select all
v10.50.0007 - 2011-11-02 19:40
+ Scripting got a new function.
Name: PopupMenu
Action: Pops a menu and returns the selected item.
Syntax: popupmenu(itemlist, [x=-1], [y=-1], [start=1], [count=-1], [flags=0], [sep_itemlist="|"], [sep_item=";"], [on_cancel=""])
itemlist: List of items separated by sep_itemlist.
Each item is made of a Caption and optionally a Data part, separated by sep_item: "Caption;Data"
x: X position; -1 to use current mouse X.
y: Y position; -1 to use current mouse Y.
start: Index of first item to show; 1 = first item.
count: Count of items to show; -1 = show all.
flags: 1: Return index (instead of caption/data).
sep_itemlist: Separates items; can have more than one char.
sep_item: Separates caption from data; can have more than one char.
on_cancel: String returned when menu is cancelled (ESC).
return: Data of selected item; caption if no data defined; index if flags AND 1.
Examples:
text popupmenu("a|-|b|c"); //- is a menu separator
text popupmenu("a;data returned on a|-|b;data b|c;data c");
text popupmenu(<get selecteditemspathnames |>);
Test
Code: Select all
$a = "Execute with option x Xy XXyy";
$b = "Execute with option K VbDFccs";
$c = "Execute with option G BjfdUpa";
//popupmenu(itemlist, x, y, start, count, flags, sep_itemlist, sep_item, [on_cancel=""])
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,1,,,"nix");
msg "You have chosen item no: $r";
if ($r==3){msg "OK, executing sub A.";}
if ($r==4){msg "You want sub B? OK.";}
if ($r==5){msg "...exec sub C.";}
if ("$r"=="nix"){msg "nothing chosen. ESC pressed or wrong clicked.";}
Problem:
on_cancel: pressing ESC-key while the dialog is visible result in nothing: // "You have chosen item no: "
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,1
,,,"nix");
And so this are not executed too:
if ("$r"==
"nix"){msg "nothing chosen. ESC pressed.";}
if (
$r=="nix"){msg "nothing chosen. ESC pressed.";}
Or:
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,1
,,,0);
if
($r==0){msg "nothing chosen. ESC pressed.";}
Only this works:
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,
1,,,"");
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,
,,1,,);
if
($r==""){msg "nothing choosen. ESC pressed.";}
Idea:
- missing center option for X and Y: x="", y="" ==> center dialog.
Currently x="", y="" is the same as x=-1, y=-1