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
}
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;
}
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.