I have taken the liberty of adapting YankeeZulu's idea and turning it into a pop-up filter menu. The following code creates a $FilterMenu command which I usually access from my lister context (right click) menu. The screen grabs show how it works.
FilterMenu.vbs.txt (3.9 KB)
' $FilterMenu [filterflags] [clear]
'
' v1.0 (2014/06/04) Pop-up menu of user defined saved filters. Sample calls..
'
' 1. $FilterMenu [select]
' 2. $FilterMenu clear
' 3. $FilterMenu deselect
' 4. $FilterMenu hidenomatch,deselect
' 5. $FilterMenu hide,deselect
'
' Pops up a menu of saved filters then executes the selected filter or does nothing if escape is pressed.
' The default action is "select" if no filterflags are specified.
' The "clear" option is a special case, used to clear all active filters. No menu is displayed.
'
' See https://resource.dopus.com/t/select-by-filter-menu-button/18483/1 for YankeeZulu's original button code.
' Adapted by AussieBoykie to use a single choice pop-up menu rather than a multiple choice checklist.
option explicit
Function OnInit(ByRef initData) ' OnInit is called by DOpus to initialize the script
initData.name = "Choose Filter From Menu"
initData.version= "1.0"
initData.desc = "Adds the $FilterMenu command to Directory Opus"
initData.copyright = "Adapted by AussieBoykie from original code by YankeeZulu"
initData.default_enable = true
dim cmd : set cmd = initData.AddCommand()
cmd.name = "$FilterMenu" ' This is the name of the command being added
cmd.method = "Main" ' This is the routine to execute when the command is invoked
cmd.desc = initData.desc
cmd.label = initdata.name
cmd.template = "Args/M,Clear/S"
End Function
Function Main(ByRef scriptCmdData) ' This is the executable code
Dim argstring, cdf, dlg, File, Filter, Filters, Folder, FSO, i, list, menu, path, result, s
Set list = DOpus.NewVector : Set menu = DOpus.NewVector
Set cdf = scriptCmdData.Func
If cdf.args.got_arg.Clear Then ' Special case
ClearAll
Exit Function
End If
If cdf.args.got_arg.Args Then ' Build an argstring for FILTERFLAGS - e.g. select,hidenomatch
argstring = trim(cdf.args.Args(0))
For i=2 to cdf.args.Args.count
argstring = argstring & " " & trim(cdf.args.Args(i-1))
Next
argstring = replace(argstring," ",",",1,-1,1) ' Eliminate embedded spaces (change to inoffensive commas)
Else
argstring = "select" ' Default argstring is select
End If
path = DOpus.FSUtil.Resolve("/dopusdata\Filters\") ' This is where Opus user defined filters are stored
Set Filters = DOpus.FSUtil.ReadDir(path) ' This is the filters folder object
list(0) = "Clear all filters" : menu(0) = 0 ' No default selection
i = 0
Do
Set Filter = Filters.next
If Filters.error Then Exit Do
If LCase(Filter.ext) = ".ofi" Then
i = i + 1
If i = 1 Then ' If there is at least one filter then insert a separator
list(i) = "-" : menu(i) = 0
i = i + 1
End If
list(i) = Filter.name_stem : menu(i) = 0
End If
Loop While Not Filters.complete
set dlg = scriptCmdData.Func.Dlg
With dlg
.choices = list
.menu = menu
.show
i = dlg.result
End With
If i = 0 Then ' Do nothing
ElseIf i = 1 Then ClearAll ' Clear all filters
Else
s = "Select """ & dlg.choices(i-1) & """ FILTER FILTERFLAGS=" & argstring
DOpus.output s
With scriptCmdData.Func.Command
.addline(s)
.addline("Set AUTOSIZECOLUMNS")
.deselect=False
.run
End With
End If
End Function
Function ClearAll
Dim cmd
Set cmd = DOpus.NewCommand
With cmd
.addline "Set SHOWFILTERFILENAME="""""
.addline "Set HIDEFILTERFILENAME="""""
.addline "Set SHOWFILTERFOLDERS="""""
.addline "Set HIDEFILTERFOLDERS="""""
.addline "Set HIDEFILTERATTR="""""
.addline "Set SHOWFILTERATTR="""""
.addline "Set QUICKFILTERCLEAR"
.addline "Select NOPATTERN SHOWHIDDEN"
.addline("Set AUTOSIZECOLUMNS")
.run
End With
End Function
I added some buttons to my lister context menu to provide a right mouse click interface.
These could just as easily be added to a toolbar.
This is part of the filters menu that pops up when I right mouse click.
Here is the result of clicking Filter (Select) from the context menu and then Last5Days.
Button code is $FilterMenu
Here is the result of clicking Show Filtered (Matched) from the context menu and then Last5Days.
Button code is $FilterMenu hidenomatch,deselect
Here is the result of clicking Show Filtered (UnMatched) from the context menu and then Last5Days.
Button code is $FilterMenu hide,deselect
You can also use $FilterMenu clear to clear all filters.
Regards, AB