Refresh Titlebar

I am in search of a JScript function that can be called within a standard Opus function to refresh the titlebar when certain triggers occur (ie a quickfilter is set) that don't already have built-in script events.

Thanks in advance!

The available events are listed here:

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

If there isn't one for the thing you want, then there may not be any way to trigger a script in reaction to that, and you'd have to make-do with using another event that might happen less often, or maybe triggering the update as part of the command that makes the change (which might not work with the quick filter example, but could with others).

Leo,

thanks for replying. None of those will work, unfortunately. I did take a look at the following post that appears to work around this current limitation:

Lister Title Bar Clock

In addition, the following post appears to add actual commands to the available standard function (Opus or external) library available in the command editor:

Fast Search With Everything

I'm no coding expert, but there may be a path to yes through some lessons in these two scripts. Am I on to something, or is this just wishful thinking?

Seems like a legit idea.

You could create a custom scripting command which when executed runs a loop which queries the QuickFilter object of Lister's Tabs, and updates the Lister title when it detects the relevant QuickFilter change (be careful in your design not to have multiple instances of this command piling up needlessly since you'll be triggering it manually). Also limit the loop's frequency to something like 100 ms (by using DOpus.Delay).

Without understanding what exactly you are trying to accomplish, I can't give any more relevant hint(s).

@bytespiller Thanks for the response. I have a filter toolbar by letter, so if I click the "A" button, DOpus will apply the "A*" quickfilter. I have since added a quickfilter indicator to my title bar.

var quickFilterSet = tab.quickfilter.filter;
	var quickFilterFlag = ""
	
	if (quickFilterSet === '')
	{
		quickFilterFlag = "Off"
	} else 
	{
		quickFilterFlag = "On - Set to < " + quickFilterSet + " >"
	}

The filter works as expected. The title bar, however does NOT update until an established DOpus script event (ie OnActivateTab) triggers. I can click on another tab, then go back to the tab with the quickfilter and see the expected title bar change.

My thought was like yours, add the trigger via code to the quickfilter object. Just don't know how to go from there.

That said, I do realize the quickfilter, when set, is indicated on the filter bar. I simply want to see it in the title bar.

Ultimately, I would think being able to trigger a title bar update could be used for any number of indicators, not just quickfilter, but I digress.

Appreciate any input you might have!

I don't understand in which situation the titlebar fails to update.
I've tried to replicate what you've described and the lister title updates instantly:

function OnClick(clickData)
{
	var tab = DOpus.listers.lastactive.activetab;
	var quickFilterSet = tab.quickfilter.filter;	
	var quickFilterFlag = ""
	
	if (quickFilterSet === '')
	{
		quickFilterFlag = "Off"
	} else 
	{
		quickFilterFlag = "On - Set to < " + quickFilterSet + " >"
	}

	var dopusCommand = DOpus.NewCommand;
	dopusCommand.RunCommand('Set LISTERTITLE "' + quickFilterFlag + '"');
}

Obviously the code above requires setting the filter manually beforehand to have the output changed.

Here is the version which automatically resets the titlebar back to "Off" when the quickfilter gets disabled (or tab stops existing):

function resetTitleOnQuickFilterDisabled(tab)
{
	while(true)
	{
		tab.Update(); //  Re-synchronize the object with the tab's current state (see docs).
		var currentQuickFilterSet = tab.quickfilter != null ? tab.quickfilter.filter : '';
		if (currentQuickFilterSet === '')
		{
			var dopusCommand = DOpus.NewCommand;
			dopusCommand.RunCommand('Set LISTERTITLE "Off"');
			break;
		}
		else
		{
			DOpus.Delay(100);
		}

		//DOpus.Output("still going...");
	}
}

function OnClick(clickData)
{
	var tab = DOpus.listers.lastactive.activetab;
	var quickFilterSet = tab.quickfilter.filter;	
	var quickFilterFlag = ""
	
	if (quickFilterSet === '')
	{
		quickFilterFlag = "Off"
	} else 
	{
		quickFilterFlag = "On - Set to < " + quickFilterSet + " >"
	}

	var dopusCommand = DOpus.NewCommand;
	dopusCommand.RunCommand('Set LISTERTITLE "' + quickFilterFlag + '"');

	if (quickFilterSet != '')
	{
		resetTitleOnQuickFilterDisabled(tab)
	}
}

Your code works, but as you say it requires the filter be set first, then the button or script trigger your OnCLick function to update the title.

So how would I take an existing button with the following code:

@toggle
Set QUICKFILTER A*

And incorporate the OnClick event to immediately update the title bar?

Having scripts which never complete, and sit in an endless loop with a delay or timer is not something we recommend at all, by the way.

Here is the command provider script, you just have to drag & drop it to Toolbars > Scripts in the Preferences to install it:

function OnInit(initData) // Called by Directory Opus to initialize the script
{
	initData.name = "Command.QuickFilterStatusOnTitlebar";
	initData.version = "1.0";
	initData.default_enable = true;
	initData.min_version = "12.0";

	var cmd = initData.AddCommand();
	cmd.name = "QuickFilterStatusToListerTitle";
	cmd.label = "QuickFilterStatusToListerTitle";
	cmd.method = "Command_QuickFilterStatusToListerTitle";
}

function Command_QuickFilterStatusToListerTitle(commandData)
{
	var tab = DOpus.listers.lastactive.activetab;
	var quickFilterSet = tab.quickfilter.filter;
	var quickFilterFlag = ""

	if (quickFilterSet === '')
	{
		quickFilterFlag = "Off"
	} else
	{
		quickFilterFlag = "On - Set to < " + quickFilterSet + " >"
	}

	var dopusCommand = DOpus.NewCommand;
	dopusCommand.RunCommand('Set LISTERTITLE "' + quickFilterFlag + '"');

	if (quickFilterSet != '')
	{
		resetTitleOnQuickFilterDisabled(tab)
	}
}

function resetTitleOnQuickFilterDisabled(tab)
{
	while(true)
	{
		tab.Update(); //  Re-synchronize the object with the tab's current state (see docs).
		var currentQuickFilterSet = tab.quickfilter != null ? tab.quickfilter.filter : '';
		if (currentQuickFilterSet === '')
		{
			var dopusCommand = DOpus.NewCommand;
			dopusCommand.RunCommand('Set LISTERTITLE "Off"');
			break;
		}
		else
		{
			DOpus.Delay(100);
		}

		//DOpus.Output("still going...");
	}
}

This will now give you a new custom command QuickFilterStatusToListerTitle which you can use in your Standard Opus Function.


It will even be listed in a Command menu.

You do your stuff in the Standard Function, and use it at the end simply by calling it like this:

@toggle
Set QUICKFILTER A*
QuickFilterStatusToListerTitle

All this is quick & dirty educational example, you'll probably have to tweak it further (or make it from scratch).

Yes, it's a pure hack, and it's easy for this to cause all kinds of side effects (or at least impact the performance) especially if one is not careful. It should definitely be viewed only as a curiosity or proof of concept (as in "it's possible with Opus even if it's not recommended").

@bytespiller and @Leo Thanks for the input. Yes, this is mostly an exercise in curiosity. I will mess with this and see how it goes.

Thanks again!

It could delay shutdown/restart of Opus and Windows as well, since we may wait a while for scripts to finish before giving up & killing them.

And may also make editing scripts impossible if we don't let a new version load while an old is still running. Or confusing, if the old versions continue to run alongside the new one each time an edit is made... It's a can of worms, I think. :smiley:

(I'm not sure what we do currently, but it's subject to change even if it doesn't happen right now.)