OnOpenLister Behaviour

Here is a simple OnOpenLister test script.

[code]function OnInit(d)
{
d.name = "OnOpenLister Test";
d.default_enable = true;
}

function OnOpenLister(l)
{
var objcmd = DOpus.create.command;
var objlst = l.lister; // newly created lister object
DOpus.output("tab count = " + objlst.tabs.count);
var objtab = objlst.tabs(0); // first tab in new lister
DOpus.output("tab visible = " + objtab.visible);
DOpus.output("tab path = " + objtab.path);
}[/code]
When run with Opus v12.0.3. tab count is always 1, regardless of how many tabs are open and tab path is always blank.

OnOpenLister Test: tab count = 1
OnOpenLister Test: tab visible = true
OnOpenLister Test: tab path =

Am I missing something?

Regards, AB

The tabs haven't been opened yet. There's another event for when each tab opens.

I will of course try it, but the reason I didn't bother earlier is that the help for OnOpenTab reads...

The OpenTabData.tab property identifies the newly opened tab. Note that this method is not called when a new Lister is opened, irrespective of how many tabs it contains - instead, you can identify all the tabs in the newly opened Lister by implementing the OnOpenLister event.

Regards, AB

The manual is definitely not describing the current reality there, you're right.

You won't get OnOpenTab for the first tab in a new lister, but you will get it for others.

You need to use OnBeforeFolderChange or OnAfterFolderChange if you want to be notified of all the paths loaded into all tabs. Those both work for the initial tab and subsequent tabs.

Here's my test:

[code]function OnInit(initData)
{
initData.name = "testopen";
initData.desc = "";
initData.copyright = "(c) 2016 Leo Davidson";
initData.version = "1.0";
initData.default_enable = true;
}

function OnOpenLister(openListerData)
{
var objlst = openListerData.lister; // newly created lister object
DOpus.output("OnOpenLister L - tab count = " + objlst.tabs.count);
for (var i = 0; i < objlst.tabs.count; ++i)
{
var objtab = objlst.tabs(i); // first tab in new lister
DOpus.output("OnOpenLister [" + i + "] - tab visible = " + objtab.visible + " tab path = " + objtab.path);
}
}

function OnOpenTab(openTabData)
{
DOpus.output("OnOpenTab - tab visible = " + openTabData.tab.visible + ", tab path = " + openTabData.tab.path);

var objlst = openTabData.tab.lister;
DOpus.output("OnOpenTab - tab count = " + objlst.tabs.count);
for (var i = 0; i < objlst.tabs.count; ++i)
{
var objtab = objlst.tabs(i); // first tab in new lister
DOpus.output("OnOpenTab [" + i + "] - tab visible = " + objtab.visible + ", tab path = " + objtab.path);
}
}

function OnBeforeFolderChange(beforeFolderChangeData)
{
DOpus.output("OnBeforeFolderChange - path = " + beforeFolderChangeData.path + ", initial = " + beforeFolderChangeData.initial);
DOpus.output("OnBeforeFolderChange - tab visible = " + beforeFolderChangeData.tab.visible + ", tab path = " + beforeFolderChangeData.tab.path);
}

function OnAfterFolderChange(afterFolderChangeData)
{
if (afterFolderChangeData.result)
{
DOpus.output("OnAfterFolderChange (read success) - tab visible = " + afterFolderChangeData.tab.visible + ", tab path = " + afterFolderChangeData.tab.path);
}
else
{
DOpus.output("OnAfterFolderChange (read failure) - path = " + afterFolderChangeData.path);
}
}[/code]

Opening a layout with tabs for C:\ D:\ E:\ produces something like this:

testopen: OnOpenLister L - tab count = 1 testopen: OnOpenLister [0] - tab visible = true tab path = testopen: OnBeforeFolderChange - path = C:\, initial = true testopen: OnBeforeFolderChange - tab visible = true, tab path = testopen: OnOpenTab - tab visible = false, tab path = testopen: OnOpenTab - tab count = 2 testopen: OnOpenTab [0] - tab visible = true, tab path = C:\ testopen: OnOpenTab [1] - tab visible = false, tab path = testopen: OnAfterFolderChange (read success) - tab visible = true, tab path = C:\ testopen: OnBeforeFolderChange - path = D:\, initial = true testopen: OnBeforeFolderChange - tab visible = false, tab path = testopen: OnOpenTab - tab visible = false, tab path = testopen: OnOpenTab - tab count = 3 testopen: OnOpenTab [0] - tab visible = true, tab path = C:\ testopen: OnAfterFolderChange (read success) - tab visible = false, tab path = D:\ testopen: OnOpenTab [1] - tab visible = false, tab path = D:\ testopen: OnOpenTab [2] - tab visible = false, tab path = testopen: OnBeforeFolderChange - path = E:\, initial = true testopen: OnBeforeFolderChange - tab visible = false, tab path = testopen: OnAfterFolderChange (read success) - tab visible = false, tab path = E:\

Some of the events are running in parallel there, which confuses things. It's easier to see if I re-order things so everything that happens for each tab is grouped together:

[code]testopen: OnOpenLister L - tab count = 1
testopen: OnOpenLister [0] - tab visible = true tab path =

--- First tab (C:) ---

testopen: OnBeforeFolderChange - path = C:, initial = true
testopen: OnBeforeFolderChange - tab visible = true, tab path =

testopen: OnAfterFolderChange (read success) - tab visible = true, tab path = C:\

--- Second tab (D:) ---

testopen: OnOpenTab - tab visible = false, tab path =
testopen: OnOpenTab - tab count = 2
testopen: OnOpenTab [0] - tab visible = true, tab path = C:
testopen: OnOpenTab [1] - tab visible = false, tab path =

testopen: OnBeforeFolderChange - path = D:, initial = true
testopen: OnBeforeFolderChange - tab visible = false, tab path =

testopen: OnAfterFolderChange (read success) - tab visible = false, tab path = D:\

--- Third tab (E:) ---

testopen: OnOpenTab - tab visible = false, tab path =
testopen: OnOpenTab - tab count = 3
testopen: OnOpenTab [0] - tab visible = true, tab path = C:
testopen: OnOpenTab [1] - tab visible = false, tab path = D:
testopen: OnOpenTab [2] - tab visible = false, tab path =

testopen: OnBeforeFolderChange - path = E:, initial = true
testopen: OnBeforeFolderChange - tab visible = false, tab path =

testopen: OnAfterFolderChange (read success) - tab visible = false, tab path = E:[/code]

Maybe we need to fix the documentation and also add a new event that runs after a lister is open and all of its tabs have loaded. OnOpenLister is triggered too early if you want to work on all the tabs at once. The other events are useful if you want to do things to a single tab but things get complicated if you want to make decisions based on all the tabs.