Mercurial > snowl
changeset 21:df5025ed1a7b
supress some log messages
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Tue, 15 Apr 2008 21:34:24 -0700 |
parents | 4e124a4b89b0 |
children | 4cd2eca37361 |
files | extension/content/sidebar.js extension/content/sidebar.xul extension/content/snowl.js extension/modules/feed.js extension/modules/log4moz.js |
diffstat | 5 files changed, 117 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/extension/content/sidebar.js Tue Apr 15 17:23:50 2008 -0700 +++ b/extension/content/sidebar.js Tue Apr 15 21:34:24 2008 -0700 @@ -15,6 +15,8 @@ getInterface(Ci.nsIDOMWindow); SourcesView = { + _log: null, + // Observer Service get _obsSvc() { let obsSvc = Cc["@mozilla.org/observer-service;1"]. @@ -39,12 +41,53 @@ }, init: function() { + this._log = Log4Moz.Service.getLogger("Snowl.Sidebar"); this._obsSvc.addObserver(this, "sources:changed", true); - this._rebuildView(); + this._rebuildModel(); + this._tree.view = this; + + // Add a capturing click listener to the tree so we can find out if the user + // clicked on a row that is already selected (in which case we let them edit + // the source name). + this._tree.addEventListener("mousedown", function(aEvent) { SourcesView.onClick(aEvent) }, true); + }, + + + //**************************************************************************// + // nsITreeView + + rowCount: 0, + getCellText : function(row,column){ + if (column.id == "nameCol") return this._model[row].title; + return "foo"; + }, + setTree: function(treebox){ this._treebox = treebox; }, + isContainer: function(row){ return false; }, + isSeparator: function(row){ return false; }, + isSorted: function(){ return false; }, + getLevel: function(row){ return 0; }, + getImageSrc: function(row,col){ return null; }, + getRowProperties: function(row,props){}, + getCellProperties: function(row,col,props){}, + getColumnProperties: function(colid,col,props){}, + isEditable: function() { + return true; + }, + setCellText: function(row, col, value) { + let statement = SnowlDatastore.createStatement("UPDATE sources SET title = :title WHERE id = :id"); + statement.params.title = this._model[row].title = value; + statement.params.id = this._model[row].id; + + try { + statement.execute(); + } + finally { + statement.reset(); + } }, //**************************************************************************// - // XPCOM Interface Implementations + // Misc XPCOM Interface Implementations // nsISupports QueryInterface: function(aIID) { @@ -65,6 +108,27 @@ } }, + _model: null, + _rebuildModel: function() { + let statementString = "SELECT title, id FROM sources ORDER BY title"; + let statement = SnowlDatastore.createStatement(statementString); + + this._model = []; + + let i = 0; + this._model[i] = { id: null, title: "All" }; + + try { + while (statement.step()) + this._model[++i] = { id: statement.row.id, title: statement.row.title }; + } + finally { + statement.reset(); + } + + this.rowCount = i + 1; + }, + _rebuildView: function() { let statementString = "SELECT title, id FROM sources ORDER BY title"; @@ -103,12 +167,27 @@ }, onSelect: function(aEvent) { +this._log.info("on select"); +//this._log.info(Log4Moz.enumerateProperties(aEvent).join("\n")); if (this._tree.currentIndex == -1) return; let sourceID = this._children.childNodes[this._tree.currentIndex].sourceID; gBrowserWindow.SnowlView.setSource(sourceID); }, + onClick: function(aEvent) { +this._log.info("on click"); +//this._log.info(Log4Moz.enumerateProperties(aEvent).join("\n")); +//this._log.info(aEvent.target.nodeName); + + let row = {}, col = {}, child = {}; + this._tree.treeBoxObject.getCellAt(aEvent.clientX, aEvent.clientY, row, col, child); + if (this._tree.view.selection.isSelected(row.value)) +this._log.info(row.value + " is selected"); +else +this._log.info(row.value + " is not selected"); + }, + onUnsubscribe: function(aEvent) { let sourceID = this._tree.view.getItemAtIndex(this._tree.currentIndex).sourceID;
--- a/extension/content/sidebar.xul Tue Apr 15 17:23:50 2008 -0700 +++ b/extension/content/sidebar.xul Tue Apr 15 21:34:24 2008 -0700 @@ -42,8 +42,8 @@ <script type="application/x-javascript" src="chrome://snowl/content/sidebar.js"/> - <tree id="sourcesView" flex="1" onselect="SourcesView.onSelect(event)" - context="sourcesContextMenu"> + <tree id="sourcesView" flex="1" context="sourcesContextMenu" editable="true" + onselect="SourcesView.onSelect(event)"> <treecols> <treecol id="nameCol" label="Name" flex="1"/> </treecols>
--- a/extension/content/snowl.js Tue Apr 15 17:23:50 2008 -0700 +++ b/extension/content/snowl.js Tue Apr 15 21:34:24 2008 -0700 @@ -46,7 +46,7 @@ statementString += " ORDER BY timestamp DESC"; - this._log.info("getMessages: statementString = " + statementString); + //this._log.info("getMessages: statementString = " + statementString); let statement = SnowlDatastore.createStatement(statementString);
--- a/extension/modules/feed.js Tue Apr 15 17:23:50 2008 -0700 +++ b/extension/modules/feed.js Tue Apr 15 21:34:24 2008 -0700 @@ -1,5 +1,3 @@ -dump("begin importing feed.js\n"); - EXPORTED_SYMBOLS = ["SnowlFeed"]; const Cc = Components.classes; @@ -39,7 +37,7 @@ onError: function(aEvent) { // FIXME: figure out what to do here. - Log4Moz.Service.getLogger("Snowl.FeedClient").error("loading feed " + aEvent.target.channel.originalURI); + Log4Moz.Service.getLogger("Snowl.FeedClient").error("loading feed " + aEvent.target.channel.originalURI.spec); } }; @@ -374,5 +372,3 @@ } }; - -dump("end importing feed.js\n");
--- a/extension/modules/log4moz.js Tue Apr 15 17:23:50 2008 -0700 +++ b/extension/modules/log4moz.js Tue Apr 15 21:34:24 2008 -0700 @@ -497,3 +497,35 @@ }; Log4Moz.Service = new Log4MozService(); + +Log4Moz.enumerateInterfaces = function(aObject) { + let interfaces = []; + + for (i in Ci) { + try { + aObject.QueryInterface(Ci[i]); + interfaces.push(i); + } + catch(ex) {} + } + + return interfaces; +}; + +Log4Moz.enumerateProperties = function(aObject, aExcludeComplexTypes) { + let properties = []; + + for (p in aObject) { + try { + if (aExcludeComplexTypes && + (typeof aObject[p] == "object" || typeof aObject[p] == "function")) + continue; + properties.push(p + " = " + aObject[p]); + } + catch(ex) { + properties.push(p + " = " + ex); + } + } + + return properties; +};