OnTabClick and OnSourceDestChange small issues (but solved)

This is perhaps only for documentation purposes - but I had some doubts about my solution. In a script that I use to react on changing folders, I found that Opus did not detect, in Dual lister mode, that I switched from source to destination or vice versa when this change did not involve also clicking on another (non-active) tab. So in addition to OnAfterFolderchange() and OnActivateTab() I added the event handler OnSourceDestChange() to handle this situation ) but then I found out that this event handler gave me the wrong tab - that is: the tab that is “left behind” when you change from source to destination:

function OnAfterFolderChange(AfterFolderChangeData) {
	// Called after a new folder is read in a tab
	if (AfterFolderChangeData.result != true) {
		DOpus.Output("Folder was not read properly!");
	return;
	}
	RunNewFolderFunction(AfterFolderChangeData.tab);
}
function OnActivateTab(ActivateTabData) { // Called after another tab was clicked
	RunNewFolderFunction(ActivateTabData.newtab);
	return false;
}
function OnSourceDestChange(SourceDestData) {
	// We can't do anything with the received object because OnSourceDestChange()
	// gives the OLD tab. So we fetch tne new one from DOpus, then run our core function:
	var newtab = DOpus.Listers.LastActive().activetab;
	RunNewFolderFunction(newtab);
}

function RunNewFolderFunction(tab) {
	//... Whatever it is we want to happen after the folder change
}

I suppose this is on purpose: SourceDestData gives the old tab as an object, not the new one. Now this was easy to solve, by invoking DOpus.Listers.LastActive().activetab.

In fact I first tried other things - the event handler OnTabClick() was the closest thing I could find, unfortunately this event handler does not react on a standard mouse-click, it has to be a combination with a key (like CTRL or ALT, etc) - but of course that’s not what one wants to do at every folder change (not to speak of its side-effects - in this case: locking the tab, or whatever). I suppose this is also by design - although I do not understan why OnTabClick() seems designed not to react on a standard mouse click. Would it hurt anyone if it did? My feeling is that this event handler would have been the more straightforward way to manage tab clicks.

But, as I said: the solution via the OnSourceDestChange() handler works, and this post can be considered “for documentation”.

OnBeforeFolderChange and OnAfterFolderChange are events that happen when a tab navigates to a folder. They don't fire when you change to another tab.

OnTabClick exists to allow scripts to add gestures to the tabs when clicking them with different things held down. It's not the event to use for tab activation, and there are also other ways to activate a tab without clicking on it.

1 Like

Ok but the point was to activate something when clicking on an already-active tab, or simply clicking within the non active lister window of a dual-lister display. For those, I did not find “multiple” event handlers but just one: OnSourceDestChange(). I take your explanation as a confirmation that my solution is sound, and the most logical (or even only feasible) way to do it.

I remain sceptic about two things. First, as I said, I don’t see why OnTabClick() wouldn’t be logically improved by reacting to a standard click. Not only do I see no harm in it, but it seems the most logical way to treat clicks on an already active tab. Second: OnSourceDestChange() could have delivered an object that contains both an oldtab and newtab object - this seems very logical to me.

Those are just marginal considerations without much further ado.