Expandable drive button

Discuss and share scripts and script files...
Post Reply
serendipity
Posts: 3358
Joined: 07 May 2007 18:14
Location: NJ/NY

Expandable drive button

Post by serendipity »

LAST UPDATED: 26 Oct 2013
ExpandDriveButton v2.4
ExpandDriveButton.xys
(3.81 KiB) Downloaded 478 times
Expandable button.gif
Expandable button.gif (13.72 KiB) Viewed 7370 times
Changelog:
v2.4-
1. Certain title templates caused second instance of XY to open.
Added /hwnd=<hwnd> switch which was added in v13.10.0137.

v2.3-
1. Two missing commas were causing problems. Fixed.

v2.2-
1. Fixed #2 for the bug from v2.1

v2.1-
1. Fixed a small bug where ctbindex 1 could not be differentiated from 10

v2-
1. Added 3 ways to collapse button:
  • a. Manual (toggle to collapse/expand drive)
    b. Auto (auto-collapse when clicking on list) - DEFAULT
    c. Timed (Close after x seconds)

2. Configurable icons for Collapse and Expand
3. Fixed a bug where creating a new button was ignored on next session start
4. Added unset to remove most permanent variables

v1.5-
1. Removed <get trigger ctbindex>, instead the script has to be run from script file to allow auto-close ctb feature.
2. Added the auto-close ctb feature with 5 seconds set as default.
3. Uses run command to initiate script label "_Autoclose" from outside, therefore allowing full control of clicks inside XY
Thanks to Ken, to help me get rid of the black DOS window!

v1-
1. First release: Expand Drive Button adds drive button to it's right
2. Use of new <get trigger ctbindex> to get button index and expand button


Note: This script uses permanent variable to make it work across sessions, so in menu Tools|Configuration enable: Remember permanent variables (Refresh, Icons, History - Scripting)

Code: Select all

//Expandable Drive Button -v2.4
/*This script expands the Custom Toolbar Button (CTB) to show button fixed drives to it's right.
The CTB can be collapsed manually or automatically (see settings)
How to use it:
1) Save the script as XY script file and put it in XY's script folder.
2) Make a new CTB and note it's index and change it in the script below.
3) Enter load "ExpandDriveButton.xys"; in the CTB's "On click:" field.
*/
         perm $p_ctbindex, $p_officon, $p_onicon;
         
//Settings (tagged with ###)          
//### 
//(1) CTB index: change the below "$p_ctbindex" to the index of your ctb
        $p_ctbindex="18";
        
//###
//(2) Autocollapse options: change $collapse to one of the following-
//   a) 0 = Manual collapse 
//   b) -1 = Default: Auto-collapse button when clicking on list (or catalog or addressbar) 
//   c) Any positive number = seconds to wait before collapsing button           
        $collapse=-1;                       
        
//### 
//(3) CTB icons: use either in-built XY icon (":drives")or your own (eg:"drive.ico")
        $p_officon=":drives";  //collapsed icon
        $p_onicon=":drives";  //expanded icon
         
        $curctb="ctb$p_ctbindex";
        $toolbar=toolbar();
           if (ctbstate(,$p_ctbindex) == 0) {
               sub "_PVCheck";
               perm $p_toolbar;
               $p_toolbar=$toolbar;
                   if(ctbicon(,$p_ctbindex)==""){
                      ctbicon("$p_officon",$p_ctbindex);
                      }
               ctbicon("$p_onicon",$p_ctbindex); 
               ctbstate(1,$p_ctbindex);
               $newtoolbar=replace($toolbar,"$curctb,","$curctb,{drives_fix},-,") ;              
                toolbar($newtoolbar);
                      if($collapse=="0") {
                         end(1==1);
                        }
                      elseif($collapse=="-1"){
                             run "cmd /c cd /d <xypath> & xyplorer.exe /script=""::load 'ExpandDriveButton.xys','_AutoCollapse'"" /flg=2 /hwnd=<hwnd>", , 0,0; 
                             end(1==1);
                             }
                      else{
                           run "cmd /c ping -n $collapse 127.0.0.1 >nul & cd /d <xypath> & xyplorer.exe /script=""::load 'ExpandDriveButton.xys','_WaitCollapse'"" /flg=2 /hwnd=<hwnd>", , 0,0; 
                           }                      
               }              
               
          else {
                ctbicon("$p_officon",$p_ctbindex);
                ctbstate(0,$p_ctbindex);
                $oldtoolbar=replace($toolbar,"$curctb,{drives_fix},-,","$curctb,");
                toolbar($oldtoolbar);
                unset $p_ctbindex, $p_officon, $p_onicon;
                end(1==1);
               }

"_PVCheck"
       $PV_ON=getkey("ScriptRetainPVs", "Settings");
          if($PV_ON==1){
            //nothing
             }
          else{
           $confirm= confirm ("To make this script work accross sessions, please check: <br>'Remember Permanent Variables' from <br>Tools | Configuration| Refresh, Icons, History - Scripting <br>Go to configuration now? <br>OK=Yes Cancel=No");
             if ($confirm==1){
                 #600;
                 savesettings;
                 }
              }

"_WaitCollapse"
    ctbicon("$p_officon",$p_ctbindex);
    ctbstate(0,$p_ctbindex);
    toolbar($p_toolbar);
    unset $p_ctbindex, $p_officon, $p_onicon;
    
    
"_AutoCollapse"
    focus "T";
    while("<get FocusedControl>"=="T"){
           wait(100);
           //Stay in loop if focus is on address bar
           //Break out of loop if focus on list, tree or catalog
          } 
    ctbicon("$p_officon",$p_ctbindex);
    ctbstate(0,$p_ctbindex);
    toolbar($p_toolbar);
    unset $p_ctbindex, $p_officon, $p_onicon;
Last edited by serendipity on 29 Sep 2013 17:52, edited 3 times in total.

Dario
Posts: 45
Joined: 20 Aug 2011 17:06

Re: Expandable drive button

Post by Dario »

Is it possible achieve same effect without CTB. I mean, run similar script with keyboard shortcut (UDC), or from Catalog.
Thanks

serendipity
Posts: 3358
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Expandable drive button

Post by serendipity »

Dario wrote:Is it possible achieve same effect without CTB. I mean, run similar script with keyboard shortcut (UDC), or from Catalog.
Thanks
Yes you can, however you will need to know the index of your button beforehand. In the first line below the ctb index is 17, change it to whatever yours is. Then copy and paste the code wherever you want, like Catalog or menu User|Manage Commands|Run Script. In the latter of course you can assign a keyboard shortcut.

Code: Select all

//Expandable Drive Button
        //Change the below "ctbindex" to the index of your ctb:
        $ctbindex="17";
        $curctb="ctb$ctbindex";
        $toolbar=toolbar();
           if (ctbstate(,$ctbindex) == 0) {
               perm $p_toolbar;
               $p_toolbar=$toolbar;
               ctbstate(1,$ctbindex);
               $newtoolbar=replace($toolbar,"$curctb","$curctb,{drives_fix},-") ; 
               toolbar($newtoolbar);
               } 
          else {
                ctbstate(0,$ctbindex);
                toolbar($p_toolbar);
               }
Don't forget to enable Remember permanent variables in menu Tools|Configuration| Refresh, Icons, History - Scripting

serendipity
Posts: 3358
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Expandable drive button

Post by serendipity »

Updated first post.

Dario
Posts: 45
Joined: 20 Aug 2011 17:06

Re: Expandable drive button

Post by Dario »

Thanks a lot, serendipity. Your script works fine. :P

aurumdigitus
Posts: 1075
Joined: 30 May 2008 21:02
Location: Lake Erie

Re: Expandable drive button

Post by aurumdigitus »

@ serendipity - You wasted no time putting the new <get trigger> to use :!:

Wonderfully clever little function. Upgraded to a Beta (which I'm usually loathe to do) just to get this operational.

One possible improvement: an option that would automatically turn it off again after X number of seconds.

As to your new incarnation as a Forum moderator, bear in mind this admonition from Henry IV, Part 2 Act 3, scene 1 -
Uneasy lies the head that wears a crown
:mrgreen:

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

Re: Expandable drive button

Post by klownboy »

Hi serendipity, you and Stefan ought to get together and consider updating the Toolbar Manager here http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=6538 As a minimum your new code posted here could be incorporated and maybe the script could be expanded in other ways, like being able to select CTBs to add to the toolbar maybe via inputselect using a similar technique as you did here. Obviously the new modification to the toolbar would be saved like it is above, as a new toolbar, but it opens up possibilities and would make it easier for people to make quick changes to the toolbars. It might be a very useful feature until Don goes with a dual toolbar capability, hopefully one with an option which could place the second toolbar vertically on the left right or between the nav panel and list dual. :) New monitors these days have much more room for expansion horizontally than vertically.

The Toolbar Manager mentioned above has been around for awhile and XY has undergone quite a few new features since then. I noticed in playing with it the other day, it doesn't allow overwriting an existing toolbar (name) with the same name, another one is created in the ini file with the same name.
Thanks and very nice script, :appl:
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Nighted
Posts: 459
Joined: 21 Jan 2007 01:58
Location: Gitmo Nation North, Win 7/10/Linux/(x64)

Re: Expandable drive button

Post by Nighted »

That's pretty slick! (òÓ,)_\,,/
I want XY to serve soft ice cream. Please Don, make XY serve soft ice cream.

serendipity
Posts: 3358
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Expandable drive button

Post by serendipity »

aurumdigitus wrote:One possible improvement: an option that would automatically turn it off again after X number of seconds.
Tried couple of interesting stuff (like keep button expanded until focus on list and so forth) but using command wait() or any other waiting trick (like while loop) makes the toolbar inactive (but clickable), so can't think of anything until toolbar responds to clicks.
@Don: maybe activate toolbar clicks during while loop wait or SC wait()?
aurumdigitus wrote:As to your new incarnation as a Forum moderator, bear in mind this admonition from Henry IV, Part 2 Act 3, scene 1 -
Uneasy lies the head that wears a crown
:mrgreen:
Nice one, learnt something new.
But, like Don said, most of the regulars have been doing this for a while now, so nothing really changes for me honestly. :)

serendipity
Posts: 3358
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Expandable drive button

Post by serendipity »

klownboy wrote:Hi serendipity, you and Stefan ought to get together .....
Ken
Hi Ken! You or Stefan are free to make use of this script in whatever way you like. I just like to fool around with new toys here. :)

j_c_hallgren
XY Blog Master
Posts: 5824
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Expandable drive button

Post by j_c_hallgren »

serendipity wrote:
aurumdigitus wrote:As to your new incarnation as a Forum moderator, bear in mind this admonition from Henry IV, Part 2 Act 3, scene 1 -
Uneasy lies the head that wears a crown
:mrgreen:
Nice one, learnt something new.
But, like Don said, most of the regulars have been doing this for a while now, so nothing really changes for me honestly. :)
Well, the real change that I see is that now when we (who were promoted) see a troll or spam while Don is unavailable, we can actually do something about it instead of just :naughty: at our screen, right?
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

serendipity
Posts: 3358
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Expandable drive button

Post by serendipity »

j_c_hallgren wrote:Well, the real change that I see is that now when we (who were promoted) see a troll or spam while Don is unavailable, we can actually do something about it instead of just :naughty: at our screen, right?
Aah yes! you are right, it's easy for us to remove the fine folks trying to sell enlargement pills etc, saving Don time.
We are the bouncers to the XY bar run by Don! :biggrin:

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

Re: Expandable drive button

Post by TheQwerty »

serendipity wrote:
aurumdigitus wrote:One possible improvement: an option that would automatically turn it off again after X number of seconds.
Tried couple of interesting stuff (like keep button expanded until focus on list and so forth) but using command wait() or any other waiting trick (like while loop) makes the toolbar inactive (but clickable), so can't think of anything until toolbar responds to clicks.
@Don: maybe activate toolbar clicks during while loop wait or SC wait()?
It's not yet a solution but it was a thought that I had and it needs more experimentation and patience.

You could use Windows' Task Scheduler to call XY and pass a script on the command line.
You can create a new task via script by using Windows' at.exe (requires admin) or schtasks.exe. However, be ready to spend a considerable amount of time debugging your Run command to get the correct magical incantation of correctly escaped quotes. (I've attempted it and failed thus far.)

The problem with this though is you cannot prevent possible conflicts with a user actually using XY when it attempts to run the scheduled script. If you keep the script simple, short, and speedy it may not matter, but it's still a risk.

So you could have your script create a scheduled task 2 minutes from "now" to call another script which would hide the buttons again.

Here's where I was when I gave up trying to figure out how to properly escape the command:

Code: Select all

"Schedule"
  // A unique task name.
  $tname = 'xytask';
  // The command to execute.
  $tcmd = """<xypath>\<xyexe>"" /script=""::msg 'hi!';""";

  // Escape the cmd - Experimenting since I have no idea what needs to be done.
  $tcmd = Replace($tcmd, '\', '\\');
  //$tcmd = Replace($tcmd, '/', '\/');
  $tcmd = Replace($tcmd, '''', '\''');
  $tcmd = Replace($tcmd, '"', '\"');

  // schtasks only accepts hh:nn for times and complains if the time may have already passed.
  // We could shift by 1 minute, but there's a slim chance time will rollover.
  $st = FormatDate(, 'hh:nn', 'n', 2);

  // /CREATEs a new task.
  // /SC once  = Scheduled to run one.
  // /ST $st  = Start time.
  // /F  = Force overwriting tasks of the same name.
  // /TN $tname  = Task name.
  // /TR ""$tcmd""  = Task to run.
  Run """schtasks"" /CREATE /SC once /ST $st /F /TN $tname /TR ""$tcmd""";


What would be ideal is for someone to write a program (AHK could work here) that is strictly an XY script scheduler. A script could register itself or another script with this program with some options (frequency, priority, run when XY's inactive/idle) and this program would wait until those conditions are met and then make the appropriate calls to execute the registered scripts in XY. Unfortunately this is not something I currently have the time to do myself.

serendipity
Posts: 3358
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Expandable drive button

Post by serendipity »

TheQwerty: Thanks for trying. :)
I gave up too after trying for an hour or so. Maybe with vbscript or something else it can be done, but too much hassle to just close the button.

Marco
Posts: 2347
Joined: 27 Jun 2011 15:20

Re: Expandable drive button

Post by Marco »

However, be ready to spend a considerable amount of time debugging your Run command to get the correct magical incantation of correctly escaped quotes. (I've attempted it and failed thus far.)
Have you tried heredoc?
Also, an external script executor like XYcopy would be a killer feature for scripters... :whistle: ...
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Post Reply