1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-06 01:08:25 +01:00

Tab deletion confirmation now shows the complete file name IF it's not a .ino. Fixes #2350

This commit is contained in:
Federico Fissore 2015-06-08 15:32:15 +02:00
parent bef09e4d03
commit fec9fb4d0e
2 changed files with 59 additions and 114 deletions

View File

@ -445,7 +445,7 @@ public class Sketch {
Object[] options = { _("OK"), _("Cancel") }; Object[] options = { _("OK"), _("Cancel") };
String prompt = (currentIndex == 0) ? String prompt = (currentIndex == 0) ?
_("Are you sure you want to delete this sketch?") : _("Are you sure you want to delete this sketch?") :
I18n.format(_("Are you sure you want to delete \"{0}\"?"), current.getCode().getPrettyName()); I18n.format(_("Are you sure you want to delete \"{0}\"?"), current.getCode().getFileNameWithExtensionIfNotIno());
int result = JOptionPane.showOptionDialog(editor, int result = JOptionPane.showOptionDialog(editor,
prompt, prompt,
_("Delete"), _("Delete"),
@ -1075,58 +1075,6 @@ public class Sketch {
// return build(tempBuildFolder.getAbsolutePath()); // return build(tempBuildFolder.getAbsolutePath());
} }
/**
* Map an error from a set of processed .java files back to its location
* in the actual sketch.
* @param message The error message.
* @param filename The .java file where the exception was found.
* @param line Line number of the .java file for the exception (1-indexed)
* @return A RunnerException to be sent to the editor, or null if it wasn't
* possible to place the exception to the sketch code.
*/
// public RunnerException placeExceptionAlt(String message,
// String filename, int line) {
// String appletJavaFile = appletClassName + ".java";
// SketchCode errorCode = null;
// if (filename.equals(appletJavaFile)) {
// for (SketchCode code : getCode()) {
// if (code.isExtension("ino")) {
// if (line >= code.getPreprocOffset()) {
// errorCode = code;
// }
// }
// }
// } else {
// for (SketchCode code : getCode()) {
// if (code.isExtension("java")) {
// if (filename.equals(code.getFileName())) {
// errorCode = code;
// }
// }
// }
// }
// int codeIndex = getCodeIndex(errorCode);
//
// if (codeIndex != -1) {
// //System.out.println("got line num " + lineNumber);
// // in case this was a tab that got embedded into the main .java
// line -= getCode(codeIndex).getPreprocOffset();
//
// // lineNumber is 1-indexed, but editor wants zero-indexed
// line--;
//
// // getMessage() will be what's shown in the editor
// RunnerException exception =
// new RunnerException(message, codeIndex, line, -1);
// exception.hideStackTrace();
// return exception;
// }
// return null;
// }
/** /**
* Run the build inside the temporary build folder. * Run the build inside the temporary build folder.
* @return null if compilation failed, main class name if not * @return null if compilation failed, main class name if not

View File

@ -22,30 +22,36 @@
package processing.app; package processing.app;
import java.io.*; import processing.app.helpers.FileUtils;
import java.util.List;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import static processing.app.I18n._; import static processing.app.I18n._;
import processing.app.helpers.FileUtils;
/** /**
* Represents a single tab of a sketch. * Represents a single tab of a sketch.
*/ */
public class SketchCode { public class SketchCode {
/** Pretty name (no extension), not the full file name */ /**
private String prettyName; * File object for where this code is located
*/
/** File object for where this code is located */
private File file; private File file;
/** Text of the program text for this tab */ /**
* Text of the program text for this tab
*/
private String program; private String program;
private boolean modified; private boolean modified;
/** where this code starts relative to the concat'd code */ /**
* where this code starts relative to the concat'd code
*/
private int preprocOffset; private int preprocOffset;
private Object metadata; private Object metadata;
@ -62,8 +68,6 @@ public class SketchCode {
this.file = file; this.file = file;
this.metadata = metadata; this.metadata = metadata;
makePrettyName();
try { try {
load(); load();
} catch (IOException e) { } catch (IOException e) {
@ -73,13 +77,6 @@ public class SketchCode {
} }
protected void makePrettyName() {
prettyName = file.getName();
int dot = prettyName.lastIndexOf('.');
prettyName = prettyName.substring(0, dot);
}
public File getFile() { public File getFile() {
return file; return file;
} }
@ -106,7 +103,9 @@ public class SketchCode {
} }
}); });
for (File compiledFile : compiledFiles) { for (File compiledFile : compiledFiles) {
compiledFile.delete(); if (!compiledFile.delete()) {
return false;
}
} }
return true; return true;
@ -117,26 +116,28 @@ public class SketchCode {
boolean success = file.renameTo(what); boolean success = file.renameTo(what);
if (success) { if (success) {
file = what; file = what;
makePrettyName();
} }
return success; return success;
} }
protected void copyTo(File dest) throws IOException {
BaseNoGui.saveFile(program, dest);
}
public String getFileName() { public String getFileName() {
return file.getName(); return file.getName();
} }
public String getPrettyName() { public String getPrettyName() {
return prettyName; String prettyName = getFileName();
int dot = prettyName.lastIndexOf('.');
return prettyName.substring(0, dot);
} }
public String getFileNameWithExtensionIfNotIno() {
if (getFileName().endsWith(".ino")) {
return getPrettyName();
}
return getFileName();
}
public boolean isExtension(String... extensions) { public boolean isExtension(String... extensions) {
return isExtension(Arrays.asList(extensions)); return isExtension(Arrays.asList(extensions));
@ -177,25 +178,21 @@ public class SketchCode {
} }
public int getPreprocOffset() {
return preprocOffset;
}
public void addPreprocOffset(int extra) { public void addPreprocOffset(int extra) {
preprocOffset += extra; preprocOffset += extra;
} }
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/** /**
* Load this piece of code from a file. * Load this piece of code from a file.
*/ */
public void load() throws IOException { private void load() throws IOException {
program = BaseNoGui.loadFile(file); program = BaseNoGui.loadFile(file);
if (program == null) {
throw new IOException();
}
if (program.indexOf('\uFFFD') != -1) { if (program.indexOf('\uFFFD') != -1) {
System.err.println( System.err.println(
I18n.format( I18n.format(