@@ -105,6 +105,11 @@ public Sketch(Editor _editor, File file) throws IOException {
105105 protected void load () throws IOException {
106106 data .load ();
107107
108+ for (SketchCode code : data .getCodes ()) {
109+ if (code .getMetadata () == null )
110+ code .setMetadata (new SketchCodeDocument (code ));
111+ }
112+
108113 // set the main file to be the current tab
109114 if (editor != null ) {
110115 setCurrentCode (0 );
@@ -165,8 +170,8 @@ public void handleRenameCode() {
165170 renamingCode = true ;
166171 String prompt = (currentIndex == 0 ) ?
167172 "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 ();
170175 editor .status .edit (prompt , oldName );
171176 }
172177
@@ -193,7 +198,7 @@ protected void nameCode(String newName) {
193198 // (osx is case insensitive but preserving, windows insensitive,
194199 // *nix is sensitive and preserving.. argh)
195200 if (renamingCode ) {
196- if (newName .equalsIgnoreCase (current .getFileName ())) {
201+ if (newName .equalsIgnoreCase (current .getCode (). getFileName ())) {
197202 // exit quietly for the 'rename' case.
198203 // if it's a 'new' then an error will occur down below
199204 return ;
@@ -222,7 +227,7 @@ protected void nameCode(String newName) {
222227 // Don't let the user create the main tab as a .java file instead of .pde
223228 if (!isDefaultExtension (newExtension )) {
224229 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
226231 Base .showWarning (_ ("Problem with rename" ),
227232 _ ("The main file can't use an extension.\n " +
228233 "(It may be time for your to graduate to a\n " +
@@ -317,22 +322,22 @@ protected void nameCode(String newName) {
317322 // however this *will* first save the sketch, then rename
318323
319324 // 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 ());
322327 try {
323328 // save this new SketchCode
324- current .save ();
329+ current .getCode (). save ();
325330 } catch (Exception e ) {
326331 Base .showWarning (_ ("Error" ), _ ("Could not rename the sketch. (0)" ), e );
327332 return ;
328333 }
329334 }
330335
331- if (!current .renameTo (newFile )) {
336+ if (!current .getCode (). renameTo (newFile )) {
332337 Base .showWarning (_ ("Error" ),
333338 I18n .format (
334339 _ ("Could not rename \" {0}\" to \" {1}\" " ),
335- current .getFileName (),
340+ current .getCode (). getFileName (),
336341 newFile .getName ()
337342 ), null );
338343 return ;
@@ -372,11 +377,11 @@ protected void nameCode(String newName) {
372377 editor .base .rebuildSketchbookMenus ();
373378
374379 } else { // else if something besides code[0]
375- if (!current .renameTo (newFile )) {
380+ if (!current .getCode (). renameTo (newFile )) {
376381 Base .showWarning (_ ("Error" ),
377382 I18n .format (
378383 _ ("Could not rename \" {0}\" to \" {1}\" " ),
379- current .getFileName (),
384+ current .getCode (). getFileName (),
380385 newFile .getName ()
381386 ), null );
382387 return ;
@@ -399,7 +404,7 @@ protected void nameCode(String newName) {
399404 return ;
400405 }
401406 ensureExistence ();
402- data .addCode (new SketchCodeDocument (newFile ));
407+ data .addCode (( new SketchCodeDocument (newFile )). getCode ( ));
403408 }
404409
405410 // sort the entries
@@ -434,7 +439,7 @@ public void handleDeleteCode() {
434439 Object [] options = { _ ("OK" ), _ ("Cancel" ) };
435440 String prompt = (currentIndex == 0 ) ?
436441 _ ("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 ());
438443 int result = JOptionPane .showOptionDialog (editor ,
439444 prompt ,
440445 _ ("Delete" ),
@@ -461,14 +466,14 @@ public void handleDeleteCode() {
461466
462467 } else {
463468 // delete the file
464- if (!current .deleteFile (tempBuildFolder )) {
469+ if (!current .getCode (). deleteFile (tempBuildFolder )) {
465470 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 ()));
467472 return ;
468473 }
469474
470475 // remove code from the list
471- data .removeCode (current );
476+ data .removeCode (current . getCode () );
472477
473478 // just set current tab to the main tab
474479 setCurrentCode (0 );
@@ -504,7 +509,7 @@ public void handleNextCode() {
504509 public void setModified (boolean state ) {
505510 //System.out.println("setting modified to " + state);
506511 //new Exception().printStackTrace();
507- current .setModified (state );
512+ current .getCode (). setModified (state );
508513 calcModified ();
509514 }
510515
@@ -540,8 +545,8 @@ public boolean save() throws IOException {
540545 ensureExistence ();
541546
542547 // 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 ());
545550 }
546551
547552 // don't do anything if not actually modified
@@ -700,8 +705,8 @@ protected boolean saveAs() throws IOException {
700705
701706 // grab the contents of the current tab before saving
702707 // 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 ());
705710 }
706711
707712 // save the other tabs to their new location
@@ -896,7 +901,7 @@ public boolean addFile(File sourceFile) {
896901 }
897902
898903 if (codeExtension != null ) {
899- SketchCode newCode = new SketchCodeDocument (destFile );
904+ SketchCode newCode = ( new SketchCodeDocument (destFile )). getCode ( );
900905
901906 if (replacement ) {
902907 data .replaceCode (newCode );
@@ -910,7 +915,7 @@ public boolean addFile(File sourceFile) {
910915 editor .header .repaint ();
911916 if (editor .untitled ) { // TODO probably not necessary? problematic?
912917 // Mark the new code as modified so that the sketch is saved
913- current .setModified (true );
918+ current .getCode (). setModified (true );
914919 }
915920
916921 } else {
@@ -941,7 +946,7 @@ public void importLibrary(File jarPath) throws IOException {
941946 // import statements into the main sketch file (code[0])
942947 // if the current code is a .java file, insert into current
943948 //if (current.flavor == PDE) {
944- if (hasDefaultExtension (current )) {
949+ if (hasDefaultExtension (current . getCode () )) {
945950 setCurrentCode (0 );
946951 }
947952 // could also scan the text in the file to see if each import
@@ -977,13 +982,13 @@ public void setCurrentCode(int which) {
977982
978983 // get the text currently being edited
979984 if (current != null ) {
980- current .setProgram (editor .getText ());
985+ current .getCode (). setProgram (editor .getText ());
981986 current .setSelectionStart (editor .getSelectionStart ());
982987 current .setSelectionStop (editor .getSelectionStop ());
983988 current .setScrollPosition (editor .getScrollPosition ());
984989 }
985990
986- current = (SketchCodeDocument ) data .getCode (which );
991+ current = (SketchCodeDocument ) data .getCode (which ). getMetadata () ;
987992 currentIndex = which ;
988993
989994 editor .setCode (current );
@@ -1043,7 +1048,7 @@ public void prepare() throws IOException {
10431048 // make sure the user didn't hide the sketch folder
10441049 ensureExistence ();
10451050
1046- current .setProgram (editor .getText ());
1051+ current .getCode (). setProgram (editor .getText ());
10471052
10481053 // TODO record history here
10491054 //current.history.record(program, SketchHistory.RUN);
@@ -1430,7 +1435,7 @@ public int getCodeIndex(SketchCode who) {
14301435
14311436
14321437 public SketchCode getCurrentCode () {
1433- return current ;
1438+ return current . getCode () ;
14341439 }
14351440
14361441
0 commit comments