@@ -253,59 +253,68 @@ RED.keyboard = (function() {
253253 delete slot . ondown ;
254254 }
255255
256- var dialog = null ;
256+ var shortcutDialog = null ;
257257
258258 var cmdCtrlKey = '<span class="help-key">' + ( isMac ?'⌘' :'Ctrl' ) + '</span>' ;
259259
260260 function showKeyboardHelp ( ) {
261261 if ( ! RED . settings . theme ( "menu.menu-item-keyboard-shortcuts" , true ) ) {
262262 return ;
263263 }
264- if ( ! dialog ) {
265- dialog = $ ( '<div id="keyboard-help-dialog" class="hide">' +
266- '<div style="vertical-align: top;display:inline-block; box-sizing: border-box; width:50%; padding: 10px;">' +
267- '<table class="keyboard-shortcuts">' +
268- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">a</span></td><td>' + RED . _ ( "keyboard.selectAll" ) + '</td></tr>' +
269- '<tr><td><span class="help-key">Shift</span> + <span class="help-key">Click</span></td><td>' + RED . _ ( "keyboard.selectAllConnected" ) + '</td></tr>' +
270- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">Click</span></td><td>' + RED . _ ( "keyboard.addRemoveNode" ) + '</td></tr>' +
271- '<tr><td> </td><td></td></tr>' +
272- '<tr><td><span class="help-key">Enter</span></td><td>' + RED . _ ( "keyboard.editSelected" ) + '</td></tr>' +
273- '<tr><td><span class="help-key">Delete</span> / <span class="help-key">Backspace</span></td><td>' + RED . _ ( "keyboard.deleteSelected" ) + '</td></tr>' +
274- '<tr><td> </td><td></td></tr>' +
275- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">i</span></td><td>' + RED . _ ( "keyboard.importNode" ) + '</td></tr>' +
276- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">e</span></td><td>' + RED . _ ( "keyboard.exportNode" ) + '</td></tr>' +
277- '</table>' +
278- '</div>' +
279- '<div style="vertical-align: top;display:inline-block; box-sizing: border-box; width:50%; padding: 10px;">' +
280- '<table class="keyboard-shortcuts">' +
281- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">Space</span></td><td>' + RED . _ ( "keyboard.toggleSidebar" ) + '</td></tr>' +
282- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">f</span></td><td>' + RED . _ ( "keyboard.searchBox" ) + '</td></tr>' +
283- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">Shift</span> + <span class="help-key">p</span></td><td>' + RED . _ ( "keyboard.managePalette" ) + '</td></tr>' +
284- '<tr><td> </td><td></td></tr>' +
285- '<tr><td><span class="help-key">←</span> <span class="help-key">↑</span> <span class="help-key">→</span> <span class="help-key">↓</span></td><td>' + RED . _ ( "keyboard.nudgeNode" ) + '</td></tr>' +
286- '<tr><td><span class="help-key">Shift</span> + <span class="help-key">←</span> <span class="help-key">↑</span> <span class="help-key">→</span> <span class="help-key">↓</span></td><td>' + RED . _ ( "keyboard.moveNode" ) + '</td></tr>' +
287- '<tr><td> </td><td></td></tr>' +
288- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">c</span></td><td>' + RED . _ ( "keyboard.copyNode" ) + '</td></tr>' +
289- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">x</span></td><td>' + RED . _ ( "keyboard.cutNode" ) + '</td></tr>' +
290- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">v</span></td><td>' + RED . _ ( "keyboard.pasteNode" ) + '</td></tr>' +
291- '<tr><td>' + cmdCtrlKey + ' + <span class="help-key">z</span></td><td>' + RED . _ ( "keyboard.undoChange" ) + '</td></tr>' +
292- '</table>' +
293- '</div>' +
264+ if ( ! shortcutDialog ) {
265+ shortcutDialog = $ ( '<div id="keyboard-help-dialog" class="hide">' +
266+ '<ol id="keyboard-shortcut-list"></ol>' +
294267 '</div>' )
295- . appendTo ( "body" )
296- . dialog ( {
268+ . appendTo ( "body" ) ;
269+
270+ var shortcutList = $ ( '#keyboard-shortcut-list' ) . editableList ( {
271+ addButton : false ,
272+ scrollOnAdd : false ,
273+ addItem : function ( container , i , object ) {
274+ var item = $ ( '<div class="keyboard-shortcut-entry">' ) . appendTo ( container ) ;
275+
276+ var key = $ ( '<div class="keyboard-shortcut-entry-key">' ) . appendTo ( item ) ;
277+ key . append ( formatKey ( object . key ) ) ;
278+
279+ var text = object . id . replace ( / ( ^ .+ : ( [ a - z ] ) ) | ( - ( [ a - z ] ) ) / g, function ( _ , _ , A , _ , B , pos ) {
280+ if ( pos === 0 ) {
281+ return A . toUpperCase ( ) ;
282+ } else {
283+ return " " + B . toUpperCase ( ) ;
284+ }
285+ } ) ;
286+ var label = $ ( '<div>' ) . html ( text ) . appendTo ( item ) ;
287+
288+ var scope = $ ( '<div class="keyboard-shortcut-entry-scope">' ) . html ( object . scope ) . appendTo ( item ) ;
289+
290+
291+ } ,
292+ } ) ;
293+ var shortcuts = RED . actions . list ( ) ;
294+ shortcuts . sort ( function ( A , B ) {
295+ return A . id . localeCompare ( B . id ) ;
296+ } ) ;
297+ shortcuts . forEach ( function ( s ) {
298+ if ( s . key ) {
299+ shortcutList . editableList ( 'addItem' , s ) ;
300+ }
301+ } )
302+
303+ shortcutDialog . dialog ( {
297304 modal : true ,
298305 autoOpen : false ,
299306 width : "800" ,
300- title :"Keyboard shortcuts" ,
307+ height : "400" ,
308+ title :RED . _ ( "keyboard.title" ) ,
301309 resizable : false
302310 } ) ;
303311 }
304312
305- dialog . dialog ( "open" ) ;
313+ shortcutDialog . dialog ( "open" ) ;
306314 }
307315 function formatKey ( key ) {
308316 var formattedKey = isMac ?key . replace ( / c t r l - ? / , "⌘" ) :key ;
317+ formattedKey = isMac ?formattedKey . replace ( / a l t - ? / , "⌥" ) :key ;
309318 formattedKey = formattedKey . replace ( / s h i f t - ? / , "⇧" )
310319 formattedKey = formattedKey . replace ( / l e f t / , "←" )
311320 formattedKey = formattedKey . replace ( / u p / , "↑" )
0 commit comments