Page 1 of 1
To "move" check mark from one menu item to another [Solved]
Posted: 01 Apr 2022 18:00
by John_C
I have a following script for a custom toolbar button to have my own set of column layouts (since the default one is too large for me):
Code: Select all
"Standard||2"
columnlayout("standard", "load");
"Images"
columnlayout("images", "load");
-
"Save Column Layout..."
columnlayout(, "save");
How can toggle their status? That is, when I click "Images", the check mark should move from "Standard" to "Images", and vice versa? The idea is the same as how the menu of the "Views" toolbar button works.
Re: To "move" check mark from one menu item to another
Posted: 01 Apr 2022 18:04
by highend
That's not possible. You need to use popupmenu() for such functionality instead.
Re: To "move" check mark from one menu item to another
Posted: 01 Apr 2022 21:24
by John_C
Code: Select all
$cs = listfolder("<xydata>\Columns", "*.txt", 5);
$cs = replace($cs, ".txt", "");
$c = popupmenu($cs);
if ($c) {
columnlayout($c);
}
But how to tell the script to toggle check marks?
Re: To "move" check mark from one menu item to another
Posted: 01 Apr 2022 21:32
by highend
By reading the help for
popupmenu()?
State: (bit field)
1 = default (bold)
2 = checked
4 = disabled
and ofc you need to save the state of the last clicked item (e.g. in an .ini file or in a permanent variable)...
Re: To "move" check mark from one menu item to another
Posted: 01 Apr 2022 21:42
by John_C
I know about the state bit fields. But could you show which line should be changed or added?
Re: To "move" check mark from one menu item to another
Posted: 01 Apr 2022 22:01
by Filehero
It's the $cs variable (better: the fact, it is only consisting of captions - every list item can provide more parameters including the state parameter).
You need to iterate over every single entry of the listfolder() return value list (best is to build a new list aka variable for debugging purposes), set the bit fields (and other parameters of popupmenu() if needed) accordingly. When done pass this list to popupmenu().
Re: To "move" check mark from one menu item to another
Posted: 01 Apr 2022 22:01
by highend
Code: Select all
perm $P_ColumLayoutDefault;
$columns = listfolder("<xydata>\Columns", "*.txt", 1+4, <crlf>);
$columns = replace($columns, ".txt");
$menu = "";
foreach($item, $columns, <crlf>, "e") {
$state = 0;
if ($P_ColumLayoutDefault LikeI $item) { $state = 2; }
$menu .= $item . "|" . $item . "||" . $state . <crlf>;
}
$sel = popupmenu($menu, 6:=<crlf>, 7:="|");
if ($sel) {
$P_ColumLayoutDefault = $sel;
columnlayout($sel);
}
Re: To "move" check mark from one menu item to another
Posted: 01 Apr 2022 23:13
by John_C
Thanks a lot, highend. Thanks Filehero for explanations.
An updated version. There is also "Save Column Layout As..." option and you can customize the order of layouts by prefixing their filenames with a number (e.g. 1 Standard.txt, 2 Images.txt)
Code: Select all
perm $P_ColumLayoutDefault;
$columns = listfolder("<xydata>\Columns", "*.txt", 1+4, <crlf>);
$columns = replace($columns, ".txt");
$menu = "";
foreach($item, $columns, <crlf>, "e") {
$state = 0;
if ($P_ColumLayoutDefault LikeI $item) { $state = 2; }
$itemnonumber = regexreplace($item, "^\d+\s");
$menu .= $itemnonumber . "|" . $item . "||" . $state . "<crlf>";
}
$menu .= "-<crlf>#376";
$sel = popupmenu("$menu", 6:=<crlf>, 7:="|");
if ($sel && $sel != "#376") {
$P_ColumLayoutDefault = $sel;
columnlayout($sel);
}
Re: To "move" check mark from one menu item to another
Posted: 02 Apr 2022 10:23
by John_C
highend, could you you explain why it is necessary to use 6 and 7 here:
Code: Select all
$sel = popupmenu($menu, 6:=<crlf>, 7:="|");
Re: To "move" check mark from one menu item to another
Posted: 02 Apr 2022 17:23
by Norn
$menu .= $item . "|" . $item . "||" . $state . <crlf>;
Test it and you'll know...
$sel = popupmenu($menu<crlf>$a|$b, 6:=<crlf>, 7:="|"); text $sel