GP SoftwareTwitter
Opus FAQsManualCommandsObjects

GoExisting - open path, focusing existing tab if found on either side


#1

Jon very kindly made this script on this thread. It seems that it'll be useful to more people so I thought I'd repost it here with a more general name.

The script is also explained on the DearOpus scripts page.

The usage is GoExisting path
This will open the specified path. If it already exists in an open tab, on either side of a dual lister, that tab will be recycled and focused. It's similar to the findexisting argument, but it searches both sides of a dual lister.

Please anyone feel free to publish other versions, I just wanted to make a thread for the script.

Update:
ScriptWizard-enabled.

Download:
GoExisting.js.txt (5.75 KB)


Findexisting anyside
Findexisting anyside
Columns: Format My Date (define date columns using formatting syntax)
#2

For a long time now I have used a series of buttons tied to a modified GO script that defaults to NEWTAB=findexisting but my version did not check both sides of a DUAL. This is a very nice addition @jon and @playful and @jon's ++index[e.item().right ? 1 : 0]; technique taught me something I had not seen in action before.

I like to use ctrl and shift qualifiers to open in dual or open in NEW. Here is a version that does that.

[code]// GoExisting
// Original code written by @jon
// Tweaked by @playful and posted as version 1
// USEQUALKEYS support added by @aussieboykie
//
// This is a script for Directory Opus.
// See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
//
// Also see Findexisting anyside
//
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "GoExisting";
initData.desc = "";
initData.copyright = "";
initData.version = "1.1";
initData.default_enable = false;

var cmd = initData.AddCommand();
cmd.name = "GoExisting";
cmd.method = "OnGoExisting";
cmd.desc = "Equivalent of Go NEWTAB=findexistingdual";
cmd.label = "GoExisting";
cmd.template = "PATH";
}

// Implement the GoExisting command
function OnGoExisting(scriptCmdData)
{
var cmdPfx = 'Go "' + scriptCmdData.func.args.path + '"';
var cmdSfx = (scriptCmdData.func.qualifiers == "none") ? "":" USEQUALKEYS";
var cmdString = cmdPfx + cmdSfx;
if (scriptCmdData.func.sourcetab.lister.dual == 0) {
cmdString = cmdString + " NEWTAB=findexisting";
scriptCmdData.func.command.RunCommand(cmdString);
}
else {
if (!DoGoExisting(scriptCmdData, scriptCmdData.func.sourcetab.lister.tabs)) {
cmdString = cmdString + " NEWTAB";
scriptCmdData.func.command.RunCommand(cmdString);
}
}
}

function DoGoExisting(scriptCmdData, tabs)
{
var FSUtil = DOpus.FSUtil();
var e = new Enumerator(tabs);
var index = new Array(0, 0);
e.moveFirst();
while (!e.atEnd())
{
if (FSUtil.ComparePath(e.item().path, scriptCmdData.func.args.path))
{
if (scriptCmdData.func.sourcetab.right != e.item().right)
scriptCmdData.func.command.AddLine('Set FOCUS=toggle');
scriptCmdData.func.command.AddLine('Go TABSELECT ' + index[e.item().right ? 1 : 0]);
scriptCmdData.func.command.Run();
return true;
}
++index[e.item().right ? 1 : 0];
e.moveNext();
}
return false;
}
[/code]
Regards, AB


#3

Hey aussieboykie,
Thank you, it's great to see that thing evolve.

For the record I didn't tweak anything, only changed the name. :slight_smile:


#4

I liked the original name myself :slight_smile:


#5

Yeah I suppose descriptive names are overrated. Remember when you could get away with calling things v1, v2, v3, or calling the princess "kong" and the gorilla "cinderalla" Those where the days. :wink:


#6

@jon
I see why! Leaving names as they are won't yield problems, like when switching lang.. just kidding! o))

@aussie
Why is it, you only add the USEQUALKEYS switch to the GO command, when there are qualifiers held down?
Will there be any harm if USEQUALKEYS is always present and no qualifier held down? I'd say no, but not sure.


#7

@tbone

I'm sure you are right. A simple case of over engineering!

Regards, AB


#8

"Over engineering", I think I like that expression. o) Ok, thank you for clarifying. I am not familiar with that switch, never used it myself, but wanted to make sure to not miss a thing. I fixed the non-mirroring issue within the existing versions, will upload anytime soon. A nice weekened for all! o)