]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/io.jsm
Import 1.0 supporting Firefox up to 14.*
[dactyl.git] / common / modules / io.jsm
index 5eefcc17b6bb6aeaceecae247a49df9035a36846..0e0a39499c6b073e1c936e746486ce6eab70cb13 100644 (file)
@@ -41,26 +41,6 @@ var IO = Module("io", {
 
             this._lastRunCommand = ""; // updated whenever the users runs a command with :!
             this._scriptNames = [];
-
-            this.downloadListener = {
-                onDownloadStateChange: function (state, download) {
-                    if (download.state == services.downloadManager.DOWNLOAD_FINISHED) {
-                        let url   = download.source.spec;
-                        let title = download.displayName;
-                        let file  = download.targetFile.path;
-                        let size  = download.size;
-
-                        dactyl.echomsg({ domains: [util.getHost(url)], message: _("io.downloadFinished", title, file) },
-                                       1, modules.commandline.ACTIVE_WINDOW);
-                        modules.autocommands.trigger("DownloadPost", { url: url, title: title, file: file, size: size });
-                    }
-                },
-                onStateChange:    function () {},
-                onProgressChange: function () {},
-                onSecurityChange: function () {}
-            };
-
-            services.downloadManager.addListener(this.downloadListener);
         },
 
         CommandFileMode: Class("CommandFileMode", modules.CommandMode, {
@@ -84,10 +64,6 @@ var IO = Module("io", {
             }
         }),
 
-        destroy: function destroy() {
-            services.downloadManager.removeListener(this.downloadListener);
-        },
-
         /**
          * Returns all directories named *name* in 'runtimepath'.
          *
@@ -331,14 +307,19 @@ var IO = Module("io", {
      *
      * @returns {File}
      */
-    createTempFile: function createTempFile(name) {
-        if (name instanceof Ci.nsIFile)
+    createTempFile: function createTempFile(name, type) {
+        if (name instanceof Ci.nsIFile) {
             var file = name.clone();
+            if (!type || type == "file")
+                file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
+            else
+                file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, octal(777));
+        }
         else {
             file = services.directory.get("TmpD", Ci.nsIFile);
             file.append(this.config.tempFile + (name ? "." + name : ""));
+            file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
         }
-        file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(600));
 
         services.externalApp.deleteTemporaryFileOnExit(file);
 
@@ -414,7 +395,8 @@ var IO = Module("io", {
         if (bin instanceof File || File.isAbsolutePath(bin))
             return this.File(bin);
 
-        let dirs = services.environment.get("PATH").split(config.OS.isWindows ? ";" : ":");
+        let dirs = services.environment.get("PATH")
+                           .split(config.OS.pathListSep);
         // Windows tries the CWD first TODO: desirable?
         if (config.OS.isWindows)
             dirs = [io.cwd].concat(dirs);
@@ -487,10 +469,12 @@ var IO = Module("io", {
     // TODO: when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is
     // fixed use that instead of a tmpfile
     /**
-     * Runs *command* in a subshell and returns the output in a string. The
-     * shell used is that specified by the 'shell' option.
+     * Runs *command* in a subshell and returns the output. The shell used is
+     * that specified by the 'shell' option.
      *
-     * @param {string} command The command to run.
+     * @param {string|[string]} command The command to run. This can be a shell
+     *      command string or an array of strings (a command and arguments)
+     *      which will be escaped and concatenated.
      * @param {string} input Any input to be provided to the command on stdin.
      * @param {function(object)} callback A callback to be called when
      *      the command completes. @optional
@@ -556,7 +540,8 @@ var IO = Module("io", {
      *     otherwise, the return value of *func*.
      */
     withTempFiles: function withTempFiles(func, self, checked, ext) {
-        let args = array(util.range(0, func.length)).map(bind("createTempFile", this, ext)).array;
+        let args = array(util.range(0, func.length))
+                    .map(bind("createTempFile", this, ext)).array;
         try {
             if (!args.every(util.identity))
                 return false;