Skip to content

Commit 18a037f

Browse files
committed
Work on bugs
1 parent c713b48 commit 18a037f

File tree

1 file changed

+89
-80
lines changed

1 file changed

+89
-80
lines changed

src/js/handlers/editors.js

Lines changed: 89 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
var EditorsHandler = function () {
22

33
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>';
1919
this.newFileDropdownEntry = '<a class="dropdown-item action-add-tab" href="#"></a>';
2020

2121
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;
3030

3131
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3232
/// Private Helper
@@ -43,20 +43,20 @@ var EditorsHandler = function () {
4343

4444
this._loadDefaults = function () {
4545

46-
var that = this;
46+
var that = this;
4747
var deferred = $.Deferred();
4848

4949
$.get('/src/settings/ace.defaults.json', function (data) {
5050

5151
data = that.isJsonString(data) ? JSON.parse(data) : data;
5252

53-
that.defaultTheme = data.theme;
54-
that.defaultFont = data.fontFamily;
53+
that.defaultTheme = data.theme;
54+
that.defaultFont = data.fontFamily;
5555
that.defaultFontSize = data.fontSize;
5656
that.defaultFileName = data.newFileName;
5757

5858
// noinspection JSUnresolvedVariable
59-
that.defaultFileExt = data.newFileExt;
59+
that.defaultFileExt = data.newFileExt;
6060
// noinspection JSUnresolvedVariable
6161
that.undefinedFileMode = data.undefinedFile.mode;
6262
// noinspection JSUnresolvedVariable
@@ -114,7 +114,7 @@ var EditorsHandler = function () {
114114

115115
idx = parseInt(idx);
116116

117-
var that = this;
117+
var that = this;
118118
var aceEditor = ace.edit('codepad-editor-' + idx);
119119

120120
// Configure Ace
@@ -259,7 +259,7 @@ var EditorsHandler = function () {
259259
return false;
260260
}
261261

262-
var that = this;
262+
var that = this;
263263
var aceEditor = this.getEditor(idx);
264264

265265
if (typeof aceEditor === typeof undefined) {
@@ -317,13 +317,13 @@ var EditorsHandler = function () {
317317
tabName += '.' + fileExt;
318318
}
319319

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;
323323
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;
327327

328328
var $nav = $(
329329
'<li>' +
@@ -366,8 +366,8 @@ var EditorsHandler = function () {
366366

367367
this._getTabFileExtension = function (idx) {
368368

369-
idx = parseInt(idx);
370-
var $el = this.getTabNavEl(idx);
369+
idx = parseInt(idx);
370+
var $el = this.getTabNavEl(idx);
371371
var regExp = /(?:\.([^.]+))?$/;
372372

373373
if (typeof $el !== typeof undefined) {
@@ -383,12 +383,12 @@ var EditorsHandler = function () {
383383

384384
this._getTabMode = function (idx) {
385385

386-
var that = this;
386+
var that = this;
387387
var deferred = $.Deferred();
388-
idx = parseInt(idx);
388+
idx = parseInt(idx);
389389

390390
this.getAllEditorModes().then(function (data) {
391-
data = that.isJsonString(data) ? JSON.parse(data) : data;
391+
data = that.isJsonString(data) ? JSON.parse(data) : data;
392392
var ext = that._getTabFileExtension(idx);
393393
if (typeof ext === typeof undefined) {
394394
deferred.resolve({
@@ -433,7 +433,7 @@ var EditorsHandler = function () {
433433

434434
idx = parseInt(idx);
435435
this._getTabMode(idx).then(function (data) {
436-
data = that.isJsonString(data) ? JSON.parse(data) : data;
436+
data = that.isJsonString(data) ? JSON.parse(data) : data;
437437
var $el = that.getTabNavEl(idx).find('*[data-toggle="tab"]').first();
438438
$el.find('.filetype-icon').remove();
439439
$el.append(that.navTabIconHtml);
@@ -445,14 +445,14 @@ var EditorsHandler = function () {
445445

446446
idx = parseInt(idx);
447447

448-
var editor = this.getEditor(idx);
448+
var editor = this.getEditor(idx);
449449
var $statusBar = this.getStatusBarContentEl(idx);
450450

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;
453453
var lockClass = isRo ? 'fa-lock' : 'fa-unlock';
454454

455-
var mode = editor.getOption('mode').split('/').pop().toLowerCase();
455+
var mode = editor.getOption('mode').split('/').pop().toLowerCase();
456456
var lineEndings = editor.getOption('newLineMode').toLowerCase();
457457

458458
$statusBar.find('.ace_status-info').remove();
@@ -487,12 +487,12 @@ var EditorsHandler = function () {
487487
idx = parseInt(idx);
488488

489489
var found = false;
490-
var hash = this._getHash(this.getEditor(idx).getValue());
490+
var hash = this._getHash(this.getEditor(idx).getValue());
491491

492492
$.each(this.aceCleanHashes, function (i, v) {
493493
if (v.idx === idx) {
494494
v.hash = hash;
495-
found = true;
495+
found = true;
496496
}
497497
});
498498

@@ -535,7 +535,7 @@ var EditorsHandler = function () {
535535

536536
this.setTabNavFocus = function (idx) {
537537

538-
idx = parseInt(idx);
538+
idx = parseInt(idx);
539539
this.previousIdx = parseInt(this.currentIdx);
540540

541541
if (this.getNumTabs() === 0) {
@@ -592,29 +592,38 @@ var EditorsHandler = function () {
592592
// Launch default tab
593593
this._loadDefaults().then(function () {
594594

595-
var promises = [];
596-
var launchDataItems = window.launchData.items || [];
595+
var openFiles = function () {
597596

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+
});
605609
});
606-
});
607610

608-
if (promises.length > 0) {
609611
$.when.apply($, promises).done(function () {
612+
deferred.resolve();
613+
});
614+
615+
return deferred.promise();
616+
};
617+
618+
openFiles().then(function () {
619+
window.setTimeout(function () {
610620
if (that.getNumTabs() === 0) {
611621
that.onAddNewTab(that.defaultFileExt);
612622
}
613-
});
614-
}
615-
else if (that.getNumTabs() === 0) {
623+
}, 400)
624+
}).fail(function () {
616625
that.onAddNewTab(that.defaultFileExt);
617-
}
626+
});
618627
});
619628
};
620629

@@ -630,8 +639,8 @@ var EditorsHandler = function () {
630639
var that = this;
631640

632641
this.Notifications = notifications;
633-
this.IdeSettings = ideSettings;
634-
this.Files = files;
642+
this.IdeSettings = ideSettings;
643+
this.Files = files;
635644

636645
document.addEventListener('drop', function (e) {
637646
e.preventDefault();
@@ -656,9 +665,9 @@ var EditorsHandler = function () {
656665
this._populateAddTabDropDown();
657666

658667

659-
var $main = $('main');
660-
var $header = $('header');
661-
var $sidebar = $('.sidebar');
668+
var $main = $('main');
669+
var $header = $('header');
670+
var $sidebar = $('.sidebar');
662671
var $sidebarMenu = $('.sidebar-menu');
663672

664673
// Handle resize of window
@@ -693,7 +702,7 @@ var EditorsHandler = function () {
693702

694703
idx = parseInt(idx);
695704

696-
var ext = this._getTabFileExtension(idx);
705+
var ext = this._getTabFileExtension(idx);
697706
var deferred = $.Deferred();
698707

699708
if (typeof ext !== typeof undefined) {
@@ -718,7 +727,7 @@ var EditorsHandler = function () {
718727

719728
idx = parseInt(idx);
720729

721-
var that = this;
730+
var that = this;
722731
var aceEditor = this.getEditor(idx);
723732

724733
if (this.getEditorContent(idx) !== '') {
@@ -743,7 +752,7 @@ var EditorsHandler = function () {
743752

744753
idx = parseInt(idx);
745754

746-
var value = '';
755+
var value = '';
747756
var aceEditor = this.getEditor(idx);
748757

749758
if (typeof aceEditor !== typeof undefined && typeof value !== typeof undefined && value !== null) {
@@ -758,7 +767,7 @@ var EditorsHandler = function () {
758767
idx = parseInt(idx);
759768

760769
var aceEditor = this.getEditor(idx);
761-
var deferred = $.Deferred();
770+
var deferred = $.Deferred();
762771

763772
if (typeof content === typeof undefined) {
764773
this.setEditorTemplate(idx).then(function () {
@@ -841,7 +850,7 @@ var EditorsHandler = function () {
841850

842851
this.getEditor = function (idx, returnFullObj) {
843852

844-
idx = parseInt(idx);
853+
idx = parseInt(idx);
845854
var response = undefined;
846855

847856
this.editorDataObjs.forEach(function (aceEditorEntry) {
@@ -879,7 +888,7 @@ var EditorsHandler = function () {
879888
idx = parseInt(idx);
880889

881890
var isClean = false;
882-
var hash = this._getHash(this.getEditor(idx).getValue());
891+
var hash = this._getHash(this.getEditor(idx).getValue());
883892

884893
$.each(this.aceCleanHashes, function (i, v) {
885894
if (v.idx === idx && v.hash === hash) {
@@ -936,7 +945,7 @@ var EditorsHandler = function () {
936945

937946
$.each(this.getTabsNavContainer().find('.tab-name'), function (i, el) {
938947

939-
var $el = $(el);
948+
var $el = $(el);
940949
var attr = $el.attr('data-nodeid');
941950

942951
if (typeof attr !== typeof undefined && parseInt(attr) === parseInt(nodeId)) {
@@ -980,7 +989,7 @@ var EditorsHandler = function () {
980989
######################################################*/
981990
this.onAddNewTab = function (fileExt, fileName, fileContent, fileEntry, nodeId) {
982991

983-
var that = this;
992+
var that = this;
984993
var deferred = $.Deferred();
985994

986995
if (typeof fileName === typeof undefined || fileName === null) {
@@ -1011,9 +1020,9 @@ var EditorsHandler = function () {
10111020

10121021
idx = parseInt(idx);
10131022

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');
10171026
var oldFileName = $tabNameEl.html();
10181027

10191028

@@ -1129,7 +1138,7 @@ var EditorsHandler = function () {
11291138
return false;
11301139
}
11311140

1132-
var that = this;
1141+
var that = this;
11331142
var fileEntry = this.getEditorDataObj(idx);
11341143

11351144
var promise = (typeof fileEntry === typeof undefined)

0 commit comments

Comments
 (0)