mirror of
https://github.com/zen-browser/desktop.git
synced 2025-10-05 17:36:34 +00:00
Refactor DevTools keyboard shortcuts management and restore default shortcuts
This commit is contained in:
@@ -111,21 +111,6 @@ const fixedL10nIds = {
|
|||||||
'Browser:ReloadSkipCache': 'zen-nav-reload-shortcut-skip-cache',
|
'Browser:ReloadSkipCache': 'zen-nav-reload-shortcut-skip-cache',
|
||||||
cmd_close: 'zen-close-tab-shortcut',
|
cmd_close: 'zen-close-tab-shortcut',
|
||||||
'History:RestoreLastClosedTabOrWindowOrSession': 'zen-restore-last-closed-tab-shortcut',
|
'History:RestoreLastClosedTabOrWindowOrSession': 'zen-restore-last-closed-tab-shortcut',
|
||||||
|
|
||||||
// Devtools
|
|
||||||
key_toggleToolbox: 'zen-devtools-toggle-shortcut',
|
|
||||||
key_browserToolbox: 'zen-devtools-toggle-browser-toolbox-shortcut',
|
|
||||||
key_browserConsole: 'zen-devtools-toggle-browser-console-shortcut',
|
|
||||||
key_responsiveDesignMode: 'zen-devtools-toggle-responsive-design-mode-shortcut',
|
|
||||||
key_inspector: 'zen-devtools-toggle-inspector-shortcut',
|
|
||||||
key_webconsole: 'zen-devtools-toggle-web-console-shortcut',
|
|
||||||
key_jsdebugger: 'zen-devtools-toggle-js-debugger-shortcut',
|
|
||||||
key_netmonitor: 'zen-devtools-toggle-net-monitor-shortcut',
|
|
||||||
key_styleeditor: 'zen-devtools-toggle-style-editor-shortcut',
|
|
||||||
key_performance: 'zen-devtools-toggle-performance-shortcut',
|
|
||||||
key_storage: 'zen-devtools-toggle-storage-shortcut',
|
|
||||||
key_dom: 'zen-devtools-toggle-dom-shortcut',
|
|
||||||
key_accessibility: 'zen-devtools-toggle-accessibility-shortcut',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ZEN_MAIN_KEYSET_ID = 'mainKeyset';
|
const ZEN_MAIN_KEYSET_ID = 'mainKeyset';
|
||||||
@@ -750,7 +735,6 @@ class ZenKeyboardShortcutsLoader {
|
|||||||
static zenGetDefaultDevToolsShortcuts() {
|
static zenGetDefaultDevToolsShortcuts() {
|
||||||
let keySet = document.getElementById(ZEN_DEVTOOLS_KEYSET_ID);
|
let keySet = document.getElementById(ZEN_DEVTOOLS_KEYSET_ID);
|
||||||
let newShortcutList = [];
|
let newShortcutList = [];
|
||||||
|
|
||||||
for (let i = keySet.children.length - 1; i >= 0; i--) {
|
for (let i = keySet.children.length - 1; i >= 0; i--) {
|
||||||
let key = keySet.children[i];
|
let key = keySet.children[i];
|
||||||
if (this.IGNORED_DEVTOOLS_SHORTCUTS.includes(key.id)) {
|
if (this.IGNORED_DEVTOOLS_SHORTCUTS.includes(key.id)) {
|
||||||
@@ -912,6 +896,7 @@ class ZenKeyboardShortcutsVersioner {
|
|||||||
window.removeEventListener('zen-devtools-keyset-added', listener);
|
window.removeEventListener('zen-devtools-keyset-added', listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
gZenKeyboardShortcutsManager._hasToLoadDefaultDevtools = true;
|
||||||
window.addEventListener('zen-devtools-keyset-added', listener);
|
window.addEventListener('zen-devtools-keyset-added', listener);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
@@ -1034,12 +1019,16 @@ var gZenKeyboardShortcutsManager = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async updatedDefaultDevtoolsShortcuts(shortcuts) {
|
async updatedDefaultDevtoolsShortcuts(shortcuts) {
|
||||||
|
this._hasToLoadDefaultDevtools = false;
|
||||||
this._currentShortcutList = this._currentShortcutList.concat(shortcuts);
|
this._currentShortcutList = this._currentShortcutList.concat(shortcuts);
|
||||||
await this._saveShortcuts();
|
await this._saveShortcuts();
|
||||||
this._hasAddedDevtoolShortcuts();
|
this._hasAddedDevtoolShortcuts();
|
||||||
},
|
},
|
||||||
|
|
||||||
_hasAddedDevtoolShortcuts() {
|
_hasAddedDevtoolShortcuts() {
|
||||||
|
if (this._hasToLoadDevtools || this._hasToLoadDefaultDevtools) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this._hasToLoadDevtools = true;
|
this._hasToLoadDevtools = true;
|
||||||
this.triggerShortcutRebuild();
|
this.triggerShortcutRebuild();
|
||||||
},
|
},
|
||||||
@@ -1093,12 +1082,16 @@ var gZenKeyboardShortcutsManager = {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let child = key.toXHTMLElement(browser);
|
let child = key.toXHTMLElement(browser);
|
||||||
|
// child.addEventListener('command', event);
|
||||||
devtoolsKeyset.appendChild(child);
|
devtoolsKeyset.appendChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let key of remainingChildren) {
|
for (let key of remainingChildren) {
|
||||||
devtoolsKeyset.appendChild(key);
|
devtoolsKeyset.appendChild(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mainKeyset = browser.document.getElementById(ZEN_MAIN_KEYSET_ID);
|
||||||
|
mainKeyset.before(devtoolsKeyset);
|
||||||
},
|
},
|
||||||
|
|
||||||
async resetAllShortcuts() {
|
async resetAllShortcuts() {
|
||||||
|
@@ -733,6 +733,21 @@ var zenMissingKeyboardShortcutL10n = {
|
|||||||
|
|
||||||
goHome: 'zen-key-go-home',
|
goHome: 'zen-key-go-home',
|
||||||
key_redo: 'zen-key-redo',
|
key_redo: 'zen-key-redo',
|
||||||
|
|
||||||
|
// Devtools
|
||||||
|
key_toggleToolbox: 'zen-devtools-toggle-shortcut',
|
||||||
|
key_browserToolbox: 'zen-devtools-toggle-browser-toolbox-shortcut',
|
||||||
|
key_browserConsole: 'zen-devtools-toggle-browser-console-shortcut',
|
||||||
|
key_responsiveDesignMode: 'zen-devtools-toggle-responsive-design-mode-shortcut',
|
||||||
|
key_inspector: 'zen-devtools-toggle-inspector-shortcut',
|
||||||
|
key_webconsole: 'zen-devtools-toggle-web-console-shortcut',
|
||||||
|
key_jsdebugger: 'zen-devtools-toggle-js-debugger-shortcut',
|
||||||
|
key_netmonitor: 'zen-devtools-toggle-net-monitor-shortcut',
|
||||||
|
key_styleeditor: 'zen-devtools-toggle-style-editor-shortcut',
|
||||||
|
key_performance: 'zen-devtools-toggle-performance-shortcut',
|
||||||
|
key_storage: 'zen-devtools-toggle-storage-shortcut',
|
||||||
|
key_dom: 'zen-devtools-toggle-dom-shortcut',
|
||||||
|
key_accessibility: 'zen-devtools-toggle-accessibility-shortcut',
|
||||||
};
|
};
|
||||||
|
|
||||||
var gZenCKSSettings = {
|
var gZenCKSSettings = {
|
||||||
@@ -742,9 +757,11 @@ var gZenCKSSettings = {
|
|||||||
this.__hasInitialized = true;
|
this.__hasInitialized = true;
|
||||||
this._currentActionID = null;
|
this._currentActionID = null;
|
||||||
this._initializeEvents();
|
this._initializeEvents();
|
||||||
|
gZenKeyboardShortcutsManager._devToolsEvents = ZenMultiWindowFeature.currentBrowser.gZenKeyboardShortcutsManager._devToolsEvents;
|
||||||
window.addEventListener('unload', () => {
|
window.addEventListener('unload', () => {
|
||||||
this.__hasInitialized = false;
|
this.__hasInitialized = false;
|
||||||
document.getElementById(ZEN_CKS_WRAPPER_ID).innerHTML = '';
|
document.getElementById(ZEN_CKS_WRAPPER_ID).innerHTML = '';
|
||||||
|
gZenKeyboardShortcutsManager._devToolsEvents = {};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -1,8 +1,18 @@
|
|||||||
diff --git a/devtools/startup/DevToolsStartup.sys.mjs b/devtools/startup/DevToolsStartup.sys.mjs
|
diff --git a/devtools/startup/DevToolsStartup.sys.mjs b/devtools/startup/DevToolsStartup.sys.mjs
|
||||||
index 0c9db6cb85c491a9f0fc216071afc66e553dcd51..10faeb699a35bb53bd0bd4bce36f18626a8f3288 100644
|
index 0c9db6cb85c491a9f0fc216071afc66e553dcd51..f0e7911c1e284c9d9f20fc8a6a370f387419c8da 100644
|
||||||
--- a/devtools/startup/DevToolsStartup.sys.mjs
|
--- a/devtools/startup/DevToolsStartup.sys.mjs
|
||||||
+++ b/devtools/startup/DevToolsStartup.sys.mjs
|
+++ b/devtools/startup/DevToolsStartup.sys.mjs
|
||||||
@@ -806,6 +806,8 @@ DevToolsStartup.prototype = {
|
@@ -798,14 +798,18 @@ DevToolsStartup.prototype = {
|
||||||
|
|
||||||
|
const keyset = doc.createXULElement("keyset");
|
||||||
|
keyset.setAttribute("id", "devtoolsKeyset");
|
||||||
|
+ this._zenTempWindow = window;
|
||||||
|
|
||||||
|
this.attachKeys(doc, lazy.KeyShortcuts, keyset);
|
||||||
|
|
||||||
|
+ this._zenTempWindow = null;
|
||||||
|
// Appending a <key> element is not always enough. The <keyset> needs
|
||||||
|
// to be detached and reattached to make sure the <key> is taken into
|
||||||
// account (see bug 832984).
|
// account (see bug 832984).
|
||||||
const mainKeyset = doc.getElementById("mainKeyset");
|
const mainKeyset = doc.getElementById("mainKeyset");
|
||||||
mainKeyset.parentNode.insertBefore(keyset, mainKeyset);
|
mainKeyset.parentNode.insertBefore(keyset, mainKeyset);
|
||||||
@@ -11,3 +21,11 @@ index 0c9db6cb85c491a9f0fc216071afc66e553dcd51..10faeb699a35bb53bd0bd4bce36f1862
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -935,6 +939,7 @@ DevToolsStartup.prototype = {
|
||||||
|
k.setAttribute("modifiers", mod);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ this._zenTempWindow.gZenKeyboardShortcutsManager._devToolsEvents[k.id] = oncommand;
|
||||||
|
k.addEventListener("command", oncommand);
|
||||||
|
|
||||||
|
return k;
|
||||||
|
Reference in New Issue
Block a user