@@ -4,6 +4,7 @@ CloudPebble.Editor = (function() {
4
4
var unsaved_files = 0 ;
5
5
var is_fullscreen = false ;
6
6
var resume_fullscreen = false ;
7
+ var current_editor = null ;
7
8
8
9
var add_source_file = function ( file ) {
9
10
CloudPebble . Sidebar . AddSourceFile ( file , function ( ) {
@@ -214,12 +215,8 @@ CloudPebble.Editor = (function() {
214
215
return CodeMirror . Pass ;
215
216
} ;
216
217
}
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' ;
223
220
224
221
settings . gutters = [ 'CodeMirror-linenumbers' , 'CodeMirror-foldgutter' ] ;
225
222
if ( file_kind_in ( [ 'js' , 'json' ] ) ) {
@@ -243,6 +240,7 @@ CloudPebble.Editor = (function() {
243
240
code_mirror . on ( 'shown' , function ( ) {
244
241
is_autocompleting = true ;
245
242
} ) ;
243
+ current_editor = code_mirror ;
246
244
247
245
// The browser should probably do this without our help. Sometimes Safari doesn't.
248
246
$ ( document ) . click ( function ( e ) {
@@ -580,16 +578,12 @@ CloudPebble.Editor = (function() {
580
578
} ,
581
579
pattern )
582
580
} ;
581
+ code_mirror . show_rename_prompt = show_rename_prompt ;
583
582
584
583
var ib_pane = $ ( '#ui-editor-pane-template' ) . clone ( ) . removeClass ( 'hide' ) . appendTo ( pane ) . hide ( ) ;
585
584
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' ) ) ;
586
585
var ib_showing = false ;
587
586
588
- CloudPebble . GlobalShortcuts . SetShortcutHandlers ( {
589
- save : function ( ) {
590
- save ( ) . catch ( alert ) ;
591
- }
592
- } ) ;
593
587
594
588
function toggle_ib ( ) {
595
589
if ( ! ib_showing ) {
@@ -765,13 +759,6 @@ CloudPebble.Editor = (function() {
765
759
fullscreen ( code_mirror , true ) ;
766
760
}
767
761
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
-
775
762
// Tell Google
776
763
ga ( 'send' , 'event' , 'file' , 'open' ) ;
777
764
return code_mirror ;
@@ -823,14 +810,66 @@ CloudPebble.Editor = (function() {
823
810
edit_source_file ( item . file ) ;
824
811
}
825
812
} ) ;
826
- var commands = { } ;
813
+ var global_commands = { } ;
827
814
if ( CloudPebble . ProjectProperties . is_runnable ) {
828
- commands [ gettext ( 'Run' ) ] = run ;
815
+ global_commands [ gettext ( 'Run' ) ] = run ;
829
816
} else {
830
- commands [ gettext ( 'Build' ) ] = run ;
817
+ global_commands [ gettext ( 'Build' ) ] = run ;
831
818
}
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
+ } ) ;
832
871
833
- CloudPebble . FuzzyPrompt . AddCommands ( commands ) ;
872
+ CloudPebble . FuzzyPrompt . AddCommands ( gettext ( 'Actions' ) , global_commands ) ;
834
873
835
874
}
836
875
0 commit comments