| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
| 3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
| 4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 Cu.import("resource://gre/modules/Services.jsm"); | 7 Cu.import("resource://gre/modules/Services.jsm"); |
| 8 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", null); | |
| 8 | 9 |
| 9 let {Prefs} = require("prefs"); | 10 let {Prefs} = require("prefs"); |
| 10 let {WindowObserver} = require("windowObserver"); | 11 let {WindowObserver} = require("windowObserver"); |
| 11 | 12 |
| 13 let CustomizableUI = null; | |
|
Wladimir Palant
2014/07/30 09:38:55
No point keeping a global reference to Customizabl
saroyanm
2014/07/30 10:56:23
Done.
| |
| 14 | |
| 12 var WindowFeature = | 15 var WindowFeature = |
| 13 { | 16 { |
| 14 observer: null, | 17 observer: null, |
| 15 | 18 |
| 16 init: function() | 19 init: function() |
| 17 { | 20 { |
| 18 if (!this.observer) | 21 if (!this.observer) |
| 19 this.observer = new WindowObserver(this, "ready"); | 22 this.observer = new WindowObserver(this, "ready"); |
| 20 }, | 23 }, |
| 21 | 24 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 34 }, | 37 }, |
| 35 | 38 |
| 36 removeFromWindow: function(window) | 39 removeFromWindow: function(window) |
| 37 { | 40 { |
| 38 if (window.location.href != this.windowUrl) | 41 if (window.location.href != this.windowUrl) |
| 39 return; | 42 return; |
| 40 this._removeFromWindow(window); | 43 this._removeFromWindow(window); |
| 41 } | 44 } |
| 42 } | 45 } |
| 43 | 46 |
| 47 /** | |
| 48 * Object initializing add-on options, observes add-on manager notifications | |
| 49 * about add-on options being opened. | |
| 50 * @type nsIObserver | |
| 51 */ | |
| 52 let optionsObserver = | |
| 53 { | |
| 54 init: function() | |
| 55 { | |
| 56 Services.obs.addObserver(this, "addon-options-displayed", true); | |
| 57 onShutdown.add(function() | |
| 58 { | |
| 59 Services.obs.removeObserver(this, "addon-options-displayed"); | |
| 60 }.bind(this)); | |
| 61 }, | |
| 62 | |
| 63 initOptionsDoc: function(/**Document*/ doc) | |
| 64 { | |
| 65 if (CustomizableUI) | |
| 66 doc.getElementById("abpcustomization-icondisplay").collapsed = true; | |
| 67 }, | |
| 68 | |
| 69 observe: function(subject, topic, data) | |
| 70 { | |
| 71 let {addonID} = require("info") | |
| 72 if (data != addonID) | |
| 73 return; | |
| 74 | |
| 75 this.initOptionsDoc(subject.QueryInterface(Ci.nsIDOMDocument)); | |
| 76 }, | |
| 77 | |
| 78 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]) | |
| 79 }; | |
| 80 optionsObserver.init(); | |
| 81 | |
| 44 var VerticalPreferencesLayout = | 82 var VerticalPreferencesLayout = |
| 45 { | 83 { |
| 46 __proto__: WindowFeature, | 84 __proto__: WindowFeature, |
| 47 windowUrl: "chrome://adblockplus/content/ui/filters.xul", | 85 windowUrl: "chrome://adblockplus/content/ui/filters.xul", |
| 48 | 86 |
| 49 _applyToWindow: function(window) | 87 _applyToWindow: function(window) |
| 50 { | 88 { |
| 51 let content = window.document.getElementById("content"); | 89 let content = window.document.getElementById("content"); |
| 52 let splitter = window.document.getElementById("filtersSplitter"); | 90 let splitter = window.document.getElementById("filtersSplitter"); |
| 53 if (!content || !splitter) | 91 if (!content || !splitter) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 "vertical-preferences-layout": VerticalPreferencesLayout, | 209 "vertical-preferences-layout": VerticalPreferencesLayout, |
| 172 "preferences-one-line-subscriptions": OneLineSubscriptions, | 210 "preferences-one-line-subscriptions": OneLineSubscriptions, |
| 173 "preferences-remove-actions-button": RemoveActionsButton, | 211 "preferences-remove-actions-button": RemoveActionsButton, |
| 174 "toolbar-icon-display": ToolbarIconDisplay, | 212 "toolbar-icon-display": ToolbarIconDisplay, |
| 175 "green-icon": GreenIcon, | 213 "green-icon": GreenIcon, |
| 176 "remove-menus": RemoveMenus | 214 "remove-menus": RemoveMenus |
| 177 }; | 215 }; |
| 178 | 216 |
| 179 function updateFeature(name) | 217 function updateFeature(name) |
| 180 { | 218 { |
| 219 try | |
| 220 { | |
| 221 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", nul l); | |
| 222 } catch (e) {} | |
|
Wladimir Palant
2014/07/30 09:38:55
Why run this for each feature? It should be best t
saroyanm
2014/07/30 10:56:23
Oops, too inattentive today!
| |
| 223 | |
| 181 if (name in features) | 224 if (name in features) |
| 182 { | 225 { |
| 183 let enabled; | 226 let enabled; |
| 184 if (name == "addon-page-styles") | 227 if (name == "addon-page-styles") |
| 185 enabled = true; | 228 enabled = true; |
|
Wladimir Palant
2014/07/30 09:38:55
Actually, seeing this - it's probably cleaner to i
saroyanm
2014/07/30 10:56:23
Awesome, great idea. How could I miss that.
| |
| 229 else if (name == "toolbar-icon-display" && CustomizableUI) | |
| 230 enabled = false; | |
| 186 else | 231 else |
| 187 enabled = Prefs[name]; | 232 enabled = Prefs[name]; |
| 188 | 233 |
| 189 if (enabled) | 234 if (enabled) |
| 190 features[name].init(); | 235 features[name].init(); |
| 191 else | 236 else |
| 192 features[name].shutdown(); | 237 features[name].shutdown(); |
| 193 } | 238 } |
| 194 } | 239 } |
| 195 | 240 |
| 196 | |
| 197 // Initialize features and make sure to update them on changes | 241 // Initialize features and make sure to update them on changes |
| 198 for (let feature in features) | 242 for (let feature in features) |
| 199 updateFeature(feature); | 243 updateFeature(feature); |
| 200 | 244 |
| 201 Prefs.addListener(updateFeature); | 245 Prefs.addListener(updateFeature); |
| OLD | NEW |