Page 1 of 1

Custom keyboard shortcut to select named tab?

Posted: 15 Apr 2013 15:40
by Reve_Etrange
Hi all,

Is it possible to define a custom keyboard shortcut that select (ie. make active) a named tab?
Basically I have a favorite tab with caption an custom icon, and pretty often I am running thru the tab MRU list (Ctrl-Tab) just to go back there.

I have searched a bit, but couldn't find anything; perhaps some script guru has an idea?

Re: Custom keyboard shortcut to select named tab?

Posted: 15 Apr 2013 16:08
by TheQwerty
Go > Tablist... (#538) might be more useful than your current method.

The Tab SC doesn't have a "select/focus/activate" option, so while you can locate a tab within the current pane, there isn't an easy way to switch to it.

The next best option would be to have a script cycle through all tabs in the pane until the one with the desired name is active - it's not a solution I like since XY will re-draw the tabs.

Code: Select all

"Select Dropbox Tab"
  Global $G_TAB_NAME = 'Dropbox';
  Sub('_selectTab');

"_selectTab"
  Global $G_TAB_NAME;
  End ! $G_TAB_NAME, 'Global variable $G_TAB_NAME is not defined!';
  $i = 0;
  $tCount = Tab('Get', 'Count');
  while ($i < $tCount) {
    $ctName = Tab('Get', 'Name');
    End $G_TAB_NAME LikeI $ctName;
    $i++;
    #1019; //Miscellaneous | Tab Functions | Cycle Tabs Backward
  }

Re: Custom keyboard shortcut to select named tab?

Posted: 15 Apr 2013 16:30
by Reve_Etrange
Thanks for the reply.
I Ctrl-Tab a lot because it most often does what I need: cycle between the two tabs I am working with (and my fave tab is one of them).
Conceptually, I could have an MRU tab list with my fave tab locked in 2nd position, if you see what I mean.

Anyway, if there is no "select/focus/activate" option for tabs, I guess it cannot be done.
Any chance to have it implemented sometime?

Re: Custom keyboard shortcut to select named tab?

Posted: 15 Apr 2013 16:42
by admin
seltab

Re: Custom keyboard shortcut to select named tab?

Posted: 15 Apr 2013 17:01
by Reve_Etrange
\o/

I made a User Command going to location

Code: Select all

::seltab -3
, since my fave tab is the third from the right, and bound it to some key shortcut.

Re: Custom keyboard shortcut to select named tab?

Posted: 15 Apr 2013 17:48
by TheQwerty
Doh - that's right I forgot about SelTab! :oops:

For anyone that wants a solution that does not rely on the tab's position being kept...

Code: Select all

// Examples of how to call the script.
"Select Tab By Name"
  Global $G_TAB_NAME = Input('Select Tab By Name...', 'Name of the tab to select?', 'TabName');
  Sub '_checkBothPanes';

"Select Tab By Name (In Active Pane Only)"
  Global $G_TAB_NAME = Input('Select Tab By Name...', 'Name of the tab to select?', 'TabName');
  Sub '_checkActivePane';

//------------------------------------------------------------------------------

// Checks the active pane for a named tab...
// If not found, activates and searches the inactive pane.
// If still not found, returns the user to the original pane.
"_checkBothPanes"
  // Ensure we have a query.
  Global $G_TAB_NAME;
  End ! $G_TAB_NAME, 'Global variable $G_TAB_NAME not defined!';
  Global $G_CHECKING_BOTH_PANES = true;

  // Check active pane.
  Sub '_checkActivePane';
  Status 'Checking inactive pane...',, 'progress';

  // Try inactive pane.
  Focus 'PI';
  Sub '_checkActivePane';

  // Return to original pane.
  Focus 'PI';
  Status "No tab named '$G_TAB_NAME' found!",, 'alert';
  Sound 'SystemHand';

// Checks for a tab with matching name in the active pane.
"_checkActivePane"
  // Ensure we have a query.
  Global $G_TAB_NAME, $G_CHECKING_BOTH_PANES;
  End ! $G_TAB_NAME, 'Global variable $G_TAB_NAME not defined!';

  // Enumerate over all tabs searching for a match.
  $i = 1;
  $tCount = Tab('Get', 'Count');
  while ($i <= $tCount) {
    $tName = Tab('Get', 'Name', $i);

    // If found select tab and exit.
    if ($tName LikeI $G_TAB_NAME) {
      SelTab $i;
      Status 'Tab found!',, 'ready';
      Sound 'SystemExit';
      End true;
    }

    $i++;
  }

  // If only checking active pane display an alert at the end.
  if (! $G_CHECKING_BOTH_PANES) {
    Status "No tab named '$G_TAB_NAME' found in this pane!",, 'alert';
    Sound 'SystemHand';
  }