GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Copy/Move items to the tab next to current active tab (script button)


Here is a bit of code for finding the tab next to current active tab.
I couldn't find an easier way to do it, maybe code could be simpler.

As an example, I use it here to copy/move selected items in current active tab to the tab folder next to my current tab.

It could easily be extended to get previous tab too (keeping enumTabs previous item in the loop).

function OnClick(clickData)
	var enumTabs = new Enumerator(clickData.func.sourcetab.lister.tabs);
	var bActiveTabFound = false;
    while ( !bActiveTabFound && !enumTabs.atEnd() ) {
		bActiveTabFound = (enumTabs.item().visible);  // active tab in lister has been found

	var nextTab = null;
	if ( bActiveTabFound && !enumTabs.atEnd() ) {
		// if tab is found, enumTabs.item = the tab next to active tab in Lister
		// => this is what we want here
		nextTab = enumTabs.item();
	} // enumTabs is at end, meaning no other tab is next to active tab

	// move selected files/folders to next tab (if any)
    var cmd = clickData.func.command;
	if (nextTab != null)
	    cmd.RunCommand("Copy MOVE TO=\""+nextTab.path+"\"");