option explicit ' Search Format Lock ' (C) 2014 Leo Davidson ' ' This is a script for Directory Opus. ' See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information. ' Called by Directory Opus to initialize the script Function OnInit(initData) initData.name = "Search Format Lock" initData.desc = "Preserves the current columns when using the Search field instead of switching to the Search Results folder format." initData.copyright = "(C) 2014 Leo Davidson" initData.version = "1.0" initData.default_enable = true initData.config.Add_Location_Column = True initData.config.Sort_Location_Column = True End Function Function GetLockVarName(objTab) If (objTab.right) Then GetLockVarName = "SearchFormatLock_Right" Else GetLockVarName = "SearchFormatLock_Left" End If End Function ' Called before a new folder is read in a tab Function OnBeforeFolderChange(beforeFolderChangeData) OnBeforeFolderChange = False ' Allow the folder change to go ahead as normal. If (beforeFolderChangeData.initial) Then ' Don't do anything if it's the first read of a new tab. Exit Function End If If (Not DOpus.FSUtil.ComparePath(beforeFolderChangeData.Path, "coll://%%Lister-Quick-Find-Results%%", "p")) Then ' Don't do anything if we're not changing to some search results Exit Function End If Dim objTab Set objTab = beforeFolderChangeData.tab Dim objCmd Set objCmd = DOpus.CreateCommand objCmd.SetSourceTab(objTab) If (objCmd.IsSet("FORMATLOCK=Toggle")) Then ' Don't do anything if the format lock is already on. (So we don't turn it off after changing.) Exit Function End If ' Set a variable which tells us to undo the format lock after the folder change. ' The format locks are per-lister, but there is a seperate one for the left and right ' halves of a dual-display lister, so we need to make a note of which one is ours. objTab.Vars.Set GetLockVarName(objTab), True ' Turn on the format lock, so whatever the format is now will stay after the folder change. objCmd.RunCommand "Set FORMATLOCK=On" End Function ' Called after a new folder is read in a tab Function OnAfterFolderChange(afterFolderChangeData) OnAfterFolderChange = False ' Ensure normal behaviour if the folder read failed. Dim objTab Set objTab = afterFolderChangeData.tab Dim objVars Set objVars = objTab.Vars Dim strVarName strVarName = GetLockVarName(objTab) If (Not objVars.Exists(strVarName)) Then ' Variable wasn't set, which means the format lock was already turned on by the user. ' We should leave both the lock and the format alone. Exit Function End If ' Remove our variable. objVars.Delete strVarName Dim objCmd Set objCmd = DOpus.CreateCommand objCmd.SetSourceTab(objTab) ' Turn off the format lock again. objCmd.RunCommand "Set FORMATLOCK=Off" If (afterFolderChangeData.result And Script.config.Add_Location_Column) Then ' The folder read succeeded (i.e. we are now in a Search Results folder) ' and we are configured to add the Location column. If ((Not objCmd.IsSet("COLUMNSADD=pathrel")) And (Not objCmd.IsSet("COLUMNSADD=path"))) Then ' Neither Location column is present already. ' Add Location (Relative) as the first column. objCmd.RunCommand "Set COLUMNSADD=pathrel(0)" If (Script.config.Sort_Location_Column) Then ' Sort by the location column, if we're configured to and added it. objCmd.RunCommand "Set SORTBY=pathrel" End If End If End If End Function