Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2131 from adobe/jasonsanjose/keyboard-prefs
Browse files Browse the repository at this point in the history
Refactor core keyboard bindings into an external json file
  • Loading branch information
njx committed Dec 5, 2012
2 parents 626e482 + 366a1dc commit d5074de
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 69 deletions.
222 changes: 222 additions & 0 deletions defaults/keyboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
{
"file.new": [
"Ctrl-N"
],
"file.open": [
"Ctrl-O"
],
"file.close": [
"Ctrl-W"
],
"file.close_all": [
"Ctrl-Shift-W"
],
"file.save": [
"Ctrl-S"
],
"file.saveAll": [
"Ctrl-Alt-S"
],
"file.liveFilePreview": [
"Ctrl-Alt-P"
],
"file.previewHighlight": [
"Ctrl-Shift-C"
],
"file.quit": [
"Ctrl-Q"
],
"edit.selectAll": [
"Ctrl-A"
],
"edit.selectLine": [
{
"key": "Ctrl-L",
"platform": "win"
},
{
"key": "Ctrl-L",
"platform": "mac"
}
],
"edit.find": [
"Ctrl-F"
],
"edit.findInFiles": [
"Ctrl-Shift-F"
],
"edit.findNext": [
{
"key": "F3",
"platform": "win"
},
{
"key": "Cmd-G",
"platform": "mac"
}
],
"edit.findPrevious": [
{
"key": "Shift-F3",
"platform": "win"
},
{
"key": "Cmd-Shift-G",
"platform": "mac"
}
],
"edit.replace": [
{
"key": "Ctrl-H",
"platform": "win"
},
{
"key": "Cmd-Alt-F",
"platform": "mac"
}
],
"edit.indent": [
{
"key": "Indent",
"displayKey": "Tab"
}
],
"edit.unindent": [
{
"key": "Unindent",
"displayKey": "Shift-Tab"
}
],
"edit.duplicate": [
"Ctrl-D"
],
"edit.deletelines": [
"Ctrl-Shift-D"
],
"edit.lineUp": [
{
"key": "Ctrl-Shift-Up",
"displayKey": "Ctrl-Shift-↑",
"platform": "win"
},
{
"key": "Cmd-Ctrl-Up",
"displayKey": "Cmd-Ctrl-↑",
"platform": "mac"
}
],
"edit.lineDown": [
{
"key": "Ctrl-Shift-Down",
"displayKey": "Ctrl-Shift-↓",
"platform": "win"
},
{
"key": "Cmd-Ctrl-Down",
"displayKey": "Cmd-Ctrl-↓",
"platform": "mac"
}
],
"edit.lineComment": [
"Ctrl-/"
],
"edit.blockComment": [
"Ctrl-Shift-/"
],
"view.hideSidebar": [
"Ctrl-Shift-H"
],
"view.increaseFontSize": [
{
"key": "Ctrl-=",
"displayKey": "Cmd-+"
},
{
"key": "Ctrl-+",
"displayKey": "Cmd-+"
}
],
"view.decreaseFontSize": [
{
"key": "Ctrl--",
"displayKey": "Cmd-−"
}
],
"view.restoreFontSize": [
"Ctrl-0"
],
"navigate.quickOpen": [
"Ctrl-Shift-O"
],
"navigate.gotoLine": [
{
"key": "Ctrl-G",
"platform": "win"
},
{
"key": "Cmd-L",
"platform": "mac"
}
],
"navigate.gotoDefinition": [
"Ctrl-T"
],
"navigate.nextDoc": [
{
"key": "Ctrl-Tab",
"platform": "win"
},
{
"key": "Ctrl-Tab",
"platform": "mac"
}
],
"navigate.prevDoc": [
{
"key": "Ctrl-Shift-Tab",
"platform": "win"
},
{
"key": "Ctrl-Shift-Tab",
"platform": "mac"
}
],
"navigate.toggleQuickEdit": [
"Ctrl-E"
],
"navigate.previousMatch": [
{
"key": "Alt-Up",
"displayKey": "Alt-↑"
}
],
"navigate.nextMatch": [
{
"key": "Alt-Down",
"displayKey": "Alt-↓"
}
],
"debug.showDeveloperTools": [
{
"key": "F12",
"platform": "win"
},
{
"key": "Cmd-Opt-I",
"platform": "mac"
}
],
"debug.refreshWindow": [
{
"key": "F5",
"platform": "win"
},
{
"key": "Cmd-R",
"platform": "mac"
}
],
"file.rename": [
"F2"
]
}
5 changes: 3 additions & 2 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

require.config({
paths: {
"text" : "thirdparty/text",
"i18n" : "thirdparty/i18n"
"text" : "thirdparty/text",
"i18n" : "thirdparty/i18n",
"defaults" : "../defaults"
},
// Use custom brackets property until CEF sets the correct navigator.language
// NOTE: When we change to navigator.language here, we also should change to
Expand Down
6 changes: 6 additions & 0 deletions src/command/CommandManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
/**
* Manages global application commands that can be called from menu items, key bindings, or subparts
* of the application.
*
* This module dispatches these event(s):
* - commandRegistered -- when a new command is registered
*/
define(function (require, exports, module) {
"use strict";
Expand Down Expand Up @@ -179,6 +182,9 @@ define(function (require, exports, module) {

var command = new Command(name, id, commandFn);
_commands[id] = command;

$(exports).triggerHandler("commandRegistered", [command]);

return command;
}

Expand Down
13 changes: 13 additions & 0 deletions src/command/KeyBindingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ define(function (require, exports, module) {
KeyEvent = require("utils/KeyEvent"),
Strings = require("strings");

var KeyboardPrefs = JSON.parse(require("text!defaults/keyboard.json"));

/**
* Maps normalized shortcut descriptor to key binding info.
* @type {!Object.<string, {commandID: string, key: string, displayKey: string}>}
Expand Down Expand Up @@ -482,6 +484,15 @@ define(function (require, exports, module) {
var bindings = _commandMap[commandID];
return bindings || [];
}

function _handleCommandRegistered(event, command) {
var commandId = command.getID(),
defaults = KeyboardPrefs[commandId];

if (defaults) {
addBinding(commandId, defaults);
}
}

/**
* Install keydown event listener.
Expand All @@ -499,6 +510,8 @@ define(function (require, exports, module) {
true
);
}

$(CommandManager).on("commandRegistered", _handleCommandRegistered);

// unit test only
exports._reset = _reset;
Expand Down
Loading

0 comments on commit d5074de

Please sign in to comment.