FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make the change detector not reload the sketch · processing/processing@83784f6 · GitHub

Repository navigation

Commit 83784f6

Browse files
committed
Make the change detector not reload the sketch
Fixes #4713, fixes #4849
1 parent 7215447 commit 83784f6

4 files changed

Lines changed: 244 additions & 73 deletions

File tree

‎app/src/processing/app/Messages.java‎

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,34 @@ static public int showYesNoQuestion(Frame editor, String title,
265265
"<br>" + secondary, title,
266266
JOptionPane.YES_NO_OPTION,
267267
JOptionPane.QUESTION_MESSAGE);
268+
} else {
269+
int result = showCustomQuestion(editor, title, primary, secondary,
270+
0, "Yes", "No");
271+
if (result == 0) {
272+
return JOptionPane.YES_OPTION;
273+
} else if (result == 1) {
274+
return JOptionPane.NO_OPTION;
275+
} else {
276+
return JOptionPane.CLOSED_OPTION;
277+
}
278+
}
279+
}
280+
281+
282+
/**
283+
* @param highlight A valid array index for options[] that specifies the
284+
* default (i.e. safe) choice.
285+
* @return The (zero-based) index of the selected value, -1 otherwise.
286+
*/
287+
static public int showCustomQuestion(Frame editor, String title,
288+
String primary, String secondary,
289+
int highlight, String... options) {
290+
Object result;
291+
if (!Platform.isMacOS()) {
292+
return JOptionPane.showOptionDialog(editor,
293+
"<html><body><b>" + primary + "</b><br>" + secondary, title,
294+
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
295+
options, options[highlight]);
268296
} else {
269297
// Pane formatting adapted from the Quaqua guide
270298
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
@@ -275,29 +303,23 @@ static public int showYesNoQuestion(Frame editor, String title,
275303
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+
276304
"</style> </head>" +
277305
"<b>" + primary + "</b>" +
278-
"<p>" + secondary + "</p>",
306+
"<p>" + secondary, // + "</p>",
279307
JOptionPane.QUESTION_MESSAGE);
280308

281-
String[] options = new String[] {
282-
"Yes", "No"
283-
};
284309
pane.setOptions(options);
285310

286311
// highlight the safest option ala apple hig
287-
pane.setInitialValue(options[0]);
312+
pane.setInitialValue(options[highlight]);
288313

289314
JDialog dialog = pane.createDialog(editor, null);
290315
dialog.setVisible(true);
291316

292-
Object result = pane.getValue();
293-
if (result == options[0]) {
294-
return JOptionPane.YES_OPTION;
295-
} else if (result == options[1]) {
296-
return JOptionPane.NO_OPTION;
297-
} else {
298-
return JOptionPane.CLOSED_OPTION;
299-
}
317+
result = pane.getValue();
318+
}
319+
for (int i = 0; i < options.length; i++) {
320+
if (result != null && result.equals(options[i])) return i;
300321
}
322+
return -1;
301323
}
302324

303325

@@ -340,4 +362,4 @@ static public void loge(String message) {
340362
System.err.println(message);
341363
}
342364
}
343-
}
365+
}

‎app/src/processing/app/Sketch.java‎

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ public void reload() {
227227
}
228228

229229

230+
/**
231+
* Load a tab that the user added to the sketch or modified with an external
232+
* editor.
233+
*/
234+
public void loadNewTab(String filename, String ext, boolean newAddition) {
235+
if (newAddition) {
236+
insertCode(new SketchCode(new File(folder, filename), ext));
237+
} else {
238+
replaceCode(new SketchCode(new File(folder, filename), ext));
239+
}
240+
sortCode();
241+
}
242+
243+
230244
protected void replaceCode(SketchCode newCode) {
231245
for (int i = 0; i < codeCount; i++) {
232246
if (code[i].getFileName().equals(newCode.getFileName())) {
@@ -685,7 +699,11 @@ public void handleDeleteCode() {
685699
}
686700

687701

688-
protected void removeCode(SketchCode which) {
702+
/**
703+
* Remove a SketchCode from the list of files without deleting its file.
704+
* @see #handleDeleteCode()
705+
*/
706+
public void removeCode(SketchCode which) {
689707
// remove it from the internal list of files
690708
// resort internal list of files
691709
for (int i = 0; i < codeCount; i++) {
@@ -757,6 +775,16 @@ public boolean isModified() {
757775
}
758776

759777

778+
/**
779+
* Ensure that all SketchCodes are up-to-date, so that sc.save() works.
780+
*/
781+
public void updateSketchCodes() {
782+
// if (current.isModified()) {
783+
current.setProgram(editor.getText());
784+
// }
785+
}
786+
787+
760788
/**
761789
* Save all code in the current sketch. This just forces the files to save
762790
* in place, so if it's an untitled (un-saved) sketch, saveAs() should be
@@ -767,9 +795,7 @@ public boolean save() throws IOException {
767795
ensureExistence();
768796

769797
// first get the contents of the editor text area
770-
// if (current.isModified()) {
771-
current.setProgram(editor.getText());
772-
// }
798+
updateSketchCodes();
773799

774800
// don't do anything if not actually modified
775801
//if (!modified) return false;
@@ -911,9 +937,7 @@ public boolean saveAs() throws IOException {
911937

912938
// grab the contents of the current tab before saving
913939
// first get the contents of the editor text area
914-
if (current.isModified()) {
915-
current.setProgram(editor.getText());
916-
}
940+
updateSketchCodes();
917941

918942
File[] copyItems = folder.listFiles(new FileFilter() {
919943
public boolean accept(File file) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL