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); }); }
(function () { const {Cc, Ci} = require("chrome"); var profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler); var prefs = require("ko/prefs"); var enabled = prefs.getBoolean("profilerEnabled", false); var activeProfiler = null; /** * Enable profiling, none of the other methods in this module will do anything * otherwise * * @returns {Void} */ this.enable = () => { enabled = true; } /** * Disable profiling, does not stop already active profilers * * @returns {Void} */ this.disable = () => { enabled = false; } /** * Start profiling * * If a name is given it will only run if the "profilerEnabledName" is set * to the same name. * * The named profilers are mainly intended for profiling code that runs on startup, * for anything else you should just call start() without a name. * * @param {String} name name of profiler (optional) * * @returns {Void} */ this.start = (name = "") => { if (name == "" && ! enabled) return; if (name) { if (prefs.getString("profilerEnabledName", "") !== name) return; } this.stop(activeProfiler); activeProfiler = name; var features = prefs.getString("profilerFeatures", "stackwalk,js").split(","); profiler.StartProfiler( prefs.getLong("profilerMemory", 10000000), prefs.getLong("profilerSampleRate", 1), features, features.length ); }; /** * Check whether a profiler is running * * @returns {Boolean} */ this.isActive = () => { return profiler.IsActive(); }; /** * Stop profiling * * @param {String} name * * @returns {Void} */ this.stop = (name = "") => { if ( ! profiler.IsActive() || name !== activeProfiler) return; profiler.StopProfiler(); }; /** * Pause profiling * * @param {String} name * * @returns {Void} */ this.pause = (name = "") => { if ( ! profiler.IsActive() || name !== activeProfiler) return; profiler.PauseSampling(); }; /** * Resume profiling * * @param {String} name * * @returns {Void} */ this.resume = (name = "") => { if ( ! profiler.IsPaused() || name !== activeProfiler) return; profiler.ResumeSampling(); }; /** * Save the log, this should be called before calling stop() * * Logs are saved to profiledir/profiler * * @param {String} name * * @returns {Void} */ this.save = (name = "") => { if ( ! profiler.IsActive() || name !== activeProfiler) return; if (name == "") name = "unnamed"; var sys = require("sdk/system"); var koFile = require("ko/file"); var profileDir = sys.pathFor("ProfD"); var dir = koFile.join(profileDir, '..', 'profiler'); koFile.mkpath(dir); var profileObj = profiler.getProfileData(); var file = koFile.open(koFile.join(dir, `${name}-${Date.now()}.cleo`), "w"); file.write(JSON.stringify(profileObj)); file.close(); }; }).apply(module.exports);
var _applyInterface = () => { var style = ""; var name = prefs.getString("interface-scheme"); var scheme = schemeService.getScheme(name); // Write interfaceChrome.less path = koFile.join(koDirSvc.userDataDir, "interfaceChrome.less"); fp = koFile.open(path, "w"); style = scheme.getInterfaceStyle("css", "code") || ""; fp.write(style); fp.close(); var defer = prefs.getBoolean("interface-font-defer"); var font = prefs.getString("interface-font"); var size = prefs.getString("interface-font-size"); // Write colors.less style = ""; var path = koFile.join(koDirSvc.userDataDir, "colors.less"); var fp = koFile.open(path, "w"); var _apply = (scheme, mapping) => { for (let k in mapping) { // Defer font to global pref if ( ! defer && k == "font") { style += `@${k}: ${font};` + "\n"; continue; } // Defer font size to global pref if ( ! defer && k == "size") { style += `@${k}: ${size};` + "\n"; continue; } let v = mapping[k]; let value = scheme.getInterfaceStyle(v[0], v[1]); if (value && value.length) style += `@${k}: ${value};` + "\n"; } }; _apply(scheme, interfaceMapping); scheme = schemeService.getScheme(prefs.getString('widget-scheme')); _apply(scheme, interfaceMappingWidgets); fp.write(style); fp.close(); require("ko/less").reload(true); var observerSvc = Cc["@mozilla.org/observer-service;1"]. getService(Ci.nsIObserverService); observerSvc.notifyObservers(null, 'interface-scheme-changed', name); }
this.share = function(data, meta) { var locale; var useClipboard = prefs.getBoolean("kopy_copy_to_clipboard", true); var showInBrowser = prefs.getBoolean("kopy_show_in_browser", true); if ( ! useClipboard && ! showInBrowser) { locale = "Could not share code via kopy.io; both clipboard and browser settings are disabled"; require("notify/notify").send(locale, "kopy", {priority: "warning"}); return; } locale = "You are about to share your current code selection with others, \ this means anyone with access to the URL can view your code.\ Are you sure you want to do this?"; if ( ! require("ko/dialogs").confirm(locale, {doNotAskPref: "kopy_donotask"})) { log.debug("kopy cancelled by confirmation"); return; } if ( ! meta.language) { meta.language = 'null'; } var params = require("sdk/querystring").stringify( { data: data, language: meta.language, scheme: prefs.getStringPref("editor-scheme").replace(/\-(dark|light)$/, '.$1') }); var baseUrl = prefs.getString("kopy_baseurl", "https://kopy.io"); var httpReq = new window.XMLHttpRequest({mozSystem: true}); httpReq.open("post", baseUrl + '/documents', true); httpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); httpReq.setRequestHeader("Content-length", params.length); httpReq.setRequestHeader("Connection", "close"); httpReq.send(params); httpReq.onload = function () { try { var key = JSON.parse(this.responseText).key; } catch (e) { var errorMsg = "kopy.io: Code sharing failed, malformed response"; log.warn(errorMsg + ": " + this.responseText); require("notify/notify").send(errorMsg, "kopy", {priority: "error"}); } var url = baseUrl + '/' + key; if (useClipboard) { require("sdk/clipboard").set(url); var msg = "URL copied to clipboard: " + url; require("notify/notify").send(msg, "kopy", { command: () => { legacy.browse.openUrlInDefaultBrowser(url) } }); } if (showInBrowser) { legacy.browse.openUrlInDefaultBrowser(url); } }; httpReq.onerror = function(e) { var errorMsg = "kopy.io: HTTP Request Failed: " + e.target.status; log.warn(errorMsg); require("notify/notify").send(errorMsg, "kopy", {priority: "error"}); } }
this.createFields = () => { fields.keybinding = this.getFieldKeybindings(); fields.browser = this.getFieldBrowsers(); fields.colorScheme = this.getFieldColorSchemes(); fields.classicMode = require("ko/ui/checkbox").create("I don't like changes"); fields.classicMode.checked( prefs.getBoolean("ui.classic.mode") ); fields.classicMode.onChange(() => { if (fields.classicMode.checked()) { fields.nativeBorders.checked(true); fields.colorScheme.value("Classic"); fields.keybinding.value("Legacy"); } else { fields.nativeBorders.checked(false); } }); fields.nativeBorders = require("ko/ui/checkbox").create("Use native window borders"); fields.nativeBorders.checked( ! prefs.getBoolean("ui.hide.chrome") ); fields.minimap = require("ko/ui/checkbox").create("Use code minimap"); fields.minimap.checked( prefs.getBoolean("editShowMinimap") ); fields.taborspace = require("ko/ui/checkbox").create("Prefer tabs over spaces for indentation"); fields.taborspace.checked( prefs.getBoolean("useTabs") ); fields.wrapping = require("ko/ui/checkbox").create("Wrap long lines"); fields.wrapping.checked( !! prefs.getLong("editWrapType") ); fields.autoDelimiters = require("ko/ui/checkbox").create("Wrap selection with typed delimiters (eg. quotes)"); fields.autoDelimiters.checked( prefs.getBoolean("editSmartWrapSelection") ); fields.autofill = require("ko/ui/checkbox").create("Automatically pick code completions using delimiters"); fields.autofill.checked( prefs.getBoolean("codeintel_completion_auto_fillups_enabled") ); fields.softchars = require("ko/ui/checkbox").create("Automatically insert ending delimiters and tags"); fields.softchars.checked( prefs.getBoolean("codeintelAutoInsertEndTag") ); fields.showLineNumbers = require("ko/ui/checkbox").create("Show line numbers in Editor"); fields.showLineNumbers.value( prefs.getBoolean("showLineNumbers") ); fields.indentWidth = require("ko/ui/textbox").create({attributes: { type: "number", min: 1, max: 16, width: 60, maxlength: 2 }}); fields.indentWidth.value( prefs.getLong("tabWidth") ); fields.snippetBehavior = require("ko/ui/radiogroup").create( "Snippet Behaviour: ", [ { attributes: { label: "Trigger automatically while typing", value: "auto" }}, { attributes: { label: "Insert using TAB key", value: "tab" }} ]); fields.snippetBehavior.value("auto"); // This is hard to detect given the way this is currently stored };