1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-29 18:52:13 +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") };
String prompt = (currentIndex == 0) ?
_("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,
prompt,
_("Delete"),
@ -1075,58 +1075,6 @@ public class Sketch {
// 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.
* @return null if compilation failed, main class name if not

View File

@ -22,31 +22,37 @@
package processing.app;
import java.io.*;
import java.util.List;
import java.util.Arrays;
import static processing.app.I18n._;
import processing.app.helpers.FileUtils;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static processing.app.I18n._;
/**
* Represents a single tab of a sketch.
* Represents a single tab of a sketch.
*/
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;
/** Text of the program text for this tab */
/**
* Text of the program text for this tab
*/
private String program;
private boolean modified;
/** where this code starts relative to the concat'd code */
private int preprocOffset;
/**
* where this code starts relative to the concat'd code
*/
private int preprocOffset;
private Object metadata;
@ -62,8 +68,6 @@ public class SketchCode {
this.file = file;
this.metadata = metadata;
makePrettyName();
try {
load();
} catch (IOException e) {
@ -73,28 +77,21 @@ public class SketchCode {
}
protected void makePrettyName() {
prettyName = file.getName();
int dot = prettyName.lastIndexOf('.');
prettyName = prettyName.substring(0, dot);
}
public File getFile() {
return file;
}
protected boolean fileExists() {
return file.exists();
}
protected boolean fileReadOnly() {
return !file.canWrite();
}
protected boolean deleteFile(File tempBuildFolder) {
if (!file.delete()) {
return false;
@ -106,38 +103,42 @@ public class SketchCode {
}
});
for (File compiledFile : compiledFiles) {
compiledFile.delete();
if (!compiledFile.delete()) {
return false;
}
}
return true;
}
protected boolean renameTo(File what) {
boolean success = file.renameTo(what);
if (success) {
file = what;
makePrettyName();
}
return success;
}
protected void copyTo(File dest) throws IOException {
BaseNoGui.saveFile(program, dest);
}
public String getFileName() {
return file.getName();
}
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) {
return isExtension(Arrays.asList(extensions));
}
@ -145,23 +146,23 @@ public class SketchCode {
public boolean isExtension(List<String> extensions) {
return FileUtils.hasExtension(file, extensions);
}
public String getProgram() {
return program;
}
public void setProgram(String replacement) {
program = replacement;
}
public int getLineCount() {
return BaseNoGui.countLines(program);
}
public void setModified(boolean modified) {
this.modified = modified;
}
@ -177,25 +178,21 @@ public class SketchCode {
}
public int getPreprocOffset() {
return preprocOffset;
}
public void addPreprocOffset(int extra) {
preprocOffset += extra;
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Load this piece of code from a file.
*/
public void load() throws IOException {
private void load() throws IOException {
program = BaseNoGui.loadFile(file);
if (program == null) {
throw new IOException();
}
if (program.indexOf('\uFFFD') != -1) {
System.err.println(
I18n.format(
@ -209,7 +206,7 @@ public class SketchCode {
);
System.err.println();
}
setModified(false);
}