Bug 1316630 - move PrefObserver to devtools/shared/prefs.js; r=jdescottes

MozReview-Commit-ID: C4KxFxv2LVT

--HG--
extra : rebase_source : 484a654309eab406913f944d6aa8988c567641d7
This commit is contained in:
Tom Tromey 2016-11-14 15:46:19 -07:00
parent 38a04b8138
commit b6eca933c1
12 changed files with 42 additions and 50 deletions

View File

@ -13,7 +13,7 @@ const promise = require("promise");
const defer = require("devtools/shared/defer");
const Services = require("Services");
const {OutputParser} = require("devtools/client/shared/output-parser");
const {PrefObserver, PREF_ORIG_SOURCES} = require("devtools/client/styleeditor/utils");
const {PrefObserver} = require("devtools/client/shared/prefs");
const {createChild} = require("devtools/client/inspector/shared/utils");
const {gDevTools} = require("devtools/client/framework/devtools");
const {getCssProperties} = require("devtools/shared/fronts/css-properties");
@ -33,6 +33,8 @@ const STYLE_INSPECTOR_PROPERTIES = "devtools/shared/locales/styleinspector.prope
const {LocalizationHelper} = require("devtools/shared/l10n");
const STYLE_INSPECTOR_L10N = new LocalizationHelper(STYLE_INSPECTOR_PROPERTIES);
const PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled";
const FILTER_CHANGED_TIMEOUT = 150;
const HTML_NS = "http://www.w3.org/1999/xhtml";

View File

@ -19,7 +19,7 @@ const {KeyShortcuts} = require("devtools/client/shared/key-shortcuts");
const {scrollIntoViewIfNeeded} = require("devtools/client/shared/scroll");
const {UndoStack} = require("devtools/client/shared/undo");
const {HTMLTooltip} = require("devtools/client/shared/widgets/tooltip/HTMLTooltip");
const {PrefObserver} = require("devtools/client/styleeditor/utils");
const {PrefObserver} = require("devtools/client/shared/prefs");
const HTMLEditor = require("devtools/client/inspector/markup/views/html-editor");
const MarkupElementContainer = require("devtools/client/inspector/markup/views/element-container");
const MarkupReadOnlyContainer = require("devtools/client/inspector/markup/views/read-only-container");

View File

@ -13,7 +13,7 @@ const {Tools} = require("devtools/client/definitions");
const {l10n} = require("devtools/shared/inspector/css-logic");
const {ELEMENT_STYLE} = require("devtools/shared/specs/styles");
const {OutputParser} = require("devtools/client/shared/output-parser");
const {PrefObserver, PREF_ORIG_SOURCES} = require("devtools/client/styleeditor/utils");
const {PrefObserver} = require("devtools/client/shared/prefs");
const {ElementStyle} = require("devtools/client/inspector/rules/models/element-style");
const {Rule} = require("devtools/client/inspector/rules/models/rule");
const {RuleEditor} = require("devtools/client/inspector/rules/views/rule-editor");
@ -40,6 +40,7 @@ const PREF_DEFAULT_COLOR_UNIT = "devtools.defaultColorUnit";
const PREF_ENABLE_MDN_DOCS_TOOLTIP =
"devtools.inspector.mdnDocsTooltip.enabled";
const FILTER_CHANGED_TIMEOUT = 150;
const PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled";
// This is used to parse user input when filtering.
const FILTER_PROP_RE = /\s*([^:\s]*)\s*:\s*(.*?)\s*;?$/;

View File

@ -14,7 +14,7 @@
"use strict";
const { PrefObserver } = require("devtools/client/styleeditor/utils");
const { PrefObserver } = require("devtools/client/shared/prefs");
const PREF_ENABLE_MDN_DOCS_TOOLTIP =
"devtools.inspector.mdnDocsTooltip.enabled";
const PROPERTY_NAME_CLASS = "ruleview-propertyname";

View File

@ -8,7 +8,7 @@
// it is preffed on.
var PREF_UA_STYLES = "devtools.inspector.showUserAgentStyles";
const { PrefObserver } = require("devtools/client/styleeditor/utils");
const { PrefObserver } = require("devtools/client/shared/prefs");
const TEST_URI = URL_ROOT + "doc_author-sheet.html";

View File

@ -6,7 +6,6 @@
const {l10n} = require("devtools/shared/inspector/css-logic");
const {ELEMENT_STYLE} = require("devtools/shared/specs/styles");
const {PREF_ORIG_SOURCES} = require("devtools/client/styleeditor/utils");
const {Rule} = require("devtools/client/inspector/rules/models/rule");
const {InplaceEditor, editableField, editableItem} =
require("devtools/client/shared/inplace-editor");
@ -33,6 +32,8 @@ const STYLE_INSPECTOR_PROPERTIES = "devtools/shared/locales/styleinspector.prope
const {LocalizationHelper} = require("devtools/shared/l10n");
const STYLE_INSPECTOR_L10N = new LocalizationHelper(STYLE_INSPECTOR_PROPERTIES);
const PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled";
/**
* RuleEditor is responsible for the following:
* Owns a Rule object and creates a list of TextPropertyEditors

View File

@ -6,7 +6,6 @@
"use strict";
const {PREF_ORIG_SOURCES} = require("devtools/client/styleeditor/utils");
const Services = require("Services");
const {Task} = require("devtools/shared/task");
@ -28,6 +27,7 @@ const STYLE_INSPECTOR_L10N = new LocalizationHelper(STYLE_INSPECTOR_PROPERTIES);
const PREF_ENABLE_MDN_DOCS_TOOLTIP =
"devtools.inspector.mdnDocsTooltip.enabled";
const PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled";
/**
* Style inspector context menu

View File

@ -176,3 +176,31 @@ function makeObserver(self, cache, prefsRoot, prefsBlueprint) {
}
exports.PrefsHelper = PrefsHelper;
/**
* A PreferenceObserver observes a pref branch for pref changes.
* It emits an event for each preference change.
*/
function PrefObserver(branchName) {
this.branchName = branchName;
this.branch = Services.prefs.getBranch(branchName);
this.branch.addObserver("", this, false);
EventEmitter.decorate(this);
}
exports.PrefObserver = PrefObserver;
PrefObserver.prototype = {
observe: function (subject, topic, data) {
if (topic == "nsPref:changed") {
this.emit(this.branchName + data);
}
},
destroy: function () {
if (this.branch) {
this.branch.removeObserver("", this);
}
},
};

View File

@ -32,7 +32,7 @@ const RE_JUMP_TO_LINE = /^(\d+):?(\d+)?/;
const Services = require("Services");
const promise = require("promise");
const events = require("devtools/shared/event-emitter");
const { PrefObserver } = require("devtools/client/styleeditor/utils");
const { PrefObserver } = require("devtools/client/shared/prefs");
const { getClientCssProperties } = require("devtools/shared/fronts/css-properties");
const {KeyShortcuts} = require("devtools/client/shared/key-shortcuts");

View File

@ -26,7 +26,7 @@ const {
const {SplitView} = require("resource://devtools/client/shared/SplitView.jsm");
const {StyleSheetEditor} = require("resource://devtools/client/styleeditor/StyleSheetEditor.jsm");
const {PluralForm} = require("devtools/shared/plural-form");
const {PrefObserver, PREF_ORIG_SOURCES} = require("devtools/client/styleeditor/utils");
const {PrefObserver} = require("devtools/client/shared/prefs");
const csscoverage = require("devtools/shared/fronts/csscoverage");
const {console} = require("resource://gre/modules/Console.jsm");
const promise = require("promise");
@ -41,6 +41,7 @@ const SELECTOR_HIGHLIGHTER_TYPE = "SelectorHighlighter";
const PREF_MEDIA_SIDEBAR = "devtools.styleeditor.showMediaSidebar";
const PREF_SIDEBAR_WIDTH = "devtools.styleeditor.mediaSidebarWidth";
const PREF_NAV_WIDTH = "devtools.styleeditor.navSidebarWidth";
const PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled";
/**
* StyleEditorUI is controls and builds the UI of the Style Editor, including

View File

@ -12,5 +12,4 @@ DevToolsModules(
'StyleEditorUI.jsm',
'StyleEditorUtil.jsm',
'StyleSheetEditor.jsm',
'utils.js',
)

View File

@ -1,40 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const Services = require("Services");
const EventEmitter = require("devtools/shared/event-emitter");
exports.PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled";
/**
* A PreferenceObserver observes a pref branch for pref changes.
* It emits an event for each preference change.
*/
function PrefObserver(branchName) {
this.branchName = branchName;
this.branch = Services.prefs.getBranch(branchName);
this.branch.addObserver("", this, false);
EventEmitter.decorate(this);
}
exports.PrefObserver = PrefObserver;
PrefObserver.prototype = {
observe: function (subject, topic, data) {
if (topic == "nsPref:changed") {
this.emit(this.branchName + data);
}
},
destroy: function () {
if (this.branch) {
this.branch.removeObserver("", this);
}
}
};