syncContent: function () {
    var file = require("sdk/io/file");
    var info = {
      host: require("./hostname").hostname,
      profileDir: file.basename(require("sdk/system").pathFor("ProfD"))
    };

    info.profileID = (info.host + "-" + info.profileDir).replace(/[\.\$\[\]\#\/]/g, "");
    this.clientId = info.profileID;

    var contentTypes = [
      'tabs',
      'downloads',
      'addons',
      'favicons',
      'snippets'
    ];

    contentTypes.forEach(function(type) {
    });

    this._processContentType('tabs');
    this._processContentType('downloads');
    this._processContentType('addons');
    this._processContentType('favicons');
    this._processContentType('snippets');
  },
Example #2
0
    function doPaste()
    {
        var item = commando.getSubscope();
        var path = (local.cut || local.copy).data.path;
        var ioFile = require("ko/file");
        var newPath = ioFile.join(item.data.path, ioFile.basename(path));

        if (local.cut)
            ioFile.move(path, newPath);
        else
            ioFile.copy(path, newPath);

        item.isExpanded = false;
        commando.clear();

        if (local.cut)
        {
            commando.tip('Moved "'+local.cut.name+'" here');
            local.cut = null;
        }
        else
        {
            commando.tip('Copied "'+local.copy.name+'" here');
            local.copy = null;
        }
    }
Example #3
0
    var getShortcuts = function()
    {
        // Reload shortcuts when a change is detected.
        var koDoc = ko.views.manager.currentView.koDoc;
        var koFile = koDoc.file || {};
        var scopeVersion = scope.shortcutsVersion + (koFile.path || "");
        if (shortcutsVersion != scopeVersion) {
            log.debug("Updating shortcut cache");

            shortcutsCache = JSON.parse(scope.getShortcutsAsJson());
            shortcutsVersion = scopeVersion;

            var spref = prefs.getPref("scope-files-shortcuts");

            for (let x=0;x<spref.length;x++)
            {
                let [shortcut, path] = spref.getString(x).split(":");
                shortcutsCache[shortcut] = path;
            }

            if ("baseName" in koFile)
            {
                log.debug("Including koDoc.file shorcuts");
                shortcutsCache["%d"] = ioFile.basename(koFile.dirName);
                shortcutsCache["%D"] = koFile.dirName;
            }

            var url = require("sdk/url");
            var curProject = partSvc.currentProject;
            if (curProject)
            {
                log.debug("Including curProject shorcuts");
                shortcutsCache["%i"] = curProject.liveDirectory;
                shortcutsCache["%P"] = url.URL(curProject.url).path;
            }

            shortcutsCache["%w"] = url.URL(ko.places.getDirectory()).path;
        }

        if ( ! "observing" in getShortcuts)
        {
            log.debug("Adding shortcut pref observer");

            getShortcuts.observing = true;

            prefs.onChange("scope-files-shortcuts", function()
            {
                shortcutsVersion = -1;
            });
        }

        return shortcutsCache;
    }
Example #4
0
 this.create = (path, name) =>
 {
     if (name) path = ioFile.join(path, name);
     
     if (ioFile.exists(path))
     {
         throw new Error("File already exists: " + ioFile.basename(path));
     }
     
     ioFile.open(path, "w").close();
     
     require("ko/dom")(window.parent).trigger("folder_touched", {path: ioFile.dirname(path)});
     
     return true;
 }
exports.autocompleteValues = function (data, emit) {

    var optValues,
        userVal = data.value,
        dir = file.dirname(userVal),
        base = file.basename(userVal);

    if (file.exists(userVal)) {
        if (userVal.match(/(?:\/|\\)$/)) {
            optValues = file.list(userVal).map(function (fileInDir) {
                return file.join(userVal, fileInDir);
            });
        }
        else {
            optValues = [userVal];
        }
    }
    else if (file.exists(dir)) {
        optValues = file.list(dir).filter(function (fileInDir) {
            return fileInDir.indexOf(base) === 0;
        }).map(function (fileInDir) {
            return file.join(dir, fileInDir);
        });
    }
    
    
    optValues = data.dirOnly ?
        optValues.filter(function (optValue) {
            try {
                return getFile(optValue).isDirectory();
            }
            catch (e) {
                return false;
            }
        }) :
        optValues;

    return {
        listID: data.listID,
        optValues: optValues,
        userVal: userVal // Just for debugging on the other side
    };

};
Example #6
0
    function doRename()
    {
        var ioFile = require("sdk/io/file");
        var item = commando.getSubscope();

        var oldName = ioFile.basename(item.data.path);
        newName = commando.prompt("Renaming " + item.data.path, "New Name: ", oldName);

        if ( ! newName) return;

        var newpath = require("ko/file").rename(item.data.path, newName);

        item.data.path = newpath;
        item.name = newName;
        item.icon  = item.data.type == 'dir' ? item.icon : "koicon://" + newpath + "?size=16",

        commando.setSubscope(item, false);
        commando.reSearch();
        commando.focus();
    }
Example #7
0
    this.rename = (path, newName = null) =>
    {
        if ( ! newName)
        {
            var oldName = ioFile.basename(path);
            newName = require("ko/dialogs").prompt("Renaming " + path,
            {
                label: "New Name: ",
                value: oldName
            });

            if ( ! newName) return;
        }

        var mkCommon = require("ko/windows").getMain().ko.moreKomodo.MoreKomodoCommon;
        var result = mkCommon.renameFile("file://" + path, newName, false);
    
        require("ko/dom")(window.parent).trigger("folder_touched", {path: path});
        
        return result;
    }
Example #8
0
    var parsePaths = function(query, subscope, opts)
    {
        query = query.replace(isep, sep); // force os native path separators

        log.debug("Parsing paths for query: " + query + ", and path: " + subscope.path);
        
        if (query == "") return [query, subscope, opts];
        
        var _query = query.split(sep); // Convert query to array (split by path separators)
        var recursive = _query.length >= 1 ? !! _query.slice(-1)[0].match(/^\W/) : false;
        
        // Shortcuts
        if (opts["allowShortcuts"]) {
            var shortcuts = getShortcuts();
            if (query.match(/^[\w~%_\-]+(?:\/|\\)/) && (_query[0] in shortcuts))
            {
                log.debug("Running query against shortcuts");
    
                query = query.replace(_query[0], shortcuts[_query[0]]);
                opts["allowShortcuts"] = false;
                opts["cacheable"] = false;
                return parsePaths(query, subscope, opts);
            }
        }

        // Absolute paths
        var dirname = _dirname(query);
        if (query.indexOf(sep) !== -1 && (_ioFile("exists", query) || _ioFile("exists", dirname)))
        {
            log.debug("Query is absolute");

            opts["recursive"] = recursive;
            opts["fullpath"] = true;
            opts["cacheable"] = false;
            subscope.name = "";

            if (query.substr(-1) == sep)
            {
                subscope.path = query;
                query = "";
            }
            else
            {
                subscope.path = dirname;
                query = ioFile.basename(query);
            }
            
            if (subscope.path.substr(-1) != sep) 
                subscope.path = subscope.path + sep
                
            return [query, subscope, opts];
        }

        var view = ko.views.manager.currentView;
        if (view && view.koDoc && view.koDoc.file)
        {
            // Relative paths
            var isRelative = query.substr(0,2) == ("." + sep) || query.substr(0,3) == (".." + sep);
            var url = require("sdk/url");
            var curProject = partSvc.currentProject;
            if (curProject)
            {
                log.debug("Including curProject shorcuts");
                shortcutsCache["%i"] = curProject.liveDirectory;
                shortcutsCache["%P"] = url.URL(curProject.url).path;
            }

            shortcutsCache["%w"] = url.URL(ko.places.getDirectory()).path;
            var curProject = partSvc.currentProject;
            var cwd = curProject ? curProject.liveDirectory : ko.uriparse.URIToPath(ko.places.getDirectory());
            var relativePath = cwd + sep + query;
            dirname = _dirname(relativePath);
            if (isRelative && (_ioFile("exists", relativePath) || _ioFile("exists", dirname)))
            {
                log.debug("Query is relative");

                opts["recursive"] = recursive;
                opts["fullpath"] = true;
                opts["cacheable"] = false;
                subscope.name = "";

                if (query.substr(-1) == sep)
                {
                    subscope.path = relativePath;
                    query = "";
                }
                else
                {
                    subscope.path = dirname;
                    query = ioFile.basename(relativePath);
                }

                if (subscope.path.substr(-1) != sep)
                    subscope.path = subscope.path + sep

                return [query, subscope, opts];
            }

            return [query, subscope, opts];
        }

        return [query, subscope, opts]
    }
Example #9
0
    this.onSearch = function(query, uuid, onComplete)
    {
        log.debug(uuid + " - Starting Scoped Search");

        activeUuid = uuid;

        var opts = {
            "maxresults": ko.prefs.getLong("commando_search_max_results", 50),
            "allowShortcuts": ko.prefs.getBoolean("commando_allow_shortcuts", true),
            "recursive": true,
            "usecache": true,
            "cacheable": true
        }

        // Detect directory to search in
        var curProject = partSvc.currentProject;
        var subscope = commando.getSubscope();
        if ( ! subscope && curProject)
        {
            subscope = {name: curProject.name.split(".")[0], path: curProject.liveDirectory};
        }
        else if ( ! subscope)
        {
            var placesPath = ko.uriparse.URIToPath(ko.places.getDirectory());
            subscope = {name: ioFile.basename(placesPath), path: placesPath};
        }
        else
        {
            subscope.path = subscope.data.path;
            opts["cacheable"] = false;
        }

        [query, subscope, opts] = parsePaths(query, subscope, opts);

        if (query == "")
            opts["recursive"] = false;

        if ( ! opts['recursive'])
            opts["usecache"] = false;

        // Set includes/excludes, if relevant
        if (curProject && subscope.path.indexOf(curProject.liveDirectory) === 0)
        {
            opts["excludes"] = curProject.prefset.getString("import_exclude_matches");
            opts["includes"] = curProject.prefset.getString("import_include_matches");

            opts["excludes"] = opts["excludes"] == "" ? [] : opts["excludes"].split(";");
            opts["includes"] = opts["includes"] == "" ? [] : opts["includes"].split(";");
        }

        opts["weightMatch"] = prefs.getBoolean('commando_files_weight_multiplier_match', 30);
        opts["weightHits"] = prefs.getBoolean('commando_files_weight_multiplier_hits', 20);
        opts["weightDepth"] = prefs.getBoolean('commando_files_weight_multiplier_depth', 10);

        var _opts = JSON.stringify(opts);
        log.debug(uuid + " - Query: "+ query +", Path: "+ subscope.path +", Opts: " + _opts);

        scope.search(query, uuid, subscope.path, _opts, function(status, results)
        {
            if (activeUuid != uuid)
            {
                if ( ! (uuid in local.warned))
                {
                    log.debug(uuid + " - No longer the active search, don't pass result");
                    local.warned[uuid] = true;
                }
                return; // Don't waste any more time on past search queries
            }

            if (results == "done") // search complete
            {
                // Since python is multi-threaded, results might still be processed
                // Todo: find proper solution
                onComplete();
                return;
            }

            var folderIcon = "chrome://komodo/skin/images/folder-closed.png";
            if (system.platform == "linux")
                folderIcon = "moz-icon://stock/gtk-directory?size=16";

            var _results = [];
            for (let x in results)
            {
                let entry = results[x];

                var [name, path, relativePath, type, description, weight] = entry;

                descriptionComplex = "<html:div class=\"crop rtl\" xmlns:html=\"http://www.w3.org/1999/xhtml\">";
                descriptionComplex += "<html:span dir=\"ltr\">"+description+"</html:span></html:div>";

                _results.push({
                    id: path,
                    name: name,
                    description: relativePath,
                    descriptionComplex: descriptionComplex,
                    crop: "start",
                    icon: type == 'dir' ? folderIcon : "koicon://" + path + "?size=16",
                    isScope: type == 'dir',
                    weight: weight,
                    scope: "scope-files",
                    descriptionPrefix: subscope.name,
                    data: {
                        path: path,
                        type: type
                    },
                    allowMultiSelect: type != 'dir'
                });
            }

            commando.renderResults(_results, uuid);
        });
    }