Deeply navigate into a complex folder tree on an unique path

I have many folder structures on my harddisk that are deeply nested. For such long pathes mostly there are parts in the middle that only consists of single nested subfolders (that is pretty common for source code repositories). It would be so nice to have a GO DEEP command that allows to skip all unique folders in both direction (backward/upward).

Example:

Assuming you want to navigate to a certain file Foo.java that is located at the following path:

D:\Svn\ProjectA[u]src\main\com\eads\space\mission\mars[/u]\data\parser\xml\Foo.java

The bold marked part in the middle of this path chain consists of 7 folders that only have a single subfolder. Thus it would be possible to just deeply navigate from src up to mars in one step by using such a convenient "GO DEEP" command (skipping all folders having only one subfolder and no files).

Is that a candidate for a new argument of the Go command or maybe a new script add-in?

PS: Unfortunately I have no idea (particurlarly the backwards way from deep to shallow) whether and how this can be done by a JScript.

Is anybody out there who can help? :thumbsup:

You should be able to write that pretty easily using javascript. Opus provides an object for reading directory listings, so you use that to count how many folders are below the folder you're about to go into, and go into its child folder instead if there is only one, then repeat the check with the newly chosen folder.

Maybe it's better to append the appropriate folders to a string and finally pass it to DOpus Go command. Otherwise there may be the transitions of the navigation operation visible?

Thanks for the hint, I will have a look to that.

Is there any example showing how to access {sourcepath$} in a JScript (needed for backward navigation)?

Is it mandatory to perform the directory reading using the Opus object (do you have an API link for me) or can it be done by using JScript file operations as well?

Scripting overview:
gpsoft.com.au/help/opus11/in ... ipting.htm

Scripting reference:
gpsoft.com.au/help/opus11/in ... erence.htm

The tab object's path property will tell you the tab's path:
gpsoft.com.au/help/opus11/in ... ng/Tab.htm

Ok, I think that should be possible to achieve for me. Thanks for the references.

Ok, here are both scripts for going downward and upward deeply.

@runonce
@dirsonly 
@script jscript

function goDownDeep(dir) {
  DOpus.NewCommand().RunCommand("Go \"" + dir + "\"");
  var enumItems = DOpus.FSUtil.ReadDir(dir);
  if (!enumItems.complete) {
    var item = enumItems.Next();
    if (item != null && item.is_dir && enumItems.complete) {
      DOpus.Delay(50);
      goDownDeep(item);
    }
  }
}

function OnClick(clickData) {
  var enumDirs = new Enumerator(clickData.func.sourcetab.selected_dirs)
  if (!enumDirs.atEnd()) {
    goDownDeep(enumDirs.item());
  }
}
@runonce
@script jscript

function goUpDeep(path) {
  if (path.test_parent) {
    DOpus.NewCommand().RunCommand("Go UP BACK");
    path.Parent();
    var enumItems = DOpus.FSUtil.ReadDir(path);
    if (!enumItems.complete) {
      var item = enumItems.Next();
      if (item != null && item.is_dir && enumItems.complete) {
        DOpus.Delay(50);
        goUpDeep(path);
      }
    }
  }
}

function OnClick(clickData) {
  goUpDeep(clickData.func.sourcetab.path);
}

Unfortunately DOpus crashed three times yesterday when using the GoUpDeep command. I guess DOpus doesn't like the fast calls of "Go UP BACK" each 50ms to walk along the parent path. Unfortunately the user needs some visual feedback to be aware that multiple folders were skipped.

I can't get it to crash. Was a crash dump created?

Here are slightly improved versions of both scripts:

Up:

[code]@script jscript

function goUpDeep(sourcetab, command) {
var oldPath = sourcetab.path;
if (oldPath.test_parent) {
command.RunCommand("Go UP BACK");
sourcetab.Update();
command.SetSourceTab(sourcetab);
if (!DOpus.FSUtil.ComparePath(oldPath, sourcetab.path)) { // Ensure we really changed folder.
var enumItems = DOpus.FSUtil.ReadDir(sourcetab.path);
if (!enumItems.complete) {
var item = enumItems.Next();
if (item != null && item.is_dir && enumItems.complete) {
DOpus.Delay(50);
goUpDeep(sourcetab, command);
}
}
}
}
}

function OnClick(clickData) {
goUpDeep(clickData.func.sourcetab, clickData.func.command);
}[/code]

Down:

[code]@script jscript

function goDownDeep(sourcetab, command) {
var oldPath = sourcetab.path;
command.RunCommand("Go FROMSEL");
sourcetab.Update();
command.SetSourceTab(sourcetab);
if (!DOpus.FSUtil.ComparePath(oldPath, sourcetab.path)) { // Ensure we really changed folder.
var enumItems = DOpus.FSUtil.ReadDir(sourcetab.path);
if (!enumItems.complete) {
var item = enumItems.Next();
if (item != null && item.is_dir && enumItems.complete) {
DOpus.Delay(50);
command.ClearFiles();
command.AddFile(item);
goDownDeep(sourcetab, command);
}
}
}
}

function OnClick(clickData) {
goDownDeep(clickData.func.sourcetab, clickData.func.command);
}[/code]

Yes, I have several crash dumps from yesterday, where should I send them?

Ok, I haven't had success in crashing the new version but I will let you know if it happens again.

Please email the crash dumps to leo@gpsoft.com.au

Maybe the new version won't crash anyway, but it's still worth us having a look in case there's a bug we can fix that might cause other problems.