Bug 1468002 - Set the initial grid highlighter settings in the reducer. r=pbro
MozReview-Commit-ID: HawQonSotgW
--- a/devtools/client/inspector/grids/reducers/highlighter-settings.js
+++ b/devtools/client/inspector/grids/reducers/highlighter-settings.js
@@ -1,24 +1,32 @@
/* 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 {
UPDATE_SHOW_GRID_AREAS,
UPDATE_SHOW_GRID_LINE_NUMBERS,
UPDATE_SHOW_INFINITE_LINES
} = require("../actions/index");
-const INITIAL_HIGHLIGHTER_SETTINGS = {
- showGridAreasOverlay: false,
- showGridLineNumbers: false,
- showInfiniteLines: false,
+const SHOW_GRID_AREAS = "devtools.gridinspector.showGridAreas";
+const SHOW_GRID_LINE_NUMBERS = "devtools.gridinspector.showGridLineNumbers";
+const SHOW_INFINITE_LINES = "devtools.gridinspector.showInfiniteLines";
+
+const INITIAL_HIGHLIGHTER_SETTINGS = () => {
+ return {
+ showGridAreasOverlay: Services.prefs.getBoolPref(SHOW_GRID_AREAS),
+ showGridLineNumbers: Services.prefs.getBoolPref(SHOW_GRID_LINE_NUMBERS),
+ showInfiniteLines: Services.prefs.getBoolPref(SHOW_INFINITE_LINES),
+ };
};
const reducers = {
[UPDATE_SHOW_GRID_AREAS](highlighterSettings, { enabled }) {
return Object.assign({}, highlighterSettings, {
showGridAreasOverlay: enabled,
});
@@ -33,15 +41,15 @@ const reducers = {
[UPDATE_SHOW_INFINITE_LINES](highlighterSettings, { enabled }) {
return Object.assign({}, highlighterSettings, {
showInfiniteLines: enabled,
});
},
};
-module.exports = function(highlighterSettings = INITIAL_HIGHLIGHTER_SETTINGS, action) {
+module.exports = function(highlighterSettings = INITIAL_HIGHLIGHTER_SETTINGS(), action) {
const reducer = reducers[action.type];
if (!reducer) {
return highlighterSettings;
}
return reducer(highlighterSettings, action);
};
--- a/devtools/client/inspector/shared/highlighters-overlay.js
+++ b/devtools/client/inspector/shared/highlighters-overlay.js
@@ -1,33 +1,23 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set 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");
const {
VIEW_NODE_VALUE_TYPE,
VIEW_NODE_SHAPE_POINT_TYPE
} = require("devtools/client/inspector/shared/node-types");
-const {
- updateShowGridAreas,
- updateShowGridLineNumbers,
- updateShowInfiniteLines,
-} = require("devtools/client/inspector/grids/actions/highlighter-settings");
-
const DEFAULT_GRID_COLOR = "#4B0082";
-const SHOW_GRID_AREAS = "devtools.gridinspector.showGridAreas";
-const SHOW_GRID_LINE_NUMBERS = "devtools.gridinspector.showGridLineNumbers";
-const SHOW_INFINITE_LINES_PREF = "devtools.gridinspector.showInfiniteLines";
/**
* Highlighters overlay is a singleton managing all highlighters in the Inspector.
*/
class HighlightersOverlay {
/**
* @param {Inspector} inspector
* Inspector toolbox panel.
@@ -82,18 +72,16 @@ class HighlightersOverlay {
this._handleRejection = this._handleRejection.bind(this);
this.onShapesHighlighterShown = this.onShapesHighlighterShown.bind(this);
this.onShapesHighlighterHidden = this.onShapesHighlighterHidden.bind(this);
// Add inspector events, not specific to a given view.
this.inspector.on("markupmutation", this.onMarkupMutation);
this.inspector.target.on("will-navigate", this.onWillNavigate);
- this.loadGridHighlighterSettings();
-
EventEmitter.decorate(this);
}
/**
* Returns whether `node` is somewhere inside the DOM of the rule view.
*
* @param {DOMNode} node
* @return {Boolean}
@@ -128,31 +116,16 @@ class HighlightersOverlay {
removeFromView(view) {
const el = view.element;
el.removeEventListener("click", this.onClick, true);
el.removeEventListener("mousemove", this.onMouseMove);
el.removeEventListener("mouseout", this.onMouseOut);
}
/**
- * Load the grid highligher display settings into the store from the stored preferences.
- */
- loadGridHighlighterSettings() {
- const { dispatch } = this.inspector.store;
-
- const showGridAreas = Services.prefs.getBoolPref(SHOW_GRID_AREAS);
- const showGridLineNumbers = Services.prefs.getBoolPref(SHOW_GRID_LINE_NUMBERS);
- const showInfinteLines = Services.prefs.getBoolPref(SHOW_INFINITE_LINES_PREF);
-
- dispatch(updateShowGridAreas(showGridAreas));
- dispatch(updateShowGridLineNumbers(showGridLineNumbers));
- dispatch(updateShowInfiniteLines(showInfinteLines));
- }
-
- /**
* Toggle the shapes highlighter for the given node.
* @param {NodeFront} node
* The NodeFront of the element with a shape to highlight.
* @param {Object} options
* Object used for passing options to the shapes highlighter.
* @param {TextProperty} textProperty
* TextProperty where to write changes.