Commit 88ac834d authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

DevTools: Remove Panel.registerShortcuts

Panel.registerShortcuts was mainly used by the sources panel as an
alternative to UI.ActionDelegate. It prevents actions from easily being
used elsewhere in DevTools, like the command menu or settings screen.

Bug: none
Change-Id: I2e8810de25b146c0566ea5bf813117d0b2220c54
Reviewed-on: https://chromium-review.googlesource.com/676091
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535910}
parent 23f97cab
......@@ -410,16 +410,6 @@ Sources.CallStackSidebarPane = class extends UI.SimpleView {
}
InspectorFrontendHost.copyText(text.join('\n'));
}
/**
* @param {function(!Array.<!UI.KeyboardShortcut.Descriptor>, function(!Event=):boolean)} registerShortcutDelegate
*/
registerShortcuts(registerShortcutDelegate) {
registerShortcutDelegate(
UI.ShortcutsScreen.SourcesPanelShortcuts.NextCallFrame, this._selectNextCallFrameOnStack.bind(this));
registerShortcutDelegate(
UI.ShortcutsScreen.SourcesPanelShortcuts.PrevCallFrame, this._selectPreviousCallFrameOnStack.bind(this));
}
};
Sources.CallStackSidebarPane._defaultMaxAsyncStackChainDepth = 32;
......@@ -433,3 +423,27 @@ Sources.CallStackSidebarPane._defaultMaxAsyncStackChainDepth = 32;
* }}
*/
Sources.CallStackSidebarPane.Item;
/**
* @implements {UI.ActionDelegate}
*/
Sources.CallStackSidebarPane.ActionDelegate = class {
/**
* @override
* @param {!UI.Context} context
* @param {string} actionId
* @return {boolean}
*/
handleAction(context, actionId) {
var callStackSidebarPane = self.runtime.sharedInstance(Sources.CallStackSidebarPane);
switch (actionId) {
case 'debugger.next-call-frame':
callStackSidebarPane._selectNextCallFrameOnStack();
return true;
case 'debugger.previous-call-frame':
callStackSidebarPane._selectPreviousCallFrameOnStack();
return true;
}
return false;
}
};
......@@ -91,7 +91,6 @@ Sources.SourcesPanel = class extends UI.Panel {
this._sourcesView = new Sources.SourcesView();
this._sourcesView.addEventListener(Sources.SourcesView.Events.EditorSelected, this._editorSelected.bind(this));
this._sourcesView.registerShortcuts(this.registerShortcuts.bind(this));
this._toggleNavigatorSidebarButton = this.editorView.createShowHideSidebarButton('navigator');
this._toggleDebuggerSidebarButton = this._splitWidget.createShowHideSidebarButton('debugger');
......@@ -100,7 +99,6 @@ Sources.SourcesPanel = class extends UI.Panel {
this._threadsSidebarPane = null;
this._watchSidebarPane = /** @type {!UI.View} */ (UI.viewManager.view('sources.watch'));
this._callstackPane = self.runtime.sharedInstance(Sources.CallStackSidebarPane);
this._callstackPane.registerShortcuts(this.registerShortcuts.bind(this));
Common.moduleSetting('sidebarPosition').addChangeListener(this._updateSidebarPosition.bind(this));
this._updateSidebarPosition();
......
......@@ -133,41 +133,6 @@ Sources.SourcesView = class extends UI.VBox {
return defaultScores;
}
/**
* @param {function(!Array.<!UI.KeyboardShortcut.Descriptor>, function(!Event=):boolean)} registerShortcutDelegate
*/
registerShortcuts(registerShortcutDelegate) {
/**
* @this {Sources.SourcesView}
* @param {!Array.<!UI.KeyboardShortcut.Descriptor>} shortcuts
* @param {function(!Event=):boolean} handler
*/
function registerShortcut(shortcuts, handler) {
registerShortcutDelegate(shortcuts, handler);
this._registerShortcuts(shortcuts, handler);
}
registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.JumpToPreviousLocation,
this._onJumpToPreviousLocation.bind(this));
registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.JumpToNextLocation, this._onJumpToNextLocation.bind(this));
registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.CloseEditorTab, this._onCloseEditorTab.bind(this));
registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.GoToLine, this._showGoToLineQuickOpen.bind(this));
registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.GoToMember, this._showOutlineQuickOpen.bind(this));
registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.ToggleBreakpoint,
this._toggleBreakpoint.bind(this, false /* onlyDisable */));
registerShortcut.call(
this, UI.ShortcutsScreen.SourcesPanelShortcuts.ToggleBreakpointEnabled,
this._toggleBreakpoint.bind(this, true /* onlyDisable */));
registerShortcut.call(this, UI.ShortcutsScreen.SourcesPanelShortcuts.Save, this._save.bind(this));
registerShortcut.call(this, UI.ShortcutsScreen.SourcesPanelShortcuts.SaveAll, this._saveAll.bind(this));
}
/**
* @return {!UI.Toolbar}
*/
......@@ -260,9 +225,9 @@ Sources.SourcesView = class extends UI.VBox {
}
/**
* @param {!Event=} event
* @return {boolean}
*/
_onCloseEditorTab(event) {
_onCloseEditorTab() {
var uiSourceCode = this._editorContainer.currentFile();
if (!uiSourceCode)
return false;
......@@ -270,20 +235,12 @@ Sources.SourcesView = class extends UI.VBox {
return true;
}
/**
* @param {!Event=} event
*/
_onJumpToPreviousLocation(event) {
_onJumpToPreviousLocation() {
this._historyManager.rollback();
return true;
}
/**
* @param {!Event=} event
*/
_onJumpToNextLocation(event) {
_onJumpToNextLocation() {
this._historyManager.rollover();
return true;
}
/**
......@@ -640,39 +597,22 @@ Sources.SourcesView = class extends UI.VBox {
sourceFrame.replaceAllWith(searchConfig, replacement);
}
/**
* @param {!Event=} event
*/
_showOutlineQuickOpen(event) {
_showOutlineQuickOpen() {
QuickOpen.QuickOpen.show('@');
return true;
}
/**
* @param {!Event=} event
* @return {boolean}
*/
_showGoToLineQuickOpen(event) {
_showGoToLineQuickOpen() {
if (this._editorContainer.currentFile())
QuickOpen.QuickOpen.show(':');
return true;
}
/**
* @return {boolean}
*/
_save() {
this._saveSourceFrame(this.currentSourceFrame());
return true;
}
/**
* @return {boolean}
*/
_saveAll() {
var sourceFrames = this._editorContainer.fileViews();
sourceFrames.forEach(this._saveSourceFrame.bind(this));
return true;
}
/**
......@@ -792,7 +732,7 @@ Sources.SourcesView.SwitchFileActionDelegate = class {
* @implements {UI.ActionDelegate}
* @unrestricted
*/
Sources.SourcesView.CloseAllActionDelegate = class {
Sources.SourcesView.ActionDelegate = class {
/**
* @override
* @param {!UI.Context} context
......@@ -803,7 +743,37 @@ Sources.SourcesView.CloseAllActionDelegate = class {
var sourcesView = UI.context.flavor(Sources.SourcesView);
if (!sourcesView)
return false;
sourcesView._editorContainer.closeAllFiles();
return true;
switch (actionId) {
case 'sources.close-all':
sourcesView._editorContainer.closeAllFiles();
return true;
case 'sources.jump-to-previous-location':
sourcesView._onJumpToPreviousLocation();
return true;
case 'sources.jump-to-next-location':
sourcesView._onJumpToNextLocation();
return true;
case 'sources.close-editor-tab':
return sourcesView._onCloseEditorTab();
case 'sources.go-to-line':
sourcesView._showGoToLineQuickOpen();
return true;
case 'sources.go-to-member':
sourcesView._showOutlineQuickOpen();
return true;
case 'debugger.toggle-breakpoint':
return sourcesView._toggleBreakpoint(false /* onlyDisable */);
case 'debugger.toggle-breakpoint-enabled':
return sourcesView._toggleBreakpoint(true /* onlyDisable */);
case 'sources.save':
sourcesView._save();
return true;
case 'sources.save-all':
sourcesView._saveAll();
return true;
}
return false;
}
};
......@@ -587,9 +587,151 @@
"type": "action",
"category": "Sources",
"actionId": "sources.close-all",
"className": "Sources.SourcesView.CloseAllActionDelegate",
"className": "Sources.SourcesView.ActionDelegate",
"title": "Close All"
},
{
"type": "action",
"actionId": "sources.jump-to-previous-location",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"shortcut": "Alt+Minus"
}
]
},
{
"type": "action",
"actionId": "sources.jump-to-next-location",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"shortcut": "Alt+Plus"
}
]
},
{
"type": "action",
"actionId": "sources.close-editor-tab",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"shortcut": "Alt+w"
}
]
},
{
"type": "action",
"actionId": "sources.go-to-line",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"shortcut": "Ctrl+g"
}
]
},
{
"type": "action",
"actionId": "sources.go-to-member",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"platform":"windows,linux",
"shortcut": "Ctrl+Shift+o"
},
{
"platform":"mac",
"shortcut": "Meta+Shift+o"
}
]
},
{
"type": "action",
"actionId": "debugger.toggle-breakpoint",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"platform":"windows,linux",
"shortcut": "Ctrl+b"
},
{
"platform":"mac",
"shortcut": "Meta+b"
}
]
},
{
"type": "action",
"actionId": "debugger.toggle-breakpoint-enabled",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"platform":"windows,linux",
"shortcut": "Ctrl+Shift+b"
},
{
"platform":"mac",
"shortcut": "Meta+Shift+b"
}
]
},
{
"type": "action",
"actionId": "sources.save",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"platform":"windows,linux",
"shortcut": "Ctrl+s"
},
{
"platform":"mac",
"shortcut": "Meta+s"
}
]
},
{
"type": "action",
"actionId": "sources.save-all",
"className": "Sources.SourcesView.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"platform":"windows,linux",
"shortcut": "Ctrl+Shift+s"
},
{
"platform":"mac",
"shortcut": "Meta+Alt+s"
}
]
},
{
"type": "action",
"category": "Sources",
......@@ -664,6 +806,34 @@
"SDK.DebuggerModel.CallFrame"
],
"className": "Sources.ScopeChainSidebarPane"
},
{
"type": "action",
"category": "Debugger",
"actionId": "debugger.previous-call-frame",
"className": "Sources.CallStackSidebarPane.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"shortcut": "Ctrl+,"
}
]
},
{
"type": "action",
"category": "Debugger",
"actionId": "debugger.next-call-frame",
"className": "Sources.CallStackSidebarPane.ActionDelegate",
"contextTypes": [
"Sources.SourcesPanel"
],
"bindings": [
{
"shortcut": "Ctrl+."
}
]
}
],
"dependencies": [
......
......@@ -53,15 +53,10 @@ Timeline.TimelinePanel = class extends UI.Panel {
this._recordReloadAction =
/** @type {!UI.Action }*/ (UI.actionRegistry.action('timeline.record-reload'));
if (!Runtime.experiments.isEnabled('timelineKeepHistory')) {
if (!Runtime.experiments.isEnabled('timelineKeepHistory'))
this._historyManager = null;
} else {
else
this._historyManager = new Timeline.TimelineHistoryManager();
this.registerShortcuts(
UI.ShortcutsScreen.PerformancePanelShortcuts.PreviousRecording, () => this._navigateHistory(1));
this.registerShortcuts(
UI.ShortcutsScreen.PerformancePanelShortcuts.NextRecording, () => this._navigateHistory(-1));
}
/** @type {!Array<!TimelineModel.TimelineModelFilter>} */
this._filters = [];
......@@ -1329,6 +1324,16 @@ Timeline.TimelinePanel.ActionDelegate = class {
case 'timeline.show-history':
panel._showHistory();
return true;
case 'timeline.previous-recording':
if (!Runtime.experiments.isEnabled('timelineKeepHistory'))
return false;
panel._navigateHistory(1);
return true;
case 'timeline.next-recording':
if (!Runtime.experiments.isEnabled('timelineKeepHistory'))
return false;
panel._navigateHistory(-1);
return true;
}
return false;
}
......
......@@ -190,6 +190,44 @@
"persistence": "closeable",
"order": 65,
"className": "Profiler.JSProfilerPanel"
},
{
"type": "action",
"actionId": "timeline.previous-recording",
"className": "Timeline.TimelinePanel.ActionDelegate",
"experiment": "timelineKeepHistory",
"contextTypes": [
"Timeline.TimelinePanel"
],
"bindings": [
{
"platform": "windows,linux",
"shortcut": "Alt+Left"
},
{
"platform": "mac",
"shortcut": "Meta+Left"
}
]
},
{
"type": "action",
"actionId": "timeline.next-recording",
"className": "Timeline.TimelinePanel.ActionDelegate",
"experiment": "timelineKeepHistory",
"contextTypes": [
"Timeline.TimelinePanel"
],
"bindings": [
{
"platform": "windows,linux",
"shortcut": "Alt+Right"
},
{
"platform": "mac",
"shortcut": "Meta+Right"
}
]
}
],
"dependencies": [
......
......@@ -75,15 +75,6 @@ UI.Panel = class extends UI.VBox {
event.handled = true;
}
/**
* @param {!Array.<!UI.KeyboardShortcut.Descriptor>} keys
* @param {function(!Event=):boolean} handler
*/
registerShortcuts(keys, handler) {
for (var i = 0; i < keys.length; ++i)
this._shortcuts[keys[i].key] = handler;
}
/**
* @param {!UI.Infobar} infobar
*/
......
......@@ -94,8 +94,9 @@ UI.ShortcutsScreen = class {
section.addAlternateKeys(
UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-out'), Common.UIString('Step out'));
var nextAndPrevFrameKeys = UI.ShortcutsScreen.SourcesPanelShortcuts.NextCallFrame.concat(
UI.ShortcutsScreen.SourcesPanelShortcuts.PrevCallFrame);
var nextAndPrevFrameKeys =
UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.next-call-frame')
.concat(UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.previous-call-frame'));
section.addRelatedKeys(nextAndPrevFrameKeys, Common.UIString('Next/previous call frame'));
section.addAlternateKeys(
......@@ -104,24 +105,29 @@ UI.ShortcutsScreen = class {
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.AddSelectionToWatch, Common.UIString('Add selection to watch'));
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.ToggleBreakpoint, Common.UIString('Toggle breakpoint'));
UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoint'),
Common.UIString('Toggle breakpoint'));
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.ToggleBreakpointEnabled, Common.UIString('Toggle breakpoint enabled'));
UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoint-enabled'),
Common.UIString('Toggle breakpoint enabled'));
section.addAlternateKeys(
UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoints-active'),
Common.UIString('Toggle all breakpoints'));
// Editing
section = UI.shortcutsScreen.section(Common.UIString('Text Editor'));
section.addAlternateKeys(UI.ShortcutsScreen.SourcesPanelShortcuts.GoToMember, Common.UIString('Go to member'));
section.addAlternateKeys(
UI.shortcutRegistry.shortcutDescriptorsForAction('sources.go-to-member'), Common.UIString('Go to member'));
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.ToggleAutocompletion, Common.UIString('Autocompletion'));
section.addAlternateKeys(UI.ShortcutsScreen.SourcesPanelShortcuts.GoToLine, Common.UIString('Go to line'));
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.JumpToPreviousLocation,
UI.shortcutRegistry.shortcutDescriptorsForAction('sources.go-to-line'), Common.UIString('Go to line'));
section.addAlternateKeys(
UI.shortcutRegistry.shortcutDescriptorsForAction('sources.jump-to-previous-location'),
Common.UIString('Jump to previous editing location'));
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.JumpToNextLocation, Common.UIString('Jump to next editing location'));
UI.shortcutRegistry.shortcutDescriptorsForAction('sources.jump-to-next-location'),
Common.UIString('Jump to next editing location'));
section.addAlternateKeys(UI.ShortcutsScreen.SourcesPanelShortcuts.ToggleComment, Common.UIString('Toggle comment'));
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.IncreaseCSSUnitByOne, Common.UIString('Increment CSS unit by 1'));
......@@ -137,7 +143,8 @@ UI.ShortcutsScreen = class {
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.GotoMatchingBracket, Common.UIString('Go to matching bracket'));
section.addAlternateKeys(
UI.ShortcutsScreen.SourcesPanelShortcuts.CloseEditorTab, Common.UIString('Close editor tab'));
UI.shortcutRegistry.shortcutDescriptorsForAction('sources.close-editor-tab'),
Common.UIString('Close editor tab'));
section.addAlternateKeys(
UI.shortcutRegistry.shortcutDescriptorsForAction('sources.switch-file'),
Common.UIString('Switch between files with the same name and different extensions.'));
......@@ -163,8 +170,8 @@ UI.ShortcutsScreen = class {
UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.show-history'),
Common.UIString('Pick a recording from history'));
section.addRelatedKeys(
UI.ShortcutsScreen.PerformancePanelShortcuts.PreviousRecording.concat(
UI.ShortcutsScreen.PerformancePanelShortcuts.NextRecording),
UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.previous-recording')
.concat(UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.next-recording')),
Common.UIString('Show previous/next recording'));
}
......@@ -427,37 +434,8 @@ UI.ShortcutsScreen.SourcesPanelShortcuts = {
AddSelectionToWatch: [UI.KeyboardShortcut.makeDescriptor(
'a', UI.KeyboardShortcut.Modifiers.Shift | UI.KeyboardShortcut.Modifiers.Ctrl)],
GoToMember: [UI.KeyboardShortcut.makeDescriptor(
'o', UI.KeyboardShortcut.Modifiers.CtrlOrMeta | UI.KeyboardShortcut.Modifiers.Shift)],
GoToLine: [UI.KeyboardShortcut.makeDescriptor('g', UI.KeyboardShortcut.Modifiers.Ctrl)],
ToggleBreakpoint: [UI.KeyboardShortcut.makeDescriptor('b', UI.KeyboardShortcut.Modifiers.CtrlOrMeta)],
ToggleBreakpointEnabled: [UI.KeyboardShortcut.makeDescriptor(
'b', UI.KeyboardShortcut.Modifiers.CtrlOrMeta | UI.KeyboardShortcut.Modifiers.Shift)],
NextCallFrame:
[UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Period, UI.KeyboardShortcut.Modifiers.Ctrl)],
PrevCallFrame:
[UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Comma, UI.KeyboardShortcut.Modifiers.Ctrl)],
ToggleComment:
[UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Slash, UI.KeyboardShortcut.Modifiers.CtrlOrMeta)],
JumpToPreviousLocation:
[UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Minus, UI.KeyboardShortcut.Modifiers.Alt)],
JumpToNextLocation:
[UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Plus, UI.KeyboardShortcut.Modifiers.Alt)],
CloseEditorTab: [UI.KeyboardShortcut.makeDescriptor('w', UI.KeyboardShortcut.Modifiers.Alt)],
Save: [UI.KeyboardShortcut.makeDescriptor('s', UI.KeyboardShortcut.Modifiers.CtrlOrMeta)],
SaveAll: [UI.KeyboardShortcut.makeDescriptor(
's', UI.KeyboardShortcut.Modifiers.CtrlOrMeta | UI.KeyboardShortcut.Modifiers.ShiftOrOption)],
};
UI.ShortcutsScreen.LayersPanelShortcuts = {
......@@ -487,12 +465,3 @@ UI.ShortcutsScreen.LayersPanelShortcuts = {
Right: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Right), UI.KeyboardShortcut.makeDescriptor('d')]
};
UI.ShortcutsScreen.PerformancePanelShortcuts = {
PreviousRecording: [UI.KeyboardShortcut.makeDescriptor(
UI.KeyboardShortcut.Keys.Left,
Host.isMac() ? UI.KeyboardShortcut.Modifiers.Meta : UI.KeyboardShortcut.Modifiers.Alt)],
NextRecording: [UI.KeyboardShortcut.makeDescriptor(
UI.KeyboardShortcut.Keys.Right,
Host.isMac() ? UI.KeyboardShortcut.Modifiers.Meta : UI.KeyboardShortcut.Modifiers.Alt)],
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment