@@ -105,6 +105,11 @@ public Sketch(Editor _editor, File file) throws IOException {
105
105
protected void load () throws IOException {
106
106
data .load ();
107
107
108
+ for (SketchCode code : data .getCodes ()) {
109
+ if (code .getMetadata () == null )
110
+ code .setMetadata (new SketchCodeDocument (code ));
111
+ }
112
+
108
113
// set the main file to be the current tab
109
114
if (editor != null ) {
110
115
setCurrentCode (0 );
@@ -165,8 +170,8 @@ public void handleRenameCode() {
165
170
renamingCode = true ;
166
171
String prompt = (currentIndex == 0 ) ?
167
172
"New name for sketch:" : "New name for file:" ;
168
- String oldName = (current .isExtension ("ino" )) ?
169
- current .getPrettyName () : current .getFileName ();
173
+ String oldName = (current .getCode (). isExtension ("ino" )) ?
174
+ current .getCode (). getPrettyName () : current . getCode () .getFileName ();
170
175
editor .status .edit (prompt , oldName );
171
176
}
172
177
@@ -193,7 +198,7 @@ protected void nameCode(String newName) {
193
198
// (osx is case insensitive but preserving, windows insensitive,
194
199
// *nix is sensitive and preserving.. argh)
195
200
if (renamingCode ) {
196
- if (newName .equalsIgnoreCase (current .getFileName ())) {
201
+ if (newName .equalsIgnoreCase (current .getCode (). getFileName ())) {
197
202
// exit quietly for the 'rename' case.
198
203
// if it's a 'new' then an error will occur down below
199
204
return ;
@@ -222,7 +227,7 @@ protected void nameCode(String newName) {
222
227
// Don't let the user create the main tab as a .java file instead of .pde
223
228
if (!isDefaultExtension (newExtension )) {
224
229
if (renamingCode ) { // If creating a new tab, don't show this error
225
- if (current == data .getCode (0 )) { // If this is the main tab, disallow
230
+ if (current . getCode () == data .getCode (0 )) { // If this is the main tab, disallow
226
231
Base .showWarning (_ ("Problem with rename" ),
227
232
_ ("The main file can't use an extension.\n " +
228
233
"(It may be time for your to graduate to a\n " +
@@ -317,22 +322,22 @@ protected void nameCode(String newName) {
317
322
// however this *will* first save the sketch, then rename
318
323
319
324
// first get the contents of the editor text area
320
- if (current .isModified ()) {
321
- current .setProgram (editor .getText ());
325
+ if (current .getCode (). isModified ()) {
326
+ current .getCode (). setProgram (editor .getText ());
322
327
try {
323
328
// save this new SketchCode
324
- current .save ();
329
+ current .getCode (). save ();
325
330
} catch (Exception e ) {
326
331
Base .showWarning (_ ("Error" ), _ ("Could not rename the sketch. (0)" ), e );
327
332
return ;
328
333
}
329
334
}
330
335
331
- if (!current .renameTo (newFile )) {
336
+ if (!current .getCode (). renameTo (newFile )) {
332
337
Base .showWarning (_ ("Error" ),
333
338
I18n .format (
334
339
_ ("Could not rename \" {0}\" to \" {1}\" " ),
335
- current .getFileName (),
340
+ current .getCode (). getFileName (),
336
341
newFile .getName ()
337
342
), null );
338
343
return ;
@@ -372,11 +377,11 @@ protected void nameCode(String newName) {
372
377
editor .base .rebuildSketchbookMenus ();
373
378
374
379
} else { // else if something besides code[0]
375
- if (!current .renameTo (newFile )) {
380
+ if (!current .getCode (). renameTo (newFile )) {
376
381
Base .showWarning (_ ("Error" ),
377
382
I18n .format (
378
383
_ ("Could not rename \" {0}\" to \" {1}\" " ),
379
- current .getFileName (),
384
+ current .getCode (). getFileName (),
380
385
newFile .getName ()
381
386
), null );
382
387
return ;
@@ -399,7 +404,7 @@ protected void nameCode(String newName) {
399
404
return ;
400
405
}
401
406
ensureExistence ();
402
- data .addCode (new SketchCodeDocument (newFile ));
407
+ data .addCode (( new SketchCodeDocument (newFile )). getCode ( ));
403
408
}
404
409
405
410
// sort the entries
@@ -434,7 +439,7 @@ public void handleDeleteCode() {
434
439
Object [] options = { _ ("OK" ), _ ("Cancel" ) };
435
440
String prompt = (currentIndex == 0 ) ?
436
441
_ ("Are you sure you want to delete this sketch?" ) :
437
- I18n .format (_ ("Are you sure you want to delete \" {0}\" ?" ), current .getPrettyName ());
442
+ I18n .format (_ ("Are you sure you want to delete \" {0}\" ?" ), current .getCode (). getPrettyName ());
438
443
int result = JOptionPane .showOptionDialog (editor ,
439
444
prompt ,
440
445
_ ("Delete" ),
@@ -461,14 +466,14 @@ public void handleDeleteCode() {
461
466
462
467
} else {
463
468
// delete the file
464
- if (!current .deleteFile (tempBuildFolder )) {
469
+ if (!current .getCode (). deleteFile (tempBuildFolder )) {
465
470
Base .showMessage (_ ("Couldn't do it" ),
466
- I18n .format (_ ("Could not delete \" {0}\" ." ), current .getFileName ()));
471
+ I18n .format (_ ("Could not delete \" {0}\" ." ), current .getCode (). getFileName ()));
467
472
return ;
468
473
}
469
474
470
475
// remove code from the list
471
- data .removeCode (current );
476
+ data .removeCode (current . getCode () );
472
477
473
478
// just set current tab to the main tab
474
479
setCurrentCode (0 );
@@ -504,7 +509,7 @@ public void handleNextCode() {
504
509
public void setModified (boolean state ) {
505
510
//System.out.println("setting modified to " + state);
506
511
//new Exception().printStackTrace();
507
- current .setModified (state );
512
+ current .getCode (). setModified (state );
508
513
calcModified ();
509
514
}
510
515
@@ -540,8 +545,8 @@ public boolean save() throws IOException {
540
545
ensureExistence ();
541
546
542
547
// first get the contents of the editor text area
543
- if (current .isModified ()) {
544
- current .setProgram (editor .getText ());
548
+ if (current .getCode (). isModified ()) {
549
+ current .getCode (). setProgram (editor .getText ());
545
550
}
546
551
547
552
// don't do anything if not actually modified
@@ -700,8 +705,8 @@ protected boolean saveAs() throws IOException {
700
705
701
706
// grab the contents of the current tab before saving
702
707
// first get the contents of the editor text area
703
- if (current .isModified ()) {
704
- current .setProgram (editor .getText ());
708
+ if (current .getCode (). isModified ()) {
709
+ current .getCode (). setProgram (editor .getText ());
705
710
}
706
711
707
712
// save the other tabs to their new location
@@ -896,7 +901,7 @@ public boolean addFile(File sourceFile) {
896
901
}
897
902
898
903
if (codeExtension != null ) {
899
- SketchCode newCode = new SketchCodeDocument (destFile );
904
+ SketchCode newCode = ( new SketchCodeDocument (destFile )). getCode ( );
900
905
901
906
if (replacement ) {
902
907
data .replaceCode (newCode );
@@ -910,7 +915,7 @@ public boolean addFile(File sourceFile) {
910
915
editor .header .repaint ();
911
916
if (editor .untitled ) { // TODO probably not necessary? problematic?
912
917
// Mark the new code as modified so that the sketch is saved
913
- current .setModified (true );
918
+ current .getCode (). setModified (true );
914
919
}
915
920
916
921
} else {
@@ -941,7 +946,7 @@ public void importLibrary(File jarPath) throws IOException {
941
946
// import statements into the main sketch file (code[0])
942
947
// if the current code is a .java file, insert into current
943
948
//if (current.flavor == PDE) {
944
- if (hasDefaultExtension (current )) {
949
+ if (hasDefaultExtension (current . getCode () )) {
945
950
setCurrentCode (0 );
946
951
}
947
952
// could also scan the text in the file to see if each import
@@ -977,13 +982,13 @@ public void setCurrentCode(int which) {
977
982
978
983
// get the text currently being edited
979
984
if (current != null ) {
980
- current .setProgram (editor .getText ());
985
+ current .getCode (). setProgram (editor .getText ());
981
986
current .setSelectionStart (editor .getSelectionStart ());
982
987
current .setSelectionStop (editor .getSelectionStop ());
983
988
current .setScrollPosition (editor .getScrollPosition ());
984
989
}
985
990
986
- current = (SketchCodeDocument ) data .getCode (which );
991
+ current = (SketchCodeDocument ) data .getCode (which ). getMetadata () ;
987
992
currentIndex = which ;
988
993
989
994
editor .setCode (current );
@@ -1043,7 +1048,7 @@ public void prepare() throws IOException {
1043
1048
// make sure the user didn't hide the sketch folder
1044
1049
ensureExistence ();
1045
1050
1046
- current .setProgram (editor .getText ());
1051
+ current .getCode (). setProgram (editor .getText ());
1047
1052
1048
1053
// TODO record history here
1049
1054
//current.history.record(program, SketchHistory.RUN);
@@ -1430,7 +1435,7 @@ public int getCodeIndex(SketchCode who) {
1430
1435
1431
1436
1432
1437
public SketchCode getCurrentCode () {
1433
- return current ;
1438
+ return current . getCode () ;
1434
1439
}
1435
1440
1436
1441
0 commit comments