Mercurial > snowl
annotate extension/content/sidebar.js @ 28:0d34d2108b49
use a custom view for the message pane
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Thu, 17 Apr 2008 16:57:40 -0700 |
parents | df5025ed1a7b |
children | cd9bf64a84e1 |
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 |
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
6 Cu.import("resource://snowl/service.js"); |
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
7 Cu.import("resource://snowl/datastore.js"); |
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
8 Cu.import("resource://snowl/log4moz.js"); |
8efec269810d
get rid of init.js and a bunch of unused code in snowl.js
Myk Melez <myk@mozilla.org>
parents:
12
diff
changeset
|
9 |
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
|
10 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
|
11 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
|
12 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
|
13 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
|
14 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
|
15 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
|
16 |
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
|
17 SourcesView = { |
21 | 18 _log: null, |
19 | |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
20 // Observer Service |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
21 get _obsSvc() { |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
22 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
|
23 getService(Ci.nsIObserverService); |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
24 delete this._obsSvc; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
25 this._obsSvc = obsSvc; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
26 return this._obsSvc; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
27 }, |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
28 |
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
|
29 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
|
30 let tree = document.getElementById("sourcesView"); |
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
|
31 delete this._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
|
32 this._tree = 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
|
33 return this._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
|
34 }, |
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
|
35 |
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
|
36 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
|
37 let children = this._tree.getElementsByTagName("treechildren")[0]; |
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._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
|
39 this._children = 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
|
40 return this._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
|
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 |
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 init: function() { |
21 | 44 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
|
45 this._obsSvc.addObserver(this, "sources:changed", true); |
21 | 46 this._rebuildModel(); |
47 this._tree.view = this; | |
48 | |
49 // Add a capturing click listener to the tree so we can find out if the user | |
50 // clicked on a row that is already selected (in which case we let them edit | |
51 // the source name). | |
52 this._tree.addEventListener("mousedown", function(aEvent) { SourcesView.onClick(aEvent) }, true); | |
53 }, | |
54 | |
55 | |
56 //**************************************************************************// | |
57 // nsITreeView | |
58 | |
59 rowCount: 0, | |
60 getCellText : function(row,column){ | |
61 if (column.id == "nameCol") return this._model[row].title; | |
62 return "foo"; | |
63 }, | |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
64 |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
65 _treebox: null, |
21 | 66 setTree: function(treebox){ this._treebox = treebox; }, |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
67 |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
68 isContainer: function(aRow) { return false }, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
69 isSeparator: function(aRow) { return false }, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
70 isSorted: function() { return false }, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
71 getLevel: function(aRow) { return 0 }, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
72 getImageSrc: function(aRow, aColumn) { return null }, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
73 getRowProperties: function (aRow, aProperties) {}, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
74 getCellProperties: function (aRow, aColumn, aProperties) {}, |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
75 getColumnProperties: function(aColumnID, aColumn, aProperties) {}, |
21 | 76 isEditable: function() { |
77 return true; | |
78 }, | |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
79 |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
80 setCellText: function(aRow, aCol, aValue) { |
21 | 81 let statement = SnowlDatastore.createStatement("UPDATE sources SET title = :title WHERE id = :id"); |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
82 statement.params.title = this._model[aRow].title = aValue; |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
83 statement.params.id = this._model[aRow].id; |
21 | 84 |
85 try { | |
86 statement.execute(); | |
87 } | |
88 finally { | |
89 statement.reset(); | |
90 } | |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
91 }, |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
92 |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
93 |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
94 //**************************************************************************// |
21 | 95 // 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
|
96 |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
97 // nsISupports |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
98 QueryInterface: function(aIID) { |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 return this; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
103 |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
104 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
|
105 }, |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
106 |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
107 // nsIObserver |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
108 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
|
109 switch (topic) { |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
110 case "sources:changed": |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
111 this._rebuildView(); |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
112 break; |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
113 } |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
114 }, |
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
115 |
21 | 116 _model: null, |
117 _rebuildModel: function() { | |
118 let statementString = "SELECT title, id FROM sources ORDER BY title"; | |
119 let statement = SnowlDatastore.createStatement(statementString); | |
120 | |
121 this._model = []; | |
122 | |
123 let i = 0; | |
124 this._model[i] = { id: null, title: "All" }; | |
125 | |
126 try { | |
127 while (statement.step()) | |
128 this._model[++i] = { id: statement.row.id, title: statement.row.title }; | |
129 } | |
130 finally { | |
131 statement.reset(); | |
132 } | |
133 | |
134 this.rowCount = i + 1; | |
135 }, | |
136 | |
10
64defcf896f1
update the list of sources when the user subscribes to one
Myk Melez <myk@mozilla.org>
parents:
9
diff
changeset
|
137 _rebuildView: function() { |
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
|
138 let statementString = "SELECT title, id FROM sources ORDER BY title"; |
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
|
139 |
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
|
140 let statement = SnowlDatastore.createStatement(statementString); |
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
|
141 |
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
|
142 // Empty the view. |
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
|
143 while (this._children.hasChildNodes()) |
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
|
144 this._children.removeChild(this._children.lastChild); |
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
|
145 |
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
|
146 // Rebuild the view. |
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
|
147 this._addItem(null, "All"); |
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
|
148 while (statement.step()) |
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
|
149 this._addItem(statement.row.id, statement.row.title); |
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
|
150 |
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
|
151 // Select the subscription that the messages view is currently displaying. |
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
|
152 for (let i = 0; i < this._children.childNodes.length; i++) { |
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
|
153 let item = this._children.childNodes[i]; |
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
|
154 if (item.sourceID == gBrowserWindow.SnowlView.sourceID) { |
9
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
155 this._tree.view.selection.select(i); |
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
|
156 break; |
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
|
157 } |
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
|
158 } |
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
|
159 }, |
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
|
160 |
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
|
161 _addItem: function(aSourceID, aTitle) { |
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
|
162 let item = document.createElement("treeitem"); |
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
|
163 item.sourceID = aSourceID; |
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
|
164 let row = document.createElement("treerow"); |
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
|
165 |
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
|
166 let titleCell = document.createElement("treecell"); |
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
|
167 titleCell.setAttribute("label", aTitle); |
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
|
168 |
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
|
169 row.appendChild(titleCell); |
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
|
170 item.appendChild(row); |
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
|
171 this._children.appendChild(item); |
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
|
172 }, |
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
|
173 |
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
|
174 onSelect: function(aEvent) { |
21 | 175 this._log.info("on select"); |
176 //this._log.info(Log4Moz.enumerateProperties(aEvent).join("\n")); | |
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
|
177 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
|
178 return; |
28
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
179 |
0d34d2108b49
use a custom view for the message pane
Myk Melez <myk@mozilla.org>
parents:
21
diff
changeset
|
180 let sourceID = this._model[this._tree.currentIndex].id; |
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
|
181 gBrowserWindow.SnowlView.setSource(sourceID); |
9
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
182 }, |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
183 |
21 | 184 onClick: function(aEvent) { |
185 this._log.info("on click"); | |
186 //this._log.info(Log4Moz.enumerateProperties(aEvent).join("\n")); | |
187 //this._log.info(aEvent.target.nodeName); | |
188 | |
189 let row = {}, col = {}, child = {}; | |
190 this._tree.treeBoxObject.getCellAt(aEvent.clientX, aEvent.clientY, row, col, child); | |
191 if (this._tree.view.selection.isSelected(row.value)) | |
192 this._log.info(row.value + " is selected"); | |
193 else | |
194 this._log.info(row.value + " is not selected"); | |
195 }, | |
196 | |
9
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
197 onUnsubscribe: function(aEvent) { |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
198 let sourceID = this._tree.view.getItemAtIndex(this._tree.currentIndex).sourceID; |
11
40c49a0e9e34
update the list of sources when the user unsubscribes from one
Myk Melez <myk@mozilla.org>
parents:
10
diff
changeset
|
199 |
9
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
200 SnowlDatastore.dbConnection.beginTransaction(); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
201 try { |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
202 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
|
203 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
|
204 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM messages WHERE sourceID = " + sourceID); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
205 SnowlDatastore.dbConnection.executeSimpleSQL("DELETE FROM sources WHERE id = " + sourceID); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
206 SnowlDatastore.dbConnection.commitTransaction(); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
207 } |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
208 catch(ex) { |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
209 SnowlDatastore.dbConnection.rollbackTransaction(); |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
210 throw ex; |
d8abd85fc94d
implement basic subscribe and unsubscribe
Myk Melez <myk@mozilla.org>
parents:
8
diff
changeset
|
211 } |
11
40c49a0e9e34
update the list of sources when the user unsubscribes from one
Myk Melez <myk@mozilla.org>
parents:
10
diff
changeset
|
212 |
12
dfd64db41b8a
make sure both sources and messages get updated when the user unsubscribes
Myk Melez <myk@mozilla.org>
parents:
11
diff
changeset
|
213 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
|
214 this._obsSvc.notifyObservers(null, "messages:changed", null); |
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
|
215 } |
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
|
216 |
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
|
217 }; |
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
|
218 |
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
|
219 window.addEventListener("load", function() { SourcesView.init() }, false); |