Page 1 of 3
Pseudo Icon states
Posted: 19 May 2013 04:46
by serendipity
With latest beta v12.40.0203, the code simplifies to this:
Example: Manual sort ON/OFF state:
1) Add a custom user button to toolbar.
2) Then paste the below code in the on-click field.
You'll ofcourse need the icons from the zip file to be placed in xyicons folder for this to work.
Code: Select all
// Manual Sort toggle
if (ctbicon() == "hand.ico") {
ctbicon("drag-green.ico");
#414;//Toggle Manual Sort
} else {
ctbicon("hand.ico");
#414;//Toggle Manual Sort
}
Until we have real icons states here is a workaround with pseudo icon state for those who like some visual feedback.
Basically all I am doing is renaming the icons and refreshing them which gives the icon toggle effect.
Example: Manual sort ON/OFF state:
1) Add a custom user button to toolbar and set the icon as <xyicons>\hand.ico.
2) Then paste the below code in the on-click field.
Note that I have my OFF icon state as "hand" and ON icon state "drag-green". If you rename your icons to something else, make sure you change that in the first 2 lines below.
[code]
//Toggle Manual Sort
$icon1="hand";
$icon2="drag-green";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
#502;//Refresh Icons
#414;//Toggle Manual Sort
[/code]
Edit: SC swapnames would have been perfect, but for that I have to preselect filenames.
Manual Sort.png
ManualSortIcons.zip
Re: Pseudo Icon states
Posted: 19 May 2013 04:58
by serendipity
And this simplifies to:
Code: Select all
// Minitree toggle
if (ctbicon() == "tree1.ico" AND get(#489)==0) {
ctbicon("tree2.ico");
button "minitree";//Toggle Manual Sort
} else {
ctbicon("tree1.ico");
button "minitree";//Toggle Manual Sort
}
Note: added get command in line "if" condition to retrieve minitree state.
One more example with Mini tree OFF/ON:
[code]
//Toggle Mini tree icon
$icon1="tree1";
$icon2="tree2";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
#502;//Refresh Icons
button "minitree";
[/code]Modified icons from Fatcow.
ToggleMiniTree.png
MiniTree.zip
Re: Pseudo Icon states
Posted: 19 May 2013 05:49
by serendipity
And this ofcourse provided by Don, works great:
Code: Select all
// cloud cycle
$n = substr(ctbicon(), 1, 1);
$n++;
if ($n == 5) {
$n = 1;
}
ctbicon("c$n.ico");
One last post, this is a proof-of-concept to show that you can toggle more than two icon states in the toolbar.
Below code toggles between 4 different cloud states continuously 3 times. Its pretty useless, but it's to show how to toggle between 4 icons.
To make it work, unzip the zipped icons in xyicons folder and create a new user button with below code and have the icon set to <xyicons>\c1.ico, you'll see 4 cloud states toggle 3 times when you click the button.
[code]
//Toggle 4 cloud icons
$total=3;//Number of times to cycle the 4 icons
$count=0;
WHILE($count != $total){
$icon1="c1";
$icon2="c2";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
#502;//Refresh Icons
wait(100);
$icon1="c1";
$icon2="c3";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
#502;//Refresh Icons
wait(100);
$icon1="c1";
$icon2="c4";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
#502;//Refresh Icons
wait(100);
$icon1="c1";
$icon2="c2";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
#502;//Refresh Icons
wait(100);
$icon1="c2";
$icon2="c3";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
$icon1="c3";
$icon2="c4";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
$count++;
}
[/code]
CloudStates.png
CloudStates.zip
Re: Pseudo Icon states
Posted: 19 May 2013 08:38
by admin
Wow, what a dirty work.

That's near-hacking.
Re: Pseudo Icon states
Posted: 19 May 2013 15:46
by klownboy
Hi serendipity,
Very nice idea. I'll surely be killing some time with this technique!
I know it's not as meaning full as changing the icon based on the state or condition as in mini-tree, but it looks like using your technique, we can cycle an icon(s) back and forth when you're starting a program. I did that experimenting and it works fine, but it changes the icon on the CTB obviously back and forth with each run of the program.
Let's say as an example, we want to open a program like "CCleaner" and want the CTB icon assigned to change to different CCleaner version icon before opening CCleaner, but we want the icon on the CTB to revert back to the original icon assigned (in the "icon" assignment block) once the CCleaner program starts or after it's done. Before I would simply use the open command to start CCleaner, but to get the icon state to revert back to what it was previously (i.e., the one in the "icon" assignment block), I had to resort to using the "run" command with the wait state "2". Using run with the wait state though has it's drawbacks. See the example below:
Code: Select all
$icon1="ccleaner01";
$icon2="ccleaner02";
$fakename="fakeicon";
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
#502; //Refresh Icons
run """D:\Tools\CCleaner\CCleaner64.exe""", ,2;
renameitem ("$fakename", "<xyicons>\$icon2.ico");
renameitem ("$icon2", "<xyicons>\$icon1.ico");
renameitem ("$icon1", "<xyicons>\$fakename.ico");
#502; //Refresh Icons
My question is, would there be a easy way of accomplishing this without resorting to a run command?
Thanks for sharing this nice new technique,
Ken
Re: Pseudo Icon states
Posted: 19 May 2013 16:37
by admin
How about making this a bit less dirty by adding a script command to set the CTB icon?
Re: Pseudo Icon states
Posted: 19 May 2013 16:59
by klownboy
Don, that's sounds like a great idea. So we could then change the CTB's icon at will within a script. Would we call out the CTB number in some manner and an icon? Would the new script command be able to change the icon of any CTB or just the icon of the "current" CTB script? In my example above, would I still have to use the "run" command with a wait state "2" to change the icon back to what it originally was?
Thanks Don and thanks serendipity for the nifty idea,
Ken
Re: Pseudo Icon states
Posted: 19 May 2013 17:20
by admin
Yes, my idea was CTB number and icon. Later tonight I'll think deeper about it.
Re: Pseudo Icon states
Posted: 19 May 2013 17:59
by serendipity
admin wrote:How about making this a bit less dirty by adding a script command to set the CTB icon?
Well, hence my request
the other day to enhance toolbar SC.
I did not want to disturb your hype-focused
beta waves.

Re: Pseudo Icon states
Posted: 19 May 2013 18:13
by admin
serendipity wrote:admin wrote:How about making this a bit less dirty by adding a script command to set the CTB icon?
Well, hence my request
the other day to enhance toolbar SC.
I did not want to disturb your hype-focused
beta waves.


I feel a bit sorry for your ingenious filename swap idea, but it will soon be obsolete...

Re: Pseudo Icon states
Posted: 19 May 2013 18:23
by serendipity
admin wrote:serendipity wrote:admin wrote:How about making this a bit less dirty by adding a script command to set the CTB icon?
Well, hence my request
the other day to enhance toolbar SC.
I did not want to disturb your hype-focused
beta waves.


I feel a bit sorry for your ingenious filename swap idea, but it will soon be obsolete...


Re: Pseudo Icon states
Posted: 19 May 2013 20:02
by admin
Works nicely with your cloud icons.
Code: Select all
// cloud cycle
$n = substr(ctbicon(), 1, 1);
$n++;
if ($n == 5) {
$n = 1;
}
ctbicon("c$n.ico");
Re: Pseudo Icon states
Posted: 19 May 2013 20:04
by serendipity
Re: Pseudo Icon states
Posted: 19 May 2013 20:05
by admin
Is it only me, or is the forum
totally lame currently???

Re: Pseudo Icon states
Posted: 19 May 2013 20:06
by serendipity
admin wrote:Is it only me, or is the forum
totally lame currently???

You mean slow?