mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1772093 - Part 5: Use plain object for lazy getter in devtools/client/styleeditor/. r=devtools-reviewers,ochameau
Differential Revision: https://phabricator.services.mozilla.com/D147901
This commit is contained in:
parent
9f4d6c53aa
commit
725309d478
@ -25,45 +25,47 @@ const { PrefObserver } = require("devtools/client/shared/prefs");
|
||||
|
||||
const KeyShortcuts = require("devtools/client/shared/key-shortcuts");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"KeyCodes",
|
||||
"devtools/client/shared/keycodes",
|
||||
true
|
||||
);
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"OriginalSource",
|
||||
"devtools/client/styleeditor/original-source",
|
||||
true
|
||||
);
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"FileUtils",
|
||||
"resource://gre/modules/FileUtils.jsm",
|
||||
true
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NetUtil",
|
||||
"resource://gre/modules/NetUtil.jsm",
|
||||
true
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"ResponsiveUIManager",
|
||||
"devtools/client/responsive/manager"
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"openContentLink",
|
||||
"devtools/client/shared/link",
|
||||
true
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"copyString",
|
||||
"devtools/shared/platform/clipboard",
|
||||
true
|
||||
@ -422,21 +424,21 @@ class StyleEditorUI extends EventEmitter {
|
||||
|
||||
let elementToFocus;
|
||||
if (
|
||||
event.keyCode == KeyCodes.DOM_VK_PAGE_UP ||
|
||||
event.keyCode == KeyCodes.DOM_VK_HOME
|
||||
event.keyCode == lazy.KeyCodes.DOM_VK_PAGE_UP ||
|
||||
event.keyCode == lazy.KeyCodes.DOM_VK_HOME
|
||||
) {
|
||||
elementToFocus = visibleElements[0];
|
||||
} else if (
|
||||
event.keyCode == KeyCodes.DOM_VK_PAGE_DOWN ||
|
||||
event.keyCode == KeyCodes.DOM_VK_END
|
||||
event.keyCode == lazy.KeyCodes.DOM_VK_PAGE_DOWN ||
|
||||
event.keyCode == lazy.KeyCodes.DOM_VK_END
|
||||
) {
|
||||
elementToFocus = visibleElements.at(-1);
|
||||
} else if (event.keyCode == KeyCodes.DOM_VK_UP) {
|
||||
} else if (event.keyCode == lazy.KeyCodes.DOM_VK_UP) {
|
||||
const focusedIndex = visibleElements.indexOf(
|
||||
getFocusedItemWithin(this.#nav)
|
||||
);
|
||||
elementToFocus = visibleElements[focusedIndex - 1];
|
||||
} else if (event.keyCode == KeyCodes.DOM_VK_DOWN) {
|
||||
} else if (event.keyCode == lazy.KeyCodes.DOM_VK_DOWN) {
|
||||
const focusedIndex = visibleElements.indexOf(
|
||||
getFocusedItemWithin(this.#nav)
|
||||
);
|
||||
@ -580,7 +582,7 @@ class StyleEditorUI extends EventEmitter {
|
||||
editor = null;
|
||||
|
||||
for (const { id: originalId, url: originalURL } of sources) {
|
||||
const original = new OriginalSource(
|
||||
const original = new lazy.OriginalSource(
|
||||
originalURL,
|
||||
originalId,
|
||||
sourceMapService
|
||||
@ -703,9 +705,9 @@ class StyleEditorUI extends EventEmitter {
|
||||
// nothing selected
|
||||
return;
|
||||
}
|
||||
NetUtil.asyncFetch(
|
||||
lazy.NetUtil.asyncFetch(
|
||||
{
|
||||
uri: NetUtil.newURI(selectedFile),
|
||||
uri: lazy.NetUtil.newURI(selectedFile),
|
||||
loadingNode: this.#window.document,
|
||||
securityFlags:
|
||||
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_INHERITS_SEC_CONTEXT,
|
||||
@ -716,7 +718,7 @@ class StyleEditorUI extends EventEmitter {
|
||||
this.emit("error", { key: LOAD_ERROR, level: "warning" });
|
||||
return;
|
||||
}
|
||||
const source = NetUtil.readInputStreamToString(
|
||||
const source = lazy.NetUtil.readInputStreamToString(
|
||||
stream,
|
||||
stream.available()
|
||||
);
|
||||
@ -798,7 +800,7 @@ class StyleEditorUI extends EventEmitter {
|
||||
*/
|
||||
#openLinkNewTab = () => {
|
||||
if (this.#contextMenuStyleSheet) {
|
||||
openContentLink(this.#contextMenuStyleSheet.href);
|
||||
lazy.openContentLink(this.#contextMenuStyleSheet.href);
|
||||
}
|
||||
};
|
||||
|
||||
@ -807,7 +809,7 @@ class StyleEditorUI extends EventEmitter {
|
||||
*/
|
||||
#copyUrl = () => {
|
||||
if (this.#contextMenuStyleSheet) {
|
||||
copyString(this.#contextMenuStyleSheet.href);
|
||||
lazy.copyString(this.#contextMenuStyleSheet.href);
|
||||
}
|
||||
};
|
||||
|
||||
@ -900,7 +902,7 @@ class StyleEditorUI extends EventEmitter {
|
||||
summary.querySelector(".stylesheet-name").addEventListener(
|
||||
"keypress",
|
||||
event => {
|
||||
if (event.keyCode == KeyCodes.DOM_VK_RETURN) {
|
||||
if (event.keyCode == lazy.KeyCodes.DOM_VK_RETURN) {
|
||||
this.setActiveSummary(summary);
|
||||
}
|
||||
},
|
||||
@ -1405,12 +1407,14 @@ class StyleEditorUI extends EventEmitter {
|
||||
const tab = this.currentTarget.localTab;
|
||||
const win = this.currentTarget.localTab.ownerDocument.defaultView;
|
||||
|
||||
await ResponsiveUIManager.openIfNeeded(win, tab, {
|
||||
await lazy.ResponsiveUIManager.openIfNeeded(win, tab, {
|
||||
trigger: "style_editor",
|
||||
});
|
||||
this.emit("responsive-mode-opened");
|
||||
|
||||
ResponsiveUIManager.getResponsiveUIForTab(tab).setViewportSize(options);
|
||||
lazy.ResponsiveUIManager.getResponsiveUIForTab(tab).setViewportSize(
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1444,7 +1448,7 @@ class StyleEditorUI extends EventEmitter {
|
||||
try {
|
||||
// The fileName is in resource means this stylesheet was imported from file by user.
|
||||
const { fileName } = resource;
|
||||
let file = fileName ? new FileUtils.File(fileName) : null;
|
||||
let file = fileName ? new lazy.FileUtils.File(fileName) : null;
|
||||
|
||||
// recall location of saved file for this sheet after page reload
|
||||
if (!file) {
|
||||
|
@ -24,9 +24,11 @@ const { loader, require } = ChromeUtils.import(
|
||||
const Services = require("Services");
|
||||
const gStringBundle = Services.strings.createBundle(PROPERTIES_URL);
|
||||
|
||||
loader.lazyRequireGetter(this, "Menu", "devtools/client/framework/menu");
|
||||
const lazy = {};
|
||||
|
||||
loader.lazyRequireGetter(lazy, "Menu", "devtools/client/framework/menu");
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"MenuItem",
|
||||
"devtools/client/framework/menu-item"
|
||||
);
|
||||
@ -209,9 +211,9 @@ function showFilePicker(
|
||||
* A Menu object holding the MenuItems
|
||||
*/
|
||||
function optionsPopupMenu(toggleOrigSources, toggleMediaSidebar) {
|
||||
const popupMenu = new Menu();
|
||||
const popupMenu = new lazy.Menu();
|
||||
popupMenu.append(
|
||||
new MenuItem({
|
||||
new lazy.MenuItem({
|
||||
id: "options-origsources",
|
||||
label: getString("showOriginalSources.label"),
|
||||
accesskey: getString("showOriginalSources.accesskey"),
|
||||
@ -221,7 +223,7 @@ function optionsPopupMenu(toggleOrigSources, toggleMediaSidebar) {
|
||||
})
|
||||
);
|
||||
popupMenu.append(
|
||||
new MenuItem({
|
||||
new lazy.MenuItem({
|
||||
id: "options-show-media",
|
||||
label: getString("showMediaSidebar.label"),
|
||||
accesskey: getString("showMediaSidebar.accesskey"),
|
||||
|
@ -18,14 +18,16 @@ const { throttle } = require("devtools/shared/throttle");
|
||||
const Services = require("Services");
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"FileUtils",
|
||||
"resource://gre/modules/FileUtils.jsm",
|
||||
true
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
lazy,
|
||||
"NetUtil",
|
||||
"resource://gre/modules/NetUtil.jsm",
|
||||
true
|
||||
@ -239,14 +241,14 @@ StyleSheetEditor.prototype = {
|
||||
|
||||
let path;
|
||||
const href = removeQuery(relatedSheet.href);
|
||||
const uri = NetUtil.newURI(href);
|
||||
const uri = lazy.NetUtil.newURI(href);
|
||||
|
||||
if (uri.scheme == "file") {
|
||||
const file = uri.QueryInterface(Ci.nsIFileURL).file;
|
||||
path = file.path;
|
||||
} else if (this.savedFile) {
|
||||
const origHref = removeQuery(this.styleSheet.href);
|
||||
const origUri = NetUtil.newURI(origHref);
|
||||
const origUri = lazy.NetUtil.newURI(origHref);
|
||||
path = findLinkedFilePath(uri, origUri, this.savedFile);
|
||||
} else {
|
||||
// we can't determine path to generated file on disk
|
||||
@ -749,14 +751,14 @@ StyleSheetEditor.prototype = {
|
||||
this._state.text = this.sourceEditor.getText();
|
||||
}
|
||||
|
||||
const ostream = FileUtils.openSafeFileOutputStream(returnFile);
|
||||
const ostream = lazy.FileUtils.openSafeFileOutputStream(returnFile);
|
||||
const converter = Cc[
|
||||
"@mozilla.org/intl/scriptableunicodeconverter"
|
||||
].createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
converter.charset = "UTF-8";
|
||||
const istream = converter.convertToInputStream(this._state.text);
|
||||
|
||||
NetUtil.asyncCopy(istream, ostream, status => {
|
||||
lazy.NetUtil.asyncCopy(istream, ostream, status => {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
if (callback) {
|
||||
callback(null);
|
||||
@ -764,7 +766,7 @@ StyleSheetEditor.prototype = {
|
||||
this.emit("error", { key: SAVE_ERROR });
|
||||
return;
|
||||
}
|
||||
FileUtils.closeSafeFileOutputStream(ostream);
|
||||
lazy.FileUtils.closeSafeFileOutputStream(ostream);
|
||||
|
||||
this.onFileSaved(returnFile);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user