does notifications when there's an error
authorKevin Dangoor <kdangoor@mozilla.com>
Fri, 24 Sep 2010 12:24:09 -0400
changeset 2048 0d4ea22d5728fa226f89baca700079493bfa011b
parent 2047 e76cf0e214f1086e605856ac050bc4543dc5e5b6
child 2049 9130e60c4f9ba2673ec1489ab18a23181de810f6
push id924
push userkdangoor@mozilla.com
push dateFri, 24 Sep 2010 16:24:56 +0000
does notifications when there's an error
plugins/supported/jslint_command.js
plugins/thirdparty/gritter/resources/jquery.gritter.less
--- a/plugins/supported/jslint_command.js
+++ b/plugins/supported/jslint_command.js
@@ -32,51 +32,59 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 "define metadata";
 ({
-    "dependencies": { "file_commands": "0.0.0", "jslint": "0.0.0" },
+    "dependencies": { "jslint": "0.0.0", "notifier": "0.0.0" },
     "description": "Provides the JSLint command to check code for errors.",
     "objects": [],
     "provides": [
         {
             "ep": "command",
             "name": "jslint",
             "params": [],
             "description": "Run JSLint to check the current file",
             "pointer": "#jslintCommand",
+            "key": "ctrl_shift_v",
             "predicates": { "context": "js" }
         },
         {
             "ep": "savehook",
             "name": "jslint",
             "description": "Runs JSLint when a JavaScript file is saved",
             "pointer": "#jslintSaveHook"
+        },
+        {
+            "ep": "notification",
+            "name": "jslint_error",
+            "description": "JSLint errors",
+            "level": "error"
         }
     ]
 });
 "end";
 
 var env = require('environment').env;
 var jslint = require('jslint').jslint;
+var catalog = require("bespin:plugins").catalog;
 
 function runJSLint(model) {
     var ok = jslint(model.getValue());
     if (ok) {
         return "JSLint succeeded";
     }
 
     var errors = jslint.errors;
     var plural = (errors.length === 1) ? "" : "s";
-    var output = [ "<div>JSLint reported ", errors.length, " error", plural,
-        ":</div>" ];
+    var message = "JSLint reported " + errors.length + " error" + plural;
+    var output = [ "<div>", message, ":</div>" ];
 
     errors.forEach(function(err) {
         if (err == null) {
             return;
         }
 
         output.push("<div>");
         output.push(err.line);
@@ -93,27 +101,38 @@ function runJSLint(model) {
         output.push("<pre>");
         output.push(line);
         output.push("\n");
         for (var i = 0; i < character; i++) {
             output.push(".");
         }
         output.push('^</pre>');
     });
+    
+    if (errors[errors.length-1] === null) {
+        var notifier = catalog.getObject('notifier');
+        if (notifier) {
+            notifier.notify({
+                plugin: 'jslint_command',
+                notification: 'jslint_error',
+                body: message
+            });
+        }
+    }
 
     return output.join("");
-}
+};
 
 exports.jslintCommand = function(args, req) {
     req.done(runJSLint(env.model));
-}
+};
 
 exports.jslintSaveHook = function(file) {
     var extension = file.extension();
     if (extension !== "js" && extension !== "jsm") {
         return "";
     }
 
     return runJSLint(env.model);
-}
+};
 
 exports.runJSLint = runJSLint;