Page 1 of 2

Dynamic icon in CTB context menu caption with alias not working

Posted: 23 Oct 2021 01:13
by autocart
Hi Don,
I want to file this as a bug and hope that you agree.
Paste the CTB snippet into a CTB.
The right click context menu should show an icon on the left side of the first entry, but it only shows a "?" icon.

That the aliases are recognized, you can see, e.g., if you delete the pipe character. Besides, the normal text of the caption is dynamic. This part works well. So, the icon should work too, right? But doesn't.
I also tried putting the pipe and colon both into the caption directly or both into the alias. Or the whole string into one alias instead of two. Nothing makes the icon show up.

If I type ":dark" or ":sync" into the first line of "ScriptR" after the pipe directly, then it works: The icon is displayed.

Code: Select all

Snip: CTB 1
  XYplorer 22.30.0204, 23.10.2021 01:00:18
Action
  NewUserButton
Name
  
Icon
  
ScriptL
  
ScriptR
  "<@autocart_label_ToggleLocationCEAs>|<@autocart_label_ToggleLocationCEAs_Icon>"
   if (tweak("SkipBrowseEvents") == 1) {
    tweak("SkipBrowseEvents", 0);
   } else {
    tweak("SkipBrowseEvents", 1);
   }
  "_Initialize"
   if (tweak("SkipBrowseEvents")==1) {
    goto "@autocart_label_ToggleLocationCEAs=[Location CEAs are OFF]: Activate";
    goto "@autocart_label_ToggleLocationCEAs_Icon=:dark";
   } else {
    goto "@autocart_label_ToggleLocationCEAs=[Location CEAs are ON]: Deactivate";
    goto "@autocart_label_ToggleLocationCEAs_Icon=:sync";
   }
FireClick
  0

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 23 Oct 2021 13:08
by admin
Sorry, no time to walk through this. Try to narrow it down.

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 23 Oct 2021 13:23
by autocart
I can try to shorten the description of the problem. (The problem itself is super narrow already.)

Problem deals with:
Icon in caption of a CTB context / pop-up menu

Working example:
See here: viewtopic.php?p=192020#p192020

What I want to do:
Make the icon dynamic by replacing the static icon description, e.g. ":dark" after the pipe ("|") with an alias variable, like "<@iconname>".

Problem:
Although it does work, to make the normal caption text dynamic with an alias variable, it does not work to do so for the icon part. Even though the alias is resolved to the same string as if I had typed it without an alias, XY refuses to turn it into an icon. Instead, XY either draws a "?" icon, a grey icon, or no icon at all, depending on the exact implementation of the alias in the caption string.

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 24 Oct 2021 19:11
by admin
Hm. Give me the complete steps including the alias definitions.

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 24 Oct 2021 19:26
by autocart
Ähmm, may I please say: If you would read the first post...
Its all there in the CTB snippet.
If you want to try it out, just make a new CTB and paste the snippet.

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 24 Oct 2021 19:36
by admin
Whoops :whistle:

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 24 Oct 2021 19:44
by admin
Next beta will show your dynamic icons.

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 24 Oct 2021 19:51
by autocart
Thank you very much!

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 25 Oct 2021 12:59
by autocart
Thanks, but not perfect yet:
The context menu needs to be called two times, as it seems, before the icon gets updated.
The first time, ofc, that icon toggling entry must not be selected but the context menu discareded.

If I use that context menu in a "normal" way and right click each time only one time and select that entry immedeately, then the icon does update always one click too late, resulting in an exactly reversed icon toggle -> When it should show "off" it shows "on" and vice versa.

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 25 Oct 2021 14:26
by admin
In the next beta it will work if you put the "_Initialize" before the other code:

Code: Select all

"_Initialize"
 if (tweak("SkipBrowseEvents")==1) {
  goto "@autocart_label_ToggleLocationCEAs=[Location CEAs are OFF]: Activate";
  goto "@autocart_label_ToggleLocationCEAs_Icon=:dark";
 } else {
  goto "@autocart_label_ToggleLocationCEAs=[Location CEAs are ON]: Deactivate";
  goto "@autocart_label_ToggleLocationCEAs_Icon=:sync";
 }
"<@autocart_label_ToggleLocationCEAs>|<@autocart_label_ToggleLocationCEAs_Icon>"
 if (tweak("SkipBrowseEvents") == 1) {
  tweak("SkipBrowseEvents", 0);
 } else {
  tweak("SkipBrowseEvents", 1);
 }

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 25 Oct 2021 14:31
by autocart
:tup: Looking forward, thank you for your support!

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 25 Oct 2021 14:33
by klownboy
I tried to do exactly the same using perm variable and got the same result as using aliases. The icon will work but it's not the latest permed value in the script. Try this on script to check either in a CTB or simply running the script. Perms were made to work in a script title as shown quite awhile ago. but not in this case. The perm icon set in "_Initialize" is not the updated one which should be used in the title line.

Code: Select all

"_Initialize"; //step;
  //unset $autocart_label_ToggleLocationCEAs, $autocart_label_ToggleLocationCEAs_Icon;
  if (tweak("SkipBrowseEvents")=="1") {
   perm $autocart_label_ToggleLocationCEAs="[Location CEAs are OFF]: Activate";
   perm $autocart_label_ToggleLocationCEAs_Icon=":" . "exitnosave";  // tried this as well  ":exitnosave";
    } else {
    perm $autocart_label_ToggleLocationCEAs="[Location CEAs are ON]: Deactivate";
    perm $autocart_label_ToggleLocationCEAs_Icon=":" . "select"; 
   }
   writePV;

"Of mice and Men|:cfi"
  status "Hello Lenni";
  end 1;

"$autocart_label_ToggleLocationCEAs|$autocart_label_ToggleLocationCEAs_Icon";
   if (tweak("SkipBrowseEvents") == "1") {
    tweak("SkipBrowseEvents", "0");
   } else {
    tweak("SkipBrowseEvents", "1");
   }
  end 1;
   unset $autocart_label_ToggleLocationCEAs, $autocart_label_ToggleLocationCEAs_Icon;
EDIT: Don, I just noticed your last entry about putting "_Initialize" before other code. So that in theory should make the above "perm" (vs alias) version work as well. Correct?

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 25 Oct 2021 15:08
by admin
You will tell me... :)

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 25 Oct 2021 15:29
by klownboy
admin wrote: ↑25 Oct 2021 15:08 You will tell me...
Unfortunately that script I posted above using perm variables still doesn't work with beta v22.30.0210. The perm icon is not updated to the new value in "_Initialize". The title itself, variable $autocart_label_ToggleLocationCEAs is updated, but the icon $autocart_label_ToggleLocationCEAs_Icon is not. So it appears what's on the right side of the "|" is not updated.

Re: Dynamic icon in CTB context menu caption with alias not working

Posted: 25 Oct 2021 15:31
by autocart
klownboy wrote: ↑25 Oct 2021 15:29
admin wrote: ↑25 Oct 2021 15:08 You will tell me...
Unfortunately that script I posted above using perm variables still doesn't work with beta v22.30.0210. The perm icon is not updated to the new value in "_Initialize". The title itself, variable $autocart_label_ToggleLocationCEAs is updated, but the icon $autocart_label_ToggleLocationCEAs_Icon is not. So it appears what's on the right side of the "|" is not updated.
Yes, Don wrote his announcement after 0210.