Mercurial > snowl
annotate extension/content/sidebar.js @ 178:1a27019af73e
reimplement the 'All' collection on the new architecture
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Thu, 17 Jul 2008 18:41:03 -0700 |
parents | 06a3197f71b1 |
children | ab9b528514e6 |
rev | line source |
---|---|
16
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
1 const Cc = Components.classes; |
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
2 const Ci = Components.interfaces; |
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
3 const Cr = Components.results; |
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
4 const Cu = Components.utils; |
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
5 |
45
a3811857c5dc
register the resource alias to the top-level directory rather than the modules directory for consistency with resource://gre/modules/ URLs and so we can use it to load resources from elsewhere in the extension later; this means converting chrome://snowl/module.js URLs into chrome://snowl/modules/module.js URLs
Myk Melez <myk@mozilla.org>
parents:
39
diff
changeset
|
6 Cu.import("resource://snowl/modules/service.js"); |
a3811857c5dc
register the resource alias to the top-level directory rather than the modules directory for consistency with resource://gre/modules/ URLs and so we can use it to load resources from elsewhere in the extension later; this means converting chrome://snowl/module.js URLs into chrome://snowl/modules/module.js URLs
Myk Melez <myk@mozilla.org>
parents:
39
diff
changeset
|
7 Cu.import("resource://snowl/modules/datastore.js"); |
a3811857c5dc
register the resource alias to the top-level directory rather than the modules directory for consistency with resource://gre/modules/ URLs and so we can use it to load resources from elsewhere in the extension later; this means converting chrome://snowl/module.js URLs into chrome://snowl/modules/module.js URLs
Myk Melez <myk@mozilla.org>
parents:
39
diff
changeset
|
8 Cu.import("resource://snowl/modules/log4moz.js"); |
108
ec5e374be495
show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents:
106
diff
changeset
|
9 Cu.import("resource://snowl/modules/source.js"); |
106
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
105
diff
changeset
|
10 Cu.import("resource://snowl/modules/feed.js"); |
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
105
diff
changeset
|
11 Cu.import("resource://snowl/modules/URI.js"); |
165 | 12 Cu.import("resource://snowl/modules/identity.js"); |
169
d5cc6dfafc40
basic support for grouping in the collection object
Myk Melez <myk@mozilla.org>
parents:
167
diff
changeset
|
13 Cu.import("resource://snowl/modules/collection.js"); |
16
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
14 |
173
4d59aa183d57
get loading of a group into the list view working
Myk Melez <myk@mozilla.org>
parents:
172
diff
changeset
|
15 // FIXME: call this SnowlViewWindow to facilitate reuse of this sidebar code |
4d59aa183d57
get loading of a group into the list view working
Myk Melez <myk@mozilla.org>
parents:
172
diff
changeset
|
16 // in the river view, where the window it will reference will not be a browser |
4d59aa183d57
get loading of a group into the list view working
Myk Melez <myk@mozilla.org>
parents:
172
diff
changeset
|
17 // window. |
8
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
18 var gBrowserWindow = window.QueryInterface(Ci.nsIInterfaceRequestor). |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
19 getInterface(Ci.nsIWebNavigation). |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
20 QueryInterface(Ci.nsIDocShellTreeItem). |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
21 rootTreeItem. |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
22 QueryInterface(Ci.nsIInterfaceRequestor). |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
23 getInterface(Ci.nsIDOMWindow); |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
24 |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
25 SourcesView = { |
21 | 26 _log: null, |
27 | |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
28 // Observer Service |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
29 get _obsSvc() { |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
30 let obsSvc = Cc["@mozilla.org/observer-service;1"]. |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
31 getService(Ci.nsIObserverService); |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
32 delete this._obsSvc; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
33 this._obsSvc = obsSvc; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
34 return this._obsSvc; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
35 }, |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
36 |
8
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
37 get _tree() { |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
38 delete this._tree; |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
39 return this._tree = document.getElementById("sourcesView"); |
8
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
40 }, |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
41 |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
42 get _children() { |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
43 delete this._children; |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
44 return this._children = this._tree.getElementsByTagName("treechildren")[0]; |
8
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
45 }, |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
46 |
106
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
105
diff
changeset
|
47 |
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
105
diff
changeset
|
48 //**************************************************************************// |
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
105
diff
changeset
|
49 // Initialization & Destruction |
2a08b4a82802
integrate OPML import into the sidebar
Myk Melez <myk@mozilla.org>
parents:
105
diff
changeset
|
50 |
8
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
51 init: function() { |
21 | 52 this._log = Log4Moz.Service.getLogger("Snowl.Sidebar"); |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
53 this._obsSvc.addObserver(this, "sources:changed", true); |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
54 this._getCollections(); |
21 | 55 this._tree.view = this; |
56 | |
57 // Add a capturing click listener to the tree so we can find out if the user | |
58 // clicked on a row that is already selected (in which case we let them edit | |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
59 // the collection name). |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
60 // FIXME: disable this for names that can't be changed. |
21 | 61 this._tree.addEventListener("mousedown", function(aEvent) { SourcesView.onClick(aEvent) }, true); |
62 }, | |
63 | |
64 | |
65 //**************************************************************************// | |
66 // nsITreeView | |
67 | |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
68 selection: null, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
69 |
108
ec5e374be495
show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents:
106
diff
changeset
|
70 get rowCount() { |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
71 return this._rows.length; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
72 }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
73 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
74 // FIXME: consolidate these two references. |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
75 _treebox: null, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
76 setTree: function(treeBox) { |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
77 this._treeBox = treeBox; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
78 }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
79 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
80 getCellText : function(row, column) { |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
81 return this._rows[row].name; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
82 }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
83 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
84 isContainer: function(row) { |
177 | 85 //this._log.info("isContainer: " + (this._rows[row].groups ? true : false)); |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
86 return (this._rows[row].groups ? true : false); |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
87 }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
88 isContainerOpen: function(row) { |
177 | 89 //this._log.info("isContainerOpen: " + this._rows[row].isOpen); |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
90 return this._rows[row].isOpen; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
91 }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
92 isContainerEmpty: function(row) { |
177 | 93 //this._log.info("isContainerEmpty: " + row + " " + this._rows[row].groups.length + " " + (this._rows[row].groups.length == 0)); |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
94 return (this._rows[row].groups.length == 0); |
108
ec5e374be495
show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents:
106
diff
changeset
|
95 }, |
ec5e374be495
show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents:
106
diff
changeset
|
96 |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
97 isSeparator: function(row) { return false }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
98 isSorted: function() { return false }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
99 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
100 // FIXME: make this return true for collection names that are editable, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
101 // and then implement name editing on the new architecture. |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
102 isEditable: function(row, column) { return false }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
103 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
104 getParentIndex: function(row) { |
177 | 105 //this._log.info("getParentIndex: " + row); |
106 | |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
107 // XXX Assumes only one level of hierarchy (so anything that is a container |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
108 // is at the top level). |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
109 // FIXME: stop assuming that by giving collections a reference to their |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
110 // parent collection. |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
111 if (this.isContainer(row)) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
112 return -1; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
113 for (let t = row - 1; t >= 0; t--) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
114 if (this.isContainer(t)) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
115 return t; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
116 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
117 throw "getParentIndex: couldn't figure out parent index for row " + row; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
118 }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
119 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
120 getLevel: function(row) { |
177 | 121 //this._log.info("getLevel: " + row); |
122 | |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
123 // XXX Assumes only one level of hierarchy (so anything that is a container |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
124 // is at the top level). |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
125 // FIXME: stop assuming that by giving collections a reference to their |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
126 // parent collection, then counting the number of parents to determine the level. |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
127 if (this.isContainer(row)) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
128 return 0; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
129 return 1; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
130 }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
131 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
132 hasNextSibling: function(idx, after) { |
177 | 133 //this._log.info("hasNextSibling: " + idx + " " + after); |
134 | |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
135 let thisLevel = this.getLevel(idx); |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
136 for (let t = idx + 1; t < this._rows.length; t++) { |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
137 let nextLevel = this.getLevel(t); |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
138 if (nextLevel == thisLevel) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
139 return true; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
140 if (nextLevel < thisLevel) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
141 return false; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
142 } |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
143 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
144 return false; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
145 }, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
146 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
147 getImageSrc: function(row, column) { |
177 | 148 if (column.id == "nameCol") { |
149 let faviconURI = this._rows[row].faviconURI; | |
150 if (faviconURI) | |
151 return faviconURI.spec; | |
152 } | |
153 | |
108
ec5e374be495
show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents:
106
diff
changeset
|
154 return null; |
21 | 155 }, |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
156 |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
157 toggleOpenState: function(idx) { |
177 | 158 //this._log.info("toggleOpenState: " + idx); |
159 | |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
160 let item = this._rows[idx]; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
161 if (!item.groups) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
162 return; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
163 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
164 if (item.isOpen) { |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
165 item.isOpen = false; |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
166 |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
167 let thisLevel = this.getLevel(idx); |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
168 let numToDelete = 0; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
169 for (let t = idx + 1; t < this._rows.length; t++) { |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
170 if (this.getLevel(t) > thisLevel) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
171 numToDelete++; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
172 else |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
173 break; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
174 } |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
175 if (numToDelete) { |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
176 this._rows.splice(idx + 1, numToDelete); |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
177 this._treeBox.rowCountChanged(idx + 1, -numToDelete); |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
178 } |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
179 } |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
180 else { |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
181 item.isOpen = true; |
108
ec5e374be495
show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents:
106
diff
changeset
|
182 |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
183 let groups = this._rows[idx].groups; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
184 for (let i = 0; i < groups.length; i++) |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
185 this._rows.splice(idx + 1 + i, 0, groups[i]); |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
186 this._treeBox.rowCountChanged(idx + 1, groups.length); |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
187 } |
108
ec5e374be495
show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents:
106
diff
changeset
|
188 }, |
ec5e374be495
show favicons in the subscriptions sidebar
Myk Melez <myk@mozilla.org>
parents:
106
diff
changeset
|
189 |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
190 getRowProperties: function (aRow, aProperties) {}, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
191 getCellProperties: function (aRow, aColumn, aProperties) {}, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
192 getColumnProperties: function(aColumnID, aColumn, aProperties) {}, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
193 |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
194 setCellText: function(aRow, aCol, aValue) { |
75
877a7694445f
update the sources table schema, changing the title column to name and differentiating between machine-processable and human-readable URIs
Myk Melez <myk@mozilla.org>
parents:
45
diff
changeset
|
195 let statement = SnowlDatastore.createStatement("UPDATE sources SET name = :name WHERE id = :id"); |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
196 statement.params.name = this._rows[aRow].name = aValue; |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
197 statement.params.id = this._rows[aRow].id; |
21 | 198 |
199 try { | |
200 statement.execute(); | |
201 } | |
202 finally { | |
203 statement.reset(); | |
204 } | |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
205 }, |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
206 |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
207 |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
208 //**************************************************************************// |
21 | 209 // Misc XPCOM Interface Implementations |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
210 |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
211 // nsISupports |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
212 QueryInterface: function(aIID) { |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
213 if (aIID.equals(Ci.nsIObserver) || |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
214 aIID.equals(Ci.nsISupportsWeakReference) || |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
215 aIID.equals(Ci.nsISupports)) |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
216 return this; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
217 |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
218 throw Cr.NS_ERROR_NO_INTERFACE; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
219 }, |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
220 |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
221 // nsIObserver |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
222 observe: function(subject, topic, data) { |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
223 switch (topic) { |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
224 case "sources:changed": |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
225 this._getCollections(); |
105
cd3267665afd
reinit the sidebar view when the number of rows changes
Myk Melez <myk@mozilla.org>
parents:
75
diff
changeset
|
226 // Rebuild the view to reflect the new collection of messages. |
cd3267665afd
reinit the sidebar view when the number of rows changes
Myk Melez <myk@mozilla.org>
parents:
75
diff
changeset
|
227 // Since the number of rows might have changed, we do this by reinitializing |
cd3267665afd
reinit the sidebar view when the number of rows changes
Myk Melez <myk@mozilla.org>
parents:
75
diff
changeset
|
228 // the view instead of merely invalidating the box object (which doesn't |
cd3267665afd
reinit the sidebar view when the number of rows changes
Myk Melez <myk@mozilla.org>
parents:
75
diff
changeset
|
229 // expect changes to the number of rows). |
cd3267665afd
reinit the sidebar view when the number of rows changes
Myk Melez <myk@mozilla.org>
parents:
75
diff
changeset
|
230 this._tree.view = this; |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
231 break; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
232 } |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
233 }, |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
234 |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
235 _collections: null, |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
236 _getCollections: function() { |
178
1a27019af73e
reimplement the 'All' collection on the new architecture
Myk Melez <myk@mozilla.org>
parents:
177
diff
changeset
|
237 this._collections = []; |
1a27019af73e
reimplement the 'All' collection on the new architecture
Myk Melez <myk@mozilla.org>
parents:
177
diff
changeset
|
238 |
1a27019af73e
reimplement the 'All' collection on the new architecture
Myk Melez <myk@mozilla.org>
parents:
177
diff
changeset
|
239 // FIXME: figure out why this gets indented. |
1a27019af73e
reimplement the 'All' collection on the new architecture
Myk Melez <myk@mozilla.org>
parents:
177
diff
changeset
|
240 let all = new SnowlCollection(); |
1a27019af73e
reimplement the 'All' collection on the new architecture
Myk Melez <myk@mozilla.org>
parents:
177
diff
changeset
|
241 all.name = "All"; |
1a27019af73e
reimplement the 'All' collection on the new architecture
Myk Melez <myk@mozilla.org>
parents:
177
diff
changeset
|
242 all.defaultFaviconURI = URI.get("chrome://snowl/content/icons/rainbow.png"); |
1a27019af73e
reimplement the 'All' collection on the new architecture
Myk Melez <myk@mozilla.org>
parents:
177
diff
changeset
|
243 this._collections.push(all); |
165 | 244 |
175
5409a8759186
collection object rearch: encapsulate grouping info into grouping object
Myk Melez <myk@mozilla.org>
parents:
174
diff
changeset
|
245 let grouping = { |
5409a8759186
collection object rearch: encapsulate grouping info into grouping object
Myk Melez <myk@mozilla.org>
parents:
174
diff
changeset
|
246 nameColumn: "sources.name", |
177 | 247 uriColumn: "sources.humanURI", |
248 // the default favicon for sources | |
249 // FIXME: use a source type-specific favicon. | |
250 defaultFaviconURI: URI.get("chrome://browser/skin/feeds/feedIcon16.png") | |
175
5409a8759186
collection object rearch: encapsulate grouping info into grouping object
Myk Melez <myk@mozilla.org>
parents:
174
diff
changeset
|
251 } |
176
0e5d80b88d1b
collection object rearch: genericize the setting of conditions on collections, and distinguish between conditions that define the initial state of the collection (called constraints) and those that temporarily further refine the results returned by the collection (called filters)
Myk Melez <myk@mozilla.org>
parents:
175
diff
changeset
|
252 let collection = new SnowlCollection(null, null, grouping); |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
253 collection.name = "Sources"; |
178
1a27019af73e
reimplement the 'All' collection on the new architecture
Myk Melez <myk@mozilla.org>
parents:
177
diff
changeset
|
254 this._collections.push(collection); |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
255 |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
256 // Build the list of rows in the tree. By default, all containers |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
257 // are closed, so this is the same as the list of collections, although |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
258 // in the future we might persist and restore the open state. |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
259 // XXX Should this work be in a separate function? |
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
260 this._rows = [collection for each (collection in this._collections)]; |
21 | 261 }, |
262 | |
8
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
263 onSelect: function(aEvent) { |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
264 if (this._tree.currentIndex == -1) |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
265 return; |
173
4d59aa183d57
get loading of a group into the list view working
Myk Melez <myk@mozilla.org>
parents:
172
diff
changeset
|
266 |
4d59aa183d57
get loading of a group into the list view working
Myk Melez <myk@mozilla.org>
parents:
172
diff
changeset
|
267 let collection = this._rows[this._tree.currentIndex]; |
4d59aa183d57
get loading of a group into the list view working
Myk Melez <myk@mozilla.org>
parents:
172
diff
changeset
|
268 gBrowserWindow.SnowlView.setCollection(collection); |
9
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
269 }, |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
270 |
21 | 271 onClick: function(aEvent) { |
272 this._log.info("on click"); | |
273 //this._log.info(Log4Moz.enumerateProperties(aEvent).join("\n")); | |
274 //this._log.info(aEvent.target.nodeName); | |
275 | |
276 let row = {}, col = {}, child = {}; | |
277 this._tree.treeBoxObject.getCellAt(aEvent.clientX, aEvent.clientY, row, col, child); | |
278 if (this._tree.view.selection.isSelected(row.value)) | |
279 this._log.info(row.value + " is selected"); | |
280 else | |
281 this._log.info(row.value + " is not selected"); | |
282 }, | |
283 | |
138
58b04d16257c
integrate subscription UI into a single page
Myk Melez <myk@mozilla.org>
parents:
137
diff
changeset
|
284 subscribe: function(event) { |
58b04d16257c
integrate subscription UI into a single page
Myk Melez <myk@mozilla.org>
parents:
137
diff
changeset
|
285 gBrowserWindow.gBrowser.selectedTab = |
58b04d16257c
integrate subscription UI into a single page
Myk Melez <myk@mozilla.org>
parents:
137
diff
changeset
|
286 gBrowserWindow.gBrowser.addTab("chrome://snowl/content/subscribe.xul"); |
58b04d16257c
integrate subscription UI into a single page
Myk Melez <myk@mozilla.org>
parents:
137
diff
changeset
|
287 }, |
58b04d16257c
integrate subscription UI into a single page
Myk Melez <myk@mozilla.org>
parents:
137
diff
changeset
|
288 |
58b04d16257c
integrate subscription UI into a single page
Myk Melez <myk@mozilla.org>
parents:
137
diff
changeset
|
289 unsubscribe: function(aEvent) { |
172
3ec4ba145105
support for a hierarchical tree view
Myk Melez <myk@mozilla.org>
parents:
171
diff
changeset
|
290 let sourceID = this._collections[this._tree.currentIndex].id; |
11
40c49a0e9e34
update the list of sources when the user unsubscribes from one
Myk Melez <myk@mozilla.org>
parents:
10
diff
changeset
|
291 |
9
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
292 SnowlDatastore.dbConnection.beginTransaction(); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
293 try { |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
294 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM metadata WHERE messageID IN (SELECT id FROM messages WHERE sourceID = " + sourceID + ")"); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
295 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM parts WHERE messageID IN (SELECT id FROM messages WHERE sourceID = " + sourceID + ")"); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
296 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM messages WHERE sourceID = " + sourceID); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
297 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM sources WHERE id = " + sourceID); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
298 SnowlDatastore.dbConnection.commitTransaction(); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
299 } |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
300 catch(ex) { |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
301 SnowlDatastore.dbConnection.rollbackTransaction(); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
302 throw ex; |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
303 } |
11
40c49a0e9e34
update the list of sources when the user unsubscribes from one
Myk Melez <myk@mozilla.org>
parents:
10
diff
changeset
|
304 |
12
dfd64db41b8a
make sure both sources and messages get updated when the user unsubscribes
Myk Melez <myk@mozilla.org>
parents:
11
diff
changeset
|
305 this._obsSvc.notifyObservers(null, "sources:changed", null); |
dfd64db41b8a
make sure both sources and messages get updated when the user unsubscribes
Myk Melez <myk@mozilla.org>
parents:
11
diff
changeset
|
306 this._obsSvc.notifyObservers(null, "messages:changed", null); |
167 | 307 }, |
308 | |
309 | |
310 //**************************************************************************// | |
311 // OPML Export | |
312 // Based on code in Thunderbird's feed-subscriptions.js | |
313 | |
314 exportOPML: function() { | |
315 let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); | |
316 fp.init(window, "Export feeds as an OPML file", Ci.nsIFilePicker.modeSave); | |
317 fp.appendFilter("OPML Files", "*.opml"); | |
318 fp.appendFilters(Ci.nsIFilePicker.filterXML | Ci.nsIFilePicker.filterAll); | |
319 fp.defaultString = "feeds.opml"; | |
320 fp.defaultExtension = "opml"; | |
321 | |
322 let rv = fp.show(); | |
323 | |
324 if (rv == Ci.nsIFilePicker.returnCancel) | |
325 return; | |
326 | |
327 let doc = this._createOPMLDocument(); | |
328 | |
329 // Format the document with newlines and indentation so it's easier | |
330 // for humans to read. | |
331 this._prettifyNode(doc.documentElement, 0); | |
332 | |
333 let serializer = new XMLSerializer(); | |
334 let foStream = Cc["@mozilla.org/network/file-output-stream;1"]. | |
335 createInstance(Ci.nsIFileOutputStream); | |
336 // default mode: write | create | truncate | |
337 let mode = 0x02 | 0x08 | 0x20; | |
338 foStream.init(fp.file, mode, 0666, 0); | |
339 serializer.serializeToStream(doc, foStream, "utf-8"); | |
340 }, | |
341 | |
342 _createOPMLDocument: function() { | |
343 let doc = document.implementation.createDocument("", "opml", null); | |
344 let root = doc.documentElement; | |
345 root.setAttribute("version", "1.0"); | |
346 | |
347 // Create the <head> element. | |
348 let head = doc.createElement("head"); | |
349 root.appendChild(head); | |
350 | |
351 let title = doc.createElement("title"); | |
352 head.appendChild(title); | |
353 title.appendChild(doc.createTextNode("Snowl OPML Export")); | |
354 | |
355 let dt = doc.createElement("dateCreated"); | |
356 head.appendChild(dt); | |
357 dt.appendChild(doc.createTextNode((new Date()).toGMTString())); | |
358 | |
359 // Create the <body> element. | |
360 let body = doc.createElement("body"); | |
361 root.appendChild(body); | |
362 | |
363 // Populate the <body> element with <outline> elements. | |
364 let sources = SnowlSource.getAll(); | |
365 for each (let source in sources) { | |
366 let outline = doc.createElement("outline"); | |
367 // XXX Should we specify the |type| attribute, and should we specify | |
368 // type="atom" for Atom feeds or just type="rss" for all feeds? | |
369 // This document says the latter but is three years old: | |
370 // http://www.therssweblog.com/?guid=20051003145153 | |
371 //outline.setAttribute("type", "rss"); | |
372 outline.setAttribute("text", source.name); | |
373 outline.setAttribute("url", source.humanURI.spec); | |
374 outline.setAttribute("xmlUrl", source.machineURI.spec); | |
375 body.appendChild(outline); | |
376 } | |
377 | |
378 return doc; | |
379 }, | |
380 | |
381 _prettifyNode: function(node, level) { | |
382 let doc = node.ownerDocument; | |
383 | |
384 // Create a string containing two spaces for every level deep we are. | |
385 let indentString = new Array(level + 1).join(" "); | |
386 | |
387 // Indent the tag. | |
388 if (level > 0) | |
389 node.parentNode.insertBefore(doc.createTextNode(indentString), node); | |
390 | |
391 // Grab the list of nodes to format. We can't just use node.childNodes | |
392 // because it'd change under us as we insert formatting nodes. | |
393 let childNodesToFormat = []; | |
394 for (let i = 0; i < node.childNodes.length; i++) | |
395 if (node.childNodes[i].nodeType == node.ELEMENT_NODE) | |
396 childNodesToFormat.push(node.childNodes[i]); | |
397 | |
398 if (childNodesToFormat.length > 0) { | |
399 for each (let childNode in childNodesToFormat) | |
400 this._prettifyNode(childNode, level + 1); | |
401 | |
402 // Insert a newline after the opening tag. | |
403 node.insertBefore(doc.createTextNode("\n"), node.firstChild); | |
404 | |
405 // Indent the closing tag. | |
406 node.appendChild(doc.createTextNode(indentString)); | |
407 } | |
408 | |
409 // Insert a newline after the tag. | |
410 if (level > 0) { | |
411 if (node.nextSibling) | |
412 node.parentNode.insertBefore(doc.createTextNode("\n"), | |
413 node.nextSibling); | |
414 else | |
415 node.parentNode.appendChild(doc.createTextNode("\n")); | |
416 } | |
8
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
417 } |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
418 |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
419 }; |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
420 |
87c6af76db52
add a sidebar listing subscriptions with basic support for selecting a subscription and seeing just its messages
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
421 window.addEventListener("load", function() { SourcesView.init() }, false); |