From 5e2401fa99c6032e3f909e77b31c9cdaa79729fc Mon Sep 17 00:00:00 2001 From: Philipp von Weitershausen Date: Sun, 11 Jul 2010 15:59:56 +0200 Subject: [PATCH] Preference overhaul * Get rid of "tap" nomenclature. * Make load*Tabs preferences integers so we can configure multiple behaviours (e.g. load, lazy, progressive, ...) * Rename hostWhitelist to just whitelist in anticipation of feature generalization. * Drop some preferences from the pref window, including the ability to add new entries to the whitelist. --- content/browser.js | 1 + content/preferences.js | 90 ++++--------------- content/preferences.xul | 100 ++++++--------------- defaults/preferences/prefs.js | 18 ++-- modules/prototypes.js | 160 +++++++++++++++++++++++----------- 5 files changed, 166 insertions(+), 203 deletions(-) diff --git a/content/browser.js b/content/browser.js index cf3451c..dc0e4bd 100644 --- a/content/browser.js +++ b/content/browser.js @@ -3,6 +3,7 @@ Components.utils.import("resource://bartab/prototypes.js"); // Initialize BarTab as soon as possible. window.addEventListener("DOMContentLoaded", function() { window.removeEventListener("DOMContentLoaded", arguments.callee, false); + BarTabUtils.migratePrefs(); var tabbrowser = document.getElementById("content"); (new BarTabHandler).init(tabbrowser); }, false); diff --git a/content/preferences.js b/content/preferences.js index 0da2864..631e8a7 100644 --- a/content/preferences.js +++ b/content/preferences.js @@ -3,14 +3,13 @@ Components.utils.import("resource://bartab/prototypes.js"); var BarTabPreferences = { init: function() { - BarTabUtils.mPrefs.addObserver("extensions.bartap.hostWhitelist", this, false); + BarTabUtils.mPrefs.addObserver("extensions.bartab.whitelist", this, false); this.onTimeoutChange(); - this.onLoadChange(); - this.updateHostWhitelist(); + this.updateWhitelist(); }, destroy: function() { - BarTabUtils.mPrefs.removeObserver("extensions.bartap.hostWhitelist", this); + BarTabUtils.mPrefs.removeObserver("extensions.bartab.whitelist", this); }, QueryInterface: function(aIID) { @@ -31,32 +30,25 @@ var BarTabPreferences = { timerWidgets.style.visibility = visibility; }, - onLoadChange: function() { - var menuitem = document.getElementById('loadOnSelect').selectedItem; - var delayWidgets = document.getElementById('delayWidgets'); - var visibility = (menuitem.value == "2") ? 'visible' : 'hidden'; - delayWidgets.style.visibility = visibility; - }, - - // Add to and remove hosts from whitelist + // Add to and remove entries from whitelist - updateHostWhitelist: function() { - var list = document.getElementById("hostWhitelist"); + updateWhitelist: function() { + var list = document.getElementById("whitelist"); while (list.firstChild) { list.removeChild(list.firstChild); } - var whitelist = BarTabUtils.getHostWhitelist(); - whitelist.forEach(function(host) { + var whitelist = BarTabUtils.getWhitelist(); + whitelist.forEach(function(entry) { let row = document.createElement("listitem"); - row.setAttribute("label", host); + row.setAttribute("label", entry); list.appendChild(row); }); }, - hostSelected: function() { - var removeButton = document.getElementById("hostWhitelistRemove"); - var list = document.getElementById("hostWhitelist"); + whiteListEntrySelected: function() { + var removeButton = document.getElementById("whitelistRemove"); + var list = document.getElementById("whitelist"); if (list.selectedItems.length) { removeButton.setAttribute("disabled", "false"); } else { @@ -64,70 +56,26 @@ var BarTabPreferences = { } }, - removeHost: function() { - var list = document.getElementById("hostWhitelist"); - var whitelist = BarTabUtils.getHostWhitelist(); + removeWhitelistEntry: function() { + var list = document.getElementById("whitelist"); + var whitelist = BarTabUtils.getWhitelist(); var self = this; list.selectedItems.forEach(function (item) { - var host = item.getAttribute("label"); - var index = whitelist.indexOf(host); + var entry = item.getAttribute("label"); + var index = whitelist.indexOf(entry); if (index == -1) { return; } whitelist.splice(index, 1); }); - BarTabUtils.setHostWhitelist(whitelist); - }, - - addHost: function() { - var textbox = document.getElementById("hostWhitelistNewHost"); - var whitelist = BarTabUtils.getHostWhitelist(); - var host = textbox.value.trim(); - - if (!host) { - return; - } - - // Convert whole URLs to hostnames - if ((host.substr(0, 7) == "http://") - || (host.substr(0, 8) == "https://")) { - try { - host = BarTabUtils.makeURI(host).host; - } catch(ex) { - // Ignore - } - } - - // Sort out duplicates. - if (whitelist.indexOf(host) != -1) { - textbox.value = ""; - return; - } - - // We don't allow semicolon in the host name - // TODO it couldn't hurt to do a proper check for illegal characters - if (host.indexOf(';') != -1) { - return; - } - - whitelist.push(host); - BarTabUtils.setHostWhitelist(whitelist); - textbox.value = ""; - }, - - onNewHostKeyPress: function(event) { - switch (event.keyCode) { - case event.DOM_VK_ENTER: - case event.DOM_VK_RETURN: - this.addHost(); - } + BarTabUtils.setWhitelist(whitelist); }, observe: function(aSubject, aTopic, aData) { if (aTopic != "nsPref:changed") { return; } - this.updateHostWhitelist(); + this.updateWhitelist(); } }; diff --git a/content/preferences.xul b/content/preferences.xul index 676afe1..d974921 100644 --- a/content/preferences.xul +++ b/content/preferences.xul @@ -11,33 +11,27 @@ - - - - - - - - + - + @@ -53,10 +47,10 @@ accesskey="&restoredTabs.accesskey;" control="menuRestoredTabs" /> + preference="extensions.bartab.loadRestoredTabs"> - - + + @@ -68,10 +62,10 @@ accesskey="&backgroundTabs.accesskey;" control="menuBackgroundTabs" /> + preference="extensions.bartab.loadBackgroundTabs"> - - + + @@ -83,7 +77,7 @@ accesskey="&unloadAfterTimeout.accesskey;" control="tapAfterTimeout" /> @@ -94,10 +88,10 @@ + preference="extensions.bartab.timeoutUnit"> @@ -114,63 +108,27 @@ - + onselect="BarTabPreferences.whitelistEntrySelected(event);"> -