Welcome, guest | Sign In | My Account | Store | Cart
function relativePath(fromPath, toPath)
{
    var nsFileFrom = Components.classes["@mozilla.org/file/local;1"]
                          .createInstance(Components.interfaces.nsILocalFile);
    nsFileFrom.initWithPath(fromPath);
    var nsFileTo = Components.classes["@mozilla.org/file/local;1"]
                          .createInstance(Components.interfaces.nsILocalFile);
    nsFileTo.initWithPath(toPath);
    return nsFileTo.getRelativeDescriptor(nsFileFrom);
}

var currentView = ko.views.manager.currentView;
var cwd = currentView.document.file.dirName;
var path = ko.filepicker.openFile(cwd);
if (path) {
    var relpath = relativePath(cwd, path);
    var editor = currentView.scimoz;
    editor.insertText(editor.currentPos, relpath);
}

Diff to Previous Revision

--- revision 1 2010-07-14 18:10:13
+++ revision 2 2010-07-14 19:20:24
@@ -10,7 +10,7 @@
 }
 
 var currentView = ko.views.manager.currentView;
-var cwd = currentView.koDoc.file.dirName;
+var cwd = currentView.document.file.dirName;
 var path = ko.filepicker.openFile(cwd);
 if (path) {
     var relpath = relativePath(cwd, path);

History