changeset 8:87c6af76db52

add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
author Myk Melez <myk@mozilla.org>
date Sun, 09 Mar 2008 22:31:06 -0700
parents 856bfe5af5d4
children d8abd85fc94d
files extension/content/sidebar.js extension/content/sidebar.xul extension/content/snowl.xul extension/content/view.js
diffstat 4 files changed, 151 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extension/content/sidebar.js	Sun Mar 09 22:31:06 2008 -0700
@@ -0,0 +1,69 @@
+var gBrowserWindow = window.QueryInterface(Ci.nsIInterfaceRequestor).
+                     getInterface(Ci.nsIWebNavigation).
+                     QueryInterface(Ci.nsIDocShellTreeItem).
+                     rootTreeItem.
+                     QueryInterface(Ci.nsIInterfaceRequestor).
+                     getInterface(Ci.nsIDOMWindow);
+
+SourcesView = {
+  get _tree() {
+    let tree = document.getElementById("sourcesView");
+    delete this._tree;
+    this._tree = tree;
+    return this._tree;
+  },
+
+  get _children() {
+    let children = this._tree.getElementsByTagName("treechildren")[0];
+    delete this._children;
+    this._children = children;
+    return this._children;
+  },
+
+  init: function() {
+    let statementString = "SELECT title, id FROM sources ORDER BY title";
+
+    let statement = SnowlDatastore.createStatement(statementString);
+
+    // Empty the view.
+    while (this._children.hasChildNodes())
+      this._children.removeChild(this._children.lastChild);
+
+    // Rebuild the view.
+    this._addItem(null, "All");
+    while (statement.step())
+      this._addItem(statement.row.id, statement.row.title);
+
+    // Select the subscription that the messages view is currently displaying.
+    for (let i = 0; i < this._children.childNodes.length; i++) {
+      let item = this._children.childNodes[i];
+      if (item.sourceID == gBrowserWindow.SnowlView.sourceID) {
+        this._tree.view.selection.select(i)
+        break;
+      }
+    }
+  },
+
+  _addItem: function(aSourceID, aTitle) {
+    let item = document.createElement("treeitem");
+    item.sourceID = aSourceID;
+    let row = document.createElement("treerow");
+
+    let titleCell = document.createElement("treecell");
+    titleCell.setAttribute("label", aTitle);
+
+    row.appendChild(titleCell);
+    item.appendChild(row);
+    this._children.appendChild(item);
+  },
+
+  onSelect: function(aEvent) {
+    if (this._tree.currentIndex == -1)
+      return;
+    let sourceID = this._children.childNodes[this._tree.currentIndex].sourceID;
+    gBrowserWindow.SnowlView.setSource(sourceID);
+  }
+
+};
+
+window.addEventListener("load", function() { SourcesView.init() }, false);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extension/content/sidebar.xul	Sun Mar 09 22:31:06 2008 -0700
@@ -0,0 +1,54 @@
+<?xml version="1.0"?>
+<!-- ***** BEGIN LICENSE BLOCK *****
+   - Version: MPL 1.1/GPL 2.0/LGPL 2.1
+   -
+   - The contents of this file are subject to the Mozilla Public License Version
+   - 1.1 (the "License"); you may not use this file except in compliance with
+   - the License. You may obtain a copy of the License at
+   - http://www.mozilla.org/MPL/
+   -
+   - Software distributed under the License is distributed on an "AS IS" basis,
+   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+   - for the specific language governing rights and limitations under the
+   - License.
+   -
+   - The Original Code is Snowl.
+   -
+   - The Initial Developer of the Original Code is Mozilla.
+   - Portions created by the Initial Developer are Copyright (C) 2008
+   - the Initial Developer. All Rights Reserved.
+   -
+   - Contributor(s):
+   -   Myk Melez <myk@mozilla.org> (original author)
+   -
+   - Alternatively, the contents of this file may be used under the terms of
+   - either the GNU General Public License Version 2 or later (the "GPL"), or
+   - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+   - in which case the provisions of the GPL or the LGPL are applicable instead
+   - of those above. If you wish to allow use of your version of this file only
+   - under the terms of either the GPL or the LGPL, and not to allow others to
+   - use your version of this file under the terms of the MPL, indicate your
+   - decision by deleting the provisions above and replace them with the notice
+   - and other provisions required by the LGPL or the GPL. 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 ***** -->
+
+<?xml-stylesheet href="chrome://global/skin/" type"text/css"?>
+
+<page id="snowlSidebar" title="Subscriptions"
+      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+  <script type="application/x-javascript" src="chrome://snowl/content/init.js"/>
+  <script type="application/x-javascript" src="chrome://snowl/content/sidebar.js"/>
+
+  <tree id="sourcesView" flex="1" onselect="SourcesView.onSelect(event)">
+    <treecols>
+      <treecol id="nameCol" label="Name" flex="1"/>
+    </treecols>
+
+    <treechildren flex="1"/>
+  </tree>
+
+</page>
--- a/extension/content/snowl.xul	Sun Mar 09 20:46:04 2008 -0700
+++ b/extension/content/snowl.xul	Sun Mar 09 22:31:06 2008 -0700
@@ -17,6 +17,21 @@
               checked="true" oncommand="Snowl.toggleView()" accesskey="M"/>
   </menupopup>
 
+  <menupopup id="viewSidebarMenu">
+    <menuitem observes="viewSnowlSidebar"/>
+  </menupopup>
+
+  <broadcasterset id="mainBroadcasterSet"> 
+    <broadcaster id="viewSnowlSidebar"
+                 label="Subscriptions"
+                 autoCheck="false"
+                 type="checkbox"
+                 group="sidebar"
+                 sidebarurl="chrome://snowl/content/sidebar.xul"
+                 sidebartitle="Subscriptions"
+                 oncommand="toggleSidebar('viewSnowlSidebar');" />
+  </broadcasterset>
+
   <vbox id="appcontent">
     <vbox id="snowlViewContainer" insertbefore="content">
       <toolbar id="snowlViewToolbar" pack="end">
--- a/extension/content/view.js	Sun Mar 09 20:46:04 2008 -0700
+++ b/extension/content/view.js	Sun Mar 09 22:31:06 2008 -0700
@@ -1,10 +1,15 @@
 let SnowlView = {
+  sourceID: null,
+
   _getMessages: function(aMatchWords) {
     let conditions = [];
 
     if (aMatchWords)
       conditions.push("messages.id IN (SELECT messageID FROM parts WHERE content MATCH :matchWords)");
 
+    if (this.sourceID != null)
+      conditions.push("sourceID = :sourceID");
+
     let statementString = 
       "SELECT sources.title AS sourceTitle, subject, author, link, timestamp, content \
        FROM sources JOIN messages ON sources.id = messages.sourceID \
@@ -20,6 +25,9 @@
     if (aMatchWords)
       statement.params.matchWords = aMatchWords;
 
+    if (this.sourceID != null)
+      statement.params.sourceID = this.sourceID;
+
     let messages = [];
     try {
       while (statement.step()) {
@@ -125,6 +133,10 @@
     let children = tree.getElementsByTagName("treechildren")[0];
     let link = children.childNodes[tree.currentIndex].link;
     openUILink(link, aEvent, false, false, false, null, null);
-  }
+  },
 
+  setSource: function(aSourceID) {
+    this.sourceID = aSourceID;
+    this._rebuildView();
+  }
 };