Can you show/hide the tab bar with a script?

Discuss and share scripts and script files...
Post Reply
neminem
Posts: 94
Joined: 13 Aug 2012 20:31

Can you show/hide the tab bar with a script?

Post by neminem »

So... apparently Don is not interested in my request to show the tab bar when there's more than one tab, and hide it when there's only one. I dunno why, I thought it was fairly reasonable, but it's his software, he can do what he wants. I still want that functionality, though, and the original thread mentioned I could probably script it. So I figure I'd ask here: I looked through the help, and I didn't see anything that would let you script showing the tab bar? (At which point, it'd be easy enough to get a list of the current open tabs, check whether the list has more than one element, and toggle appropriately.)

In the scripting help: I see button(), but toggling the tab bar doesn't seem to be in the list of available toolbar buttons, just in the menu and as a keyboard shortcut. I see get() lets you get whether the tab bar is visible (#commandid 662), but no corresponding set(). I see setkey(), but that doesn't set it immediately, just on disk. setting() looked promising, but it doesn't seem to have the tab bar in its list, either. Am I missing anything about any of these, or anything else, that would let me toggle showing that bar immediately?

In retrospect, it's probably better scripting this anyway, as I've also become used to ctrl-w closing the window if it runs out of tabs to close - which Don would be completely right to not want to change that behavior now if I asked him to, as presumably loads of people are used to it not doing that, and would be annoyed ;).

highend
Posts: 14942
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Can you show/hide the tab bar with a script?

Post by highend »

If get let's you see if the bar is currently visible why don't you use it's return parameter and the output of tab(get, "c"); to decide if you use just #662; to toggle it?
One of my scripts helped you out? Please donate via Paypal

neminem
Posts: 94
Joined: 13 Aug 2012 20:31

Re: Can you show/hide the tab bar with a script?

Post by neminem »

Oh, huh. That is the answer to my question, kind of roundabout-ly: I missed the part where you could invoke a command just by looking up its number and then invoking it as a command by itself using its id. I am a noob. :p

i.e. You could have just replied to my query by saying: "Yes, just run '#662' by itself." Totally works. :D

(I also missed the "c" parameter of tab(), though, so thanks for that as well. Way less of a hack than requesting a delimited list of tabs and parsing it.)

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

Re: Can you show/hide the tab bar with a script?

Post by TheQwerty »

The following script will count the tabs, accounting for the inactive pane when visible, and toggle the tab bar accordingly.
To get it to "automatically" work, you'll essentially need to run this script after every command that opens a tab, closes a tab, or changes which panes are visible.

As I said in the original thread going this route is a hack at best. :wink:

Code: Select all

"Toggle Tab Bar"
	// Start by getting the tab count for the active pane.
	$minTabs = 1;
	$tabCount = Tab('Get','c');
	
	// If the inactive pane is visible count its tabs too.
	if (Get('#800')) { // Panes | Dual Pane
		$minTabs = 2;
		// This allows us to count the tabs without activating the pane.
		$tabCount = $tabCount + GetToken(Get('Tabs','|','i'),'count','|');
	}

	// Toggle the bar when needed.
	$barVisible = Get('#662'); // Window | Show Tab Bar
	if (($barVisible && $tabCount <= $minTabs) || (!$barVisible && $tabCount > $minTabs)) {
		#662; // Window | Show Tab Bar
	}

neminem
Posts: 94
Joined: 13 Aug 2012 20:31

Re: Can you show/hide the tab bar with a script?

Post by neminem »

Nifty. I agree, that's totally a hack, but it's a completely working one, and in fact, I probably would've gone that route anyway. Turns out, not only do I not completely like the behavior of closing a tag (my script can close the window if it runs out of tags to close), I also don't completely like the behavior of opening a new one (if I have a folder selected, I'd like it to open the folder). So it is pretty cool just being able to write exactly the behavior I want myself. I was most of the way there, as I said, I just totally failed at figuring out the very basic fact about scripting, that a command id by itself was a valid command. :)

Is there a way to hook a script into an existing command, though? Doing it this way works great for keyboarding, which is what I use most of the time - I just made custom user actions for opening and closing, that perform the open/close I want, then toggle like you show, and set ctrl/[w|t] to those actions over their defaults. But unlike in the example of the previous hack, where Visual Studio, it turned out, was happy to let you replace items in context menus with your custom commands, I don't see anything in xyplorer that lets you do that (for the benefit of a folder's "Open in New Tab", for instance). I could be wrong, though.

And I do have one more related question: is there a way to check quickly in a script, whether the result of get("Item") is a directory or a file? (Or equivalently in this case, to get the path-part of a path that might optionally include a filename, so "c:\temp\temp.bmp" would return "c:\temp". Either one would do.)

Thanks for all the help!

highend
Posts: 14942
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Can you show/hide the tab bar with a script?

Post by highend »

whether the result of get("Item") is a directory or a file?
exists()
(Or equivalently in this case, to get the path-part of a path that might optionally include a filename, so "c:\temp\temp.bmp" would return "c:\temp"
getpathcomponent()
One of my scripts helped you out? Please donate via Paypal

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

Re: Can you show/hide the tab bar with a script?

Post by TheQwerty »

neminem wrote:Is there a way to hook a script into an existing command, though?
You can replace the keyboard events and toolbar buttons (well 32 of them anyway), but beyond that there isn't a way to hook into existing commands.

Don does have Custom Event Action (CEA) on the roadmap which should allow some hooking.
neminem wrote:is there a way to check quickly in a script, whether the result of get("Item") is a directory or a file? (Or equivalently in this case, to get the path-part of a path that might optionally include a filename, so "c:\temp\temp.bmp" would return "c:\temp". Either one would do.)
Take a look at Exists(), GetPathComponent(), Get('CurItem') and the various native variables (<curitem>, <curpath>).

neminem
Posts: 94
Joined: 13 Aug 2012 20:31

Re: Can you show/hide the tab bar with a script?

Post by neminem »

Thanks again! Dunno how I missed exists() (I saw it, but I didn't notice that it returned an int stating whether it was a file or not.) I do know how I missed GetPathComponent() though: it's not in the list of commands, and I just did a search of the whole help file for it, and got no results :p.

Exists() works exactly as I needed it to, though. So, good enough - ctrl-[w|t] work exactly as I wanted them to now, that's like 99% of the tab opening/closing I do, shouldn't be too annoying to make it 100% instead. :)

Any future users who like their tab opening/closing to act like mine, this is what my commands looked like in the end:

Bound to ctrl-t, to open:

Code: Select all

"Open Tab"
  $item = get("Item");
  if (exists($item) == 2) // if the current selected item is a folder, open a tab with that folder
  {
    tab("new", $item);
  }
  else // open a tab with the current folder
  {
    tab("new");
  }

  // Start by getting the tab count for the active pane.
  $minTabs = 1;
  $tabCount = Tab('Get','c');
  
  // If the inactive pane is visible count its tabs too.
  if (Get('#800'))  // Panes | Dual Pane
  { 
     $minTabs = 2;
     // This allows us to count the tabs without activating the pane.
     $tabCount = $tabCount + GetToken(Get('Tabs','|','i'),'count','|');
  }

  // Toggle the bar when needed.
  $barVisible = Get('#662'); // Window | Show Tab Bar
  if (($barVisible && $tabCount <= $minTabs) || (!$barVisible && $tabCount > $minTabs)) 
  {
    #662; // Window | Show Tab Bar
  }
Bound to ctrl-w, to close:

Code: Select all

"Close Tab"
  // Start by getting the tab count for the active pane.
  $minTabs = 1;
  $tabCount = Tab('Get','c');
  
  // If the inactive pane is visible count its tabs too.
  if (Get('#800'))  // Panes | Dual Pane
  { 
     $minTabs = 2;
     // This allows us to count the tabs without activating the pane.
     $tabCount = $tabCount + GetToken(Get('Tabs','|','i'),'count','|');
  }

  if ($tabCount == 1)
  {
    #192; // exit
  }
  else
  {
    tab("close", 1);
 
    // have to reload the tab count - tab closing could have been canceled, in which case don't do anything
    $minTabs = 1;
    $tabCount = Tab('Get','c');
      if (Get('#800'))  // Panes | Dual Pane
    { 
       $minTabs = 2;
       $tabCount = $tabCount + GetToken(Get('Tabs','|','i'),'count','|');
    }

    // Toggle the bar when needed.
    $barVisible = Get('#662'); // Window | Show Tab Bar
    if (($barVisible && $tabCount <= $minTabs) || (!$barVisible && $tabCount > $minTabs)) 
    {
      #662; // Window | Show Tab Bar
    }
  }
Last edited by neminem on 30 Aug 2012 23:12, edited 1 time in total.

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

Re: Can you show/hide the tab bar with a script?

Post by TheQwerty »

neminem wrote:I do know how I missed GetPathComponent() though: it's not in the list of commands, and I just did a search of the whole help file for it, and got no results :p.
It's a relatively new command: http://www.xyplorer.com/xyfc/viewtopic. ... 454#p75454
admin wrote:

Code: Select all

v11.40.0202 - 2012-08-17 20:58
    ...
    + Scripting got a new function.
      Name:   getPathComponent
      Action: Returns the specified component of a path.
      Syntax: getpathcomponent([path], [component])
        path:     The path to parse; can be a folder or a file.
                  Defaults to the current folder or file.
        component: The component to return; can be any of the following:
          drive:  the drive or share
          path:   [default] the path without any file
          parent: the parent folder
          file:   the file without path
          base:   the file without path and without extension
          ext:    the extension
      Notes:
        Paths are returned unslashed.
      Examples:
        echo getpathcomponent(, "file"); //current item without path
        echo getpathcomponent("E:\x\y.txt", "ext");   // txt
        echo getpathcomponent("E:\x\y.txt", "base");  // y
        echo getpathcomponent("E:\x\y.txt", "file");  // y.txt
        echo getpathcomponent("E:\x\y.txt", "parent");// x
        echo getpathcomponent("E:\x\y.txt", "path");  // E:\x
        echo getpathcomponent("E:\x\y.txt", "drive"); // E:
Though there's been a few updates so don't use those instructions with the current version of XY.

Post Reply