Merge Filter conditions

Is there a (preferably easy) method to merge Filter patterns? I mean I have a made a couple of buttons, each toggling the hide filter for a certain name pattern, for example

Button 1

Set HIDEFILTERFILENAME !*.sql

Button 2

Set HIDEFILTERFILENAME #*.sql

and so forth.

Pressing one of the buttons will toggle the hide filter for that pattern (and it conveniently shows the toggle on the button as well). Now, pressing another button will apply that filter instead of the first one rather than in addition to it. Is there a way to make it filter on both conditions at the same time ?

I know I could create another (3rd) button that combines the Filter conditions of the other two. But that approach gets hard to maintain and then out of control as the number of Filters increase, so it's not really a solution. Actually, it's not even a workaround (it has a greater overhead than the entire problem it is aimed to solve).

I don't think there's anything built-in. If you used QuickFilters, you could write a script that manipulates the settings based on the QuickFilter object.

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/QuickFilter.htm

1 Like

Yes, I was afraid it could only be done by scripting but that would hardly qualify as "preferably easy". I guess I'd also have manage the states of the buttons by script (if that's even possible) and I also think it would require modifying the each time a new button with a new condition was added. That goes way beyond being worth to be done. :slightly_frowning_face:

Scripts can find out what the current filter pattern is and modify that. If you only need it to work with certain simple, known patterns then making the script combine them should be easy enough (especially if it's always the script generating the patterns, and it ignores any pattern set by hand that it doesn't understand).

If you make the script add a Script Command, you could then create buttons which run that command and pass it different file extensions (or other types of patterns), without having to modify the script each time you add a new button.

Is it possible to alter/read the state (toggle?) of the buttons from the script (so that it would not only be able to turn on the filter for a pattern but to turn off as well, hitting the same button)?

You should be able to do that using variables which the script sets/deletes. If you pass in the variable name that the button tests as an argument to the script's command, that would probably be the easiest way.

In the script, you'd want to set (or delete) a variable on the folder tab, via the Tab.Vars object, and then tell Opus it should update the state of toolbar buttons via the Command.UpdateToggle method.

In each button, you'd use @toggle:if $tab:MyVariableName or similar to make the button appear pushed in when MyVariableName exists on the active folder tab. (This must be done on the very first line of the button.)

1 Like

@Leo I've run into a minor problem. Whenever I try to assign a value (the new filter pattern) to format.hide_files,

var func = scriptCmdData.func;
var format = func.sourcetab.format;
...
format.hide_files = combinedFilter;

I get an error message:

...
 2020-10-19 12:10 MultiFilter:  Error at line 111, position 5
 2020-10-19 12:10 MultiFilter:  A method was called unexpectedly (0x8000ffff)
...

It seems that I can read that property (if there are any values set for the current folder, that is returned) but I cannot write it.
Any tips on what am I doing wrong? Is Format.hide_files read-only?

Most properties are read-only. To change them, have the script run the same commands you would run from a button, via the Command object (Command.RunCommand if it's just a one-line command you need to run).

A Command object is given to you, set up already to work on the current lister/folder/tab, via scriptCmdData.func.command

1 Like

Using the @toggle: if $tab:etc trick with the Tab variables and with the aid of the Command object I was able to build an add-in script that does exactly what I wanted. Thank you very much for the help, @Leo
Another thanks goes to @lxp for drawing my attention to the fact that I can modify the Filter Bar conditions using the QuickFilter object. Though it was of no use here, I rely on the Filter Bar quite often and now I'm thinking about creating buttons/hotkeys for the filter terms most frequently used.

2 Likes

One more question, if I may, @Leo.

I noticed that when I put two such buttons (the ones that can be toggled) into a Three-button, the state of that Three-button only reflects the state of the first of the buttons. Is it possible to make the Three-button change its state for either of the buttons, that is, become toggled if either of the sub-buttons is toggled and become untoggled if none of the sub-buttons is toggled? I also tried it with a menu and I can check all the button states there separately but on the other hand it doesn't show any of the states on the menu itself.

Not automatically; it'll always show the state of the main left-click button.

You could make the left-click button's toggle state check all three button's variables, or make the script set the left button's variable when any of the three are enabled.

I see. There's an example for testing for multiple commands as well:

@toggle:if Set VIEW=Details;Set COLUMNSTOGGLE=thumbnail

I've tried using that with Tab variables:

@toggle:if $tab:mfpn_h_usp;$tab:mfpn_s_usp

But that didn't work either. Is it not possible to test for two Tab variables the same way as testing for multiple commands, or did I just screw up something with the syntax?

EDIT: nevermind, I've managed to modify the script so that it handles a separate value for the button and the hide/show filters with satisfying results.