changeset 69:e6c3b67e38ff

add a source selector to the river view
author Myk Melez <myk@mozilla.org>
date Tue, 13 May 2008 16:03:33 -0700
parents abae5a36eb6d
children e7090c3ef207
files extension/content/river.js extension/content/river.xhtml extension/modules/collection.js
diffstat 3 files changed, 50 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/extension/content/river.js	Tue May 13 11:09:16 2008 -0700
+++ b/extension/content/river.js	Tue May 13 16:03:33 2008 -0700
@@ -41,6 +41,7 @@
 const Cr = Components.results;
 const Cu = Components.utils;
 
+Cu.import("resource://snowl/modules/datastore.js");
 Cu.import("resource://snowl/modules/collection.js");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://snowl/modules/log4moz.js");
@@ -111,6 +112,8 @@
     this._updateToolbar();
 
     this.writeContent();
+
+    this.rebuildSourceMenu();
   },
 
   uninit: function SH_uninit() {
@@ -189,7 +192,7 @@
     gBrowserWindow.gBrowser.docShell.setCurrentURI(uri);
 
     // FIXME: figure out how to make reload reload the new URI instead of
-    // the original one.
+    // the original one.  It looks like nsISHEntry has a setURI method I can use.
   },
 
   onScroll: function(aEvent) {
@@ -714,8 +717,38 @@
                                                    aTimestamp.getSeconds());
 
     return formattedString;
+  },
+
+  rebuildSourceMenu: function() {
+    let statementString = "SELECT title, id FROM sources ORDER BY title";
+    let statement = SnowlDatastore.createStatement(statementString);
+
+    let sources = [];
+
+    let i = 0;
+    sources[i] = { id: null, title: "All" };
+
+    try {
+      while (statement.step())
+        sources[++i] = { id: statement.row.id, title: statement.row.title };
+    }
+    finally {
+      statement.reset();
+    }
+
+    let sourceMenu = document.getElementById("sourceMenu");
+    sourceMenu.removeAllItems();
+    for each (let source in sources)
+      sourceMenu.appendItem(source.title, source.id);
+
+    sourceMenu.selectedIndex = 0;
+  },
+
+  onCommandSourceMenu: function(aEvent) {
+    let sourceMenu = document.getElementById("sourceMenu");
+    this._collection.sourceID = sourceMenu.selectedItem.value;
+    this.rebuildView();
   }
-
 };
 
 window.addEventListener("scroll", function(evt) RiverView.onScroll(evt), false);
--- a/extension/content/river.xhtml	Tue May 13 11:09:16 2008 -0700
+++ b/extension/content/river.xhtml	Tue May 13 16:03:33 2008 -0700
@@ -14,11 +14,12 @@
 ]>
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+<?xml-stylesheet href="chrome://browser/skin/" type="text/css"?>
 
 <html id="feedHandler" xmlns="http://www.w3.org/1999/xhtml"
       xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <head>
-    <title>&feedPage.title;</title>
+    <title>A River of Messages</title>
     <link rel="stylesheet" type="text/css" media="all"
           href="chrome://browser/skin/feeds/subscribe.css"/>
     <link rel="stylesheet" type="text/css" media="all"
@@ -29,6 +30,13 @@
     <xul:hbox id="toolbar" align="center">
       <xul:button id="unreadButton" type="checkbox" label="Unread"
                   oncommand="RiverView.onCommandUnreadButton(event, this)"/>
+
+      <!-- Bug 348830 means there can't be whitespace between the menulist tags
+         - and the menupopup tag. -->
+      <xul:menulist id="sourceMenu" oncommand="RiverView.onCommandSourceMenu(event)"
+        ><xul:menupopup id="sourcePopup"
+      /></xul:menulist>
+
       <xul:textbox id="filterTextbox" type="timed" timeout="200"
                    oncommand="RiverView.onCommandFilterTextbox(event, this)"/>
     </xul:hbox>
--- a/extension/modules/collection.js	Tue May 13 11:09:16 2008 -0700
+++ b/extension/modules/collection.js	Tue May 13 16:03:33 2008 -0700
@@ -34,6 +34,9 @@
   },
 
   set sourceID(newVal) {
+    if (this._sourceID == newVal)
+      return;
+
     this._sourceID = newVal;
     this.invalidate();
   },
@@ -45,6 +48,9 @@
   },
 
   set filter(newVal) {
+    if (this._filter == newVal)
+      return;
+
     this._filter = newVal;
     this.invalidate();
   },