2013-08-01 01:53:31 -07:00
|
|
|
/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-11-30 00:07:59 -08: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/. */
|
|
|
|
|
2013-12-06 23:52:32 -08:00
|
|
|
const {Cc, Ci, Cu, Cr} = require("chrome");
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-03-08 19:11:22 -08:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-12-06 23:52:32 -08:00
|
|
|
|
|
|
|
let promise = require("sdk/core/promise");
|
|
|
|
let EventEmitter = require("devtools/shared/event-emitter");
|
|
|
|
|
2013-04-25 09:46:13 -07:00
|
|
|
Cu.import("resource:///modules/devtools/StyleEditorUI.jsm");
|
|
|
|
Cu.import("resource:///modules/devtools/StyleEditorUtil.jsm");
|
|
|
|
|
2013-12-06 23:52:32 -08:00
|
|
|
loader.lazyGetter(this, "StyleSheetsFront",
|
2013-12-19 08:32:12 -08:00
|
|
|
() => require("devtools/server/actors/stylesheets").StyleSheetsFront);
|
|
|
|
|
|
|
|
loader.lazyGetter(this, "StyleEditorFront",
|
|
|
|
() => require("devtools/server/actors/styleeditor").StyleEditorFront);
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
this.StyleEditorPanel = function StyleEditorPanel(panelWin, toolbox) {
|
2012-12-13 23:05:00 -08:00
|
|
|
EventEmitter.decorate(this);
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
this._toolbox = toolbox;
|
|
|
|
this._target = toolbox.target;
|
2013-04-24 17:17:39 -07:00
|
|
|
this._panelWin = panelWin;
|
|
|
|
this._panelDoc = panelWin.document;
|
2013-04-25 09:46:13 -07:00
|
|
|
|
|
|
|
this.destroy = this.destroy.bind(this);
|
|
|
|
this._showError = this._showError.bind(this);
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
|
|
|
|
2013-12-06 23:52:32 -08:00
|
|
|
exports.StyleEditorPanel = StyleEditorPanel;
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
StyleEditorPanel.prototype = {
|
2013-04-25 09:46:13 -07:00
|
|
|
get target() this._toolbox.target,
|
2012-12-13 05:03:55 -08:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
get panelWindow() this._panelWin,
|
|
|
|
|
|
|
|
/**
|
2013-04-25 09:46:13 -07:00
|
|
|
* open is effectively an asynchronous constructor
|
2012-11-30 00:07:59 -08:00
|
|
|
*/
|
2013-04-25 09:46:13 -07:00
|
|
|
open: function() {
|
2013-07-11 00:12:20 -07:00
|
|
|
let deferred = promise.defer();
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
let targetPromise;
|
2013-04-25 09:46:13 -07:00
|
|
|
// We always interact with the target as if it were remote
|
|
|
|
if (!this.target.isRemote) {
|
2013-07-11 00:12:20 -07:00
|
|
|
targetPromise = this.target.makeRemote();
|
2012-11-30 00:07:59 -08:00
|
|
|
} else {
|
2013-07-11 00:12:20 -07:00
|
|
|
targetPromise = promise.resolve(this.target);
|
2013-03-08 19:11:22 -08:00
|
|
|
}
|
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
targetPromise.then(() => {
|
2013-04-25 09:46:13 -07:00
|
|
|
this.target.on("close", this.destroy);
|
2013-03-08 19:11:22 -08:00
|
|
|
|
2013-12-19 08:32:12 -08:00
|
|
|
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);
|
|
|
|
}
|
2013-12-06 23:52:32 -08:00
|
|
|
this.UI = new StyleEditorUI(this._debuggee, this.target, this._panelDoc);
|
2013-04-25 09:46:13 -07:00
|
|
|
this.UI.on("error", this._showError);
|
2013-03-08 19:11:22 -08:00
|
|
|
|
2013-04-25 09:46:13 -07:00
|
|
|
this.isReady = true;
|
2013-12-19 08:32:12 -08:00
|
|
|
|
2013-04-25 09:46:13 -07:00
|
|
|
deferred.resolve(this);
|
2013-12-19 08:32:12 -08:00
|
|
|
}, console.error);
|
2013-03-08 19:11:22 -08:00
|
|
|
|
2013-04-25 09:46:13 -07:00
|
|
|
return deferred.promise;
|
2013-03-08 19:11:22 -08:00
|
|
|
},
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
/**
|
2013-04-25 09:46:13 -07:00
|
|
|
* Show an error message from the style editor in the toolbox
|
|
|
|
* notification box.
|
|
|
|
*
|
|
|
|
* @param {string} event
|
|
|
|
* Type of event
|
2013-12-12 12:58:29 -08:00
|
|
|
* @param {string} code
|
2013-04-25 09:46:13 -07:00
|
|
|
* Error code of error to report
|
2013-12-12 12:58:29 -08:00
|
|
|
* @param {string} message
|
|
|
|
* Extra message to append to error message
|
2012-11-30 00:07:59 -08:00
|
|
|
*/
|
2013-12-12 12:58:29 -08:00
|
|
|
_showError: function(event, code, message) {
|
|
|
|
if (!this._toolbox) {
|
|
|
|
// could get an async error after we've been destroyed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let errorMessage = _(code);
|
|
|
|
if (message) {
|
|
|
|
errorMessage += " " + message;
|
|
|
|
}
|
|
|
|
|
2013-04-25 09:46:13 -07:00
|
|
|
let notificationBox = this._toolbox.getNotificationBox();
|
|
|
|
let notification = notificationBox.getNotificationWithValue("styleeditor-error");
|
|
|
|
if (!notification) {
|
2013-12-12 12:58:29 -08:00
|
|
|
notificationBox.appendNotification(errorMessage,
|
2013-04-25 09:46:13 -07:00
|
|
|
"styleeditor-error", "", notificationBox.PRIORITY_CRITICAL_LOW);
|
|
|
|
}
|
2012-11-30 00:07:59 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select a stylesheet.
|
2013-04-25 09:46:13 -07:00
|
|
|
*
|
|
|
|
* @param {string} href
|
|
|
|
* Url of stylesheet to find and select in editor
|
|
|
|
* @param {number} line
|
2013-06-13 13:56:36 -07:00
|
|
|
* Line number to jump to after selecting. One-indexed
|
2013-04-25 09:46:13 -07:00
|
|
|
* @param {number} col
|
2013-06-13 13:56:36 -07:00
|
|
|
* Column number to jump to after selecting. One-indexed
|
2012-11-30 00:07:59 -08:00
|
|
|
*/
|
2013-04-25 09:46:13 -07:00
|
|
|
selectStyleSheet: function(href, line, col) {
|
|
|
|
if (!this._debuggee || !this.UI) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-26 10:01:02 -08:00
|
|
|
this.UI.selectStyleSheet(href, line - 1, col ? col - 1 : 0);
|
2012-11-30 00:07:59 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-04-25 09:46:13 -07:00
|
|
|
* Destroy the style editor.
|
2012-11-30 00:07:59 -08:00
|
|
|
*/
|
2013-04-25 09:46:13 -07:00
|
|
|
destroy: function() {
|
2012-12-13 05:03:55 -08:00
|
|
|
if (!this._destroyed) {
|
|
|
|
this._destroyed = true;
|
|
|
|
|
|
|
|
this._target.off("close", this.destroy);
|
|
|
|
this._target = null;
|
|
|
|
this._toolbox = null;
|
|
|
|
this._panelDoc = null;
|
2013-04-25 09:46:13 -07:00
|
|
|
|
|
|
|
this._debuggee.destroy();
|
|
|
|
this.UI.destroy();
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
2012-12-13 05:03:55 -08:00
|
|
|
|
2013-07-11 00:12:20 -07:00
|
|
|
return promise.resolve(null);
|
2012-11-30 00:07:59 -08:00
|
|
|
},
|
|
|
|
}
|
2013-03-08 19:11:22 -08:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(StyleEditorPanel.prototype, "strings",
|
|
|
|
function () {
|
|
|
|
return Services.strings.createBundle(
|
|
|
|
"chrome://browser/locale/devtools/styleeditor.properties");
|
2013-04-04 01:23:42 -07:00
|
|
|
});
|