// ActivateRightTabOnClose // : A script add-in that after closing a tab, activates the tab to the right instead of the tab that was previously used. // - Modified from tbone's "ActivateLeftTabOnClose" obtained from: // https://resource.dopus.com/uploads/default/original/3X/e/7/e7f3d45228250bd11731101c40587e090adef56b.txt // ..in the following announcement thread: // https://resource.dopus.com/t/event-activatelefttabonclose-switch-to-left-instead-of-previously-used-tab/20723 // ..originally for this OP thread: // https://resource.dopus.com/t/how-to-close-current-and-select-left-tab/20153 //v0.2 //- fix for switching to wrong tab when closing tabs in destination //- fix for switching to wrong tab when closing inactive/invisible tabs //v0.1 //- initial prototype released in a thread I don't remember currently. // ahh, it was this one: http://resource.dopus.com/viewtopic.php?f=3&t=24028 /////////////////////////////////////////////////////////////////////////////// function OnInit(data){ //uid added via script wizard (do not change after publishing this script) var uid = "57B93B6D-A93E-4593-BAB5-3302B2DA20D8"; //resource center url added via script wizard (required for updating) var url = "http://resource.dopus.com/viewtopic.php?f=35&t=24626"; data.name = "Event.GUI: ActivateRightTabOnClose"; data.desc = "Activate the tab to the right when closing a tab, instead of activating the one previously used."; data.version = "1"; data.min_version = "11.5"; data.copyright = "syl" data.default_enable = true; } /////////////////////////////////////////////////////////////////////////////// function OnCloseTab(data) { if (!data.tab.visible){ //tab not visible, doing nothing special to activate any another tab //as closing a tab currently not used, shall not switch active/visible tabs return false; } var cmd = DOpus.Create.Command(); cmd.SetSourceTab(data.tab); var focusRight = data.tab.lister.activetab.right; var focusToggled = false; if (focusRight != data.tab.right){ cmd.RunCommand("Set FOCUS=dest"); focusToggled = true; } CloseTab(data.tab, cmd); //setting sourcetab again, as the last tab is gone now //else any additional commands will fail to run cmd.SetSourceTab(data.tab.lister.activetab); if (focusToggled){ cmd.RunCommand("Set FOCUS=dest"); } return true; } /////////////////////////////////////////////////////////////////////////////// function CloseTab(tab, command) { var tabDetails = GetTabDetails(tab); if (tabDetails.index===null) return; // [syl-mod] // command.RunCommand("Go NOSCRIPT TABSELECT " + (tabDetails.index>0?tabDetails.index-1:tabDetails.index+1)); // Closing a tab switches focus to the left adjacent tab, as OP (AKA-Mythos) prefers. command.RunCommand("Go NOSCRIPT TABSELECT " + (tabDetails.index < tabDetails.count ? tabDetails.index+1 : tabDetails.index)); // Closing a tab switches focus to the right adjacent tab, as I prefer. command.RunCommand("Go NOSCRIPT TABCLOSE " + tab ); } /////////////////////////////////////////////////////////////////////////////// function GetTabDetails(tab){ if (tab.right) { tabs = tab.lister.tabsright; tabDetails = {isLeft: false, isRight: true, index: null, count: tabs.count}; } else { tabs = tab.lister.tabsleft; tabDetails = {isLeft: true, isRight: false, index: null, count: tabs.count}; }; for (var i=0;i