gecko-dev/devtools/client/styleeditor/styleeditor-panel.js

159 строки
4.6 KiB
JavaScript
Исходник Обычный вид История

/* 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";
var Services = require("Services");
var promise = require("promise");
var {Task} = require("devtools/shared/task");
var {XPCOMUtils} = require("resource://gre/modules/XPCOMUtils.jsm");
var EventEmitter = require("devtools/shared/event-emitter");
var {StyleEditorUI} = require("resource://devtools/client/styleeditor/StyleEditorUI.jsm");
var {getString} = require("resource://devtools/client/styleeditor/StyleEditorUtil.jsm");
var {initCssProperties} = require("devtools/shared/fronts/css-properties");
loader.lazyGetter(this, "StyleSheetsFront",
() => require("devtools/shared/fronts/stylesheets").StyleSheetsFront);
loader.lazyGetter(this, "StyleEditorFront",
() => require("devtools/shared/fronts/styleeditor").StyleEditorFront);
var StyleEditorPanel = function StyleEditorPanel(panelWin, toolbox) {
EventEmitter.decorate(this);
this._toolbox = toolbox;
this._target = toolbox.target;
this._panelWin = panelWin;
this._panelDoc = panelWin.document;
this.destroy = this.destroy.bind(this);
this._showError = this._showError.bind(this);
};
exports.StyleEditorPanel = StyleEditorPanel;
StyleEditorPanel.prototype = {
get target() {
return this._toolbox.target;
},
get panelWindow() {
return this._panelWin;
},
/**
* open is effectively an asynchronous constructor
*/
open: Task.async(function* () {
// We always interact with the target as if it were remote
if (!this.target.isRemote) {
yield this.target.makeRemote();
}
this.target.on("close", this.destroy);
if (this.target.form.styleSheetsActor) {
this._debuggee = StyleSheetsFront(this.target.client, this.target.form);
} else {
/* We're talking to a pre-Firefox 29 server-side */
this._debuggee = StyleEditorFront(this.target.client, this.target.form);
}
// Initialize the CSS properties database.
const {cssProperties} = yield initCssProperties(this._toolbox);
// Initialize the UI
this.UI = new StyleEditorUI(this._debuggee, this.target, this._panelDoc,
cssProperties);
this.UI.on("error", this._showError);
yield this.UI.initialize();
this.isReady = true;
return this;
}),
/**
* Show an error message from the style editor in the toolbox
* notification box.
*
* @param {string} event
* Type of event
* @param {string} data
* The parameters to customize the error message
*/
_showError: function (event, data) {
if (!this._toolbox) {
// could get an async error after we've been destroyed
return;
}
let errorMessage = getString(data.key);
if (data.append) {
errorMessage += " " + data.append;
}
let notificationBox = this._toolbox.getNotificationBox();
let notification =
notificationBox.getNotificationWithValue("styleeditor-error");
let level = (data.level === "info") ?
notificationBox.PRIORITY_INFO_LOW :
notificationBox.PRIORITY_CRITICAL_LOW;
if (!notification) {
notificationBox.appendNotification(errorMessage, "styleeditor-error",
"", level);
}
},
/**
* Select a stylesheet.
*
* @param {string} href
* Url of stylesheet to find and select in editor
* @param {number} line
* Line number to jump to after selecting. One-indexed
* @param {number} col
* Column number to jump to after selecting. One-indexed
* @return {Promise}
* Promise that will resolve when the editor is selected and ready
* to be used.
*/
selectStyleSheet: function (href, line, col) {
if (!this._debuggee || !this.UI) {
return null;
}
return this.UI.selectStyleSheet(href, line - 1, col ? col - 1 : 0);
},
/**
* Destroy the style editor.
*/
destroy: function () {
if (!this._destroyed) {
this._destroyed = true;
this._target.off("close", this.destroy);
this._target = null;
this._toolbox = null;
this._panelWin = null;
this._panelDoc = null;
this._debuggee.destroy();
this._debuggee = null;
this.UI.destroy();
this.UI = null;
}
return promise.resolve(null);
},
};
XPCOMUtils.defineLazyGetter(StyleEditorPanel.prototype, "strings",
function () {
return Services.strings.createBundle(
Bug 1182722 - Move DevTools l10n files. r=ochameau,glandium,Pike,bgrins Move DevTools l10n files under /devtools/client and /devtools/shared. A script is attached to the bug for l10n repos to migrate their strings. --HG-- rename : browser/locales/en-US/chrome/browser/devtools/VariablesView.dtd => devtools/client/locales/en-US/VariablesView.dtd rename : browser/locales/en-US/chrome/browser/devtools/aboutdebugging.dtd => devtools/client/locales/en-US/aboutdebugging.dtd rename : browser/locales/en-US/chrome/browser/devtools/aboutdebugging.properties => devtools/client/locales/en-US/aboutdebugging.properties rename : browser/locales/en-US/chrome/browser/devtools/animationinspector.dtd => devtools/client/locales/en-US/animationinspector.dtd rename : browser/locales/en-US/chrome/browser/devtools/animationinspector.properties => devtools/client/locales/en-US/animationinspector.properties rename : browser/locales/en-US/chrome/browser/devtools/app-manager.properties => devtools/client/locales/en-US/app-manager.properties rename : browser/locales/en-US/chrome/browser/devtools/appcacheutils.properties => devtools/client/locales/en-US/appcacheutils.properties rename : browser/locales/en-US/chrome/browser/devtools/canvasdebugger.dtd => devtools/client/locales/en-US/canvasdebugger.dtd rename : browser/locales/en-US/chrome/browser/devtools/canvasdebugger.properties => devtools/client/locales/en-US/canvasdebugger.properties rename : browser/locales/en-US/chrome/browser/devtools/connection-screen.dtd => devtools/client/locales/en-US/connection-screen.dtd rename : browser/locales/en-US/chrome/browser/devtools/connection-screen.properties => devtools/client/locales/en-US/connection-screen.properties rename : browser/locales/en-US/chrome/browser/devtools/debugger.dtd => devtools/client/locales/en-US/debugger.dtd rename : browser/locales/en-US/chrome/browser/devtools/debugger.properties => devtools/client/locales/en-US/debugger.properties rename : browser/locales/en-US/chrome/browser/devtools/device.properties => devtools/client/locales/en-US/device.properties rename : browser/locales/en-US/chrome/browser/devtools/eyedropper.properties => devtools/client/locales/en-US/eyedropper.properties rename : browser/locales/en-US/chrome/browser/devtools/filterwidget.dtd => devtools/client/locales/en-US/filterwidget.dtd rename : browser/locales/en-US/chrome/browser/devtools/filterwidget.properties => devtools/client/locales/en-US/filterwidget.properties rename : browser/locales/en-US/chrome/browser/devtools/font-inspector.dtd => devtools/client/locales/en-US/font-inspector.dtd rename : browser/locales/en-US/chrome/browser/devtools/graphs.properties => devtools/client/locales/en-US/graphs.properties rename : browser/locales/en-US/chrome/browser/devtools/har.properties => devtools/client/locales/en-US/har.properties rename : browser/locales/en-US/chrome/browser/devtools/inspector.dtd => devtools/client/locales/en-US/inspector.dtd rename : browser/locales/en-US/chrome/browser/devtools/inspector.properties => devtools/client/locales/en-US/inspector.properties rename : browser/locales/en-US/chrome/browser/devtools/jsonview.properties => devtools/client/locales/en-US/jsonview.properties rename : browser/locales/en-US/chrome/browser/devtools/layoutview.dtd => devtools/client/locales/en-US/layoutview.dtd rename : browser/locales/en-US/chrome/browser/devtools/markers.properties => devtools/client/locales/en-US/markers.properties rename : browser/locales/en-US/chrome/browser/devtools/memory.properties => devtools/client/locales/en-US/memory.properties rename : browser/locales/en-US/chrome/browser/devtools/netmonitor.dtd => devtools/client/locales/en-US/netmonitor.dtd rename : browser/locales/en-US/chrome/browser/devtools/netmonitor.properties => devtools/client/locales/en-US/netmonitor.properties rename : browser/locales/en-US/chrome/browser/devtools/performance.dtd => devtools/client/locales/en-US/performance.dtd rename : browser/locales/en-US/chrome/browser/devtools/performance.properties => devtools/client/locales/en-US/performance.properties rename : browser/locales/en-US/chrome/browser/devtools/projecteditor.properties => devtools/client/locales/en-US/projecteditor.properties rename : browser/locales/en-US/chrome/browser/devtools/promisedebugger.dtd => devtools/client/locales/en-US/promisedebugger.dtd rename : browser/locales/en-US/chrome/browser/devtools/promisedebugger.properties => devtools/client/locales/en-US/promisedebugger.properties rename : browser/locales/en-US/chrome/browser/devtools/responsiveUI.properties => devtools/client/locales/en-US/responsiveUI.properties rename : browser/locales/en-US/chrome/browser/devtools/scratchpad.dtd => devtools/client/locales/en-US/scratchpad.dtd rename : browser/locales/en-US/chrome/browser/devtools/scratchpad.properties => devtools/client/locales/en-US/scratchpad.properties rename : browser/locales/en-US/chrome/browser/devtools/shadereditor.dtd => devtools/client/locales/en-US/shadereditor.dtd rename : browser/locales/en-US/chrome/browser/devtools/shadereditor.properties => devtools/client/locales/en-US/shadereditor.properties rename : browser/locales/en-US/chrome/browser/devtools/shared.properties => devtools/client/locales/en-US/shared.properties rename : browser/locales/en-US/chrome/browser/devtools/sourceeditor.dtd => devtools/client/locales/en-US/sourceeditor.dtd rename : browser/locales/en-US/chrome/browser/devtools/sourceeditor.properties => devtools/client/locales/en-US/sourceeditor.properties rename : browser/locales/en-US/chrome/browser/devtools/storage.properties => devtools/client/locales/en-US/storage.properties rename : browser/locales/en-US/chrome/browser/devtools/styleeditor.dtd => devtools/client/locales/en-US/styleeditor.dtd rename : browser/locales/en-US/chrome/browser/devtools/styleeditor.properties => devtools/client/locales/en-US/styleeditor.properties rename : browser/locales/en-US/chrome/browser/devtools/styleinspector.dtd => devtools/client/locales/en-US/styleinspector.dtd rename : browser/locales/en-US/chrome/browser/devtools/tilt.properties => devtools/client/locales/en-US/tilt.properties rename : browser/locales/en-US/chrome/browser/devtools/toolbox.dtd => devtools/client/locales/en-US/toolbox.dtd rename : browser/locales/en-US/chrome/browser/devtools/toolbox.properties => devtools/client/locales/en-US/toolbox.properties rename : browser/locales/en-US/chrome/browser/devtools/webConsole.dtd => devtools/client/locales/en-US/webConsole.dtd rename : browser/locales/en-US/chrome/browser/devtools/webaudioeditor.dtd => devtools/client/locales/en-US/webaudioeditor.dtd rename : browser/locales/en-US/chrome/browser/devtools/webaudioeditor.properties => devtools/client/locales/en-US/webaudioeditor.properties rename : browser/locales/en-US/chrome/browser/devtools/webconsole.properties => devtools/client/locales/en-US/webconsole.properties rename : browser/locales/en-US/chrome/browser/devtools/webide.dtd => devtools/client/locales/en-US/webide.dtd rename : browser/locales/en-US/chrome/browser/devtools/webide.properties => devtools/client/locales/en-US/webide.properties rename : toolkit/locales/en-US/chrome/global/devtools/csscoverage.dtd => devtools/shared/locales/en-US/csscoverage.dtd rename : toolkit/locales/en-US/chrome/global/devtools/csscoverage.properties => devtools/shared/locales/en-US/csscoverage.properties rename : toolkit/locales/en-US/chrome/global/devtools/debugger.properties => devtools/shared/locales/en-US/debugger.properties rename : toolkit/locales/en-US/chrome/global/devtools/gcli.properties => devtools/shared/locales/en-US/gcli.properties rename : toolkit/locales/en-US/chrome/global/devtools/gclicommands.properties => devtools/shared/locales/en-US/gclicommands.properties rename : toolkit/locales/en-US/chrome/global/devtools/styleinspector.properties => devtools/shared/locales/en-US/styleinspector.properties extra : commitid : 8hcm3tr7AAi
2015-11-05 00:35:53 +03:00
"chrome://devtools/locale/styleeditor.properties");
});