Overview:
Navigation Lock is a feature in Directory Opus where you can move around two similar directory structures, one on each side of a dual-display lister, with navigations done in the active side mirrored in the other side (as long as a folder with the same name exists to go to in both sides).
This script add-in enhances Navigation Lock by making it automatically create any missing folders on the other side when you enter them.
The script can be turned on and off per-lister (using buttons provided in the zip, below). You can also configure whether it is turned on or off in new windows.
Download & Install:
NavLock_Folder_Create.zip (3.04 KB)
To use the script, extract the attached zip file and drag NavLock Folder Create.vbs to Preferences / Toolbars / Scripts, where you can also Configure the default on/off state for new windows.
The zip file also includes three buttons which let you turn the script on and off for the active lister. One button toggles it, and is probably the only one you'll need. The others explicitly turn it on and off.
History:
Version 1.1 - 06/Jan/2014
- First version posted to the Scripts Area.
- You can now turn the script on and off per-lister, with the provided buttons.
- No longer restricted to only navigations triggered by double-click. (But see Limitations, below.)
Version 1.0 - 25/Nov/2014
- Initial version, originally from IDEA: Nav-lock automagically create folders
Limitations:
-
The script currently only creates folders if you navigate exactly one level down.
For example, if you are in Folder1 and go to Folder1\Folder2, it will create Folder2 on the other side if it is missing. But if you are in Folder1\Folder2 and jump directly to a sibling, Folder1\Folder3, it will not create Folder3 in the other side. You would have to first go back up to Folder1 and then down to Folder1\Folder3 instead of jumping directly to it.
This mainly affects navigation using the Folder Tree, since it is unusual to navigate in this way via other methods. This may be improved in a future version of the script.
Script and Button Code:
Everything you need is in the zip file above, but is reproduced here for people browsing the forum for scripting techniques.
Button - NavLock Folder Create - Off:
@toggle:if !$lst:NavLockFolderCreateActive
@set $lst:NavLockFolderCreateActive
Button - NavLock Folder Create - On:
@toggle:if $lst:NavLockFolderCreateActive
@set $lst:NavLockFolderCreateActive=1
Button - NavLock Folder Create - Toggle:
@toggle:if $lst:NavLockFolderCreateActive
@ifset:$lst:NavLockFolderCreateActive
@set $lst:NavLockFolderCreateActive
@ifset:else
@set $lst:NavLockFolderCreateActive=1
Script - NavLock Folder Create.vbs:
option explicit
' NavLock Folder Create
'
' This is a script for Directory Opus.
' See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
' Commands to put in toolbar buttons, hotkeys, etc. to turn the script on and off in the current lister.
' (Whether the script is on or off in new listers by default is controled via the script's configuration.)
'
' TOGGLE:
' @toggle:if $lst:NavLockFolderCreateActive
' @ifset:$lst:NavLockFolderCreateActive
' @set $lst:NavLockFolderCreateActive
' @ifset:else
' @set $lst:NavLockFolderCreateActive=1
'
' ON:
' @toggle:if $lst:NavLockFolderCreateActive
' @set $lst:NavLockFolderCreateActive=1
'
' OFF:
' @toggle:if $lst:NavLockFolderCreateActive
' @set $lst:NavLockFolderCreateActive
' Called by Directory Opus to initialize the script
Function OnInit(initData)
initData.name = "NavLock Folder Create"
initData.desc = "When using NavLock, double-clicking a folder that only exists on one side will create it on the other side automatically"
initData.copyright = "(c) 2015 Leo Davidson"
initData.version = "1.1"
initData.default_enable = true
initData.config_desc = DOpus.Create.Map
initData.config.ActiveByDefault = true
initData.config_desc("ActiveByDefault") = "The script can be toggled on and off per lister. This sets the state for new windows. The state in existing listers will also be reset if the setting is changed."
End Function
' Called just after OnInit, when the Script.Config object is available.
' We do not actually add any commands, we just use this to access Script.Config, which isn't possible during OnInit itself.
Function OnAddCommands(addCmdData)
SetVarInAllListers
End Function
' Called when the script config changes
Function OnScriptConfigChange(configChangeData)
Dim settingName
For Each settingName In configChangeData.changed
If (settingName = "ActiveByDefault") Then
SetVarInAllListers
End If
Next
End Function
' Called when a new lister opens
Function OnOpenLister(openListerData)
If (Script.config.ActiveByDefault) Then
openListerData.lister.vars.set "NavLockFolderCreateActive", true
End If
End Function
' Called by other methods to reset the NavLockFolderCreateActive variable in all open listers
Function SetVarInAllListers
Dim activate, lister, atLeastOne, cmd
activate = Script.config.ActiveByDefault
For Each lister in DOpus.listers
atLeastOne = true
If (Activate) Then
lister.vars.set "NavLockFolderCreateActive", true
Else
lister.vars.delete "NavLockFolderCreateActive"
End If
Next
If (atLeastOne) Then
Set cmd = DOpus.Create.Command
cmd.UpdateToggle ' Update toolbar button states in all listers.
End If
End Function
' Called before a new folder is read in a tab
Function OnBeforeFolderChange(beforeFolderChangeData)
Dim fac, cmd, fsu, tab, lister, pathCheck, folderName
If (beforeFolderChangeData.initial) Then
Exit Function
End If
If (beforeFolderChangeData.action <> "normal" AND beforeFolderChangeData.action <> "dblclk") Then
Exit Function
End If
Set tab = beforeFolderChangeData.tab
If (Not tab.source) Then
Exit Function
End If
Set lister = tab.lister
If (lister.dual = 0) Then
Exit Function
End If
If (Not lister.vars.Exists("NavLockFolderCreateActive")) Then
Exit Function ' We are not activated for this lister.
End If
Set fac = DOpus.Create
Set cmd = fac.Command
cmd.SetSourceTab beforeFolderChangeData.tab
If (Not cmd.IsSet("NAVLOCK=Toggle")) Then
Exit Function
End If
Set fsu = DOpus.FSUtil
Set pathCheck = fsu.NewPath(beforeFolderChangeData.path)
If (Not pathCheck.test_parent) Then
Exit Function
End If
pathCheck.Parent
If (pathCheck = "") Then
Exit Function
End If
If (Not fsu.ComparePath(pathCheck, tab.path)) Then
Exit Function
End If
folderName = beforeFolderChangeData.path.filepart
pathCheck.Set lister.desttab.path
If (fsu.Exists(pathCheck)) Then
pathCheck.Add folderName
If (Not fsu.Exists(pathCheck)) Then
cmd.SetSourceTab lister.desttab
cmd.RunCommand "CreateFolder NAME=""" & folderName & """ NOSEL NOUPDATESETTINGS READAUTO=yes"
End If
End If
End Function