Skip to content

Commit fec9fb4

Browse files
author
Federico Fissore
committed
Tab deletion confirmation now shows the complete file name IF it's not a .ino. Fixes #2350
1 parent bef09e4 commit fec9fb4

File tree

2 files changed

+57
-112
lines changed

2 files changed

+57
-112
lines changed

app/src/processing/app/Sketch.java

+1-53
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public void handleDeleteCode() {
445445
Object[] options = { _("OK"), _("Cancel") };
446446
String prompt = (currentIndex == 0) ?
447447
_("Are you sure you want to delete this sketch?") :
448-
I18n.format(_("Are you sure you want to delete \"{0}\"?"), current.getCode().getPrettyName());
448+
I18n.format(_("Are you sure you want to delete \"{0}\"?"), current.getCode().getFileNameWithExtensionIfNotIno());
449449
int result = JOptionPane.showOptionDialog(editor,
450450
prompt,
451451
_("Delete"),
@@ -1075,58 +1075,6 @@ public void prepare() throws IOException {
10751075
// return build(tempBuildFolder.getAbsolutePath());
10761076
}
10771077

1078-
1079-
1080-
/**
1081-
* Map an error from a set of processed .java files back to its location
1082-
* in the actual sketch.
1083-
* @param message The error message.
1084-
* @param filename The .java file where the exception was found.
1085-
* @param line Line number of the .java file for the exception (1-indexed)
1086-
* @return A RunnerException to be sent to the editor, or null if it wasn't
1087-
* possible to place the exception to the sketch code.
1088-
*/
1089-
// public RunnerException placeExceptionAlt(String message,
1090-
// String filename, int line) {
1091-
// String appletJavaFile = appletClassName + ".java";
1092-
// SketchCode errorCode = null;
1093-
// if (filename.equals(appletJavaFile)) {
1094-
// for (SketchCode code : getCode()) {
1095-
// if (code.isExtension("ino")) {
1096-
// if (line >= code.getPreprocOffset()) {
1097-
// errorCode = code;
1098-
// }
1099-
// }
1100-
// }
1101-
// } else {
1102-
// for (SketchCode code : getCode()) {
1103-
// if (code.isExtension("java")) {
1104-
// if (filename.equals(code.getFileName())) {
1105-
// errorCode = code;
1106-
// }
1107-
// }
1108-
// }
1109-
// }
1110-
// int codeIndex = getCodeIndex(errorCode);
1111-
//
1112-
// if (codeIndex != -1) {
1113-
// //System.out.println("got line num " + lineNumber);
1114-
// // in case this was a tab that got embedded into the main .java
1115-
// line -= getCode(codeIndex).getPreprocOffset();
1116-
//
1117-
// // lineNumber is 1-indexed, but editor wants zero-indexed
1118-
// line--;
1119-
//
1120-
// // getMessage() will be what's shown in the editor
1121-
// RunnerException exception =
1122-
// new RunnerException(message, codeIndex, line, -1);
1123-
// exception.hideStackTrace();
1124-
// return exception;
1125-
// }
1126-
// return null;
1127-
// }
1128-
1129-
11301078
/**
11311079
* Run the build inside the temporary build folder.
11321080
* @return null if compilation failed, main class name if not

arduino-core/src/processing/app/SketchCode.java

+56-59
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,37 @@
2222

2323
package processing.app;
2424

25-
import java.io.*;
26-
import java.util.List;
25+
import processing.app.helpers.FileUtils;
26+
27+
import java.io.File;
28+
import java.io.FileFilter;
29+
import java.io.IOException;
2730
import java.util.Arrays;
31+
import java.util.List;
2832

2933
import static processing.app.I18n._;
30-
import processing.app.helpers.FileUtils;
3134

3235
/**
33-
* Represents a single tab of a sketch.
36+
* Represents a single tab of a sketch.
3437
*/
3538
public class SketchCode {
36-
37-
/** Pretty name (no extension), not the full file name */
38-
private String prettyName;
3939

40-
/** File object for where this code is located */
40+
/**
41+
* File object for where this code is located
42+
*/
4143
private File file;
4244

43-
/** Text of the program text for this tab */
45+
/**
46+
* Text of the program text for this tab
47+
*/
4448
private String program;
4549

4650
private boolean modified;
4751

48-
/** where this code starts relative to the concat'd code */
49-
private int preprocOffset;
52+
/**
53+
* where this code starts relative to the concat'd code
54+
*/
55+
private int preprocOffset;
5056

5157
private Object metadata;
5258

@@ -62,8 +68,6 @@ private void init(File file, Object metadata) {
6268
this.file = file;
6369
this.metadata = metadata;
6470

65-
makePrettyName();
66-
6771
try {
6872
load();
6973
} catch (IOException e) {
@@ -73,28 +77,21 @@ private void init(File file, Object metadata) {
7377
}
7478

7579

76-
protected void makePrettyName() {
77-
prettyName = file.getName();
78-
int dot = prettyName.lastIndexOf('.');
79-
prettyName = prettyName.substring(0, dot);
80-
}
81-
82-
8380
public File getFile() {
8481
return file;
8582
}
86-
87-
83+
84+
8885
protected boolean fileExists() {
8986
return file.exists();
9087
}
91-
92-
88+
89+
9390
protected boolean fileReadOnly() {
9491
return !file.canWrite();
9592
}
96-
97-
93+
94+
9895
protected boolean deleteFile(File tempBuildFolder) {
9996
if (!file.delete()) {
10097
return false;
@@ -106,62 +103,66 @@ public boolean accept(File pathname) {
106103
}
107104
});
108105
for (File compiledFile : compiledFiles) {
109-
compiledFile.delete();
106+
if (!compiledFile.delete()) {
107+
return false;
108+
}
110109
}
111110

112111
return true;
113112
}
114-
115-
113+
114+
116115
protected boolean renameTo(File what) {
117116
boolean success = file.renameTo(what);
118117
if (success) {
119118
file = what;
120-
makePrettyName();
121119
}
122120
return success;
123121
}
124-
125-
126-
protected void copyTo(File dest) throws IOException {
127-
BaseNoGui.saveFile(program, dest);
128-
}
129-
122+
130123

131124
public String getFileName() {
132125
return file.getName();
133126
}
134-
135-
127+
128+
136129
public String getPrettyName() {
137-
return prettyName;
130+
String prettyName = getFileName();
131+
int dot = prettyName.lastIndexOf('.');
132+
return prettyName.substring(0, dot);
133+
}
134+
135+
public String getFileNameWithExtensionIfNotIno() {
136+
if (getFileName().endsWith(".ino")) {
137+
return getPrettyName();
138+
}
139+
return getFileName();
138140
}
139-
140-
141+
141142
public boolean isExtension(String... extensions) {
142143
return isExtension(Arrays.asList(extensions));
143144
}
144145

145146
public boolean isExtension(List<String> extensions) {
146147
return FileUtils.hasExtension(file, extensions);
147148
}
148-
149-
149+
150+
150151
public String getProgram() {
151152
return program;
152153
}
153-
154-
154+
155+
155156
public void setProgram(String replacement) {
156157
program = replacement;
157158
}
158-
159-
159+
160+
160161
public int getLineCount() {
161162
return BaseNoGui.countLines(program);
162163
}
163-
164-
164+
165+
165166
public void setModified(boolean modified) {
166167
this.modified = modified;
167168
}
@@ -177,25 +178,21 @@ public void setPreprocOffset(int preprocOffset) {
177178
}
178179

179180

180-
public int getPreprocOffset() {
181-
return preprocOffset;
182-
}
183-
184-
185181
public void addPreprocOffset(int extra) {
186182
preprocOffset += extra;
187183
}
188184

189185

190-
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
191-
192-
193186
/**
194187
* Load this piece of code from a file.
195188
*/
196-
public void load() throws IOException {
189+
private void load() throws IOException {
197190
program = BaseNoGui.loadFile(file);
198191

192+
if (program == null) {
193+
throw new IOException();
194+
}
195+
199196
if (program.indexOf('\uFFFD') != -1) {
200197
System.err.println(
201198
I18n.format(
@@ -209,7 +206,7 @@ public void load() throws IOException {
209206
);
210207
System.err.println();
211208
}
212-
209+
213210
setModified(false);
214211
}
215212

0 commit comments

Comments
 (0)