如何在扩展程序中设置Komodo中的默认目录?

时间:2014-07-29 11:41:33

标签: komodo komodoedit

我正在开发一个KomodoIDE / KomodoEdit扩展程序,用于创建新文件,然后使用

在新的编辑选项卡中打开它
...
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);
}

有效,但我也希望将Komodo的默认目录设置为该文件所在的同一目录,但我没有看到自动执行此操作的方法。

我找到了doCommand ......

ko.commands.doCommand('cmd_openDirectory')

但这只是启动一个文件对话框,要求用户选择一个目录。我想做一些事情,使用像...这样的东西来编程设置它。

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

(我知道这不起作用但是有点想法)。

2 个答案:

答案 0 :(得分:0)

nsIFile接口提供:

// Get current working directory

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

Komodo偏好服务也是一个选择:

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

<强>参考

答案 1 :(得分:0)

我刚刚发现ko.places.manager对象具有设置默认Places窗口窗格目录的功能。下面是我如何使用它的一个例子。应该将uri设置为完整的目录路径,对于Windows,反斜杠应该被转义...

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);
    }
}