Save and restore QuickFilter settings

This add-in saves and restores the quickfilter settings per folder when navigating in a tab. It's useful if you don't want to keep a quickfilter in a newly opened folder (Preferences / File Displays / FAYT and Filter Bar Options / Clear Quick filter automatically when changing folders), but like to automatically restore a quickfilter when coming back to a previously used folder.

The quickfilter definitions are stored with the tab, so they won't affect folders in other tabs and they will be gone once the tab is closed.

function OnInit(initData) {
    initData.name = 'SaveQuickFilter';
    initData.version = '2023-02-19';
    initData.copyright = '';
    initData.url = 'https://resource.dopus.com/t/save-and-restore-quickfilter-settings/43718';
    initData.desc = 'Save and restore QuickFilter settings';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnBeforeFolderChange(beforeFolderChangeData) {
    var tab = beforeFolderChangeData.tab;
    if (tab.quickfilter.filter == '') return;
    tab.vars.Set(String(tab.path), tab.quickfilter.filter);
}

function OnAfterFolderChange(afterFolderChangeData) {
    var tab = afterFolderChangeData.tab;
    var tabPath = String(tab.path);
    if (tabPath == 'undefined') return; // this seems to potentially be the case when Layouts or Tabgroups get opened

    if (!tab.vars.Exists(tabPath)) return;

    var cmd = DOpus.Create().Command();
    cmd.SetSourceTab(tab);
    cmd.RunCommand('Set QUICKFILTER="' + tab.vars.Get(tabPath) + '"');
}

Save EventSaveQuickFilter.js.txt to

%appdata%\GPSoftware\Directory Opus\Script AddIns

and use this button to turn the add-in on and off:

@toggle:invert
Prefs SCRIPTDISABLE="EventSaveQuickFilter.js*,toggle"
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>SaveQuickFilter</label>
	<icon1>#filterfolder</icon1>
	<function type="normal">
		<instruction>@toggle:invert</instruction>
		<instruction>Prefs SCRIPTDISABLE=&quot;EventSaveQuickFilter.js*,toggle&quot;</instruction>
	</function>
</button>

How to use buttons and scripts from this forum

5 Likes

hello. it's pretty good. but how i can to delete a saved filter?

Closing the tab and opening a new one should clear any filter saved for that tab. (At least, based on my reading of the root post.)

(There are also some add-ins on here that let you look and manage at variables in general, which could be used to delete the tab variable that stores the filter. I'm not sure which is the best one these days, but the first few posts here have some options: Search results for 'variables #buttons-scripts' - Directory Opus Resource Centre )

1 Like

Thanks. Global Variable Buttons and Management Dialog are good.
but i see no variables for this script with them. there's for EveryThingSize, some others, but not for this script.

Yes, because this script limits the scope to the tab level.

If you were asking because the filter gets re-applied (but shouldn't) when navigating, try this version:

EventSaveQuickFilter.js.txt (2023-06-05)

1 Like

this works great!

I agree that this is worth doing.
I have added it to my navigation toolbar with a few changes.
I have modified this to be an icon toggle run from a tab focused variable.
The highlighting doesn't show much where I have the button placed, but the button still needs the code AFAIK for now.

@toggle invert
@if:$tab:QF
@set tab:QF
Prefs SCRIPTDISABLE="EventSaveQuickFilter.js*,toggle"
@if:else
@set tab:QF=1
@icon:#default:filterfield,set $tab:QF
Prefs SCRIPTDISABLE="EventSaveQuickFilter.js*,toggle"

I also added Set Quickfilter From Clipboard in a dropdown menu with the additional line

tmp = tmp.replace(/-/g, '|');

This helps me filter photos that are date and time named in my personal naming scheme.

Save Quickfilter.dcf (2.9 KB)

Nav1

Nav2

Thank you lxp for the nice script. and Thanks David your button is very useful for me. I have been also added your button in my navigation bar.

The default search box doesn't save the search keyword which windows file explorer does. Its a request if possible please write a script for the default search box (which at the toolbar not the find pane) for remember search keyword

1 Like

This box sends its queries directly to Windows Search. It's not accessible from a script, I am afraid.

This is super useful! Sort of makes we wish we had Excel like dropdown arrows to the right of the text label of each column header that would bring up a dropdown menu with the various filtering options like manual text input and a checkbox list of all the different values in that column.

2 Likes

Did you peek at my to-do list? :smiley:

1 Like

Crazy coincidence!

Hi,
I tried your button code provided, but I noticed that while the button highlights correctly, the icon doesn't toggle as expected.

I managed to fix this by additionally placing the @icon (whithout set) within @if branches . Here is the modified version that works correctly for me:

@toggle invert
@if:$tab:QF
@set tab:QF
//add the line below
@icon:#default:filterfield, $tab:QF
Prefs SCRIPTDISABLE="EventSaveQuickFilter.js*,toggle"

@if:else
@set tab:QF=1
@icon:#default:filterfield,set $tab:QF
Prefs SCRIPTDISABLE="EventSaveQuickFilter.js*,toggle"

By repeating the @icon line in both logic paths, the icon now switches correctly along with the variable state. I'm curious if the original button icon toggling still works correctly on your end...
Otherwise it might be a minor bug in DOpus.

@PYCHBI
Sorry I didn't answer sooner.
I have been away and didn't have access to a computer with Directory Opus.

I can't get the @icon to work at all as I have written the button.
I think it did work at one time.
The idea was to dynamically display a different icon when the button appears highlighted by the toggle.

The button used #default:filterfolder in the button's show image dialog.
2026-02-11-13-26-20-196x58

It was supposed to change to #default:filterfield when the button was highlighted.
2026-02-11-13-26-38-196x58

Let's look at how the button was supposed to work.
@if:$tab:QF asks if there is a variable named QF with Tab scope .
If there is, delete the variable QF. @set tab:QF
and then Toggle the script off.

If there isn't a variable named QF with Tab scope, create a variable named QF with tab scope and a value equal to 1 .
@if:else
@set tab:QF=1
Then display the dynamic icon if there exists a variable named QF with Tab scope.
@icon:#default:filterfield,set $tab:QF
and then toggle the script on.

I don't think variables with tab scope were ever intended to be used for something like this.
I'll think on this some more. This can probably be written better using Evaluator.

1 Like

@PYCHBI
Try this instead.

@toggle:invert
Prefs SCRIPTDISABLE="EventSaveQuickFilter.js*,toggle"
@icon:#default:filterfield,Prefs SCRIPTDISABLE="EventSaveQuickFilter.js*,enable"

Set up the button with Folder Filter as the icon.
When clicked and the script is enabled, the icon changes to Filter Field .
Click again and it changes back to Folder Filter.

Thanks for catching this !

1 Like