mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
4d6a633bba
The -*- file variable lines -*- establish per-file settings that Emacs will pick up. This patch makes the following changes to those lines (and touches nothing else): - Never set the buffer's mode. Years ago, Emacs did not have a good JavaScript mode, so it made sense to use Java or C++ mode in .js files. However, Emacs has had js-mode for years now; it's perfectly serviceable, and is available and enabled by default in all major Emacs packagings. Selecting a mode in the -*- file variable line -*- is almost always the wrong thing to do anyway. It overrides Emacs's default choice, which is (now) reasonable; and even worse, it overrides settings the user might have made in their '.emacs' file for that file extension. It's only useful when there's something specific about that particular file that makes a particular mode appropriate. - Correctly propagate settings that establish the correct indentation level for this file: c-basic-offset and js2-basic-offset should be js-indent-level. Whatever value they're given should be preserved; different parts of our tree use different indentation styles. - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil. Remove tab-width: settings, at least in files that don't contain tab characters. - Remove js2-mode settings that belong in the user's .emacs file, like js2-skip-preprocessor-directives.
155 lines
4.4 KiB
JavaScript
155 lines
4.4 KiB
JavaScript
/* -*- 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/. */
|
|
|
|
const {Cc, Ci, Cu, Cr} = require("chrome");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
|
|
let EventEmitter = require("devtools/toolkit/event-emitter");
|
|
|
|
Cu.import("resource:///modules/devtools/StyleEditorUI.jsm");
|
|
Cu.import("resource:///modules/devtools/StyleEditorUtil.jsm");
|
|
|
|
loader.lazyGetter(this, "StyleSheetsFront",
|
|
() => require("devtools/server/actors/stylesheets").StyleSheetsFront);
|
|
|
|
loader.lazyGetter(this, "StyleEditorFront",
|
|
() => require("devtools/server/actors/styleeditor").StyleEditorFront);
|
|
|
|
this.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() this._toolbox.target,
|
|
|
|
get panelWindow() this._panelWin,
|
|
|
|
/**
|
|
* open is effectively an asynchronous constructor
|
|
*/
|
|
open: function() {
|
|
let deferred = promise.defer();
|
|
|
|
let targetPromise;
|
|
// We always interact with the target as if it were remote
|
|
if (!this.target.isRemote) {
|
|
targetPromise = this.target.makeRemote();
|
|
} else {
|
|
targetPromise = promise.resolve(this.target);
|
|
}
|
|
|
|
targetPromise.then(() => {
|
|
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);
|
|
}
|
|
this.UI = new StyleEditorUI(this._debuggee, this.target, this._panelDoc);
|
|
this.UI.initialize().then(() => {
|
|
this.UI.on("error", this._showError);
|
|
|
|
this.isReady = true;
|
|
|
|
deferred.resolve(this);
|
|
});
|
|
}, console.error);
|
|
|
|
return deferred.promise;
|
|
},
|
|
|
|
/**
|
|
* 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 = _(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
|
|
*/
|
|
selectStyleSheet: function(href, line, col) {
|
|
if (!this._debuggee || !this.UI) {
|
|
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._panelDoc = null;
|
|
this._debuggee.destroy();
|
|
this._debuggee = null;
|
|
|
|
this.UI.destroy();
|
|
}
|
|
|
|
return promise.resolve(null);
|
|
},
|
|
}
|
|
|
|
XPCOMUtils.defineLazyGetter(StyleEditorPanel.prototype, "strings",
|
|
function () {
|
|
return Services.strings.createBundle(
|
|
"chrome://browser/locale/devtools/styleeditor.properties");
|
|
});
|