qpl guy
qpl guy

Reputation: 1

How to set the default directory in Komodo from an an extension?

I'm working on a KomodoIDE/KomodoEdit extension that creates a new file and then opens it in a new editing tab using

...
var obsvc = Components.classes["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
...
Display.initWithPath(Target.path);
Display.append(what);

try {
  obsvc.notifyObservers(null, 'open-url', "file://" + Display.path);
} catch (e) {
  alert(e);
}

which works, but I would also like it to set Komodo's default directory to the same directory where this file lives, but I don't see a way to do that automatically.

I found the doCommand...

ko.commands.doCommand('cmd_openDirectory')

but this just launches a file dialog that asks the user to pick a directory. I'd like to do something to set it programatically using something like...

obsvc.notifyObservers(null, 'open-directory', "file://" + Display.path);

(which I know doesn't work but is sort of the idea).

Upvotes: 0

Views: 562

Answers (2)

Paul Sweatte
Paul Sweatte

Reputation: 24637

The nsIFile interface provides this:

// Get current working directory

var file = Components.classes["@mozilla.org/file/directory_service;1"].
       getService(Components.interfaces.nsIProperties).
       get("CurProcD", Components.interfaces.nsIFile);

The Komodo preferences service would also be an option:

    var gprefs = Components.classes["@activestate.com/koPrefService;1"].
      getService(Components.interfaces.koIPrefService).prefs;
    gprefs.setStringPref("mruDirectory", "Display.path);

References

Upvotes: 0

qpl guy
qpl guy

Reputation: 1

I just discovered that the ko.places.manager object has a function to set the default Places window-pane directory. Below is an example of how I used it. The uri should be set to the full directory path and, in the case of Windows, backslashes should get escaped...

function SetPlace(ko, uri) {
    try {
    ko.places.manager.openDirURI("file:///" + uri.replace(/\\/g, "\\\\") );
    } catch(e) {
    alert("Could not set place to: " + uri.replace(/\\/g, "\\\\") + "\n" + e);
    }
}

Upvotes: 0

Related Questions