Skip to content

Commit 5e52e0c

Browse files
author
JBaron
committed
fixed two bugs
fixed bug #65 en #66
1 parent 10c0ccd commit 5e52e0c

File tree

7 files changed

+129
-114
lines changed

7 files changed

+129
-114
lines changed

CopyrightNotice.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
/* *****************************************************************************
2-
Copyright (c) JBaron. All rights reserved.
3-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4-
this file except in compliance with the License. You may obtain a copy of the
5-
License at http://www.apache.org/licenses/LICENSE-2.0
6-
7-
THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10-
MERCHANTABLITY OR NON-INFRINGEMENT.
11-
12-
See the Apache Version 2.0 License for specific language governing permissions
13-
and limitations under the License.
14-
***************************************************************************** */
15-
1+
/* *****************************************************************************
2+
Copyright (c) JBaron. All rights reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4+
this file except in compliance with the License. You may obtain a copy of the
5+
License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10+
MERCHANTABLITY OR NON-INFRINGEMENT.
11+
12+
See the Apache Version 2.0 License for specific language governing permissions
13+
and limitations under the License.
14+
***************************************************************************** */
15+

LICENSE.txt

Lines changed: 55 additions & 55 deletions
Large diffs are not rendered by default.

lib/main.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,12 @@ var Cats;
883883
cb(session);
884884
};
885885

886-
Ide.prototype.persistSession = function (session) {
887-
this.project.getWatcher().preventFileChange(session.name);
888-
session.persist();
886+
Ide.prototype.persistSession = function (session, shouldConfirm) {
887+
if (typeof shouldConfirm === "undefined") { shouldConfirm = false; }
888+
if (this.project)
889+
this.project.getWatcher().preventFileChange(session.name);
890+
891+
session.persist(shouldConfirm);
889892
};
890893

891894
/**
@@ -895,12 +898,7 @@ var Cats;
895898
Ide.prototype.closeSession = function (session) {
896899
var _this = this;
897900
var result = [];
898-
899-
if (session.changed) {
900-
var c = confirm("Save " + session.name + " before closing ?");
901-
if (c)
902-
this.persistSession(session);
903-
}
901+
this.persistSession(session, true);
904902

905903
this.sessions.forEach(function (s) {
906904
if (s !== session) {
@@ -968,21 +966,20 @@ var Cats;
968966
};
969967

970968
/**
971-
* Add a new project to the IDE
972-
* @param projectDir the directory of the new project
969+
* Close an open project
970+
* @param project to be closed
973971
*/
974972
Ide.prototype.closeProject = function (project) {
975-
this.project.close();
976-
this.project = null;
977-
978973
// TODO put code on IDE
979974
var sessions = IDE.sessions;
980975
for (var i = 0; i < sessions.length; i++) {
981976
var session = sessions[i];
982977
if (session.changed)
983-
IDE.persistSession(session);
978+
IDE.persistSession(session, true);
984979
}
985980
this.sessions = [];
981+
this.project.close();
982+
this.project = null;
986983
};
987984
return Ide;
988985
})(Cats.ObservableImpl);
@@ -1177,14 +1174,21 @@ var Cats;
11771174
/**
11781175
* Persist the edit session
11791176
*/
1180-
AceSession.prototype.persist = function () {
1177+
AceSession.prototype.persist = function (shouldConfirm) {
11811178
// Select proper folder separator according to platform used
1179+
if (typeof shouldConfirm === "undefined") { shouldConfirm = false; }
11821180
var dirSlash = process.platform == "win32" ? "\\" : "/";
11831181

11841182
if (this.name === "untitled") {
11851183
this.name = prompt("Please enter the file name", IDE.project.projectDir + dirSlash) || "untitled";
11861184
}
11871185

1186+
if (this.changed && shouldConfirm) {
1187+
var c = confirm("Save " + this.name + " before closing ?");
1188+
if (!c)
1189+
return;
1190+
}
1191+
11881192
if (this.name !== "untitled") {
11891193
OS.File.writeTextFile(this.name, this.getValue());
11901194
this.changed = false;
@@ -2834,13 +2838,15 @@ var Cats;
28342838

28352839
IDE.fileNavigation.addEventListener('contextmenu', function (ev) {
28362840
var d = Cats.UI.TreeView.getValueFromElement(ev.srcElement);
2837-
data.key = d.path;
2838-
data.isFolder = d.isFolder;
2839-
data.element = ev.srcElement;
2841+
if (d && d.path) {
2842+
data.key = d.path;
2843+
data.isFolder = d.isFolder;
2844+
data.element = ev.srcElement;
28402845

2841-
// console.log(data.key);
2842-
ev.preventDefault();
2843-
fileContextMenu.popup(ev.x, ev.y);
2846+
// console.log(data.key);
2847+
ev.preventDefault();
2848+
fileContextMenu.popup(ev.x, ev.y);
2849+
}
28442850
return false;
28452851
});
28462852
}

src/cats/acesession.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,22 @@ module Cats {
138138
/**
139139
* Persist the edit session
140140
*/
141-
persist() {
142-
// Select proper folder separator according to platform used
141+
persist(shouldConfirm=false) {
142+
// Select proper folder separator according to platform used
143+
144+
143145
var dirSlash = process.platform == "win32" ? "\\" : "/";
144146

145147
if (this.name === "untitled") {
146148
this.name = prompt("Please enter the file name", IDE.project.projectDir + dirSlash) || "untitled";
147149
}
148150

151+
if (this.changed && shouldConfirm) {
152+
var c = confirm("Save " + this.name + " before closing ?");
153+
if (!c) return;
154+
}
155+
156+
149157
if (this.name !== "untitled") {
150158
OS.File.writeTextFile(this.name, this.getValue());
151159
this.changed = false;

src/cats/ide.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,11 @@ module Cats {
314314
if (cb) cb(session);
315315
}
316316

317-
persistSession(session: Session) {
318-
this.project.getWatcher().preventFileChange(session.name);
319-
session.persist();
317+
persistSession(session: Session, shouldConfirm = false) {
318+
if (this.project)
319+
this.project.getWatcher().preventFileChange(session.name);
320+
321+
session.persist(shouldConfirm);
320322
}
321323

322324
/**
@@ -325,11 +327,8 @@ module Cats {
325327
*/
326328
closeSession(session: Session) {
327329
var result = [];
328-
329-
if (session.changed) {
330-
var c = confirm("Save " + session.name + " before closing ?");
331-
if (c) this.persistSession(session);
332-
}
330+
this.persistSession(session, true);
331+
333332

334333
this.sessions.forEach((s) => {
335334
if (s !== session) {
@@ -399,19 +398,19 @@ module Cats {
399398

400399

401400
/**
402-
* Add a new project to the IDE
403-
* @param projectDir the directory of the new project
401+
* Close an open project
402+
* @param project to be closed
404403
*/
405404
closeProject(project) {
406-
this.project.close();
407-
this.project = null;
408405
// TODO put code on IDE
409406
var sessions = IDE.sessions;
410407
for (var i = 0; i < sessions.length; i++) {
411408
var session = sessions[i];
412-
if (session.changed) IDE.persistSession(session);
409+
if (session.changed) IDE.persistSession(session,true);
413410
}
414411
this.sessions = [];
412+
this.project.close();
413+
this.project = null;
415414
}
416415

417416
}

src/cats/menu/filecontextmenu.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ module Cats.Menu {
100100

101101
IDE.fileNavigation.addEventListener('contextmenu', function(ev: any) {
102102
var d = UI.TreeView.getValueFromElement(ev.srcElement);
103-
data.key = d.path;
104-
data.isFolder = d.isFolder;
105-
data.element = ev.srcElement;
106-
// console.log(data.key);
107-
ev.preventDefault();
108-
fileContextMenu.popup(ev.x, ev.y);
103+
if (d && d.path) {
104+
data.key = d.path;
105+
data.isFolder = d.isFolder;
106+
data.element = ev.srcElement;
107+
// console.log(data.key);
108+
ev.preventDefault();
109+
fileContextMenu.popup(ev.x, ev.y);
110+
}
109111
return false;
110112
});
111113
}

src/typings/cats.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare module Cats {
5555
getValue(): string;
5656
setValue(value: string);
5757
getPosition():any;
58-
persist();
58+
persist(shouldConfirm:boolean);
5959
}
6060

6161
/**

0 commit comments

Comments
 (0)