diff --git a/common/content/buffer.js b/common/content/buffer.js index 08ab55f1..7298c8e5 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -1223,7 +1223,7 @@ const Buffer = Module("buffer", { let arg = args[0]; // FIXME: arg handling is a bit of a mess, check for filename - dactyl.assert(!arg || arg[0] == ">" && !util.isOS("WINNT"), + dactyl.assert(!arg || arg[0] == ">" && !util.OS.isWindows, "E488: Trailing characters"); prefs.withContext(function () { diff --git a/common/content/editor.js b/common/content/editor.js index 089ff5d3..3a4c7b7a 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -24,7 +24,7 @@ const Editor = Module("editor", { selectedText: function () String(Editor.getEditor(null).selection), pasteClipboard: function (clipboard, toStart) { - if (util.isOS("WINNT")) { + if (util.OS.isWindows) { this.executeCommand("cmd_paste"); return; } diff --git a/common/content/events.js b/common/content/events.js index de7f9c14..04bb0dd1 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -511,14 +511,14 @@ const Events = Module("events", { // https://bugzilla.mozilla.org/show_bug.cgi?query_format=specific&order=relevance+desc&bug_status=__open__&id=432951 // --- // - // The following fixes are only activated if util.isOS("Darwin"). + // The following fixes are only activated if util.OS.isMacOSX. // Technically, they prevent mappings from (and // if your fancy keyboard permits such things), but // these mappings are probably pathological ( // certainly is on Windows), and so it is probably // harmless to remove the has("Darwin") if desired. // - else if (util.isOS("Darwin") && event.ctrlKey && charCode >= 27 && charCode <= 31) { + else if (util.OS.isMacOSX && event.ctrlKey && charCode >= 27 && charCode <= 31) { if (charCode == 27) { // [Ctrl-Bug 1/5] the bug key = "Esc"; modifier = modifier.replace("C-", ""); diff --git a/common/content/io.js b/common/content/io.js index 76a4f58b..6981c39a 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -180,7 +180,7 @@ const IO = Module("io", { let rcFile1 = File.joinPaths(dir, "." + config.name + "rc", this.cwd); let rcFile2 = File.joinPaths(dir, "_" + config.name + "rc", this.cwd); - if (util.isOS("WINNT")) + if (util.OS.isWindows) [rcFile1, rcFile2] = [rcFile2, rcFile1]; if (rcFile1.exists() && rcFile1.isFile()) @@ -230,9 +230,9 @@ const IO = Module("io", { if (File.isAbsolutePath(program)) file = io.File(program, true); else { - let dirs = services.get("environment").get("PATH").split(util.isOS("WINNT") ? ";" : ":"); + let dirs = services.get("environment").get("PATH").split(util.OS.isWindows ? ";" : ":"); // Windows tries the CWD first TODO: desirable? - if (util.isOS("WINNT")) + if (util.OS.isWindows) dirs = [io.cwd].concat(dirs); lookup: @@ -244,7 +244,7 @@ lookup: // TODO: couldn't we just palm this off to the start command? // automatically try to add the executable path extensions on windows - if (util.isOS("WINNT")) { + if (util.OS.isWindows) { let extensions = services.get("environment").get("PATHEXT").split(";"); for (let [, extension] in Iterator(extensions)) { file = File.joinPaths(dir, program + extension, io.cwd); @@ -407,7 +407,7 @@ lookup: stdin.write(input); // TODO: implement 'shellredir' - if (util.isOS("WINNT") && !/sh/.test(options["shell"])) { + if (util.OS.isWindows && !/sh/.test(options["shell"])) { command = "cd /D " + this.cwd + " && " + command + " > " + stdout.path + " 2>&1" + " < " + stdin.path; var res = this.run(options["shell"], options["shellcmdflag"].split(/\s+/).concat(command), true); } @@ -458,7 +458,7 @@ lookup: const rtpvar = config.idName + "_RUNTIME"; let rtp = services.get("environment").get(rtpvar); if (!rtp) { - rtp = "~/" + (util.isOS("WINNT") ? "" : ".") + config.name; + rtp = "~/" + (util.OS.isWindows ? "" : ".") + config.name; services.get("environment").set(rtpvar, rtp); } return rtp; @@ -641,7 +641,7 @@ lookup: }; completion.environment = function environment(context) { - let command = util.isOS("WINNT") ? "set" : "env"; + let command = util.OS.isWindows ? "set" : "env"; let lines = io.system(command).split("\n"); lines.pop(); @@ -696,7 +696,7 @@ lookup: completion.shellCommand = function shellCommand(context) { context.title = ["Shell Command", "Path"]; context.generate = function () { - let dirNames = services.get("environment").get("PATH").split(util.isOS("WINNT") ? ";" : ":"); + let dirNames = services.get("environment").get("PATH").split(util.OS.isWindows ? ";" : ":"); let commands = []; for (let [, dirName] in Iterator(dirNames)) { @@ -726,7 +726,7 @@ lookup: }, options: function () { var shell, shellcmdflag; - if (util.isOS("WINNT")) { + if (util.OS.isWindows) { shell = "cmd.exe"; shellcmdflag = "/c"; } @@ -766,7 +766,7 @@ lookup: "string", shellcmdflag, { getter: function (value) { - if (this.hasChanged || !util.isOS("WINNT")) + if (this.hasChanged || !util.OS.isWindows) return value; return /sh/.test(options["shell"]) ? "-c" : "/c"; } diff --git a/common/content/tabs.js b/common/content/tabs.js index 4c49b583..7a622c0a 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -26,7 +26,7 @@ const Tabs = Module("tabs", { #TabsToolbar > xul|tabs > xul|tab { -moz-binding: url(chrome://dactyl/content/bindings.xml#tab-4) !important; } // FIXME: better solution for themes? .tabbrowser-tab[busy] > .tab-icon > .tab-icon-image { list-style-image: url('chrome://global/skin/icons/loading_16.png') !important; } - ]]>, /tab-./g, function (m) util.isOS("Darwin") ? "tab-mac" : m), + ]]>, /tab-./g, function (m) util.OS.isMacOSX ? "tab-mac" : m), false, true); // hide tabs initially to prevent flickering when 'stal' would hide them diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 0b01f6e7..b91114c9 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -528,16 +528,20 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) */ isDomainURL: function isDomainURL(url, domain) util.isSubdomain(util.getHost(url), domain), - /** - * Returns true if *os* matches Dactyl's notion of the current operating - * system platform. This is one of "WINNT", "Darwin" or "Unix". - * - * @param {string} os The OS platform to test. - * @returns {boolean} - */ - isOS: function isOS(os) { - let OS = services.get("runtime").OS; - return (OS == "WINNT" || OS == "Darwin") ? os == OS : os == "Unix"; + /** Dactyl's notion of the current operating system platform. */ + OS: { + _arch: services.get("runtime").OS, + /** + * @property {string} The normalised name of the OS. This is one of + * "Windows", "Mac OS X" or "Unix". + */ + get name() this.isWindows ? "Windows" : this.isMacOSX ? "Mac OS X" : "Unix", + /** @property {boolean} True if the OS is Windows. */ + get isWindows() this._arch == "WINNT", + /** @property {boolean} True if the OS is Mac OS X. */ + get isMacOSX() this._arch == "Darwin", + /** @property {boolean} True if the OS is some other *nix variant. */ + get isUnix() !this.isWindows && !this.isMacOSX }, /**