A script for MRU tabbing order.

Discuss and share scripts and script files...
Post Reply
fizzybiz
Posts: 19
Joined: 18 Jul 2020 10:05

A script for MRU tabbing order.

Post by fizzybiz »

Note: You need to use AutoHotkey with this script, to monitor Ctrl+Tab keypresses and send the right hotkeys to XYplorer.

This script keeps a list of the most recently viewed tabs, and allows you to cycle through them in "MRU order", in similar fashion to Visual Studio or Notepad++ tabs.

Step 1:

You must have AutoHotkey installed, and use the following little script.
The purpose of this is to detect the difference between:
a) The first time you press Ctrl+Tab together, and
b) Subsequent presses of the Tab key while holding Ctrl down.
Depending on either of those situations, it will send a different keypress to XYplorer, to trigger two different functions.

Code: Select all

#IfWinActive XYplorer ahk_class ThunderRT6FormDC
{
  ~^Tab::
    If (A_PriorKey = "LControl") { ; The first time you press Ctrl-Tab together.
      Send +!c ; Triggers XY script "ctrlTabFirst"
    } Else If (A_PriorKey = "Tab") { ; Subsequent presses of Tab while holding Ctrl down.
      Send ^+!c ; Triggers XY script "ctrlTabNext"
    }
    Return
}
Step 2:

In XYplorer you must go to Customise Keyboard Shortcuts and *remove* the Ctrl+Tab hotkey from the "Cycle Tabs Forward" function. This is to prevent XYplorer from handling Ctrl+Tab itself, since we are now handling that keypress via AutoHotkey.

Step 3:

Save the script below into your XYplorer data folder, to a file called "CtrlTab.xys":

Code: Select all

// This handles the *first* time Ctrl+Tab is pressed.
"CtrlTab First Hit : ctrlTabFirst"
  perm $perm_tabMRUlist;
  perm $perm_tabSequence;
  AddCurrentTabIDToMRUList();
  $perm_tabSequence = 2;
  $newTabID = ChangeToMRUTab();

// This handles *consecutive* presses of Tab key while Ctrl key is held down.
"CtrlTab Next Hit : ctrlTabNext"
  $perm_tabSequence++;
  ChangeToMRUTab();

// Add current tab ID to beginning of MRU list.
function AddCurrentTabIDToMRUList() {
  $thisTabID = tab("get", "ID");
  //RemoveFromMRUList($thisTabID); // in case already exists
  if ($perm_tabMRUlist != "") {
    $perm_tabMRUlist = "|" . $perm_tabMRUlist;
  }
  $perm_tabMRUlist = $thisTabID . $perm_tabMRUlist;
  ValidateMRUList();
}

// Get tab ID item $perm_tabSequence from MRU list.
// If list isn't that long, just to go next tab.
function ChangeToMRUTab() {
  if ($perm_tabSequence <= gettoken($perm_tabMRUlist, "count", "|")) {
    $tabID = gettoken($perm_tabMRUlist, $perm_tabSequence, "|", "t"); // The ID of the tab.
    $tabIndex = tab("get", "index", , $tabID); // The tab index corresponding to the tab ID.
    seltab $tabIndex, 1; // Select it.
  } else {
    seltab "+", 0; // Select the next tab.
  }
  // status $perm_tabMRUlist . ", " . $perm_tabSequence
}

// Remove a tab ID from the MRU list.
function RemoveFromMRUList($removeTabID) {
  $newTabMRUlist = "";
  foreach($id, $perm_tabMRUlist, "|") {
    if ($id != $removeTabID) {
      if ($newTabMRUlist != "") {
        $newTabMRUlist = $newTabMRUlist . "|";
      }
      $newTabMRUlist = $newTabMRUlist . $id;
    }
  }
  $perm_tabMRUlist = $newTabMRUlist;
}

// Go thru MRU list, removing any tab IDs that no longer exist.
function ValidateMRUList() {
  $perm_tabMRUlist = formatlist($perm_tabMRUlist, "tued", "|"); // normalise (note de-dup doesn't work 100%)
  $existingTabIDs = GetExistingTabIds();
  $newTabMRUlist = "";
  foreach($id, $perm_tabMRUlist, "|") {
    if (gettokenindex($id, $newTabMRUlist, "|", "") == 0) { // no dups
      if (gettokenindex($id, $existingTabIDs, "|", "") > 0) {
        if ($newTabMRUlist != "") { 
          $newTabMRUlist = $newTabMRUlist . "|"
        }
        $newTabMRUlist = $newTabMRUlist . $id;
      }
    }
  }
  $perm_tabMRUlist = $newTabMRUlist;
}

// Get list of currently existing tab IDs.
function GetExistingTabIds() {
  $existingTabIDs = "|";
  $tabCount = 0;
  while ($tabCount < tab("get", "count")) {
    $tabCount++;
    $existingTabIDs = $existingTabIDs . tab("get", "ID", $tabCount) . "|";
  }
  return $existingTabIDs;
}
Step 4:

Go to Manage User-Defined Functions and click "Load Script File" on the left side menu.

Click "New" -> "Add New Command"
For "Script File", browse to where you saved the above script file.
For "Label", type "ctrlTabFirst" (no quotes).
Assign the keyboard shortcut "Shift+Alt+C".

Click "New" -> "Add New Command"
For "Script File", browse to where you saved the above script file.
For "Label", type "ctrlTabNext" (no quotes).
Assign the keyboard shortcut "Ctrl+Shift+Alt+C".

Click "Ok".

That should be it. You should now be able to use Ctrl+Tab in a similar fashion to "MRU order" as implemented in other apps.

This isn't a perfect implementation, but it gets close enough for me. :)

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

Re: A script for MRU tabbing order.

Post by klownboy »

It's good to see others integrating AutoHotkey with XYplorer. :tup:
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: A script for MRU tabbing order.

Post by kotlmg »

can anyone help me in writing the autohotkey script to select clear recent items list from the attached potplayer's right click context menu.
screen shot is attached for ready reference.

Code: Select all

/::
  Send, {AppsKey}a
 Send,{Enter}
 ;Send {Down 15}
 ;Send,{Enter}
 Send,c
 Send,{Enter}
 SplashTextOn 200,20,Clear Recent Items in Potplayer,Clear Recent Items in Potplayer
    Sleep 1000
    SplashTextOff
 return


Attachments
Clipboard012.jpg
Clipboard012.jpg (39.37 KiB) Viewed 2266 times

fizzybiz
Posts: 19
Joined: 18 Jul 2020 10:05

Re: A script for MRU tabbing order.

Post by fizzybiz »

kotlmg wrote: 21 Jul 2020 16:56can anyone help me in writing the autohotkey script
1. You should start a new topic when... starting a new topic. :)

2. This isn't an autohotkey forum. :) Try posting your question here: https://www.autohotkey.com/boards/

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: A script for MRU tabbing order.

Post by kotlmg »

hai fizzybiz,
you have written code for xyplorer in autohotkey . that is why i have asked my question. i have no intention to start autohotkey forum in xyplorer forum. you have written the script in autohotkey instead of xyplorer script, that is why i have asked. As you guided i have already created my account in autohotkey. thanks.

fizzybiz
Posts: 19
Joined: 18 Jul 2020 10:05

Re: A script for MRU tabbing order.

Post by fizzybiz »

kotlmg wrote: 22 Jul 2020 07:19you have written code for xyplorer in autohotkey . that is why i have asked my question. i have no intention to start autohotkey forum in xyplorer forum. you have written the script in autohotkey instead of xyplorer script, that is why i have asked.
No, the script I posted above was an XYplorer script. I only used AHK to send keypresses to trigger the XYplorer script.
As you guided i have already created my account in autohotkey. thanks.
I think that's your best chance. Also try the Potplayer forum: https://potplayer.daum.net/forum/

Post Reply