[Pkg-mozext-commits] [itsalltext] 19/459: * cleaned up preferences - they now use an observer * fixed bug in windows where the text area is repeated a million times.
David Prévot
taffit at moszumanska.debian.org
Tue Feb 24 23:26:02 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository itsalltext.
commit facd4869ff3b083d21afb437ee474592eec22518
Author: docwhat at gerf.org <docwhat at gerf.org>
Date: Fri Dec 15 09:41:06 2006 -0500
* cleaned up preferences - they now use an observer
* fixed bug in windows where the text area is repeated a million times.
---
chrome/content/itsalltext.js | 113 +++++++++++++++++++++++++++++++------
chrome/content/options.xul | 7 +++
defaults/preferences/itsalltext.js | 1 +
3 files changed, 103 insertions(+), 18 deletions(-)
diff --git a/chrome/content/itsalltext.js b/chrome/content/itsalltext.js
index b2b92aa..97a6494 100644
--- a/chrome/content/itsalltext.js
+++ b/chrome/content/itsalltext.js
@@ -67,8 +67,10 @@ function ItsAllTextOverlay() {
};
that.debug = function() {
- try { return Firebug.Console.logFormatted(arguments); }
- catch(e) { return null; }
+ if (that.preferences.data.debug) {
+ try { return Firebug.Console.logFormatted(arguments); }
+ catch(e) { return null; }
+ }
};
var makeLocalFile = function(path) {
@@ -113,14 +115,71 @@ function ItsAllTextOverlay() {
that.cleanEditDir();
/**
+ * A Preference Observer.
+ */
+ that.preferences = {
+ /**
+ * Dictionary for storing the preferences in.
+ * @type Hash
+ */
+ data: {
+ },
+ /**
+ * Dictionary of types (well, really the method needed to get/set the
+ * type.
+ * @type Hash
+ */
+ types: {
+ 'charset': 'Char',
+ 'editor': 'Char',
+ 'refresh': 'Int',
+ 'debug': 'Bool'
+ },
+
+ /**
+ * Register the observer.
+ */
+ register: function() {
+ var prefService = Components.
+ classes["@mozilla.org/preferences-service;1"].
+ getService(Components.interfaces.nsIPrefService);
+ this._branch = prefService.getBranch("extensions."+MYSTRING+".");
+ this._branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
+ for(var type in this.types) {
+ this.data[type] = this._branch['get'+(this.types[type])+'Pref'](type);
+ }
+ this._branch.addObserver("", this, false);
+ },
+
+ /**
+ * Unregister the observer. Not currently used, but may be
+ * useful in the future.
+ */
+ unregister: function() {
+ if (!this._branch) {return;}
+ this._branch.removeObserver("", this);
+ },
+
+ /**
+ * Observation callback.
+ * @param {String} aSubject The nsIPrefBranch we're observing (after appropriate QI)e
+ * @param {String} aData The name of the pref that's been changed (relative to the aSubject).
+ * @param {String} aTopic The string defined by NS_PREFBRANCH_PREFCHANGE_TOPIC_ID
+ */
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic != "nsPref:changed") {return;}
+ if (this.data.hasOwnProperty(aData)) {
+ this.data[aData] = this._branch['get'+(this.types[aData])+'Pref'](aData);
+ }
+ }
+ };
+
+ /**
* A Preference Option: What character set should the file use?
* @returns {String} the charset to be used.
*/
that.getCharset = function() {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefService);
- var branch = prefs.getBranch("extensions."+MYSTRING+".");
- return branch.getCharPref("charset");
+ return that.preferences.data.charset;
};
/**
@@ -128,10 +187,7 @@ function ItsAllTextOverlay() {
* @returns {int} The number of seconds between checking for new content.
*/
that.getRefresh = function() {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefService);
- var branch = prefs.getBranch("extensions."+MYSTRING+".");
- var refresh = branch.getIntPref("refresh");
+ var refresh = that.preferences.data.refresh;
var retval = Math.round((1000*refresh) + (1000*Math.random()));
that.debug('refresh in',retval);
return retval;
@@ -143,10 +199,7 @@ function ItsAllTextOverlay() {
* @returns {nsILocalFile} A file object of the editor.
*/
that.getEditor = function() {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefService);
- var branch = prefs.getBranch("extensions."+MYSTRING+".");
- var editor = branch.getCharPref("editor");
+ var editor = that.preferences.data.editor;
// TODO: It'd be nice to have this use PATH.
// TODO: It should behave better the editor is unset or invalid.
@@ -161,6 +214,14 @@ function ItsAllTextOverlay() {
};
/**
+ * A Preference Option: should we display debugging info?
+ * @returns {bool}
+ */
+ that.getDebug = function() {
+ return that.preferences.data.debug;
+ }
+
+ /**
* A Cache object is used to manage the node and the file behind it.
* @constructor
* @param {Object} node A DOM Node to watch.
@@ -183,8 +244,11 @@ function ItsAllTextOverlay() {
node.setAttribute(MYSTRING+'_UID', self.uid);
cache[self.uid] = self;
- // NARF TODO: Remove this hack to shorten names
- self.filename = self.filename.slice(0,5) + '.txt';
+ /* Since the hash is supposed to be equally distributed, it shouldn't
+ * matter how we slice it. However, this does make it less unique.
+ */
+ // TODO: add hash collision detection using the raw key.
+ self.filename = self.filename.slice(0,15) + '.txt';
var editdir = that.getEditDir();
that.debug('editdir',editdir.path);
@@ -361,6 +425,16 @@ function ItsAllTextOverlay() {
var cobj = that.getCacheObj(node);
//that.log('refreshNode(): '+cobj);
+ if (that.getDebug()) {
+ if (!cobj._toggle) {
+ cobj.node.style.background = '#fed';
+ cobj._toggle = true;
+ } else {
+ cobj.node.style.background = '#def';
+ cobj._toggle = false;
+ }
+ }
+
if(!cobj) { return; }
cobj.update();
};
@@ -402,7 +476,7 @@ function ItsAllTextOverlay() {
that.refreshDocument(doc);
lasttime = new Date().valueOf();
cron[id] = lasttime;
- setTimeout(cronjob, that.getRefresh);
+ setTimeout(cronjob, that.getRefresh());
}
};
cronjob();
@@ -452,9 +526,12 @@ function ItsAllTextOverlay() {
}
document.getElementById("contentAreaContextMenu").
addEventListener("popupshowing", that.onContextMenu, false);
-
};
+ // Start watching the preferences.
+ that.preferences.register();
+
+ // Do the startup when things are loaded.
window.addEventListener("load", startup, true);
}
var itsAllTextOverlay = new ItsAllTextOverlay();
diff --git a/chrome/content/options.xul b/chrome/content/options.xul
index 35b761c..151b6dc 100644
--- a/chrome/content/options.xul
+++ b/chrome/content/options.xul
@@ -13,6 +13,8 @@
name="extensions.itsalltext.editor" type="string"/>
<preference id="pref_seconds"
name="extensions.itsalltext.refresh" type="int"/>
+ <preference id="pref_debug"
+ name="extensions.itsalltext.debug" type="bool"/>
</preferences>
<vbox>
@@ -29,6 +31,11 @@
value="Character Set (default: UTF-8): "/>
<textbox preference="pref_charset" id="charset" size="8"/>
</hbox>
+ <hbox align="right">
+ <label control="debug"
+ value="Enable Debugging: "/>
+ <checkbox preference="pref_debug" id="debug"/>
+ </hbox>
</vbox>
</prefpane>
diff --git a/defaults/preferences/itsalltext.js b/defaults/preferences/itsalltext.js
index 8d3df4b..e0fe9ea 100644
--- a/defaults/preferences/itsalltext.js
+++ b/defaults/preferences/itsalltext.js
@@ -1,3 +1,4 @@
pref("extensions.itsalltext.charset", "UTF-8");
pref("extensions.itsalltext.editor", "/usr/bin/gedit");
pref("extensions.itsalltext.refresh", 7);
+pref("extensions.itsalltext.debug", false);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git
More information about the Pkg-mozext-commits
mailing list