changeset 43:6a876da36c80

add 'set all read' keyboard shortcut
author Myk Melez <myk@mozilla.org>
date Wed, 30 Apr 2008 18:11:06 -0700
parents f0d3b1cb7ab0
children ad1dd8c09288
files extension/content/snowl.js
diffstat 1 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/extension/content/snowl.js	Wed Apr 30 16:10:48 2008 -0700
+++ b/extension/content/snowl.js	Wed Apr 30 18:11:06 2008 -0700
@@ -411,7 +411,9 @@
     this._log.info("onKeyPress: which = " + aEvent.which);
 
     if (aEvent.charCode == "r".charCodeAt(0))
-      this._toggleRead();
+      this._toggleRead(false);
+    if (aEvent.charCode == "R".charCodeAt(0))
+      this._toggleRead(true);
     else if (aEvent.charCode == " ".charCodeAt(0))
       this._onSpacePress(aEvent);
   },
@@ -474,21 +476,23 @@
     }
   },
 
-  _toggleRead: function() {
-this._log.info("_toggleRead");
+  _toggleRead: function(aAll) {
+this._log.info("_toggleRead: all? " + aAll);
     if (this._tree.currentIndex == -1)
       return;
 
     let row = this._tree.currentIndex;
     let message = this._model[row];
-    this._setRead(!message.read);
+    if (aAll)
+      this._setAllRead(!message.read);
+    else
+      this._setRead(!message.read);
   },
 
   _setRead: function(aRead) {
     let row = this._tree.currentIndex;
     let message = this._model[row];
 
-    message.read = aRead;
 try {
     SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET read = " +
                                                  (aRead ? "1" : "0") +
@@ -498,9 +502,20 @@
 this._log.error(SnowlDatastore.dbConnection.lastErrorString);
 throw ex;
 }
+    message.read = aRead;
     this._tree.boxObject.invalidateRow(row);
   },
 
+  _setAllRead: function(aRead) {
+this._log.info("_setAllRead: aRead? " + aRead);
+    let ids = this._model.map(function(v) { return v.id });
+    SnowlDatastore.dbConnection.executeSimpleSQL("UPDATE messages SET read = " +
+                                                 (aRead ? "1" : "0") +
+                                                 " WHERE id IN (" + ids.join(",") + ")");
+    this._model.forEach(function(v) { v.read = aRead });
+    this._tree.boxObject.invalidate();
+  },
+
   setSource: function(aSourceID) {
     this.sourceID = aSourceID;
     this._rebuildModel();