1
1
var EditorsHandler = function ( ) {
2
2
3
3
this . Notifications = undefined ;
4
- this . IdeSettings = undefined ;
5
- this . Files = undefined ;
6
- this . Modelist = ace . require ( "ace/ext/modelist" ) ;
7
- this . StatusBar = ace . require ( 'ace/ext/statusbar' ) . StatusBar ;
8
-
9
- this . idx = 0 ;
10
- this . aceClipboard = '' ;
11
- this . currentIdx = null ;
12
- this . previousIdx = null ;
13
- this . editorDataObjs = [ ] ;
14
- this . aceCleanHashes = [ ] ;
15
- this . navCloseBtnHtml = '<i class="fa fa-fw fa-close text-white action-close-tab" title="Close file"></i>' ;
16
- this . navDirtyBtnHtml = '<i class="fa fa-fw fa-circle-o dirty-tab modal-confirm-close-tab" data-toggle="modal" data-target=".modal-md-container" data-title="Save changes" title="Close file"></i>' ;
17
- this . navTabIconHtml = '<i class="filetype-icon icon"></i>' ;
18
- this . navFilenameHtml = '<span class="tab-name action-edit-tab"></span>' ;
4
+ this . IdeSettings = undefined ;
5
+ this . Files = undefined ;
6
+ this . Modelist = ace . require ( "ace/ext/modelist" ) ;
7
+ this . StatusBar = ace . require ( 'ace/ext/statusbar' ) . StatusBar ;
8
+
9
+ this . idx = 0 ;
10
+ this . aceClipboard = '' ;
11
+ this . currentIdx = null ;
12
+ this . previousIdx = null ;
13
+ this . editorDataObjs = [ ] ;
14
+ this . aceCleanHashes = [ ] ;
15
+ this . navCloseBtnHtml = '<i class="fa fa-fw fa-close text-white action-close-tab" title="Close file"></i>' ;
16
+ this . navDirtyBtnHtml = '<i class="fa fa-fw fa-circle-o dirty-tab modal-confirm-close-tab" data-toggle="modal" data-target=".modal-md-container" data-title="Save changes" title="Close file"></i>' ;
17
+ this . navTabIconHtml = '<i class="filetype-icon icon"></i>' ;
18
+ this . navFilenameHtml = '<span class="tab-name action-edit-tab"></span>' ;
19
19
this . newFileDropdownEntry = '<a class="dropdown-item action-add-tab" href="#"></a>' ;
20
20
21
21
this . defaultFileNameIdx = 0 ;
22
- this . defaultTheme = null ;
23
- this . defaultFont = null ;
24
- this . defaultFontSize = null ;
25
- this . defaultFileName = null ;
26
- this . defaultFileExt = null ;
27
- this . undefinedFileMode = null ;
28
- this . undefinedFileIcon = null ;
29
- this . undefinedFileName = null ;
22
+ this . defaultTheme = null ;
23
+ this . defaultFont = null ;
24
+ this . defaultFontSize = null ;
25
+ this . defaultFileName = null ;
26
+ this . defaultFileExt = null ;
27
+ this . undefinedFileMode = null ;
28
+ this . undefinedFileIcon = null ;
29
+ this . undefinedFileName = null ;
30
30
31
31
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32
32
/// Private Helper
@@ -43,20 +43,20 @@ var EditorsHandler = function () {
43
43
44
44
this . _loadDefaults = function ( ) {
45
45
46
- var that = this ;
46
+ var that = this ;
47
47
var deferred = $ . Deferred ( ) ;
48
48
49
49
$ . get ( '/src/settings/ace.defaults.json' , function ( data ) {
50
50
51
51
data = that . isJsonString ( data ) ? JSON . parse ( data ) : data ;
52
52
53
- that . defaultTheme = data . theme ;
54
- that . defaultFont = data . fontFamily ;
53
+ that . defaultTheme = data . theme ;
54
+ that . defaultFont = data . fontFamily ;
55
55
that . defaultFontSize = data . fontSize ;
56
56
that . defaultFileName = data . newFileName ;
57
57
58
58
// noinspection JSUnresolvedVariable
59
- that . defaultFileExt = data . newFileExt ;
59
+ that . defaultFileExt = data . newFileExt ;
60
60
// noinspection JSUnresolvedVariable
61
61
that . undefinedFileMode = data . undefinedFile . mode ;
62
62
// noinspection JSUnresolvedVariable
@@ -114,7 +114,7 @@ var EditorsHandler = function () {
114
114
115
115
idx = parseInt ( idx ) ;
116
116
117
- var that = this ;
117
+ var that = this ;
118
118
var aceEditor = ace . edit ( 'codepad-editor-' + idx ) ;
119
119
120
120
// Configure Ace
@@ -259,7 +259,7 @@ var EditorsHandler = function () {
259
259
return false ;
260
260
}
261
261
262
- var that = this ;
262
+ var that = this ;
263
263
var aceEditor = this . getEditor ( idx ) ;
264
264
265
265
if ( typeof aceEditor === typeof undefined ) {
@@ -317,13 +317,13 @@ var EditorsHandler = function () {
317
317
tabName += '.' + fileExt ;
318
318
}
319
319
320
- var obj = { } ;
321
- obj . idx = this . idx ;
322
- obj . contentId = 'tab-' + this . idx ;
320
+ var obj = { } ;
321
+ obj . idx = this . idx ;
322
+ obj . contentId = 'tab-' + this . idx ;
323
323
obj . codeEditorId = 'codepad-editor-' + this . idx ;
324
- obj . statusBarId = 'status-bar-' + this . idx ;
325
- obj . tabName = tabName ;
326
- obj . nodeId = nodeId ;
324
+ obj . statusBarId = 'status-bar-' + this . idx ;
325
+ obj . tabName = tabName ;
326
+ obj . nodeId = nodeId ;
327
327
328
328
var $nav = $ (
329
329
'<li>' +
@@ -366,8 +366,8 @@ var EditorsHandler = function () {
366
366
367
367
this . _getTabFileExtension = function ( idx ) {
368
368
369
- idx = parseInt ( idx ) ;
370
- var $el = this . getTabNavEl ( idx ) ;
369
+ idx = parseInt ( idx ) ;
370
+ var $el = this . getTabNavEl ( idx ) ;
371
371
var regExp = / (?: \. ( [ ^ . ] + ) ) ? $ / ;
372
372
373
373
if ( typeof $el !== typeof undefined ) {
@@ -383,12 +383,12 @@ var EditorsHandler = function () {
383
383
384
384
this . _getTabMode = function ( idx ) {
385
385
386
- var that = this ;
386
+ var that = this ;
387
387
var deferred = $ . Deferred ( ) ;
388
- idx = parseInt ( idx ) ;
388
+ idx = parseInt ( idx ) ;
389
389
390
390
this . getAllEditorModes ( ) . then ( function ( data ) {
391
- data = that . isJsonString ( data ) ? JSON . parse ( data ) : data ;
391
+ data = that . isJsonString ( data ) ? JSON . parse ( data ) : data ;
392
392
var ext = that . _getTabFileExtension ( idx ) ;
393
393
if ( typeof ext === typeof undefined ) {
394
394
deferred . resolve ( {
@@ -433,7 +433,7 @@ var EditorsHandler = function () {
433
433
434
434
idx = parseInt ( idx ) ;
435
435
this . _getTabMode ( idx ) . then ( function ( data ) {
436
- data = that . isJsonString ( data ) ? JSON . parse ( data ) : data ;
436
+ data = that . isJsonString ( data ) ? JSON . parse ( data ) : data ;
437
437
var $el = that . getTabNavEl ( idx ) . find ( '*[data-toggle="tab"]' ) . first ( ) ;
438
438
$el . find ( '.filetype-icon' ) . remove ( ) ;
439
439
$el . append ( that . navTabIconHtml ) ;
@@ -445,14 +445,14 @@ var EditorsHandler = function () {
445
445
446
446
idx = parseInt ( idx ) ;
447
447
448
- var editor = this . getEditor ( idx ) ;
448
+ var editor = this . getEditor ( idx ) ;
449
449
var $statusBar = this . getStatusBarContentEl ( idx ) ;
450
450
451
- var ro = editor . getOption ( 'readOnly' ) ;
452
- var isRo = typeof ro === typeof undefined ? false : ro ;
451
+ var ro = editor . getOption ( 'readOnly' ) ;
452
+ var isRo = typeof ro === typeof undefined ? false : ro ;
453
453
var lockClass = isRo ? 'fa-lock' : 'fa-unlock' ;
454
454
455
- var mode = editor . getOption ( 'mode' ) . split ( '/' ) . pop ( ) . toLowerCase ( ) ;
455
+ var mode = editor . getOption ( 'mode' ) . split ( '/' ) . pop ( ) . toLowerCase ( ) ;
456
456
var lineEndings = editor . getOption ( 'newLineMode' ) . toLowerCase ( ) ;
457
457
458
458
$statusBar . find ( '.ace_status-info' ) . remove ( ) ;
@@ -487,12 +487,12 @@ var EditorsHandler = function () {
487
487
idx = parseInt ( idx ) ;
488
488
489
489
var found = false ;
490
- var hash = this . _getHash ( this . getEditor ( idx ) . getValue ( ) ) ;
490
+ var hash = this . _getHash ( this . getEditor ( idx ) . getValue ( ) ) ;
491
491
492
492
$ . each ( this . aceCleanHashes , function ( i , v ) {
493
493
if ( v . idx === idx ) {
494
494
v . hash = hash ;
495
- found = true ;
495
+ found = true ;
496
496
}
497
497
} ) ;
498
498
@@ -535,7 +535,7 @@ var EditorsHandler = function () {
535
535
536
536
this . setTabNavFocus = function ( idx ) {
537
537
538
- idx = parseInt ( idx ) ;
538
+ idx = parseInt ( idx ) ;
539
539
this . previousIdx = parseInt ( this . currentIdx ) ;
540
540
541
541
if ( this . getNumTabs ( ) === 0 ) {
@@ -592,29 +592,38 @@ var EditorsHandler = function () {
592
592
// Launch default tab
593
593
this . _loadDefaults ( ) . then ( function ( ) {
594
594
595
- var promises = [ ] ;
596
- var launchDataItems = window . launchData . items || [ ] ;
595
+ var openFiles = function ( ) {
597
596
598
- launchDataItems . forEach ( function ( item ) {
599
- item . entry . type = typeof ( item . type !== typeof undefined ) ? item . type : item . entry . type ;
600
- that . Files . fileOpen ( item . entry ) . then ( function ( e , fileEntry ) {
601
- promises . push ( that . openFileEntryInAceEditor (
602
- ( typeof e . target . result === typeof undefined ) ? undefined : e . target . result ,
603
- fileEntry
604
- ) ) ;
597
+ var deferred = $ . Deferred ( ) ;
598
+ var promises = [ ] ;
599
+ var launchDataItems = window . launchData . items || [ ] ;
600
+
601
+ launchDataItems . forEach ( function ( item ) {
602
+ item . entry . type = typeof ( item . type !== typeof undefined ) ? item . type : item . entry . type ;
603
+ that . Files . fileOpen ( item . entry ) . then ( function ( e , fileEntry ) {
604
+ promises . push ( that . openFileEntryInAceEditor (
605
+ ( typeof e . target . result === typeof undefined ) ? undefined : e . target . result ,
606
+ fileEntry
607
+ ) ) ;
608
+ } ) ;
605
609
} ) ;
606
- } ) ;
607
610
608
- if ( promises . length > 0 ) {
609
611
$ . when . apply ( $ , promises ) . done ( function ( ) {
612
+ deferred . resolve ( ) ;
613
+ } ) ;
614
+
615
+ return deferred . promise ( ) ;
616
+ } ;
617
+
618
+ openFiles ( ) . then ( function ( ) {
619
+ window . setTimeout ( function ( ) {
610
620
if ( that . getNumTabs ( ) === 0 ) {
611
621
that . onAddNewTab ( that . defaultFileExt ) ;
612
622
}
613
- } ) ;
614
- }
615
- else if ( that . getNumTabs ( ) === 0 ) {
623
+ } , 400 )
624
+ } ) . fail ( function ( ) {
616
625
that . onAddNewTab ( that . defaultFileExt ) ;
617
- }
626
+ } ) ;
618
627
} ) ;
619
628
} ;
620
629
@@ -630,8 +639,8 @@ var EditorsHandler = function () {
630
639
var that = this ;
631
640
632
641
this . Notifications = notifications ;
633
- this . IdeSettings = ideSettings ;
634
- this . Files = files ;
642
+ this . IdeSettings = ideSettings ;
643
+ this . Files = files ;
635
644
636
645
document . addEventListener ( 'drop' , function ( e ) {
637
646
e . preventDefault ( ) ;
@@ -656,9 +665,9 @@ var EditorsHandler = function () {
656
665
this . _populateAddTabDropDown ( ) ;
657
666
658
667
659
- var $main = $ ( 'main' ) ;
660
- var $header = $ ( 'header' ) ;
661
- var $sidebar = $ ( '.sidebar' ) ;
668
+ var $main = $ ( 'main' ) ;
669
+ var $header = $ ( 'header' ) ;
670
+ var $sidebar = $ ( '.sidebar' ) ;
662
671
var $sidebarMenu = $ ( '.sidebar-menu' ) ;
663
672
664
673
// Handle resize of window
@@ -693,7 +702,7 @@ var EditorsHandler = function () {
693
702
694
703
idx = parseInt ( idx ) ;
695
704
696
- var ext = this . _getTabFileExtension ( idx ) ;
705
+ var ext = this . _getTabFileExtension ( idx ) ;
697
706
var deferred = $ . Deferred ( ) ;
698
707
699
708
if ( typeof ext !== typeof undefined ) {
@@ -718,7 +727,7 @@ var EditorsHandler = function () {
718
727
719
728
idx = parseInt ( idx ) ;
720
729
721
- var that = this ;
730
+ var that = this ;
722
731
var aceEditor = this . getEditor ( idx ) ;
723
732
724
733
if ( this . getEditorContent ( idx ) !== '' ) {
@@ -743,7 +752,7 @@ var EditorsHandler = function () {
743
752
744
753
idx = parseInt ( idx ) ;
745
754
746
- var value = '' ;
755
+ var value = '' ;
747
756
var aceEditor = this . getEditor ( idx ) ;
748
757
749
758
if ( typeof aceEditor !== typeof undefined && typeof value !== typeof undefined && value !== null ) {
@@ -758,7 +767,7 @@ var EditorsHandler = function () {
758
767
idx = parseInt ( idx ) ;
759
768
760
769
var aceEditor = this . getEditor ( idx ) ;
761
- var deferred = $ . Deferred ( ) ;
770
+ var deferred = $ . Deferred ( ) ;
762
771
763
772
if ( typeof content === typeof undefined ) {
764
773
this . setEditorTemplate ( idx ) . then ( function ( ) {
@@ -841,7 +850,7 @@ var EditorsHandler = function () {
841
850
842
851
this . getEditor = function ( idx , returnFullObj ) {
843
852
844
- idx = parseInt ( idx ) ;
853
+ idx = parseInt ( idx ) ;
845
854
var response = undefined ;
846
855
847
856
this . editorDataObjs . forEach ( function ( aceEditorEntry ) {
@@ -879,7 +888,7 @@ var EditorsHandler = function () {
879
888
idx = parseInt ( idx ) ;
880
889
881
890
var isClean = false ;
882
- var hash = this . _getHash ( this . getEditor ( idx ) . getValue ( ) ) ;
891
+ var hash = this . _getHash ( this . getEditor ( idx ) . getValue ( ) ) ;
883
892
884
893
$ . each ( this . aceCleanHashes , function ( i , v ) {
885
894
if ( v . idx === idx && v . hash === hash ) {
@@ -936,7 +945,7 @@ var EditorsHandler = function () {
936
945
937
946
$ . each ( this . getTabsNavContainer ( ) . find ( '.tab-name' ) , function ( i , el ) {
938
947
939
- var $el = $ ( el ) ;
948
+ var $el = $ ( el ) ;
940
949
var attr = $el . attr ( 'data-nodeid' ) ;
941
950
942
951
if ( typeof attr !== typeof undefined && parseInt ( attr ) === parseInt ( nodeId ) ) {
@@ -980,7 +989,7 @@ var EditorsHandler = function () {
980
989
######################################################*/
981
990
this . onAddNewTab = function ( fileExt , fileName , fileContent , fileEntry , nodeId ) {
982
991
983
- var that = this ;
992
+ var that = this ;
984
993
var deferred = $ . Deferred ( ) ;
985
994
986
995
if ( typeof fileName === typeof undefined || fileName === null ) {
@@ -1011,9 +1020,9 @@ var EditorsHandler = function () {
1011
1020
1012
1021
idx = parseInt ( idx ) ;
1013
1022
1014
- var that = this ;
1015
- var $tabNameEl = this . getTabNavEl ( idx ) . find ( '.tab-name' ) . first ( ) ;
1016
- var $siblings = $tabNameEl . siblings ( ) . css ( 'visibility' , 'hidden' ) ;
1023
+ var that = this ;
1024
+ var $tabNameEl = this . getTabNavEl ( idx ) . find ( '.tab-name' ) . first ( ) ;
1025
+ var $siblings = $tabNameEl . siblings ( ) . css ( 'visibility' , 'hidden' ) ;
1017
1026
var oldFileName = $tabNameEl . html ( ) ;
1018
1027
1019
1028
@@ -1129,7 +1138,7 @@ var EditorsHandler = function () {
1129
1138
return false ;
1130
1139
}
1131
1140
1132
- var that = this ;
1141
+ var that = this ;
1133
1142
var fileEntry = this . getEditorDataObj ( idx ) ;
1134
1143
1135
1144
var promise = ( typeof fileEntry === typeof undefined )
0 commit comments