2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2012-11-30 12:07:59 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2016-01-15 18:34:45 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {Cu} = require("chrome");
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-12-07 11:52:32 +04:00
|
|
|
|
2016-02-27 15:51:10 +03:00
|
|
|
var Services = require("Services");
|
2015-09-15 21:19:45 +03:00
|
|
|
var promise = require("promise");
|
2015-09-21 20:04:18 +03:00
|
|
|
var EventEmitter = require("devtools/shared/event-emitter");
|
2013-12-07 11:52:32 +04:00
|
|
|
|
2015-10-14 02:18:43 +03:00
|
|
|
Cu.import("resource://devtools/client/styleeditor/StyleEditorUI.jsm");
|
2016-01-15 18:34:45 +03:00
|
|
|
/* import-globals-from StyleEditorUtil.jsm */
|
2015-10-14 02:18:43 +03:00
|
|
|
Cu.import("resource://devtools/client/styleeditor/StyleEditorUtil.jsm");
|
2013-04-25 20:46:13 +04:00
|
|
|
|
2013-12-07 11:52:32 +04:00
|
|
|
loader.lazyGetter(this, "StyleSheetsFront",
|
2013-12-19 20:32:12 +04:00
|
|
|
() => require("devtools/server/actors/stylesheets").StyleSheetsFront);
|
|
|
|
|
|
|
|
loader.lazyGetter(this, "StyleEditorFront",
|
|
|
|
() => require("devtools/server/actors/styleeditor").StyleEditorFront);
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2016-01-15 18:34:45 +03:00
|
|
|
var StyleEditorPanel = function StyleEditorPanel(panelWin, toolbox) {
|
2012-12-14 11:05:00 +04:00
|
|
|
EventEmitter.decorate(this);
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
this._toolbox = toolbox;
|
|
|
|
this._target = toolbox.target;
|
2013-04-25 04:17:39 +04:00
|
|
|
this._panelWin = panelWin;
|
|
|
|
this._panelDoc = panelWin.document;
|
2013-04-25 20:46:13 +04:00
|
|
|
|
|
|
|
this.destroy = this.destroy.bind(this);
|
|
|
|
this._showError = this._showError.bind(this);
|
2016-01-15 18:34:45 +03:00
|
|
|
};
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-12-07 11:52:32 +04:00
|
|
|
exports.StyleEditorPanel = StyleEditorPanel;
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
StyleEditorPanel.prototype = {
|
2015-05-22 21:50:01 +03:00
|
|
|
get target() {
|
|
|
|
return this._toolbox.target;
|
|
|
|
},
|
2012-12-13 17:03:55 +04:00
|
|
|
|
2015-05-22 21:50:01 +03:00
|
|
|
get panelWindow() {
|
|
|
|
return this._panelWin;
|
|
|
|
},
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
/**
|
2013-04-25 20:46:13 +04:00
|
|
|
* open is effectively an asynchronous constructor
|
2012-11-30 12:07:59 +04:00
|
|
|
*/
|
2015-03-26 14:30:35 +03:00
|
|
|
open: Task.async(function* () {
|
2013-04-25 20:46:13 +04:00
|
|
|
// We always interact with the target as if it were remote
|
|
|
|
if (!this.target.isRemote) {
|
2015-03-26 14:30:35 +03:00
|
|
|
yield this.target.makeRemote();
|
2013-03-09 07:11:22 +04:00
|
|
|
}
|
|
|
|
|
2015-03-26 14:30:35 +03:00
|
|
|
this.target.on("close", this.destroy);
|
2013-03-09 07:11:22 +04:00
|
|
|
|
2015-03-26 14:30:35 +03:00
|
|
|
if (this.target.form.styleSheetsActor) {
|
|
|
|
this._debuggee = StyleSheetsFront(this.target.client, this.target.form);
|
2016-01-15 18:34:45 +03:00
|
|
|
} else {
|
2015-03-26 14:30:35 +03:00
|
|
|
/* We're talking to a pre-Firefox 29 server-side */
|
|
|
|
this._debuggee = StyleEditorFront(this.target.client, this.target.form);
|
|
|
|
}
|
2013-03-09 07:11:22 +04:00
|
|
|
|
2015-03-26 14:30:35 +03:00
|
|
|
// Initialize the UI
|
|
|
|
this.UI = new StyleEditorUI(this._debuggee, this.target, this._panelDoc);
|
2015-04-22 19:04:48 +03:00
|
|
|
this.UI.on("error", this._showError);
|
2015-03-26 14:30:35 +03:00
|
|
|
yield this.UI.initialize();
|
2013-12-19 20:32:12 +04:00
|
|
|
|
2015-03-26 14:30:35 +03:00
|
|
|
this.isReady = true;
|
2013-03-09 07:11:22 +04:00
|
|
|
|
2015-03-26 14:30:35 +03:00
|
|
|
return this;
|
|
|
|
}),
|
2013-03-09 07:11:22 +04:00
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
2013-04-25 20:46:13 +04:00
|
|
|
* Show an error message from the style editor in the toolbox
|
|
|
|
* notification box.
|
|
|
|
*
|
|
|
|
* @param {string} event
|
|
|
|
* Type of event
|
2014-05-26 22:57:58 +04:00
|
|
|
* @param {string} data
|
|
|
|
* The parameters to customize the error message
|
2012-11-30 12:07:59 +04:00
|
|
|
*/
|
2014-05-26 22:57:58 +04:00
|
|
|
_showError: function(event, data) {
|
2013-12-13 00:58:29 +04:00
|
|
|
if (!this._toolbox) {
|
|
|
|
// could get an async error after we've been destroyed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-26 22:57:58 +04:00
|
|
|
let errorMessage = _(data.key);
|
|
|
|
if (data.append) {
|
|
|
|
errorMessage += " " + data.append;
|
2013-12-13 00:58:29 +04:00
|
|
|
}
|
|
|
|
|
2013-04-25 20:46:13 +04:00
|
|
|
let notificationBox = this._toolbox.getNotificationBox();
|
2016-01-15 18:34:45 +03:00
|
|
|
let notification =
|
|
|
|
notificationBox.getNotificationWithValue("styleeditor-error");
|
2014-05-26 22:57:58 +04:00
|
|
|
let level = (data.level === "info") ?
|
|
|
|
notificationBox.PRIORITY_INFO_LOW :
|
|
|
|
notificationBox.PRIORITY_CRITICAL_LOW;
|
|
|
|
|
2013-04-25 20:46:13 +04:00
|
|
|
if (!notification) {
|
2014-05-26 22:57:58 +04:00
|
|
|
notificationBox.appendNotification(errorMessage, "styleeditor-error",
|
|
|
|
"", level);
|
2013-04-25 20:46:13 +04:00
|
|
|
}
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select a stylesheet.
|
2013-04-25 20:46:13 +04:00
|
|
|
*
|
|
|
|
* @param {string} href
|
|
|
|
* Url of stylesheet to find and select in editor
|
|
|
|
* @param {number} line
|
2013-06-14 00:56:36 +04:00
|
|
|
* Line number to jump to after selecting. One-indexed
|
2013-04-25 20:46:13 +04:00
|
|
|
* @param {number} col
|
2013-06-14 00:56:36 +04:00
|
|
|
* Column number to jump to after selecting. One-indexed
|
2015-03-28 08:22:50 +03:00
|
|
|
* @return {Promise}
|
|
|
|
* Promise that will resolve when the editor is selected and ready
|
|
|
|
* to be used.
|
2012-11-30 12:07:59 +04:00
|
|
|
*/
|
2013-04-25 20:46:13 +04:00
|
|
|
selectStyleSheet: function(href, line, col) {
|
|
|
|
if (!this._debuggee || !this.UI) {
|
2016-01-15 18:34:45 +03:00
|
|
|
return null;
|
2013-04-25 20:46:13 +04:00
|
|
|
}
|
2015-03-28 08:22:50 +03:00
|
|
|
return this.UI.selectStyleSheet(href, line - 1, col ? col - 1 : 0);
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-04-25 20:46:13 +04:00
|
|
|
* Destroy the style editor.
|
2012-11-30 12:07:59 +04:00
|
|
|
*/
|
2013-04-25 20:46:13 +04:00
|
|
|
destroy: function() {
|
2012-12-13 17:03:55 +04:00
|
|
|
if (!this._destroyed) {
|
|
|
|
this._destroyed = true;
|
|
|
|
|
|
|
|
this._target.off("close", this.destroy);
|
|
|
|
this._target = null;
|
|
|
|
this._toolbox = null;
|
2015-05-18 21:15:35 +03:00
|
|
|
this._panelWin = null;
|
2012-12-13 17:03:55 +04:00
|
|
|
this._panelDoc = null;
|
2014-03-19 02:52:33 +04:00
|
|
|
this._debuggee.destroy();
|
|
|
|
this._debuggee = null;
|
2013-04-25 20:46:13 +04:00
|
|
|
|
|
|
|
this.UI.destroy();
|
2015-05-18 21:15:35 +03:00
|
|
|
this.UI = null;
|
2012-11-30 12:07:59 +04:00
|
|
|
}
|
2012-12-13 17:03:55 +04:00
|
|
|
|
2013-07-11 11:12:20 +04:00
|
|
|
return promise.resolve(null);
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
2016-01-15 18:34:45 +03:00
|
|
|
};
|
2013-03-09 07:11:22 +04:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(StyleEditorPanel.prototype, "strings",
|
2016-01-15 18:34:45 +03:00
|
|
|
function() {
|
2013-03-09 07:11:22 +04:00
|
|
|
return Services.strings.createBundle(
|
2015-11-05 00:35:53 +03:00
|
|
|
"chrome://devtools/locale/styleeditor.properties");
|
2013-04-04 12:23:42 +04:00
|
|
|
});
|