[Pkg-mozext-commits] [itsalltext] 200/459: * fixed exception handling for windows * added better check for Mac (Darwin).

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository itsalltext.

commit 77aaaad439ee8ccd617e1d708ef912da693f9d93
Author: docwhat at gerf.org <docwhat at gerf.org>
Date:   Fri Apr 6 15:08:02 2007 -0400

    * fixed exception handling for windows
    * added better check for Mac (Darwin).
---
 Makefile                         |  2 +-
 src/chrome/content/badeditor.js  | 26 +++++++++++++++++++------
 src/chrome/content/cacheobj.js   | 15 ++++++++------
 src/chrome/content/itsalltext.js | 42 ++++++++++++++++++++++++----------------
 4 files changed, 55 insertions(+), 30 deletions(-)

diff --git a/Makefile b/Makefile
index 6eb571b..a98c006 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ JSMIN      := cat
 PROJNICK   := itsalltext
 PROJNAME   := "It's All Text!"
 ICONFILE   := src/chrome/content/icon.png
-VERSION    := 0.6.5
+VERSION    := 0.6.7
 
 # NOTE: do not create files or directories in here that have
 #       spaces or other special characters in their names!
diff --git a/src/chrome/content/badeditor.js b/src/chrome/content/badeditor.js
index 00e4e15..a96ae28 100644
--- a/src/chrome/content/badeditor.js
+++ b/src/chrome/content/badeditor.js
@@ -12,14 +12,28 @@ function doOnload() {
     var params = window['arguments'][0];
     var reason = document.getElementById('reason');
     var textnode = '**error**';
-    if(params.path === null) {
+    /* Errors are from
+     * http://lxr.mozilla.org/seamonkey/source/xpcom/base/nsError.h#262 */
+    if(params.exception == 'NS_ERROR_FILE_INVALID_PATH' ||
+       params.exception == 'NS_ERROR_FILE_UNRECOGNIZED_PATH' ||
+       params.exception == 'NS_ERROR_FILE_TARGET_DOES_NOT_EXIST' ||
+       params.exception == 'NS_ERROR_FILE_INVALID_PATH' ||
+       params.exception == 'NS_ERROR_FILE_NOT_FOUND' ||
+       params.exception == 'NS_ERROR_FILE_NAME_TOO_LONG' ) {
+        textnode = locale.getFormattedString('bad.noent', [params.path]);
+    } else if(params.exception == 'NS_ERROR_FILE_ACCESS_DENIED' ||
+              params.exception == 'NS_ERROR_FILE_IS_DIRECTORY' ||
+              params.exception == 'NS_ERROR_FILE_IS_LOCKED' ) {
+        textnode = locale.getFormattedString('bad.noexec', []);
+
+    /* At this point, we don't know exactly why it failed...
+     * Try some heuristics. */
+    } else if(!params.path) {
         textnode = locale.getFormattedString('bad.noset',[]);
+    } else if(params.exists) {
+        textnode = locale.getFormattedString('bad.noexec', []);
     } else {
-        if(params.exists) {
-            textnode = locale.getFormattedString('bad.noexec', []);
-        } else {
-            textnode = locale.getFormattedString('bad.noent', [params.path]);
-        }
+        textnode = locale.getFormattedString('bad.noent', [params.path]);
     }
     reason.appendChild(document.createTextNode(textnode));
 }
diff --git a/src/chrome/content/cacheobj.js b/src/chrome/content/cacheobj.js
index 1a92be3..53d7e43 100644
--- a/src/chrome/content/cacheobj.js
+++ b/src/chrome/content/cacheobj.js
@@ -234,15 +234,17 @@ CacheObj.prototype.edit = function(extension) {
     var filename = this.write();
     this.initial_background = this.node.style.backgroundColor;
     this.initial_color      = this.node.style.color;
-    var program = ItsAllText.getEditor();
+    var program = null; 
              
     try {
+        program = ItsAllText.getEditor();
         // checks
-        if (program === null)        { throw "Editor is not set."; }
-        if (!program.exists())       { throw "Editor does not exists."; }
+        if (program === null)        { throw {name:"Editor is not set."}; }
+        if (!program.exists())       { throw {name:"NS_ERROR_FILE_NOT_FOUND"}; }
         /* Mac check because of 
          * https://bugzilla.mozilla.org/show_bug.cgi?id=322865 */
-        if (!(ItsAllText.isMac() || program.isExecutable())) { throw "Editor is not executable."; }
+        if (!(ItsAllText.isDarwin() || program.isExecutable())) { 
+            throw {name:"NS_ERROR_FILE_ACCESS_DENIED"}; }
 
         // create an nsIProcess
         var process = Components.
@@ -259,10 +261,11 @@ CacheObj.prototype.edit = function(extension) {
         var result = {};
         var ec = process.run(false, args, args.length, result);
         this._is_watching = true;
-    } catch(e) {
+    } catch(e) {        
         var params = {out:null,
                       exists: program ? program.exists() : false,
-                      path: program ? program.path : null };
+                      path: ItsAllText.preferences.editor,
+                      exception: e.name };
         window.openDialog('chrome://itsalltext/chrome/badeditor.xul',
                           null,
                           "chrome,titlebar,toolbar,centerscreen,modal",
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index 333432b..32e0756 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -331,38 +331,46 @@ var ItsAllText = function() {
 
     };
 
-    that.isMac = function() {
-        var is_mac = that._is_mac;
-        if (typeof(is_mac) == 'undefined') {
-            var checks = ['/System',  '/Applications',
-                          '/Library', '/Network', '/Volumes'];
-            is_mac = true;
-            for(var i=0; i<checks.length; i++) {
-                dir = that.factoryFile(checks[i]);
-                is_mac = is_mac && dir.exists() && dir.isDirectory();
-            }
-            that._is_mac = is_mac;
+    /**
+     * Returns true if the system is running Mac OS X.
+     * @returns {boolean} Is this a Mac OS X system?
+     */
+    that.isDarwin = function() {
+        /* more help:
+         http://developer.mozilla.org/en/docs/Code_snippets:Miscellaneous#Operating_system_detection
+        */
+
+        var is_darwin = that._is_darwin;
+        if (typeof(is_darwin) == 'undefined') {
+            is_darwin = /^Darwin/i.test(Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS);
+            that._is_darwin = is_darwin;
         }
-        return is_mac;
+        return is_darwin;
     };
 
     /**
      * A Preference Option: What editor should we use?
+     *
+     * Note: On some platforms, this can return an 
+     * NS_ERROR_FILE_INVALID_PATH exception and possibly others.
+     *
+     * For a complete list of exceptions, see:
+     * http://lxr.mozilla.org/seamonkey/source/xpcom/base/nsError.h#262
      * @returns {nsILocalFile} A file object of the editor.
      */
     that.getEditor = function() {
         var editor = that.preferences.editor;
+        var retval = null;
 
-        if (editor === '' && that.isMac()) {
+        if (editor === '' && that.isDarwin()) {
             editor = '/usr/bin/open'; 
             that.preferences._set('editor', editor);
         }
 
-        if (editor === '') {
-            return null;
-        } else {
-            return that.factoryFile(editor);
+        if (editor !== '') {
+            retval = that.factoryFile(editor);
         }
+        return retval;
     };
 
     /**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git



More information about the Pkg-mozext-commits mailing list