Toggle Find Panel for selected folders & shortcuts (if any)

Requires Directory Opus 11.4.4 or above.

Overview:

This is a script button which will open and close the Find Panel.

  • If the panel is already open, the button will close the panel.

  • If the panel is not open, and nothing is selected, the button will open the panel with the current folder as the search location.

So far, everything is the same as the standard Tools -> Find Files (Ctrl-F) menu item.

But:

  • If some folders are selected, the button will open the Find Panel and set it to search in those folders instead of the current folder.

  • This also works with shortcuts to folders.

Installing:

You will probably want to replace your existing Tools -> Find Files command with this.

Here is the replacement button / menu item as a .dcf file:

To use the file, download it, and then:

  • Use Settings -> Customize Toolbars to start editing your toolbars.
  • If you want to delete the default Find Files menu item, do that by opening the Tools menu, then right-clicking the item you want to remove and selecting Delete.
  • Drag the downloaded .dcf file to where you want it (probably at the top of your Tools menus).
  • Click OK in the Customize dialog to save the changes.

Script Code:

The script code inside the above .dcf file is reproduced below, so you can see how it works without downloading anything:

MODIFIERS TAB:

@toggle:If UTILITY=Find,Toggle

SCRIPT CODE TAB (VBScript):

Option Explicit

Function OnClick(ByRef ClickData)

	Dim cmd, selDirs, selFiles, dirItem, fileItem, wsh, shortcut, fsu
	Set cmd = ClickData.Func.Command
	cmd.Deselect = False ' Leave things selected after we're done.

	If cmd.IsSet("UTILITY=Find,Toggle") Then
		' Find panel is open. Act as a toggle and turn it off.
		cmd.RunCommand "Set UTILITY=Off"
	Else
		Set selDirs = ClickData.Func.sourcetab.Selected_Dirs
		Set selFiles = ClickData.Func.sourcetab.Selected_Files
		Set wsh = Nothing ' We don't usually need these...
		Set fsu = Nothing ' ...so we create them on demand, below.

		' Only want to act on folders.
		' Clear the command's files & folders, then add back just the folders.
		cmd.ClearFiles
		For Each dirItem In selDirs
			cmd.AddFile dirItem
		Next

		' Check files for any shortcuts to folders, and include their targets as well.
		For Each fileItem In selFiles
			If UCase(fileItem.ext) = ".LNK" Then
				If (wsh Is Nothing) Or (fsu Is Nothing) Then
					Set wsh = CreateObject("WScript.Shell")
					Set fsu = DOpus.FSUtil
				End If
				Set shortcut = wsh.CreateShortcut(fileItem.realpath)
				' We have a shortcut. Is it pointing to a folder?
				' The "a" argument tells fsu.GetType to treat archives as files.
				If fsu.GetType(shortcut.TargetPath, "a") = "dir" Then
					cmd.AddFile shortcut.TargetPath
				End If
			End If
		Next

		If cmd.files.count = 0 Then
			' No folders to search so just open the Find Panel normally.
			cmd.RunCommand "Set UTILITY=Find,On"
		Else
			' We have folders. Use the "Find" command to open the Find Panel with specific folders.
			' (The command is made up from parts to avoid a bug in Opus 11.4.4 and below where button
			' codes are incorrectly interepreted if they appear as part of the script code.)
			cmd.RunCommand "Find IN {" & "allfilepath" & "}"
		End If
	End If
End Function

History:

  • 19/Jun/2014: Added @toggle:If UTILITY=Find,Toggle modifier, so the button appears pushed in when the Find Panel is open, like the normal button would.