Copy\Move to last active source?

Hello. Can i Copy\Move to last active source with two dual listers opened? (not copy\paste or drag, via one button)

no, it's copy to destination, not to last active source lister. i have to windows with dual listers in each and want to copy from {s} to {s}

I don't think Opus keeps a history list of source tabs you could access. But we can keep our own and use v13's new Evaluator to create a dynamic button :sunglasses:

Give this a try. Might need a bit of fine-tuning. I leave adding the MOVE functionality to you as a little exercise :slight_smile:

function OnInit(initData) {
    initData.name = 'LogLastSource';
    initData.version = '2023-10-06';
    initData.url = 'https://resource.dopus.com/t/copy-move-to-last-active-source/46183';
    initData.desc = '';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

var vec = DOpus.Create().Vector();

function StoreLastSource(tab) {
    if (!tab) return;
    if (!tab.path) return;

    vec.push_back(tab.path);
    if (vec.count > 2) vec.erase(0);

    DOpus.Vars.Set('lastSource', vec(0));
    // DOpus.Output('lastSource: ' + vec(0));
}

function OnActivateLister(activateListerData) {
    if (activateListerData.active) return;
    StoreLastSource(activateListerData.lister.activetab);
}

Save EventLogLastSource.js.txt to

%appdata%\GPSoftware\Directory Opus\Script AddIns

Then place this button on your toolbar (paste the XML).

@label:"Copy TO=""" + Val("$glob:lastSource") + """

@nodeselect
Copy TO="{=Val("$glob:lastSource")=}"
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>@label</label>
	<icon1>#clipcopy</icon1>
	<function type="normal">
		<instruction>@label:&quot;Copy TO=&quot;&quot;&quot; + Val(&quot;$glob:lastSource&quot;) + &quot;&quot;&quot;</instruction>
		<instruction />
		<instruction>@nodeselect</instruction>
		<instruction>Copy TO=&quot;{=Val(&quot;$glob:lastSource&quot;)=}&quot;</instruction>
	</function>
</button>

How to use buttons and scripts from this forum

3 Likes

This button works in v12, just without the fancy dynamic label (which could be shown in the status bar):

@nodeselect
Copy TO="{$glob:lastSource}"

Off topic, I'm confused about the quotes and why it can't be like this. . .
@label:'Copy TO="' + Val("$glob:lastSource") + '"'

Improvement when using the Opus 13 dynamic label version:

The label width may change a lot when the path/variable changes, but toolbars won't know to update their layouts to suit the new width unless they're told.

You can do that by adding this line to the bottom of StoreLastSource in the script:

DOpus.Create.Command.UpdateToggle();
Full modified script
function OnInit(initData) {
    initData.name = 'LogLastSource';
    initData.version = '2023-10-06';
    initData.url = 'https://resource.dopus.com/t/copy-move-to-last-active-source/46183';
    initData.desc = '';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

var vec = DOpus.Create().Vector();

function StoreLastSource(tab) {
    if (!tab) return;
    if (!tab.path) return;

    vec.push_back(tab.path);
    if (vec.count > 2) vec.erase(0);

    DOpus.Vars.Set('lastSource', vec(0));
    // DOpus.Output('lastSource: ' + vec(0));

    DOpus.Create.Command.UpdateToggle();
}

function OnActivateLister(activateListerData) {
    if (activateListerData.active) return;
    StoreLastSource(activateListerData.lister.activetab);
}

(If anyone finding this needs to do similar with a non-script button, you can use @toggle:update for a similar effect.)

2 Likes