@@ -4,6 +4,7 @@ CloudPebble.Editor = (function() {
44 var unsaved_files = 0 ;
55 var is_fullscreen = false ;
66 var resume_fullscreen = false ;
7+ var current_editor = null ;
78
89 var add_source_file = function ( file ) {
910 CloudPebble . Sidebar . AddSourceFile ( file , function ( ) {
@@ -214,12 +215,8 @@ CloudPebble.Editor = (function() {
214215 return CodeMirror . Pass ;
215216 } ;
216217 }
217- settings . extraKeys [ 'Cmd-/' ] = function toggleComment ( cm ) {
218- CodeMirror . commands . toggleComment ( cm ) ;
219- } ;
220- settings . extraKeys [ 'Ctrl-/' ] = function toggleComment ( cm ) {
221- CodeMirror . commands . toggleComment ( cm ) ;
222- } ;
218+ settings . extraKeys [ 'Ctrl-/' ] = 'toggleComment' ;
219+ settings . extraKeys [ 'Cmd-/' ] = 'toggleComment' ;
223220
224221 settings . gutters = [ 'CodeMirror-linenumbers' , 'CodeMirror-foldgutter' ] ;
225222 if ( file_kind_in ( [ 'js' , 'json' ] ) ) {
@@ -243,6 +240,7 @@ CloudPebble.Editor = (function() {
243240 code_mirror . on ( 'shown' , function ( ) {
244241 is_autocompleting = true ;
245242 } ) ;
243+ current_editor = code_mirror ;
246244
247245 // The browser should probably do this without our help. Sometimes Safari doesn't.
248246 $ ( document ) . click ( function ( e ) {
@@ -580,16 +578,12 @@ CloudPebble.Editor = (function() {
580578 } ,
581579 pattern )
582580 } ;
581+ code_mirror . show_rename_prompt = show_rename_prompt ;
583582
584583 var ib_pane = $ ( '#ui-editor-pane-template' ) . clone ( ) . removeClass ( 'hide' ) . appendTo ( pane ) . hide ( ) ;
585584 var ib_editor = new IB ( ib_pane . find ( '.ui-canvas' ) , ib_pane . find ( '#ui-properties' ) , ib_pane . find ( '#ui-toolkit' ) , ib_pane . find ( '#ui-layer-list > div' ) ) ;
586585 var ib_showing = false ;
587586
588- CloudPebble . GlobalShortcuts . SetShortcutHandlers ( {
589- save : function ( ) {
590- save ( ) . catch ( alert ) ;
591- }
592- } ) ;
593587
594588 function toggle_ib ( ) {
595589 if ( ! ib_showing ) {
@@ -765,13 +759,6 @@ CloudPebble.Editor = (function() {
765759 fullscreen ( code_mirror , true ) ;
766760 }
767761
768- var commands = { } ;
769- commands [ gettext ( 'Rename File' ) ] = function ( ) {
770- // We need to use a timeout because the rename prompt will conflict with the old prompt
771- setTimeout ( show_rename_prompt , 0 ) ;
772- } ;
773- CloudPebble . FuzzyPrompt . ReplaceCommands ( commands ) ;
774-
775762 // Tell Google
776763 ga ( 'send' , 'event' , 'file' , 'open' ) ;
777764 return code_mirror ;
@@ -823,14 +810,66 @@ CloudPebble.Editor = (function() {
823810 edit_source_file ( item . file ) ;
824811 }
825812 } ) ;
826- var commands = { } ;
813+ var global_commands = { } ;
827814 if ( CloudPebble . ProjectProperties . is_runnable ) {
828- commands [ gettext ( 'Run' ) ] = run ;
815+ global_commands [ gettext ( 'Run' ) ] = run ;
829816 } else {
830- commands [ gettext ( 'Build' ) ] = run ;
817+ global_commands [ gettext ( 'Build' ) ] = run ;
831818 }
819+ var local_commands = { } ;
820+ local_commands [ gettext ( 'Rename Source File' ) ] = function ( ) {
821+ // We need to defer because the rename prompt will conflict with the old prompt
822+ _ . defer ( function ( ) {
823+ current_editor . show_rename_prompt ( ) ;
824+ } ) ;
825+ } ;
826+
827+ function neaten_command_name ( str ) {
828+ var result = str . replace ( / ( \S ) ( [ A - Z ] ) / g, '$1 $2' ) . replace ( / ^ ./ , function ( str ) { return str . toUpperCase ( ) ; } ) ;
829+ result = result . replace ( 'Doc ' , 'Document ' ) ;
830+ result = result . replace ( 'Go ' , 'Go To ' ) ;
831+ result = result . replace ( 'Del ' , 'Delete ' ) ;
832+ return result ;
833+ }
834+
835+ var codemirror_commands = [
836+ { command : 'indentAuto' , refocus : true } ,
837+ { command : 'toggleComment' , hint : 'Cmd-/ or Ctrl-/' , refocus : true } ,
838+ 'find' , 'replace' , 'indentMore' , 'indentLess'
839+ ] ;
840+
841+ _ . each ( codemirror_commands , function ( entry ) {
842+ var command = ! ! entry . command ? entry . command : entry ;
843+ var name = ( ! ! entry . name ? entry . name : neaten_command_name ( command ) ) ;
844+ local_commands [ name ] = function ( ) {
845+ current_editor . execCommand ( command ) ;
846+ if ( ! ! entry . refocus ) current_editor . focus ( ) ;
847+ } ;
848+ local_commands [ name ] . hint = ! ! entry . hint ? entry . hint : CloudPebble . GlobalShortcuts . GetShortcutForCommand ( command ) ;
849+ } ) ;
850+
851+ // local_commands[gettext('Auto Indent')] = function() {
852+ // current_editor.execCommand('indentAuto');
853+ // current_editor.focus();
854+ // };
855+ // local_commands[gettext('Auto Indent')].hint = CloudPebble.GlobalShortcuts.GetShortcutForCommand('indentAuto');
856+ // local_commands[gettext('Find')] = function() {
857+ // current_editor.execCommand('find');
858+ // };
859+ // local_commands[gettext('Find')].hint = CloudPebble.GlobalShortcuts.GetShortcutForCommand('find');
860+
861+
862+ CloudPebble . FuzzyPrompt . AddCommands ( gettext ( 'File' ) , local_commands , function ( ) {
863+ return ( ! ! current_editor ) ;
864+ } ) ;
865+
866+ CloudPebble . GlobalShortcuts . SetShortcutHandlers ( {
867+ save : function ( ) {
868+ save ( ) . catch ( alert ) ;
869+ }
870+ } ) ;
832871
833- CloudPebble . FuzzyPrompt . AddCommands ( commands ) ;
872+ CloudPebble . FuzzyPrompt . AddCommands ( gettext ( 'Actions' ) , global_commands ) ;
834873
835874 }
836875
0 commit comments