Opposite of set SHOWFILTERFILENAME regex i.e. Read existing filter setting

Hi There
I am experimenting issuing sending these set internal commands from a Java script:
set SHOWFILTERFILENAME regex:
set SHOWFILTERFOLDERS regex:
set CLEARFILTERS

So far so good.
Now I want to read in the existing show filter into my script.
Is this possible?
Cannot find an equivalent internal command...

Many thanks as ever....

The Format object has that sort of information in it.

Thanks @Jon
Have incorporated and my script is looking cool.
JS as well.
Is there a method by which these fields can be written to?
Or do I have to use an internal command?
Thanks again

Thanks to help here I have this script which greatly enhances my productivity.
Upon invocation the script pops up a text box showing the current contents of the Folder Options > Show Filters > Filenames field.
The text can be edited and upon clicking Ok that field AND the Folder Names field is updated.
The Use regular expression checkbox is always checked for both File names and Folder Names.
So you can edit the filter of the current lister quickly and efficiently with a keystroke or button.

// 2019-01-29 Close Current Layout
// Original post from Leo
// 2020-12-09 Edit for Filtering purposes
// 2020-12-09 Want to add OR feature. Not started at this point

// 2020-12-11 Prompts with text field prepopulated with existing filter
//            Upon andit and Ok filter is adjusted accordingly
//            File and folder show filters set the same
//            RegEx file always set (i.e. checked) for both File and Folder show filter

function OnClick(clickData)
{
	DOpus.ClearOutput
	DOpus.Output ("000100 Start")

	var Dlg_Return
	var Str_Filter_ENTERED
	var Str_Filter_Existing = clickData.func.sourcetab.format.show_files
	var Bool_Filter_Existing_RegEx = clickData.func.sourcetab.format.show_files_regex
	DOpus.Output ("001000  Str_Filter_Existing          : TEST")
	DOpus.Output ("001010  Str_Filter_Existing          :" + clickData.func.sourcetab.format.show_files)
	DOpus.Output ("001020  Str_Filter_Existing          :" + Str_Filter_Existing)
	
	var dlg = clickData.func.Dlg; // creates a dialog object
    // nothing happens until you invoke the Show() or getstring() method
	dlg.getstring("Edit Show Filter:",Str_Filter_Existing,0,"OK|Cancel","Show Filter")
	DOpus.Output ("001110  dlg.Input                    :" + dlg.Input)
	if (dlg.Input == "undefined")
	{
		Str_Filter_ENTERED == ""
		DOpus.Output ("002100a Str_Filter_ENTERED           :" + Str_Filter_ENTERED + " set to empty string")
	}
	else
	{
		Str_Filter_ENTERED = dlg.Input
		DOpus.Output ("002150b Str_Filter_ENTERED           :" + Str_Filter_ENTERED + " set to dlg.Input")
	}

	DOpus.Output ("002000  Str_Filter_ENTERED entered   :" + Str_Filter_ENTERED)

    var cmd = DOpus.Create.Command()
      cmd.RunCommand("set SHOWFILTERFILENAME regex:" + Str_Filter_ENTERED)
      cmd.RunCommand("set SHOWFILTERFOLDERS regex:" + Str_Filter_ENTERED)
}

So far so good.
One thing that is not working is the attempt to handle the error whereby the text field in the popup text box is set to blank. I want this to have the effect of removing any existing filter.
dlg.Input returns "undefined" according to my DOpus.Output debugs.
But the test for this does not work.

The GetString method notes state the following:

The return value is the entered string, or an empty value if the dialog was cancelled

However it seems to return the string "undefined"
Below is a debug output for the following sequence

  1. Both file and folder show filters are blank for the current lister.
  2. Script is executed
  3. Popup with empty text field apprears (As expected as there is no filter text set)
  4. Click ok without entering any text.
  5. All files and folders disappear from the lister
  6. Inspecting the Folder Options > Show Filters > Filenames/Foldernames filed show they are now populated with the string "undefined"

This is consistent with the debug output below.
This if statement is deemed to be (unexpectedly) false
if (dlg.Input == "undefined")
In the test I am expecting the if statement above to be deemed true and then to see the following 2 lines of code executed

Str_Filter_ENTERED == ""
DOpus.Output ("002100a Str_Filter_ENTERED           :" + Str_Filter_ENTERED + " set to empty string")|

But this never happens as the if statement does not evaluate the condition as I am expecting.

000100 Start
001000 Str_Filter_Existing : TEST
001010 Str_Filter_Existing :
001020 Str_Filter_Existing :
001110 dlg.Input :undefined
002150b Str_Filter_ENTERED :undefined set to dlg.Input
002000 Str_Filter_ENTERED entered :undefined

Any help greatly appreciated

Try

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();

    DOpus.ClearOutput;

    var Str_Filter_Existing = clickData.func.sourcetab.format.show_files;

    dlg.GetString('Edit Show Filter:', Str_Filter_Existing, 0, 'OK|Cancel', 'Show Filter');

    if (dlg.result == 0) return;

    if (dlg.input == Str_Filter_Existing) return;

    var Str_Filter_ENTERED = (typeof dlg.input == 'string') ? 'regex:' + dlg.input : '';

    var cmdLine = ('Set SHOWFILTERFILENAME ' + Str_Filter_ENTERED);
    DOpus.Output(cmdLine);
    cmd.RunCommand(cmdLine);

    var cmdLine = ('Set SHOWFILTERFOLDERS  ' + Str_Filter_ENTERED);
    DOpus.Output(cmdLine);
    cmd.RunCommand(cmdLine);
}
1 Like

Thanks @lxp apologies for delay you know the muddle of life etc
I have run your script and it works of course perfectly failing to incorporate it into mine yet as I cannot for the life of me decode the line above.
Would you mind explaining?
I can see what it does when I run it and I need to drop the "regex:" string addition as that is build into my cmd.RunCommand differently.
I have worked out that (typeof dlg.input == 'string') is an evaluator of whether dlg.input comtains a string of not but that is about all.
In particular what is the function of the question mark ? ?

Gratitude as always...

what is the function of the question mark?

That is JavaScript's conditional operator. The line is the equivalent of

if (typeof dlg.input == 'string') {
    var Str_Filter_ENTERED = 'regex:' + dlg.Input;
} else {
    var Str_Filter_ENTERED = '';
}

More info e.g here:

Fantastic thanks @lxp!

My thanks again to Leo and LXP.
This script will bring up the current contents of
Folder Option >> Show Filters >> File names
field for editing.
Upon entering Ok the field (edited, unchanged or deleted i.e. so it is blank) will be applied.
The Regex checkbox is always marked.
The Folder names field is always set to whatever the File names field is set to. Regex checkbox for Folder names is also always set.

// 2019-01-29 Close Current Layout
// Original post from Leo
// 2020-12-09 Edit for Filtering purposes
// 2020-12-09 Want to add OR feature. Not started at this point

// 2020-12-11 Prompts with text field prepopulated with existing filter
//            Upon andit and Ok filter is adjusted accordingly
//            File and folder show filters set the same
//            RegEx file always set (i.e. checked) for both File and Folder show filter

function OnClick(clickData)
{
	DOpus.ClearOutput
	DOpus.Output ("000100 Start")

	var Dlg_Return
	var Str_Filter_ENTERED
	var Str_Filter_Existing = clickData.func.sourcetab.format.show_files
	var Bool_Filter_Existing_RegEx = clickData.func.sourcetab.format.show_files_regex
	DOpus.Output ("001010  clickData.func....show_files :" + clickData.func.sourcetab.format.show_files)
	DOpus.Output ("001020  Str_Filter_Existing          :" + Str_Filter_Existing)
	
	var dlg = clickData.func.Dlg; // creates a dialog object
    // nothing happens until you invoke the Show() or getstring() method
	dlg.getstring("Edit Show Filter:",Str_Filter_Existing,0,"OK|Cancel","Show Filter")
	DOpus.Output ("001110  dlg.Input                    :" + dlg.Input)
	if (dlg.Result == 0)
	{
		DOpus.Output ("002000a dlg.Result                   :" + dlg.Result)
		Str_Filter_ENTERED == ""
		DOpus.Output ("002100a Str_Filter_ENTERED           :" + Str_Filter_ENTERED + " set to empty string")
	}
	else
	{
		DOpus.Output ("002000b dlg.Result                   :" + dlg.Result)
//		Str_Filter_ENTERED = dlg.Input
//		Str_Filter_ENTERED = (typeof dlg.input == 'string') ? 'regex:' + dlg.input : '';
		Str_Filter_ENTERED = (typeof dlg.input == 'string') ? dlg.input : '';
		
		DOpus.Output ("002150b Str_Filter_ENTERED           :" + Str_Filter_ENTERED + " set to dlg.Input")
	}

	DOpus.Output ("002000  Str_Filter_ENTERED entered   :" + Str_Filter_ENTERED)

    var cmd = DOpus.Create.Command()
      cmd.RunCommand("set SHOWFILTERFILENAME regex:" + Str_Filter_ENTERED)
      cmd.RunCommand("set SHOWFILTERFOLDERS regex:" + Str_Filter_ENTERED)
}