To "move" check mark from one menu item to another [Solved]

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
John_C
Posts: 336
Joined: 16 May 2018 20:04

To "move" check mark from one menu item to another [Solved]

Post 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.
Last edited by John_C on 04 Apr 2022 23:03, edited 3 times in total.

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

Re: To "move" check mark from one menu item to another

Post by highend »

That's not possible. You need to use popupmenu() for such functionality instead.
One of my scripts helped you out? Please donate via Paypal

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

Re: To "move" check mark from one menu item to another

Post 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?

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

Re: To "move" check mark from one menu item to another

Post 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)...
One of my scripts helped you out? Please donate via Paypal

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

Re: To "move" check mark from one menu item to another

Post by John_C »

I know about the state bit fields. But could you show which line should be changed or added?

Filehero
Posts: 2734
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: To "move" check mark from one menu item to another

Post 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().
Last edited by Filehero on 01 Apr 2022 22:01, edited 1 time in total.

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

Re: To "move" check mark from one menu item to another

Post 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);
    }
One of my scripts helped you out? Please donate via Paypal

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

Re: To "move" check mark from one menu item to another

Post 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);
  }
Last edited by John_C on 02 Apr 2022 10:24, edited 2 times in total.

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

Re: To "move" check mark from one menu item to another

Post 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:="|");

Norn
Posts: 522
Joined: 24 Oct 2021 16:10

Re: To "move" check mark from one menu item to another

Post by Norn »

$menu .= $item . "|" . $item . "||" . $state . <crlf>;
Test it and you'll know...
$sel = popupmenu($menu<crlf>$a|$b, 6:=<crlf>, 7:="|"); text $sel
Windows 11 24H2 @100% 2560x1440

Post Reply