Skip to content

Commit 3d7298a

Browse files
committed
clean up internal sketch loading, breaks api but fixes processing#3586 and avoids other complications
1 parent eeb9dec commit 3d7298a

9 files changed

Lines changed: 192 additions & 197 deletions

File tree

app/src/processing/app/Base.java

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,8 @@ public Editor handleOpen(String path, boolean untitled) {
814814
}
815815

816816

817-
// protected Editor handleOpen(String path, int[] location) {
818-
// protected Editor handleOpen(String path, Rectangle bounds, int divider) {
819-
protected Editor handleOpen(String path, boolean untitled, EditorState state) {
817+
protected Editor handleOpen(String path, boolean untitled,
818+
EditorState state) {
820819
try {
821820
// System.err.println("entering handleOpen " + path);
822821

@@ -856,63 +855,65 @@ protected Editor handleOpen(String path, boolean untitled, EditorState state) {
856855
nextMode = mode;
857856
}
858857

859-
// Editor.State state = new Editor.State(editors);
860-
Editor editor = null;
861858
try {
862-
editor = nextMode.createEditor(this, path, state);
859+
Editor editor = nextMode.createEditor(this, path, state);
863860

861+
// opened successfully, let's go to work
862+
editor.getSketch().setUntitled(untitled);
863+
editors.add(editor);
864+
handleRecent(editor);
865+
866+
// now that we're ready, show the window
867+
// (don't do earlier, cuz we might move it based on a window being closed)
868+
editor.setVisible(true);
869+
870+
return editor;
871+
872+
} catch (EditorException ee) {
873+
if (!ee.getMessage().equals("")) { // blank if the user canceled
874+
Base.showWarning("Error opening sketch", ee.getMessage(), ee);
875+
}
864876
} catch (NoSuchMethodError nsme) {
865877
Base.showWarning("Mode out of date",
866878
nextMode.getTitle() + " is not compatible with this version of Processing.\n" +
867879
"Try updating the Mode or contact its author for a new version.", nsme);
868880
} catch (Throwable t) {
869-
showBadnessTrace("Mode Problems",
870-
"A nasty error occurred while trying to use " + nextMode.getTitle() + ".\n" +
871-
"It may not be compatible with this version of Processing.\n" +
872-
"Try updating the Mode or contact its author for a new version.", t, false);
873-
}
874-
if (editor == null) {
875-
// if the bad mode is the default mode, don't go into an infinite loop
876-
// trying to recreate a window with the default mode.
877-
Mode defaultMode = getDefaultMode();
878-
if (nextMode == defaultMode) {
879-
Base.showError("Editor Problems",
880-
"An error occurred while trying to change modes.\n" +
881-
"We'll have to quit for now because it's an\n" +
882-
"unfortunate bit of indigestion with the default Mode.",
883-
null);
881+
if (nextMode.equals(getDefaultMode())) {
882+
showBadnessTrace("Serious Problem",
883+
"An unexpected, unknown, and unrecoverable error occurred\n" +
884+
"while opening a new editor window. Please report this.", t, true);
884885
} else {
885-
editor = defaultMode.createEditor(this, path, state);
886+
showBadnessTrace("Mode Problems",
887+
"A nasty error occurred while trying to use " + nextMode.getTitle() + ".\n" +
888+
"It may not be compatible with this version of Processing.\n" +
889+
"Try updating the Mode or contact its author for a new version.", t, false);
886890
}
887891
}
888-
889-
// Make sure that the sketch actually loaded
890-
Sketch sketch = editor.getSketch();
891-
if (sketch == null) {
892-
return null; // Just walk away quietly
893-
}
894-
895-
sketch.setUntitled(untitled);
896-
editors.add(editor);
897-
handleRecent(editor);
898-
899-
// now that we're ready, show the window
900-
// (don't do earlier, cuz we might move it based on a window being closed)
901-
editor.setVisible(true);
902-
903-
return editor;
904-
905-
// } catch (NoSuchMethodError nsme) {
906-
// Base.showWarning(title, message);
892+
/*
893+
if (editors.isEmpty()) {
894+
// if the bad mode is the default mode, don't go into an infinite loop
895+
// trying to recreate a window with the default mode.
896+
Mode defaultMode = getDefaultMode();
897+
if (nextMode == defaultMode) {
898+
Base.showError("Editor Problems",
899+
"An error occurred while trying to change modes.\n" +
900+
"We'll have to quit for now because it's an\n" +
901+
"unfortunate bit of indigestion with the default Mode.",
902+
null);
903+
} else {
904+
editor = defaultMode.createEditor(this, path, state);
905+
}
906+
}
907+
*/
907908

908909
} catch (Throwable t) {
909910
showBadnessTrace("Terrible News",
910911
"A serious error occurred while " +
911912
"trying to create a new editor window.", t,
912913
nextMode == getDefaultMode()); // quit if default
913914
nextMode = getDefaultMode();
914-
return null;
915915
}
916+
return null;
916917
}
917918

918919

app/src/processing/app/Mode.java

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import processing.app.syntax.*;
3838
import processing.app.ui.Editor;
39+
import processing.app.ui.EditorException;
3940
import processing.app.ui.EditorState;
4041
import processing.app.ui.ExamplesFrame;
4142
import processing.app.ui.SketchbookFrame;
@@ -215,38 +216,6 @@ public void setupGUI() {
215216
}
216217

217218

218-
/*
219-
protected void loadBackground() {
220-
String suffix = Toolkit.highResDisplay() ? "-2x.png" : ".png";
221-
backgroundImage = loadImage("theme/mode" + suffix);
222-
if (backgroundImage == null) {
223-
// If the image wasn't available, try the other resolution.
224-
// i.e. we don't (currently) have low-res versions of mode.png,
225-
// so this will grab the 2x version and scale it when drawn.
226-
suffix = !Toolkit.highResDisplay() ? "-2x.png" : ".png";
227-
backgroundImage = loadImage("theme/mode" + suffix);
228-
}
229-
}
230-
231-
232-
public void drawBackground(Graphics g, int offset) {
233-
if (backgroundImage != null) {
234-
if (!Toolkit.highResDisplay()) {
235-
// Image might be downsampled from a 2x version. If so, we need nice
236-
// anti-aliasing for the very geometric images we're using.
237-
Graphics2D g2 = (Graphics2D) g;
238-
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
239-
RenderingHints.VALUE_ANTIALIAS_ON);
240-
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
241-
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
242-
}
243-
g.drawImage(backgroundImage, 0, -offset,
244-
BACKGROUND_WIDTH, BACKGROUND_HEIGHT, null);
245-
}
246-
}
247-
*/
248-
249-
250219
public File getContentFile(String path) {
251220
return new File(folder, path);
252221
}
@@ -280,8 +249,8 @@ public String getIdentifier() {
280249
/**
281250
* Create a new editor associated with this mode.
282251
*/
283-
abstract public Editor createEditor(Base base, String path, EditorState state);
284-
//abstract public Editor createEditor(Base base, String path, int[] location);
252+
abstract public Editor createEditor(Base base, String path,
253+
EditorState state) throws EditorException;
285254

286255

287256
/**

app/src/processing/app/SketchException.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,105 +28,107 @@
2828
* An exception with a line number attached that occurs
2929
* during either pre-processing, compile, or run time.
3030
*/
31-
public class SketchException extends Exception /*RuntimeException*/ {
31+
public class SketchException extends Exception {
3232
protected String message;
3333
protected int codeIndex;
3434
protected int codeLine;
3535
protected int codeColumn;
3636
protected boolean showStackTrace;
3737

38-
38+
3939
public SketchException(String message) {
4040
this(message, true);
4141
}
4242

43+
4344
public SketchException(String message, boolean showStackTrace) {
4445
this(message, -1, -1, -1, showStackTrace);
4546
}
4647

48+
4749
public SketchException(String message, int file, int line) {
4850
this(message, file, line, -1, true);
4951
}
5052

51-
53+
5254
public SketchException(String message, int file, int line, int column) {
5355
this(message, file, line, column, true);
5456
}
55-
56-
57-
public SketchException(String message, int file, int line, int column,
57+
58+
59+
public SketchException(String message, int file, int line, int column,
5860
boolean showStackTrace) {
5961
this.message = message;
6062
this.codeIndex = file;
6163
this.codeLine = line;
6264
this.codeColumn = column;
6365
this.showStackTrace = showStackTrace;
6466
}
65-
66-
67-
/**
68-
* Override getMessage() in Throwable, so that I can set
67+
68+
69+
/**
70+
* Override getMessage() in Throwable, so that I can set
6971
* the message text outside the constructor.
7072
*/
7173
public String getMessage() {
7274
return message;
7375
}
74-
75-
76+
77+
7678
public void setMessage(String message) {
7779
this.message = message;
7880
}
79-
80-
81+
82+
8183
public int getCodeIndex() {
8284
return codeIndex;
8385
}
84-
85-
86+
87+
8688
public void setCodeIndex(int index) {
8789
codeIndex = index;
8890
}
89-
90-
91+
92+
9193
public boolean hasCodeIndex() {
9294
return codeIndex != -1;
9395
}
94-
95-
96+
97+
9698
public int getCodeLine() {
9799
return codeLine;
98100
}
99-
100-
101+
102+
101103
public void setCodeLine(int line) {
102104
this.codeLine = line;
103105
}
104-
105-
106+
107+
106108
public boolean hasCodeLine() {
107109
return codeLine != -1;
108110
}
109-
110-
111+
112+
111113
public void setCodeColumn(int column) {
112114
this.codeColumn = column;
113115
}
114-
115-
116+
117+
116118
public int getCodeColumn() {
117119
return codeColumn;
118120
}
119121

120-
122+
121123
public void showStackTrace() {
122124
showStackTrace = true;
123125
}
124-
125-
126+
127+
126128
public void hideStackTrace() {
127129
showStackTrace = false;
128130
}
129-
131+
130132

131133
/**
132134
* Nix the java.lang crap out of an exception message

0 commit comments

Comments
 (0)