Open viewer pane when entering designated folders

Would you consider doing this for me? With your experience, I would think it a small matter of a couple of minutes for you to write the code I need to add to the script to make it complete. What say you?

Not on a Sunday night. Maybe during the week, time permitting.

Thank you!

Probably something wrong with it since I don't do VBS.

Option Explicit

Function OnInit(initData)
	initData.name = "AutoPane"
	initData.version = "1.0"
	initData.desc = "Automatically turn on Viewer Pane when entering configured folders"
	initData.copyright = "Based on Flat-View Auto by Leo Davidson"
	initData.default_enable = true

	Dim vecDefFolders
	Set vecDefFolders = DOpus.Create.Vector
	' Default folders / example config.
	vecDefFolders.push_back("C:\")

	initData.config.PaneOnCommand = "Set VIEWPANE=On"
    initData.config.PaneOffCommand = "Set VIEWPANE=Off"
	initData.config.ViewPaneFolders = vecDefFolders

	initData.config_desc = DOpus.Create.Map("ViewPaneFolders", "Folders which trigger the command.")
End Function

' Helper Function
Function IsPathInVector(fsu, path, vecFolders)
	IsPathInVector = False
	' Resolve aliases, libraries, etc. to their real/absolute paths.
	path = fsu.Resolve(path)
	Dim testPath
	For Each testPath in vecFolders
		If (fsu.ComparePath(path, fsu.Resolve(testPath))) Then
			IsPathInVector = True
			Exit Function
		End If
	Next
End Function

Function OnAfterFolderChange(afterFolderChangeData)

	If (Not afterFolderChangeData.result) Then
		Exit Function ' Folder didn't change.
	End If

	' Un-comment to make qualifiers (e.g. Alt, Shift, Ctrl) temporarily disable the script.
	' If (afterFolderChangeData.qualifiers <> "none") Then
	'	Exit Function
	' End If

  Dim cmd
  Set cmd = DOpus.Create.Command
  cmd.SetSourceTab afterFolderChangeData.tab
  If (Not IsPathInVector(DOpus.FSUtil, afterFolderChangeData.tab.Path, Script.config.ViewPaneFolders)) Then
    cmd.RunCommand Script.config.PaneOffCommand
  Else
    cmd.RunCommand Script.config.PaneOnCommand
  End If

End Function

Function OnActivateTab(ActivateTabData)
  Dim cmd
  Set cmd = DOpus.Create.Command

  If (Not IsPathInVector(DOpus.FSUtil, ActivateTabData.new.path, Script.config.ViewPaneFolders)) Then
    cmd.RunCommand Script.config.PaneOffCommand
  Else
    cmd.RunCommand Script.config.PaneOnCommand
  End If

End Function
3 Likes

Outstanding!! A million times, Thank You!! It works flawlessly. And you even added the section for turning off the viewer if I switch tabs while the viewer is on. Just beautiful!

And now that I've examined what you did, I can see where I went wrong with all my attempts. I simply forgot about using the Else part of an 'If-Then' statement. And I was sooo close, too. LOL

I cannot say it enough, Thank You! This will make things much easier and quicker for me, and in addition, I have learned just a very small bit about coding.

And of course, Thanks goes out to Leo for the original script!