Option Explicit Function OnInit(initData) initData.name = "Load All Thumbnails" initData.version = "1.0" initData.desc = "Load all thumbnails only in specific folders, without it being enabled globally" initData.copyright = "(c) 2019 Leo Davidson" initData.url = "https://resource.dopus.com/t/auto-load-thumbnails-only-in-specific-folders/33666" initData.default_enable = true initData.min_version = "12.17" Dim vecDefFolders Set vecDefFolders = DOpus.Create.Vector initData.config.Folders = vecDefFolders initData.config.PreCache = False initData.config_desc = DOpus.Create.Map( _ "Folders", "Folders which trigger the command. (One per line.)", _ "PreCache", "If True, thumbnails generate on folder change even if not in Thumbnails or Tiles modes.") 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 If (Not Script.config.PreCache) Then If (Not AreThumbnailsDisplayed(afterFolderChangeData.tab)) Then Exit Function ' Not displaying thumbnails, so do nothing yet. End If End If If (Not IsPathInVector(DOpus.FSUtil, afterFolderChangeData.tab.Path, Script.config.Folders)) Then Exit Function End If LoadAllThumbs afterFolderChangeData.tab End Function Function OnDisplayModeChange(displayModeChangeData) If (Script.config.PreCache) Then Exit Function ' We will have loaded them already when we changed folders. End If If (Not AreThumbnailsDisplayed(displayModeChangeData.tab)) Then Exit Function ' Not displaying thumbnails, so do nothing. End If If (Not IsPathInVector(DOpus.FSUtil, displayModeChangeData.tab.Path, Script.config.Folders)) Then Exit Function End If LoadAllThumbs displayModeChangeData.tab End Function Function AreThumbnailsDisplayed(tab) AreThumbnailsDisplayed = False Dim format, viewMode Set format = tab.format viewMode = format.view ' Check for Thumbnails or Tiles mode. If (viewMode = "thumbnails" OR viewMode = "tile") Then AreThumbnailsDisplayed = True Exit Function End If ' Also see if we're in Details or Power mode with the ' Thumbnail column turned on. (Note that we don't react to ' this being turned on by itself; we only notice if it is ' on after reading a folder or changing display modes.) If (viewMode = "details" OR viewMode = "power") Then Dim col For Each col in format.columns If (col.name = "thumbnail") Then AreThumbnailsDisplayed = True Exit Function End If Next End If End Function Function LoadAllThumbs(tab) Dim cmd Set cmd = DOpus.Create.Command cmd.SetSourceTab tab cmd.RunCommand "Show LOADALLTHUMBS" End 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