@@ -131,13 +131,12 @@ public void handleNewCode() {
131
131
*/
132
132
public void handleRenameCode () {
133
133
SketchCode current = editor .getCurrentTab ().getSketchCode ();
134
- int currentIndex = editor .getCurrentTabIndex ();
135
134
136
135
editor .status .clearState ();
137
136
// make sure the user didn't hide the sketch folder
138
137
ensureExistence ();
139
138
140
- if (currentIndex == 0 && editor .untitled ) {
139
+ if (current . isPrimary () && editor .untitled ) {
141
140
Base .showMessage (tr ("Sketch is Untitled" ),
142
141
tr ("How about saving the sketch first \n " +
143
142
"before trying to rename it?" ));
@@ -157,7 +156,7 @@ public void handleRenameCode() {
157
156
// ask for new name of file (internal to window)
158
157
// TODO maybe just popup a text area?
159
158
renamingCode = true ;
160
- String prompt = ( currentIndex == 0 ) ?
159
+ String prompt = current . isPrimary ( ) ?
161
160
"New name for sketch:" : "New name for file:" ;
162
161
String oldName = (current .isExtension ("ino" )) ? current .getPrettyName ()
163
162
: current .getFileName ();
@@ -263,7 +262,7 @@ protected void nameCode(String newName) {
263
262
return ;
264
263
}
265
264
266
- if (renamingCode && currentIndex == 0 ) {
265
+ if (renamingCode && current . isPrimary () ) {
267
266
for (SketchCode code : data .getCodes ()) {
268
267
if (sanitaryName .equalsIgnoreCase (code .getPrettyName ()) &&
269
268
code .isExtension ("cpp" )) {
@@ -296,7 +295,7 @@ protected void nameCode(String newName) {
296
295
// }
297
296
298
297
if (renamingCode ) {
299
- if (currentIndex == 0 ) {
298
+ if (current . isPrimary () ) {
300
299
// get the new folder name/location
301
300
String folderName = newName .substring (0 , newName .indexOf ('.' ));
302
301
File newFolder = new File (data .getFolder ().getParentFile (), folderName );
@@ -396,7 +395,7 @@ protected void nameCode(String newName) {
396
395
return ;
397
396
}
398
397
ensureExistence ();
399
- SketchCode code = new SketchCode (newFile );
398
+ SketchCode code = new SketchCode (newFile , false );
400
399
try {
401
400
editor .addTab (code , "" );
402
401
} catch (IOException e ) {
@@ -425,7 +424,6 @@ protected void nameCode(String newName) {
425
424
*/
426
425
public void handleDeleteCode () throws IOException {
427
426
SketchCode current = editor .getCurrentTab ().getSketchCode ();
428
- int currentIndex = editor .getCurrentTabIndex ();
429
427
editor .status .clearState ();
430
428
// make sure the user didn't hide the sketch folder
431
429
ensureExistence ();
@@ -442,7 +440,7 @@ public void handleDeleteCode() throws IOException {
442
440
443
441
// confirm deletion with user, yes/no
444
442
Object [] options = { tr ("OK" ), tr ("Cancel" ) };
445
- String prompt = ( currentIndex == 0 ) ?
443
+ String prompt = current . isPrimary ( ) ?
446
444
tr ("Are you sure you want to delete this sketch?" ) :
447
445
I18n .format (tr ("Are you sure you want to delete \" {0}\" ?" ),
448
446
current .getFileNameWithExtensionIfNotIno ());
@@ -455,7 +453,7 @@ public void handleDeleteCode() throws IOException {
455
453
options ,
456
454
options [0 ]);
457
455
if (result == JOptionPane .YES_OPTION ) {
458
- if (currentIndex == 0 ) {
456
+ if (current . isPrimary () ) {
459
457
// need to unset all the modified flags, otherwise tries
460
458
// to do a save on the handleNew()
461
459
@@ -856,7 +854,7 @@ public boolean addFile(File sourceFile) {
856
854
}
857
855
858
856
if (codeExtension != null ) {
859
- SketchCode newCode = new SketchCode (destFile );
857
+ SketchCode newCode = new SketchCode (destFile , false );
860
858
861
859
if (replacement ) {
862
860
data .replaceCode (newCode );
0 commit comments