Index: Source/devtools/front_end/SourcesView.js |
diff --git a/Source/devtools/front_end/SourcesView.js b/Source/devtools/front_end/SourcesView.js |
index 6f0805097f86970868d5688c2df6af658950039f..da99a3a3388b45f9c2051d7689cb0bfd0a9df309 100644 |
--- a/Source/devtools/front_end/SourcesView.js |
+++ b/Source/devtools/front_end/SourcesView.js |
@@ -80,6 +80,9 @@ WebInspector.SourcesView = function(workspace, sourcesPanel) |
WebInspector.panels.sources.showUISourceCode(unsavedSourceCodes[i]); |
} |
window.addEventListener("beforeunload", handleBeforeUnload, true); |
+ |
+ this._shortcuts = {}; |
+ this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false); |
} |
WebInspector.SourcesView.Events = { |
@@ -93,12 +96,42 @@ WebInspector.SourcesView.prototype = { |
*/ |
registerShortcuts: function(registerShortcutDelegate) |
{ |
- registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortcuts.JumpToPreviousLocation, this._onJumpToPreviousLocation.bind(this)); |
- registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortcuts.JumpToNextLocation, this._onJumpToNextLocation.bind(this)); |
- registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortcuts.CloseEditorTab, this._onCloseEditorTab.bind(this)); |
- registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortcuts.GoToLine, this._showGoToLineDialog.bind(this)); |
- registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortcuts.GoToMember, this._showOutlineDialog.bind(this)); |
- registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortcuts.ToggleBreakpoint, this._toggleBreakpoint.bind(this)); |
+ /** |
+ * @this {WebInspector.SourcesView} |
+ * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} shortcuts |
+ * @param {function(?Event=):boolean} handler |
+ */ |
+ function registerShortcut(shortcuts, handler) |
+ { |
+ registerShortcutDelegate(shortcuts, handler); |
+ this._registerShortcuts(shortcuts, handler); |
+ } |
+ |
+ registerShortcut.call(this, WebInspector.ShortcutsScreen.SourcesPanelShortcuts.JumpToPreviousLocation, this._onJumpToPreviousLocation.bind(this)); |
+ registerShortcut.call(this, WebInspector.ShortcutsScreen.SourcesPanelShortcuts.JumpToNextLocation, this._onJumpToNextLocation.bind(this)); |
+ registerShortcut.call(this, WebInspector.ShortcutsScreen.SourcesPanelShortcuts.CloseEditorTab, this._onCloseEditorTab.bind(this)); |
+ registerShortcut.call(this, WebInspector.ShortcutsScreen.SourcesPanelShortcuts.GoToLine, this._showGoToLineDialog.bind(this)); |
+ registerShortcut.call(this, WebInspector.ShortcutsScreen.SourcesPanelShortcuts.GoToMember, this._showOutlineDialog.bind(this)); |
+ registerShortcut.call(this, WebInspector.ShortcutsScreen.SourcesPanelShortcuts.ToggleBreakpoint, this._toggleBreakpoint.bind(this)); |
+ registerShortcut.call(this, WebInspector.ShortcutsScreen.SourcesPanelShortcuts.Save, this._save.bind(this)); |
+ }, |
+ |
+ /** |
+ * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} keys |
+ * @param {function(?Event=):boolean} handler |
+ */ |
+ _registerShortcuts: function(keys, handler) |
+ { |
+ for (var i = 0; i < keys.length; ++i) |
+ this._shortcuts[keys[i].key] = handler; |
+ }, |
+ |
+ _handleKeyDown: function(event) |
+ { |
+ var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event); |
+ var handler = this._shortcuts[shortcutKey]; |
+ if (handler && handler()) |
+ event.consume(true); |
}, |
/** |
@@ -599,6 +632,21 @@ WebInspector.SourcesView.prototype = { |
/** |
* @return {boolean} |
*/ |
+ _save: function() |
+ { |
+ var sourceFrame = this.currentSourceFrame(); |
+ if (!sourceFrame) |
+ return true; |
+ if (!(sourceFrame instanceof WebInspector.UISourceCodeFrame)) |
+ return true; |
+ var uiSourceCodeFrame = /** @type {!WebInspector.UISourceCodeFrame} */ (sourceFrame); |
+ uiSourceCodeFrame.commitEditing(); |
+ return true; |
+ }, |
+ |
+ /** |
+ * @return {boolean} |
+ */ |
_toggleBreakpoint: function() |
{ |
var sourceFrame = this.currentSourceFrame(); |