GP Software โ€ข Twitter
Opus FAQs โ€ข Manual โ€ข Commands โ€ข Objects

NavLock Folder Create

commands
vbscript
scripting

#1

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

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

IDEA: Nav-lock automagically create folders
Navigation lock vs slave tab
Roundup of Opus extensions
#2

May add a option whether repeat operation(delete files, screen scroll and so on) funtion in Navigation Lock Mode. When backup and update will be useful.


#3

If script is acitved,Dopus will crash when close mainwindow before all tabs loaded

System:Win10 pro X64 + Dopus 12.3 X64

First of all ,thanks @Leo write so nice script for us.Dopus has a lot of users and fans in China,I am one of them.I received some bugs report and feedbacks from Chinese users who used "NavLock Folder Create" .And I would report a bug for this script.


Bug report for "Navlock Folder Create" script.

If "Navlock Folder Create" script actived in Preferences / Toolbars / Scripts.And default loading tabs of Dopus more over 15(for more opening and loading time) .Dopus will crash if I close the main window of Dopus quickly(when tabs are loading or before dopus loaded all tabs completely)

@Leo please operate the following for bug checking:
1.Checked on "Navlock Folder Create" in Preferences / Toolbars / Scripts, make it was actived.
2.Quit Dopus
3.Reopen Dopus with more than over 15 tabs(make longer loading time for next operation).
4.Close mainwindow of Dopus when all tabs is loading(before all tabs loaded entired)

I look over the log of script,there are some errors:


2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 NavLock Folder Create: ่„šๆœฌๅฎŒๆˆ
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 NavLock Folder Create: ๆˆๅŠŸๅˆๅง‹ๅŒ– 'vbscript' ๅผ•ๆ“Ž
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ่„šๆœฌๅฎŒๆˆ
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ๆˆๅŠŸๅˆๅง‹ๅŒ– 'vbscript' ๅผ•ๆ“Ž
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ๅฏๅŠจ่„šๆœฌๆˆๅŠŸ
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 NavLock Folder Create: ๅฏๅŠจ่„šๆœฌๆˆๅŠŸ
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 NavLock Folder Create: ่„šๆœฌๅฎŒๆˆ
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ่„šๆœฌๅฎŒๆˆ
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 NavLock Folder Create: ๆˆๅŠŸๅˆๅง‹ๅŒ– 'vbscript' ๅผ•ๆ“Ž
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ๆˆๅŠŸๅˆๅง‹ๅŒ– 'vbscript' ๅผ•ๆ“Ž
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ๅฏๅŠจ่„šๆœฌๆˆๅŠŸ
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ๅ‘็”Ÿ้”™่ฏฏไบŽ 112,ไฝ็ฝฎ 7
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ๆ— ๆ•ˆ็š„่ฟ‡็จ‹่ฐƒ็”จๆˆ–ๅ‚ๆ•ฐ: 'DOpus.FSUtil.Resolve' (0x800a0005)
2017/2/9 ๆ˜ŸๆœŸๅ›› 11:59 OnAfterFolderChange_LinkedTab_AutoOpen: ่„šๆœฌ้”™่ฏฏ - ่„šๆœฌ่ขซไธญๆญข

2017/2/9 ๆ˜ŸๆœŸๅ›› 12:33 OnAfterFolderChange_LinkedTab_AutoOpen: ๆˆๅŠŸๅˆๅง‹ๅŒ– 'vbscript' ๅผ•ๆ“Ž
2017/2/9 ๆ˜ŸๆœŸๅ›› 12:33 OnAfterFolderChange_LinkedTab_AutoOpen: ๅฏๅŠจ่„šๆœฌๆˆๅŠŸ
2017/2/9 ๆ˜ŸๆœŸๅ›› 12:33 OnAfterFolderChange_LinkedTab_AutoOpen: ๅ‘็”Ÿ้”™่ฏฏไบŽ 210,ไฝ็ฝฎ 4
2017/2/9 ๆ˜ŸๆœŸๅ›› 12:33 OnAfterFolderChange_LinkedTab_AutoOpen: ๅฏน่ฑกไธๆ”ฏๆŒๆญคๅฑžๆ€งๆˆ–ๆ–นๆณ•: 'folderChangeData.tab.linktab' (0x800a01b6)
2017/2/9 ๆ˜ŸๆœŸๅ›› 12:33 OnAfterFolderChange_LinkedTab_AutoOpen: ่„šๆœฌ้”™่ฏฏ - ่„šๆœฌ่ขซไธญๆญข


#4

Thanks once more Leo. This proves to be extremely useful. It seems to me it should come in as standard feature option accompanying NavLock.