@@ -36,16 +36,12 @@ public class IDEController {
36
36
private final Reader reader = new Reader ();
37
37
private File file = null ;
38
38
39
- @ FXML
40
- private TreeView <String > dbFileView ;
41
- @ FXML
42
- private TabPane tabs ;
43
- @ FXML
44
- private TextArea errorMessages ;
45
- @ FXML
46
- private CodeArea codeArea ;
47
- @ FXML
48
- private TableView <ArrayList <String >> tableView ;
39
+ @ FXML private TreeView <String > dbFileView ;
40
+ @ FXML private TabPane tabs ;
41
+ @ FXML private TextArea errorMessages ;
42
+ @ FXML private CodeArea codeArea ;
43
+ @ FXML private TableView <ArrayList <String >> tableView ;
44
+ @ FXML Label fileTitle ;
49
45
50
46
private static final String KEYWORD_PATTERN = "\\ b(" + String .join ("|" , Analyzer .getKeywords ()) + ")\\ b" ;
51
47
private static final String DATATYPES_PATTERN = "\\ b(" + String .join ("|" , Analyzer .getDataTypes ()) + ")\\ b" ;
@@ -135,9 +131,17 @@ protected void openFile(ActionEvent event) {
135
131
136
132
if (file != null ) {
137
133
codeArea .replaceText (getFileContent (file ));
134
+ checkFileChanges ();
138
135
}
139
136
}
140
137
138
+ @ FXML
139
+ protected void closeFile (ActionEvent event ) {
140
+ codeArea .replaceText ("" );
141
+ file = null ;
142
+ checkFileChanges ();
143
+ }
144
+
141
145
private String getFileContent (File file ){
142
146
StringBuilder text = new StringBuilder ();
143
147
Charset charset = StandardCharsets .UTF_8 ;
@@ -165,6 +169,8 @@ protected void saveFile(ActionEvent event) {
165
169
}
166
170
167
171
saveTextToFile (codeArea .getText (), file );
172
+ file = new File (file .getAbsolutePath ());
173
+ checkFileChanges ();
168
174
}
169
175
170
176
@ FXML
@@ -180,6 +186,8 @@ protected void saveFileAs() {
180
186
selectedFile = new File (selectedFile .getAbsolutePath () + ".sql" );
181
187
}
182
188
saveTextToFile (codeArea .getText (), selectedFile );
189
+ file = selectedFile ;
190
+ checkFileChanges ();
183
191
}
184
192
}
185
193
@@ -267,11 +275,21 @@ protected void createTable(ArrayList<ArrayList <String>> data){
267
275
}
268
276
269
277
@ FXML
270
- protected void checkFileChanges (KeyEvent event ) {
278
+ protected void checkFileChanges () {
279
+ if (file == null ) {
280
+ fileTitle .setText ("Untitled" );
281
+ return ;
282
+ }
283
+
271
284
String codeAreaText = codeArea .getText ();
272
285
String fileText = getFileContent (file );
273
286
287
+ if (codeAreaText .equals (fileText )){
288
+ fileTitle .setText (file .getName ());
289
+ return ;
290
+ }
274
291
292
+ fileTitle .setText (file .getName () + " - Unsaved Changes" );
275
293
}
276
294
277
295
private StyleSpans <Collection <String >> computeHighlighting (String text ) {
0 commit comments