Option Explicit Function OnInit(initData) initData.name = "Layout Command" initData.version = "1.1" initData.desc = "Automatically run a command when specific layouts open or change tabs" initData.copyright = "(c) 2017 Leo Davidson" initData.default_enable = true Dim vecDefLayouts Set vecDefLayouts = DOpus.Create.Vector ' Default layouts / example config. vecDefLayouts.push_back("My Layout 1") vecDefLayouts.push_back("My Layout 2") initData.config.CommandOpen = "Set FONTSCALE=150,both" initData.config.CommandTab = "Set FONTSCALE=150" initData.config.OpenFirstOnly = True initData.config.Layouts = vecDefLayouts initData.config_desc = DOpus.Create.Map( _ "CommandOpen", "If set to a command, it will be run when a lister from a matching layout opens.", _ "CommandTab", "If set to a command, it will be run when you change tabs in a matching lister.", _ "Layouts", "Names of layouts which the command(s) should be run for.", _ "OpenFirstOnly", "If True, CommandOpen is only run in the first tab when a new window opens; otherwise it is run once per tab.") End Function ' Helper Function Function IsNameInVector(name, vecNames) IsNameInVector = False Dim nameU nameU = UCase(name) if (nameU = "") Then Exit Function End If Dim testName For Each testName in vecNames If (nameU = UCase(testName)) Then IsNameInVector = True Exit Function End If Next End Function Function OnOpenLister(openListerData) If (Script.config.CommandOpen = "") Then Exit Function End If ' Un-comment to make qualifiers (e.g. Alt, Shift, Ctrl) temporarily disable the script. ' If (openListerData.qualifiers <> "none") Then ' Exit Function ' End If If (Not openListerData.after) Then OnOpenLister = True ' Ask to be called again when all the tabs are open. Exit Function End If If (Not IsNameInVector(openListerData.lister.layout, Script.config.Layouts)) Then Exit Function End If Dim cmd, tab Set cmd = DOpus.Create.Command For Each tab in openListerData.lister.tabs cmd.SetSourceTab tab cmd.RunCommand Script.config.CommandOpen If Script.config.OpenFirstOnly Then Exit For End If Next End Function Function OnActivateTab(activateTabData) If (Script.config.CommandTab = "") Then Exit Function End If ' Un-comment to make qualifiers (e.g. Alt, Shift, Ctrl) temporarily disable the script. ' If (activateTabData.qualifiers <> "none") Then ' Exit Function ' End If If (Not IsNameInVector(activateTabData.newtab.lister.layout, Script.config.Layouts)) Then Exit Function End If Dim cmd Set cmd = DOpus.Create.Command cmd.SetSourceTab activateTabData.newtab cmd.RunCommand Script.config.CommandTab End Function