Commit 09ccc936 authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

DevTools: Allow files to be renamed with F2

Change-Id: Ide1e84ad7b7096467643786eb0eb06decfccee11
Reviewed-on: https://chromium-review.googlesource.com/761263
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532000}
parent e76e0e99
...@@ -52,6 +52,8 @@ Sources.NavigatorView = class extends UI.VBox { ...@@ -52,6 +52,8 @@ Sources.NavigatorView = class extends UI.VBox {
this._frameNodes = new Map(); this._frameNodes = new Map();
this.contentElement.addEventListener('contextmenu', this.handleContextMenu.bind(this), false); this.contentElement.addEventListener('contextmenu', this.handleContextMenu.bind(this), false);
UI.shortcutRegistry.addShortcutListener(
this.contentElement, 'sources.rename', this._renameShortcut.bind(this), true);
this._navigatorGroupByFolderSetting = Common.moduleSetting('navigatorGroupByFolder'); this._navigatorGroupByFolderSetting = Common.moduleSetting('navigatorGroupByFolder');
this._navigatorGroupByFolderSetting.addChangeListener(this._groupingChanged.bind(this)); this._navigatorGroupByFolderSetting.addChangeListener(this._groupingChanged.bind(this));
...@@ -647,6 +649,17 @@ Sources.NavigatorView = class extends UI.VBox { ...@@ -647,6 +649,17 @@ Sources.NavigatorView = class extends UI.VBox {
handleContextMenu(event) { handleContextMenu(event) {
} }
/**
* @return {boolean}
*/
_renameShortcut() {
var node = this._scriptsTree.selectedTreeElement && this._scriptsTree.selectedTreeElement._node;
if (!node || !node._uiSourceCode || !node._uiSourceCode.canRename())
return false;
this.rename(node, false);
return true;
}
/** /**
* @param {!Workspace.Project} project * @param {!Workspace.Project} project
* @param {string} path * @param {string} path
......
...@@ -376,6 +376,20 @@ ...@@ -376,6 +376,20 @@
} }
] ]
}, },
{
"type": "action",
"actionId": "sources.rename",
"bindings": [
{
"platform": "windows,linux",
"shortcut": "F2"
},
{
"platform": "mac",
"shortcut": "Enter"
}
]
},
{ {
"type": "setting", "type": "setting",
"settingName": "navigatorGroupByFolder", "settingName": "navigatorGroupByFolder",
......
...@@ -84,6 +84,21 @@ UI.ShortcutRegistry = class { ...@@ -84,6 +84,21 @@ UI.ShortcutRegistry = class {
return this._defaultActionToShortcut.get(actionId).valuesArray().some(descriptor => descriptor.key === key); return this._defaultActionToShortcut.get(actionId).valuesArray().some(descriptor => descriptor.key === key);
} }
/**
* @param {!Element} element
* @param {string} actionId
* @param {function():boolean} listener
* @param {boolean=} capture
*/
addShortcutListener(element, actionId, listener, capture) {
console.assert(this._defaultActionToShortcut.has(actionId), 'Unknown action ' + actionId);
element.addEventListener('keydown', event => {
if (!this.eventMatchesAction(/** @type {!KeyboardEvent} */ (event), actionId) || !listener.call(null))
return;
event.consume(true);
}, capture);
}
/** /**
* @param {number} key * @param {number} key
* @param {string} domKey * @param {string} domKey
......
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