Expandable drive button

Discuss and share scripts and script files...
eil
Posts: 1609
Joined: 13 Jan 2011 19:44

Re: Expandable drive button

Post by eil »

@klownboy, no worries, settings loss is not due to your script. i was just pointing out that script is not aware of variable may become empty(like in my case). saving to file may be a solution. for the moment i added a check for myself if a $p_toolbar is empty before each toolbar($p_toolbar).
Win 7 SP1 x64 100% 1366x768

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Expandable drive button

Post by klownboy »

New revision 1.02: I decided to make ExpandableCTB a more well-rounded Toolbar Manager. This revision provides a new function which allows the user to generate completely new whole toolbars in addition the existing expanding toolbar function explained in previous posts - see the above gif animation http://www.xyplorer.com/xyfc/viewtopic. ... 75#p113771 Making new toolbars couldn't be easier. The script presents the user with a check-off list of all the XY built-in buttons and all your customized buttons to build new toolbars. All the current toolbar buttons will be pre-checked in the inputselect dialog box. I considered, since it deviates from the original "expanding CTB" to a large degree, preparing a separate new script just for this (it certainly would have been easier), but for now it's incorporated into the expanding CTB script.

- By holding down the control key while normal left clicking the CTB, the toolbar menu shown below will display. Initially it will save your "current" toolbar so only one toolbar will show in the menu. My capture shows a number of toolbars that I can switch between and also shows the additional menu items where the user can quickly generate new toolbars and save the current under a different or same name or delete multiple toolbars. Use the "Build new Toolbar" menu item to generate a completely new toolbar.
Toolbars_menu.JPG
Toolbars_menu.JPG (16.94 KiB) Viewed 3919 times
- See the "How to use " section of the above link in this thread on setup. Essentially you just make a CTB with load("<xyscripts>\ExpandableCTB.xys"); in both the Left and Right click entries and place the included icons in your XY icons folder.

- Besides being able to generate new toolbars, the user can quickly and seamlessly change between different toolbars, save toolbars and delete toolbars. It really doesn't change the expandable CTB portion of the script (i.e., the instructions in previous posts still apply as to establishing the expandable CTBs as well their use).

- The left and right click of the CTB still does the expansion of the CTB with your selected built-in XY buttons or your CTBs.

- A normal click of the CTB with ctrl & shift keys held down will perform the reset of the ExpandableCTB buttons and you can then select new ones.

- Relatively important note: I recommend that any new whole toolbars you build include the the subject CTB so you can easily access the toolbar menu and change to the other toolbars.
ExpandableCTB_v1.02.zip
(28.47 KiB) Downloaded 148 times
Thanks and please let me know if you experience any problems if you try it.
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: Expandable drive button

Post by Filehero »

Hi Ken,

there's something wrong I think.

When adding a new CTB to the very left OR right of the current toolbar (say it's #17), left-clicking the first time always has the same undesired side-effects
- the icon of an existing - and always the same - CTB is changed (the associated script remains unchanged though)
- to the very right of this re-iconed CTB two more icons are inserted/"spawned", with one obviously being a copy of another one, and the 2nd appears always to be the first unused CTB in line.
At least it looks like magic. :wink: :lol:

Let me know how I can help debugging.

Cheers,
Filehero

PS: Thank you for another update! :)

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Expandable drive button

Post by klownboy »

Thanks Filehero for trying it out.

I edited one of my toolbars and placed my ExpandableCTB (in my case CTB 3) a the very end and then reloaded it. You're right something very odd is going on. In my case the icon simply changes back and forth from the "expanded icon assigned to the collapsed icon. It does that with either the left click or right using the proper icons, but there are no expansion icons displayed. So something fluky is going on at the end. I never assigned it to the start or end of the toolbar during my tests.

When I shifted my CTB3 back to a inner position even just one position it behaves as it should. I'll step through the script to see what's happening. Maybe it's something due to the divider, since a divider is placed after the expanded buttons. Does it work for you if the assigned CTB is moved inward? The toolbar text files can be easily edited to move the CTB around or using the Customize TB dialog. It seems to work fine for me at the full left position.

My first step through is indicating the SC 'replace' in line 124 is not working as it does when the assigned CTB is in an inner positon. Nothing is being replaced. This is where the 'one CTB' is supposed to be replaced with that 'same CTB along with the added buttons'.

Code: Select all

$newtoolbar=replace($toolbar,"$curctb,","$curctb,$added_CTBs,-,", , , 1);
Thanks again Filehero. I hope all is well.

Update: The issue is due to the fact the final toolbar button in the list does not have a following ',' in XYplorer.ini or in the toolbar text files. So SC replace for "$curctb," doesn't work when the assigned CTB is in the last position. Unfortunately, if you remove the following ',' in the replace search item ($curctb), SC replace will replace in positions it's not suppose to (e.g., for ctb3 it will replace at ctb33). I think I'll have to detect if the assigned expandable CTB is the last in the $toolbar string, if it is, I'll temporarily add a final ',' . I may get rid of the divider bar in that case as well since it's not need in the last position upon expansion. Thanks.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: Expandable drive button

Post by Filehero »

Hi Ken,

thanks for your quick reply and explanations.

Cheers,
Filehero

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Expandable drive button

Post by TheQwerty »

klownboy wrote:

Code: Select all

$newtoolbar=replace($toolbar,"$curctb,","$curctb,$added_CTBs,-,", , , 1);
Thanks again Filehero. I hope all is well.

Update: The issue is due to the fact the final toolbar button in the list does not have a following ',' in XYplorer.ini or in the toolbar text files. So SC replace for "$curctb," doesn't work when the assigned CTB is in the last position. Unfortunately, if you remove the following ',' in the replace search item ($curctb), SC replace will replace in positions it's not suppose to (e.g., for ctb3 it will replace at ctb33). I think I'll have to detect if the assigned expandable CTB is the last in the $toolbar string, if it is, I'll temporarily add a final ',' . I may get rid of the divider bar in that case as well since it's not need in the last position upon expansion. Thanks.
I haven't looked at your code but based on just this it sounds like you're trying to insert $added_CTBs into the list right afte $curctb?

May I suggest using the more appropriate GetToken instead of performing a string replace?

Code: Select all

// Find current ctb within toolbar.
$index = GetTokenIndex($curctb, $toolbar, ',', 'i');
assert $index > 0, 'CurCTB was not found on the toolbar.';

// Insert buttons into the toolbar.
$newtoolbar = GetToken($toolbar, $index, ',',, 1) . ",$added_CTBs,-," . GetToken($toolbar, $index+1, ',',, 2);

// Remove empty items.
// If current ctb was the last item we added an unnecessary trailing comma.
$newtoolbar = FormatList($newtoolbar, 'e', ',');
Attachments
Clippy.png
Clippy.png (9.55 KiB) Viewed 3846 times

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Expandable drive button

Post by klownboy »

Thanks Filehero for pointing out the issue. I should have realized new users would be adding a CTB and it would probably be at the end of the bar. Unlike me, who has had the Expandable CTB button on the toolbar for over a year. It should work alright if you move the CTB inward using XY's "Customized Toolbar" menu or the "Build new Toolbar" (you can drag and drop locations of buttons). If you have a relatively full toolbar though it actually makes sense not to have this at the end such that it expands out of sight.

In any case, I've fixed that issue, but before issuing a revision, I may also look at providing a means of adding dividers when building a new toolbar from scratch. Of course you can always add them in the normal way and then use the Save Toolbar menu item.

Hi TheQwerty, I just noticed your comment while posting. I was able to correct the issue though still using SC replace. I'll take a look at using gettoken as you suggested. I'm always open to new ideas and different / better ways to do the same thing.
Thanks.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Expandable drive button

Post by klownboy »

Hi TheQwerty, I tested your suggested code at start, middle, and end positions and it worked fine. I like that gettoken method of building from the left (start) from the index CTB . $added_CTBS . and the right (end). I decided after Filehero's comment that when the 'CTB' is at right end, I didn't want the final divider since it really doesn't make much sense at the end. So the only thing I did with your method was change the SC formatlist to SC trim to easlily get rid of any final ',' or '-'.

Code: Select all

  $newtoolbar =  trim ($newtoolbar, ",-", "R");
The method I came up with also works but is probably not as logical or appropriate.

Code: Select all

   $toolbar =  trim ($toolbar, ",", "R");  //trim ',' on the right side (if any) for the next check
     if(gettoken($toolbar, "-1", ",") LikeI $curctb) {   //check if $curctb is a the end
         $toolbar= $toolbar . ","; }        //if the CTB is at the end position temporarily add an ','
   $newtoolbar = replace($toolbar, "$curctb,", "$curctb,$added_CTBs,-,", , , 1);
   $newtoolbar = trim($newtoolbar, ",-", "R");  strip out any ',' or '-' at the end - no need for divider at the end position
Thanks again.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13260
Joined: 06 Feb 2011 00:33

Re: Expandable drive button

Post by highend »

I would have said regexreplace() but I know it's now allowed here :mrgreen:
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Expandable drive button

Post by TheQwerty »

Many ways to skin the cat... and skin it we shall! :whistle:

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Expandable drive button

Post by klownboy »

highend wrote:I would have said regexreplace() but I know it's now allowed here
Oh, it's allowed, I just don't know it. :)
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: Expandable drive button

Post by Filehero »

Hi Ken,

I'm blocked today but will "return" at the weekend!
klownboy wrote:Thanks Filehero for pointing out the issue. I should have realized new users would be adding a CTB and it would probably be at the end of the bar. Unlike me, who has had the Expandable CTB button on the toolbar for over a year. It should work alright if you move the CTB inward using XY's "Customized Toolbar" menu or the "Build new Toolbar" (you can drag and drop locations of buttons). If you have a relatively full toolbar though it actually makes sense not to have this at the end such that it expands out of sight.
.
Of course, I originally had placed the button on the left side (and will finally do so). The right side move was just to check wether this could fix the issue (aka pre-analysis on my side).

Thanks for the constant effort you're putting in this very helpful script. :D :D

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Expandable drive button

Post by klownboy »

New revision 1.03:

- As reported by Filehero above, if the ExpandableCTB was assigned to the right end position on the toolbar, the expansion of the assigned buttons would not happen. It turns out the script was looking for a final comma after the CTB that didn't exist in the end position...fixed.

- used SC gettoken in lieu of SC replace to build variable $newtoolbar as suggested by TheQwerty. It seems to be a more logical than using replace.

- I also included some separators in the selectinput dialog for use when building whole toolbars.

- The script no longer uses a separator after the expanded buttons. You can substitute the line in the code ($newtoolbar in line 126) if you'd rather have that or put separators in manually. One on each side actually works well.

Thanks TheQwerty for the SC gettoken suggestion and thank you Filehero for the comments and testing this version prior to issue.
ExpandableCTB_v1.03.zip
(22.57 KiB) Downloaded 199 times
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: Expandable drive button

Post by Filehero »

Hi Ken,

works fine, thanks for the refinements! :)

Cheers,
Filehero

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Expandable drive button

Post by klownboy »

Thank you Filehero for comments and testing. I'm glad it's working alright. Cheers. :)
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Post Reply