Page 1 of 1

Refer to custom button using its name instead of its index

Posted: 05 Jul 2019 10:21
by John_C
I have three custom buttons on the toolbar to switch between "Details", "Small Icons" and "Thumbnails #1" views.

Button 1 code:

Code: Select all

"Toggle Details View"
    $mode = get("view");
    if ($mode != 0) {
        #302;
        ctbstate(1);
        ctbstate(0, 2); // Turns off the "Small Icons" button.
        ctbstate(0, 3); // Turns off the "Thumbnails #1" button.
    }
Button 2 code:

Code: Select all

"Toggle Small Icons View"
    $mode = get("view");
    if ($mode != 3) {
        #305;
        ctbstate(1);
        ctbstate(0, 1); // Turns off the "Details" button.
        ctbstate(0, 3); // Turns off the "Thumbnails #1" button.
    }
Button 3 code:

Code: Select all

"Toggle Thumbnails #1 View"
    $mode = get("view");
    if ($mode != 4) {
        #306;
        ctbstate(1);
        ctbstate(0, 1); // Turns off the "Details" button.
        ctbstate(0, 2); // Turns off the "Small Icons" button.
    }
It works, but I don't like that buttons are referring each other using their index (for obvious reasons). I have tried to use ctbname(), but it seems it doesn't intended for such referring. Have I missed something? Does ctbname() work for this task? Or is it exist another way?

Re: Refer to custom button using its name instead of its index

Posted: 05 Jul 2019 10:56
by highend
Write two helper functions,

Code: Select all

GetRealButtonNames()
ToggleButtonState($state, $buttonName)
where GetRealButtonNames()
get's all toolbar icons with toolbar()
and fills a string with button names, depending on if the button has a name
beginning with ctb and the number behind is the id that you query with ctbname()

ToggleButtonState($state, $buttonName)
should be self explanatory after this...

Re: Refer to custom button using its name instead of its index

Posted: 05 Jul 2019 11:01
by John_C
@highend Thanks, I will try to write it and then I will post it here for other users.