/////////////////////////////////////////////////////////////////////////////// //v0.1 - o9/2o14 //- initial //v0.2.2 //- min version added //- prepared for automatic updates //todo //- evaluate tab.locked /////////////////////////////////////////////////////////////////////////////// function OnInit(data){ //uid added via script wizard (do not change after publishing this script) var uid = "3E17FEC4-3AF0-4492-A1A3-C9FB48F84048"; //resource center url added via script wizard (required for updating) var url = "http://resource.dopus.com/viewtopic.php?f=35&t=23135"; data.name = "Event.Folder: CloseTabSiblings"; data.desc = "Close tab siblings (tabs with same location)."; data.copyright = "tbone"; data.version = "0.2.2"; data.version = "11.6"; data.default_enable = true; data.min_version = "11.6"; var cmd = data.AddCommand(); cmd.name = "CloseTabSiblings" cmd.method = "Command_CloseTabSiblings"; cmd.desc = "Close equal tab siblings."; cmd.label = "CloseTabSiblings"; cmd.icon = "closetab"; /////////////////////////////////////////////////////////////////////////// function ConfigHelper(data){ this.data=data; this.descriptions=null; this.last=null; this.add = function(name, val, description){ this.data.config[name]=val; this.last=[this.data.config[name],name]; if (description!=undefined) this.des(description); return this;} this.des = function(description){ if (!(description && DOpus.version.AtLeast("11.6.1"))) return this; if (!this.descriptions){ this.descriptions=DOpus.NewMap(); data.config._descriptions=this.descriptions; } this.descriptions(this.last[1])=description; return this;} this.val = function(val){ if (typeof this.last[0]=="object") this.last[0].push_back(val); else this.last[0]=val; return this;} } /////////////////////////////////////////////////////////////////////////// var cfg = new ConfigHelper(data); cfg.add("XDebugOutput", false). des("Enable debug output in the script console."); cfg.add("StartIndex", 1). des("Close tabs only, if their index number is higher than this. A value of 3 would never automatically close the first two tabs of the row."); cfg.add("Blacklist", true). des("En/disable blacklist of paths."); cfg.add("Qualifiers", true). des("En/disable qualifier evaluation. Pressing when opening or changing tabs or folders tmp. disables tab closing. Pressing protects the tab itself and stops closing any tab with the new path."); cfg.add("Blacklist.Paths", DOpus.NewVector()). des("List of paths (regular expressions), which will never be closed automatically."). val("#never close root of drive D:\\"). val("^D:\\\\$"); cfg.add("OnAfterFolderChange", true). des("Enable automatic closing of tab siblings by monitoring tab and folder changes."); } /////////////////////////////////////////////////////////////////////////////// var COMMAND_ABORTED = true; var COMMAND_SUCCEEDED = false; var g=this; /////////////////////////////////////////////////////////////////////////////// try{ if (DOpus.vars.Exists("Script.CloseTabSiblings.OnAfterFolderChange") && DOpus.vars("Script.CloseTabSiblings.OnAfterFolderChange") == true ){ //Debug(" VAR Script.CloseTabSiblings.OnAfterFolderChange = true / notexists"); //Debug(" Binding OnBeforeFolderChange():"); this.OnAfterFolderChange = OnAfterFolderChange_Callback; } else { //Debug(" VAR Script.CloseTabSiblings.OnAfterFolderChange = false"); //Debug(" NOT Binding OnAfterFolderChange():"); } //Debug(" Config.OnAfterFolderChange = " + Script.config.OnAfterFolderChange); } catch(e){ //Debug(" Config.OnAfterFolderChange = ?"); } /////////////////////////////////////////////////////////////////////////////// function OnScriptConfigChange(){ if (Script.config.OnAfterFolderChange == true){ Debug(" Setting Script.CloseTabSiblings.OnAfterFolderChange = 1 "); DOpus.vars.Set("Script.CloseTabSiblings.OnAfterFolderChange", 1); DOpus.vars("Script.CloseTabSiblings.OnAfterFolderChange").persist = true; } else { DOpus.vars.Set("Script.CloseTabSiblings.OnAfterFolderChange", 0); DOpus.vars("Script.CloseTabSiblings.OnAfterFolderChange").persist = true; Debug(" Setting Script.CloseTabSiblings.OnAfterFolderChange = 0 "); } //Debug(" GETTING Script.CloseTabSiblings.OnAfterFolderChange = " + // DOpus.vars.Get("Script.CloseTabSiblings.OnAfterFolderChange")); delete g.OnAfterFolderChange; DOpus.ReloadScript(Script.file); } /////////////////////////////////////////////////////////////////////////////// function Command_CloseTabSiblings(data){ Debug("CloseTabSiblings():"); data.func.command.ClearFiles(); CloseTabSiblings( data.func.qualifiers, data.func.sourcetab ); } /////////////////////////////////////////////////////////////////////////////// function OnAfterFolderChange_Callback(data){ Debug("CloseTabSiblings.OnAfterFolderChange():"); Debug(" TabPath : " + data.tab.path); Debug(" Qualifs : " + data.qualifiers); if (data.action == "refresh"){ Debug(" Refresh detected, no action"); return; } CloseTabSiblings( data.qualifiers, data.tab ); } /////////////////////////////////////////////////////////////////////////////// function CloseTabSiblings( qualifiers, tab){ if (Script.config["Qualifiers"]){ if (qualifiers.indexOf("shift")!=-1){ tab.vars.set("Script.CloseTabSiblings.Locked", true); Debug(" Locking tab, shift pressed"); } if (qualifiers.indexOf("ctrl")!=-1){ Debug(" Locking tabs by path, ctrl pressed"); if (!tab.lister.vars.exists("Script.CloseTabSibling.Blacklist")) tab.lister.vars.set("Script.CloseTabSibling.Blacklist", DOpus.Create.Vector(tab.path)); else { var blacklist = tab.lister.vars.get("Script.CloseTabSibling.Blacklist"); if (!HasSimpleMatchInVector(tab.path+"", blacklist)) blacklist.push_back(tab.path+""); } } if (qualifiers.indexOf("alt")!=-1){ Debug(" Aborting, alt pressed"); return COMMAND_ABORTED; } } var tabs = GetTabsFromTabRowOfTab(tab); var cmd = null; Debug(" TabCount: " + tabs.count); Debug(" TabPath : " + tab.path); Debug(" TabID : " + tab); for(var t=0;t1 && Script.config["StartIndex"]>(t+1)){ Debug(" Equal, not closing, protected by index"); continue; //that's me! } if (sibTab.vars.exists("Script.CloseTabSiblings.Locked")){ Debug(" Equal, not closing, tab has been locked"); continue; } if (DOpus.version.AtLeast("11.7.3") && sibTab.lock!="off") { Debug(" Equal, not closing, tab is natively locked"); continue; } if (sibTab.lister.vars.exists("Script.CloseTabSibling.Blacklist")){ if (HasSimpleMatchInVector(tab.path+"", sibTab.lister.vars("Script.CloseTabSibling.Blacklist").value)){ Debug(" Equal, not closing, tab-path is blacklisted"); continue; } } if (IsBlackListed(tab.path, Script.config["Blacklist"], Script.config["Blacklist.Paths"], null, null)){ Debug(" Equal, not closing, tab-path is globally blacklisted"); continue; } Debug("I Equal, closing"); !cmd && (cmd=DOpus.Create.Command()); cmd.AddLine("Go TABCLOSE="+sibTab); } else { Debug(" Not equal, not closing"); } } cmd && cmd.Run(); } /////////////////////////////////////////////////////////////////////////////// function GetTabsFromTabRowOfTab(tab){ if (DOpus.version.AtLeast("11.7.2")) var isRight = tab.right; else var isRight = IsRightTab(tab); //workaround for bug in pre v11.7.2 if (isRight) return tab.lister.tabsright; else return tab.lister.tabsleft; } /////////////////////////////////////////////////////////////////////////////// function IsRightTab(tab){ Debug(" IsRightTab(): " + tab); if (tab.lister.dual==0){ Debug(" false (not dual)"); return false; } for (var t=0;t