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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
18 _log: null,
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
46 this._rebuildModel();
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
47 this._tree.view = this;
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
48
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
49 // Add a capturing click listener to the tree so we can find out if the user
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
50 // clicked on a row that is already selected (in which case we let them edit
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
51 // the source name).
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
52 this._tree.addEventListener("mousedown", function(aEvent) { SourcesView.onClick(aEvent) }, true);
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
53 },
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
54
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
55
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
56 //**************************************************************************//
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
57 // nsITreeView
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
58
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
59 rowCount: 0,
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
60 getCellText : function(row,column){
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
61 if (column.id == "nameCol") return this._model[row].title;
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
62 return "foo";
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
76 isEditable: function() {
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
77 return true;
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
84
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
85 try {
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
86 statement.execute();
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
87 }
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
88 finally {
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
89 statement.reset();
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
116 _model: null,
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
117 _rebuildModel: function() {
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
118 let statementString = "SELECT title, id FROM sources ORDER BY title";
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
119 let statement = SnowlDatastore.createStatement(statementString);
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
120
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
121 this._model = [];
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
122
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
123 let i = 0;
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
124 this._model[i] = { id: null, title: "All" };
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
125
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
126 try {
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
127 while (statement.step())
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
128 this._model[++i] = { id: statement.row.id, title: statement.row.title };
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
129 }
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
130 finally {
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
131 statement.reset();
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
132 }
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
133
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
134 this.rowCount = i + 1;
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
135 },
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
175 this._log.info("on select");
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
184 onClick: function(aEvent) {
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
185 this._log.info("on click");
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
186 //this._log.info(Log4Moz.enumerateProperties(aEvent).join("\n"));
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
187 //this._log.info(aEvent.target.nodeName);
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
188
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
189 let row = {}, col = {}, child = {};
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
190 this._tree.treeBoxObject.getCellAt(aEvent.clientX, aEvent.clientY, row, col, child);
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
191 if (this._tree.view.selection.isSelected(row.value))
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
192 this._log.info(row.value + " is selected");
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
193 else
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
194 this._log.info(row.value + " is not selected");
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
195 },
df5025ed1a7b supress some log messages
Myk Melez <myk@mozilla.org>
parents: 16
diff changeset
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);