This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Initial implementation of modules #45
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,59 +2,70 @@ | |
| * Copyright 2011 Adobe Systems Incorporated. All Rights Reserved. | ||
| */ | ||
|
|
||
| /** | ||
| * Manages the mapping of keyboard inputs to commands. | ||
| */ | ||
| var KeyBindingManager = { | ||
| /** | ||
| * The currently installed keymap. | ||
| */ | ||
| _keymap: null, | ||
| define(function(require, exports, module) { | ||
| CommandManager = require("CommandManager"); | ||
|
|
||
| // TODO: Move KeyMap into separate module | ||
|
|
||
| /** | ||
| * Install the specified keymap as the current keymap, overwriting the existing keymap. | ||
| * | ||
| * @param {KeyMap} keymap The keymap to install. | ||
| * Manages the mapping of keyboard inputs to commands. | ||
| */ | ||
| installKeymap: function(keymap) { | ||
| this._keymap = keymap; | ||
| }, | ||
| var KeyBindingManager = { | ||
| /** | ||
| * The currently installed keymap. | ||
| */ | ||
| _keymap: null, | ||
|
|
||
| /** | ||
| * Process the keybinding for the current key. | ||
| /** | ||
| * Install the specified keymap as the current keymap, overwriting the existing keymap. | ||
| * | ||
| * @param {KeyMap} keymap The keymap to install. | ||
| */ | ||
| installKeymap: function(keymap) { | ||
| this._keymap = keymap; | ||
| }, | ||
|
|
||
| /** | ||
| * Process the keybinding for the current key. | ||
| * | ||
| * @param {string} A key-description string. | ||
| * @return {boolean} true if the key was processed, false otherwise | ||
| */ | ||
| handleKey: function(key) { | ||
| if (this._keymap && this._keymap.map[key]) { | ||
| CommandManager.execute(this._keymap.map[key]); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| /** class Keymap | ||
| * | ||
| * A keymap specifies how keys are mapped to commands. This currently just holds the map, but in future | ||
| * it will likely be extended to include other metadata about the keymap. | ||
| * | ||
| * Keys are described by strings of the form "[modifier-modifier-...-]key", where modifier is one of | ||
| * Ctrl, Alt, or Shift. If multiple modifiers are specified, they must be specified in that order | ||
| * (i.e. "Ctrl-Alt-Shift-P" is legal, "Alt-Ctrl-Shift-P" is not). | ||
| * (TODO: the above restriction is to simplify mapping--is it too onerous?) | ||
| * -- Ctrl maps to Cmd on Mac. (This means that you can't specifically bind to the Ctrl key on Mac.) | ||
| * -- Alt maps to the Option key on Mac. | ||
| * -- Letters must be uppercase, but do not require Shift by default. To indicate that Shift must be held | ||
| * down, you must specifically include Shift. | ||
| * | ||
| * @param {string} A key-description string. | ||
| * @return {boolean} true if the key was processed, false otherwise | ||
| * @constructor | ||
| * @param {map} map An object mapping key-description strings to command IDs. | ||
| */ | ||
| handleKey: function(key) { | ||
| if (this._keymap && this._keymap.map[key]) { | ||
| CommandManager.execute(this._keymap.map[key]); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| /** class Keymap | ||
| * | ||
| * A keymap specifies how keys are mapped to commands. This currently just holds the map, but in future | ||
| * it will likely be extended to include other metadata about the keymap. | ||
| * | ||
| * Keys are described by strings of the form "[modifier-modifier-...-]key", where modifier is one of | ||
| * Ctrl, Alt, or Shift. If multiple modifiers are specified, they must be specified in that order | ||
| * (i.e. "Ctrl-Alt-Shift-P" is legal, "Alt-Ctrl-Shift-P" is not). | ||
| * (TODO: the above restriction is to simplify mapping--is it too onerous?) | ||
| * -- Ctrl maps to Cmd on Mac. (This means that you can't specifically bind to the Ctrl key on Mac.) | ||
| * -- Alt maps to the Option key on Mac. | ||
| * -- Letters must be uppercase, but do not require Shift by default. To indicate that Shift must be held | ||
| * down, you must specifically include Shift. | ||
| * | ||
| * @constructor | ||
| * @param {map} map An object mapping key-description strings to command IDs. | ||
| */ | ||
| var KeyMap = function(map) { | ||
| if (map === undefined) { | ||
| throw new Error("All parameters to the KeyMap constructor must be specified"); | ||
| } | ||
| this.map = map; | ||
| }; | ||
| var KeyMap = function(map) { | ||
| if (map === undefined) { | ||
| throw new Error("All parameters to the KeyMap constructor must be specified"); | ||
| } | ||
| this.map = map; | ||
| }; | ||
|
|
||
| // Define public API | ||
| // TODO: Once KeyMap is moved into separate module, export KeyBindingManager methods instead of the entire object | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure I understand this right: if we made KeyMap an "inner class" of KeyBindingManager, then this wouldn't be an issue, right? We'd assign public members of KeyBindingManager directly to the exports object, and one of those members would happen to be the KeyMap ctor?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we could do that (export the KeyMap ctor as a public property of KeyBindingManager), or we could make KeyMap a separate module. Either one would be fine. |
||
| exports.KeyBindingManager = KeyBindingManager; | ||
| exports.KeyMap = KeyMap; | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to have the capitalization disagree like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my fault for not capitalizing the source file correctly. When we finalize our directory structure, the strings.js file should be capitalized at its new location.