@@ -39,8 +39,11 @@ define(function (require, exports, module) {
3939 Metrics = require ( "utils/Metrics" ) ,
4040 WorkspaceManager = require ( "view/WorkspaceManager" ) ,
4141 AppInit = require ( "utils/AppInit" ) ,
42+ DropdownButton = require ( "widgets/DropdownButton" ) . DropdownButton ,
4243 Strings = require ( "strings" ) ;
4344
45+ require ( "./vscode.js" ) ;
46+
4447 const panelHtml = require ( "text!./templates/bottom-panel.html" ) ,
4548 shortcutsHtml = require ( "text!./templates/shortcut-table.html" ) ,
4649 TOGGLE_SHORTCUTS_ID = Commands . HELP_TOGGLE_SHORTCUTS_PANEL ;
@@ -49,6 +52,7 @@ define(function (require, exports, module) {
4952 $shortcutsPanel ,
5053 $filterField ,
5154 currentFilter ,
55+ presetPicker ,
5256 _updateKeyBindings ;
5357
5458 let sortByBase = 1 ,
@@ -102,11 +106,15 @@ define(function (require, exports, module) {
102106 return string ;
103107 }
104108
105- function _getOriginFromCommandId ( cmdID ) {
109+ function _getOriginFromCommandId ( cmdID , keyBinding ) {
106110 // According to CommandManager.register() documentation:
107111 // Core commands in Brackets use a simple command title as an id, for example "open.file".
108112 // Extensions should use the following format: "author.myextension.mycommandname".
109113 // For example, "lschmitt.csswizard.format.css".
114+ const customOrigin = KeyBindingManager . getCustomShortcutOrigin ( keyBinding ) ;
115+ if ( customOrigin ) {
116+ return customOrigin ;
117+ }
110118 let idArray = cmdID . split ( "." ) ;
111119 const defaultCommands = Object . values ( Commands ) ;
112120
@@ -138,36 +146,39 @@ define(function (require, exports, module) {
138146 // CodeMirror and Brackets key maps have different formats, so collect
139147 // keys into a normalized array
140148 function _getkeyList ( ) {
141- let i ,
149+ let keyBinding ,
142150 base ,
143151 command ,
144152 key ;
153+ const allCommandsWithShortcuts = new Set ( ) ;
154+ const menuCommands = Menus . getAllMenuItemCommands ( ) ;
155+ const knownBindableCommands = KeyBindingManager . _getKnownBindableCommands ( ) ;
156+ const allCommandsToList = new Set ( [ ...menuCommands , ...knownBindableCommands ] ) ;
145157
146158 // Brackets keymap
147159 let bracketsKeymap = KeyBindingManager . getKeymap ( ) ;
148160 if ( bracketsKeymap ) {
149- for ( i in bracketsKeymap ) {
150- if ( bracketsKeymap . hasOwnProperty ( i ) ) {
151- key = bracketsKeymap [ i ] ;
161+ for ( keyBinding in bracketsKeymap ) {
162+ if ( bracketsKeymap . hasOwnProperty ( keyBinding ) ) {
163+ key = bracketsKeymap [ keyBinding ] ;
152164 if ( key ) {
153- base = _getBaseKey ( i ) ;
165+ base = _getBaseKey ( keyBinding ) ;
154166 command = CommandManager . get ( key . commandID ) ;
155167 if ( ! command ) {
156168 continue ;
157169 }
158170
159- // Listen for keybinding changes
160- command . on ( "keyBindingAdded.bds keyBindingRemoved.bds" , _updateKeyBindings ) ;
161-
171+ allCommandsWithShortcuts . add ( key . commandID ) ;
162172 keyList . push ( {
163173 keyBase : KeyBindingManager . formatKeyDescriptor ( base ) ,
164- keyBinding : i ,
165- keyBindingDisplay : KeyBindingManager . formatKeyDescriptor ( i ) ,
174+ keyBinding : keyBinding ,
175+ keyBindingDisplay : KeyBindingManager . formatKeyDescriptor ( keyBinding ) ,
166176 command : command ,
167177 commandID : key . commandID ,
168178 commandName : command . getName ( ) ,
169- origin : _getOriginFromCommandId ( key . commandID ) ,
170- filter : command . getName ( ) . toLowerCase ( ) + _filterFromKeyBinding ( i )
179+ origin : _getOriginFromCommandId ( key . commandID , keyBinding ) ,
180+ filter : command . getName ( ) . toLowerCase ( ) + _filterFromKeyBinding ( keyBinding )
181+ + _getOriginFromCommandId ( key . commandID , keyBinding ) . toLowerCase ( )
171182 } ) ;
172183 }
173184 }
@@ -178,27 +189,44 @@ define(function (require, exports, module) {
178189 if ( CodeMirror . keyMap ) {
179190 let cmKeymap = ( brackets . platform === "mac" ) ? CodeMirror . keyMap . macDefault : CodeMirror . keyMap . pcDefault ;
180191 if ( cmKeymap ) {
181- for ( i in cmKeymap ) {
192+ for ( keyBinding in cmKeymap ) {
182193 // Note that we only ignore CodeMirror duplicates, but
183194 // we want to see Brackets & Extensions duplicates
184- if ( cmKeymap . hasOwnProperty ( i ) &&
185- ( i !== "fallthrough" ) &&
186- ( _findKeyBinding ( keyList , i ) === - 1 ) ) {
187- base = _getBaseKey ( i ) ;
195+ if ( cmKeymap . hasOwnProperty ( keyBinding ) &&
196+ ( keyBinding !== "fallthrough" ) &&
197+ ( _findKeyBinding ( keyList , keyBinding ) === - 1 ) ) {
198+ base = _getBaseKey ( keyBinding ) ;
199+ allCommandsWithShortcuts . add ( cmKeymap [ keyBinding ] ) ;
188200 keyList . push ( {
189201 keyBase : KeyBindingManager . formatKeyDescriptor ( base ) ,
190- keyBinding : i ,
191- keyBindingDisplay : KeyBindingManager . formatKeyDescriptor ( i ) ,
192- commandID : cmKeymap [ i ] ,
193- commandName : cmKeymap [ i ] ,
194- origin : origCodeMirror ,
195- filter : cmKeymap [ i ] . toLowerCase ( ) + _filterFromKeyBinding ( i )
202+ keyBinding : keyBinding ,
203+ keyBindingDisplay : KeyBindingManager . formatKeyDescriptor ( keyBinding ) ,
204+ commandID : cmKeymap [ keyBinding ] ,
205+ commandName : cmKeymap [ keyBinding ] ,
206+ origin : window . debugMode ? origCodeMirror : origBrackets ,
207+ filter : cmKeymap [ keyBinding ] . toLowerCase ( ) + _filterFromKeyBinding ( keyBinding ) +
208+ origCodeMirror . toLowerCase ( )
196209 } ) ;
197210 }
198211 }
199212 }
200213 }
201-
214+
215+ for ( let commandID of allCommandsToList ) {
216+ if ( allCommandsWithShortcuts . has ( commandID ) ) {
217+ continue ;
218+ }
219+ keyList . push ( {
220+ keyBase : "" ,
221+ keyBinding : "" ,
222+ keyBindingDisplay : "" ,
223+ commandID : commandID ,
224+ commandName : commandID ,
225+ origin : _getOriginFromCommandId ( commandID , keyBinding ) ,
226+ filter : commandID . toLowerCase ( ) + _getOriginFromCommandId ( commandID , keyBinding ) . toLowerCase ( )
227+ } ) ;
228+ }
229+
202230 return keyList ;
203231 }
204232
@@ -402,6 +430,15 @@ define(function (require, exports, module) {
402430 }
403431 }
404432
433+ function _presetRenderer ( item ) {
434+ var html = "<span class='stylesheet-name'>" + _ . escape ( item . name ) ;
435+ if ( item . subDirStr ) {
436+ html += "<span class='stylesheet-dir'> — " + _ . escape ( item . subDirStr ) + "</span>" ;
437+ }
438+ html += "</span>" ;
439+ return html ;
440+ }
441+
405442 AppInit . appReady ( function ( ) {
406443 let s , file_menu ;
407444
@@ -424,6 +461,11 @@ define(function (require, exports, module) {
424461
425462 $shortcutsPanel = $ ( "#shortcuts-panel" ) ;
426463
464+ presetPicker = new DropdownButton ( "Select Shortcut Presets" , [ ] , _presetRenderer , {
465+ cssClasses : "presetPicker"
466+ } ) ;
467+ $shortcutsPanel . find ( ".presetPickerContainer" ) . append ( presetPicker . $button ) ;
468+
427469 // Events
428470 $shortcutsPanel . on ( "dblclick" , function ( e ) {
429471 var $rowEl = $ ( e . target ) . closest ( "tr" ) ;
@@ -466,5 +508,7 @@ define(function (require, exports, module) {
466508 }
467509 _showCommandIdsInPanelIfNeeded ( ) ;
468510 } ) ;
511+ KeyBindingManager . on ( KeyBindingManager . EVENT_KEY_BINDING_ADDED , _updateKeyBindings ) ;
512+ KeyBindingManager . on ( KeyBindingManager . EVENT_KEY_BINDING_REMOVED , _updateKeyBindings ) ;
469513 } ) ;
470514} ) ;
0 commit comments