changeset 349:f95f6f24516f

menuitem to show flat or hierarchical collections, fix stream to unload/remove observer, wiring for menuitems and view states.
author alta88
date Tue, 28 Oct 2008 18:33:20 -0600
parents b8fbfd7ecfdf
children 3af68614eb52
files content/browser.js content/browser.xul content/collections.js content/stream.js content/stream.xul
diffstat 5 files changed, 87 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/content/browser.js	Mon Oct 27 17:07:35 2008 -0700
+++ b/content/browser.js	Tue Oct 28 18:33:20 2008 -0600
@@ -155,6 +155,18 @@
       }
     }
 
+    // Hierarchy init 
+    let hmenuitems = document.getElementsByAttribute("name", "snowlHierarchyMenuitemGroup");
+    let isHierarchical = this._prefs.get("collection.hierarchicalView");
+    let rivertab = this._snowlRiverTab();
+    if (hmenuitems) {
+      for (var i = 0; i < hmenuitems.length; i++) {
+        hmenuitems[i].setAttribute("disabled", !lchecked && !(rivertab));
+        if (i == isHierarchical)
+          hmenuitems[i].setAttribute("checked", true);
+      }
+    }
+
     // Toolbars
     document.getElementById("snowlToolbarMenuitem").setAttribute("disabled",
         (!lchecked && !schecked) ? true : false);
@@ -322,6 +334,29 @@
     return headerDeck;
   },
 
+  // Collections hierarchy toggle
+  kHierarchyOff: 0,
+  kHierarchyOn: 1,
+
+  _toggleHierarchy: function(val) {
+    let sidebarDoc = document.getElementById("sidebar").contentWindow;
+    let lchecked = document.getElementById("viewSnowlList").hasAttribute("checked");
+    if (lchecked) {
+      sidebarDoc.CollectionsView.isHierarchical = val;
+      sidebarDoc.CollectionsView._buildCollectionTree();
+    }
+
+    let rivertab = this._snowlRiverTab();
+    if (rivertab) {
+      let tabWindowDoc = gBrowser.getBrowserAtIndex(rivertab._tPos).contentWindow;
+      let tabDoc = new XPCNativeWrapper(tabWindowDoc).wrappedJSObject;
+      tabDoc.CollectionsView.isHierarchical = val;
+      tabDoc.CollectionsView._buildCollectionTree();
+    }
+
+    this._prefs.set("collection.hierarchicalView", val);
+  },
+
   // Need to init onLoad due to xul structure, toolbar exists in list and stream
   _initSnowlToolbar: function() {
     let menuitem = document.getElementById("snowlToolbarMenuitem");
@@ -336,14 +371,27 @@
   _toggleToolbar: function(event) {
     let name = event.target.getAttribute("name");
     let menuitem = document.getElementById(name+"Menuitem");
-    let doc = (name == "snowlToolbar") ?
-        document.getElementById("sidebar").contentDocument : document;
-    let toolbar = doc.getElementById(name);
+    let doc, toolbar, rtoolbar = null;
 
+    if (name == "snowlToolbar") {
+      doc = document.getElementById("sidebar").contentDocument;
+      let rivertab = this._snowlRiverTab();
+      if (rivertab)
+        rtoolbar = gBrowser.getBrowserAtIndex(rivertab._tPos).
+                   contentDocument.getElementById(name);
+    }
+    else 
+      doc = document;
+
+    toolbar = doc.getElementById(name);
     if (toolbar) {
       toolbar.hidden = !toolbar.hidden;
       menuitem.setAttribute("checked", !toolbar.hidden);
     }
+    if (rtoolbar)
+      rtoolbar.hidden = !rtoolbar.hidden;
+
+
   },
 
   // See if River tab exists
--- a/content/browser.xul	Mon Oct 27 17:07:35 2008 -0700
+++ b/content/browser.xul	Tue Oct 28 18:33:20 2008 -0600
@@ -167,6 +167,19 @@
                     headerType="Snowl.kFullHeader"
                     oncommand="Snowl._toggleHeader(event)"/>
           <menuseparator/>
+          <menuitem id="snowlHierarchyOffMenuitem"
+                    label="&hierarchyOff.label;"
+                    type="radio"
+                    accesskey="&hierarchyOff.accesskey;"
+                    name="snowlHierarchyMenuitemGroup"
+                    oncommand="Snowl._toggleHierarchy(Snowl.kHierarchyOff)"/>
+          <menuitem id="snowlHierarchyOnMenuitem"
+                    label="&hierarchyOn.label;"
+                    type="radio"
+                    accesskey="&hierarchyOn.accesskey;"
+                    name="snowlHierarchyMenuitemGroup"
+                    oncommand="Snowl._toggleHierarchy(Snowl.kHierarchyOn)"/>
+          <menuseparator/>
           <menuitem id="snowlToolbarMenuitem"
                     label="&toolbar.label;"
                     type="checkbox"
--- a/content/collections.js	Mon Oct 27 17:07:35 2008 -0700
+++ b/content/collections.js	Tue Oct 28 18:33:20 2008 -0600
@@ -44,8 +44,12 @@
 Cu.import("resource://snowl/modules/collection.js");
 Cu.import("resource://snowl/modules/opml.js");
 
-// FIXME: make this configurable.
-const SNOWL_COLLECTIONS_HIERARCHICAL = false;
+let gBrowserWindow = window.QueryInterface(Ci.nsIInterfaceRequestor).
+                     getInterface(Ci.nsIWebNavigation).
+                     QueryInterface(Ci.nsIDocShellTreeItem).
+                     rootTreeItem.
+                     QueryInterface(Ci.nsIInterfaceRequestor).
+                     getInterface(Ci.nsIDOMWindow);
 
 let CollectionsView = {
   _log: null,
@@ -69,6 +73,7 @@
     return this._children = this._tree.getElementsByTagName("treechildren")[0];
   },
 
+  isHierarchical: gBrowserWindow.Snowl._prefs.get("collection.hierarchicalView"),
 
   //**************************************************************************//
   // Initialization & Destruction
@@ -77,7 +82,7 @@
     this._log = Log4Moz.Service.getLogger("Snowl.Sidebar");
     this._obsSvc.addObserver(this, "sources:changed", true);
     this._getCollections();
-    this._tree.view = this;
+    this._buildCollectionTree();
 
     // Ensure collection selection maintained, if in List sidebar
     if (document.getElementById("snowlSidebar"))
@@ -148,7 +153,7 @@
   getLevel: function(row) {
     //this._log.info("getLevel: " + row);
 
-    if (!SNOWL_COLLECTIONS_HIERARCHICAL)
+    if (!this.isHierarchical)
       return 0;
 
     return this._rows[row].level;
@@ -252,7 +257,7 @@
         // Since the number of rows might have changed, we do this by reinitializing
         // the view instead of merely invalidating the box object (which doesn't
         // expect changes to the number of rows).
-        this._tree.view = this;
+        this._buildCollectionTree();
         break;
     }
   },
@@ -285,12 +290,13 @@
     finally {
       statement.reset();
     }
+  },
 
-    // Build the list of rows in the tree.  By default, all containers
-    // are closed, so this is the same as the list of collections, although
-    // in the future we might persist and restore the open state.
-    // XXX Should this work be in a separate function?
-    if (SNOWL_COLLECTIONS_HIERARCHICAL) {
+  // Build the list of rows in the tree.  By default, all containers
+  // are closed, so this is the same as the list of collections, although
+  // in the future we might persist and restore the open state.
+  _buildCollectionTree: function() {
+    if (this.isHierarchical) {
       this._rows = [collection for each (collection in this._collections)];
     }
     else {
@@ -303,6 +309,8 @@
           this._rows.push(collection);
       }
     }
+
+    this._tree.view = this;
   },
 
   onSelect: function(aEvent) {
--- a/content/stream.js	Mon Oct 27 17:07:35 2008 -0700
+++ b/content/stream.js	Tue Oct 28 18:33:20 2008 -0600
@@ -176,6 +176,10 @@
     gBrowserWindow.Snowl._initSnowlToolbar();
   },
 
+  onunLoad: function() {
+    Observers.remove(this, "snowl:message:added");
+  },
+
   _setMidnightTimout: function() {
     let t = this;
     let now = new Date();
--- a/content/stream.xul	Mon Oct 27 17:07:35 2008 -0700
+++ b/content/stream.xul	Tue Oct 28 18:33:20 2008 -0600
@@ -45,6 +45,7 @@
       xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
       title="&page.title;"
       onload="SnowlMessageView.onLoad()"
+      onunload="SnowlMessageView.onunLoad()"
       onclick="return window.parent.contentAreaClick(event, true);"
       onresize="try { SnowlMessageView.onResize() }
                 catch(ex) { /* before script loaded */ }">