attempts to make PdeEditorStatus modal, and work properly on quit

This commit is contained in:
benfry
2003-09-21 15:40:30 +00:00
parent 1d2357653d
commit af6e32e93c
3 changed files with 128 additions and 74 deletions
+34 -32
View File
@@ -821,40 +821,40 @@ public class PdeEditor extends JPanel {
openingName = name;
if (sketchModified) {
//System.out.println("sketch modified");
status.prompt("Save changes to " + sketchName + "?");
String prompt = "Save changes to " + sketchName + "?";
//System.out.println("showing dialog");
//Dialog dialog = new Dialog(base, "something", true);
//dialog.show();
if (checking == DO_QUIT) {
Object[] options = { "Yes", "No", "Cancel" };
int value = 0;
/*
Object[] options = {"Quit", "Cancel"}; // YES, NO
Object[] optionsModified = {"Save", "Don't save", "Cancel"}; // YES, NO, CANCEL
int value = 0;
value = JOptionPane.showOptionDialog(this,
prompt,
"Quit",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[2]);
value = JOptionPane.showOptionDialog(this,
"Save changes before quitting?",
"Quit",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
optionsModified,
optionsModified[1]);
*/
//if (value == JOptionPane.YES_OPTION) {
if (value == JOptionPane.YES_OPTION) {
//System.out.println("yes");
//System.out.println("saving");
doSave();
//System.out.println("done saving");
checkModified2();
/*
// this is *not* the way to do it.. sleeps the wrong thread
// and jsut freezes the application.
while ((status.mode == PdeEditorStatus.EDIT) ||
(status.mode == PdeEditorStatus.PROMPT)) {
System.err.println("waiting for something useful");
try {
Thread.sleep(10);
} catch (InterruptedException e) { }
} else if (value == JOptionPane.NO_OPTION) {
//System.out.println("no");
checkModified2(); // though this may just quit
} else if (value == JOptionPane.CANCEL_OPTION) {
//System.out.println("cancel");
// does nothing
}
} else {
status.prompt(prompt);
}
*/
} else {
checkModified2();
@@ -1210,10 +1210,8 @@ public class PdeEditor extends JPanel {
//projectDir.mkdirs();
appletDir.mkdirs();
///
exportSketchName =
build(program, exportSketchName, appletDir.getPath(), true);
@@ -1464,13 +1462,14 @@ public class PdeEditor extends JPanel {
}
protected void doQuit2() {
System.out.println("doquit2");
//System.out.println("doquit2");
//doStop();
// clear out projects that are empty
if (PdeBase.getBoolean("sketchbook.auto_clean", true)) {
String userPath = base.sketchbookPath + File.separator + userName;
File userFolder = new File(userPath);
if (userFolder.exists()) { // huh?
String entries[] = new File(userPath).list();
if (entries != null) {
@@ -1481,6 +1480,9 @@ public class PdeEditor extends JPanel {
File prey = new File(preyDir, entries[j] + ".pde");
if (prey.exists()) {
if (prey.length() == 0) {
// this is a candidate for deletion, but make sure
// that the user hasn't added anything else to the folder
//System.out.println("remove: " + prey);
removeDir(preyDir);
}
+74 -32
View File
@@ -27,9 +27,11 @@ import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import sun.awt.AppContext; // from java.awt.Dialog, for blocking
#ifndef SWINGSUCKS
public class PdeEditorStatus extends JPanel
public class PdeEditorStatus extends JPanel
#else
public class PdeEditorStatus extends Panel
#endif
@@ -85,7 +87,7 @@ public class PdeEditorStatus extends Panel
#endif
//boolean editRename;
//Thread promptThread;
Thread promptThread;
int response;
@@ -141,26 +143,6 @@ public class PdeEditorStatus extends Panel
}
/*
public void run() {
while (Thread.currentThread() == promptThread) {
if (response != 0) {
//System.out.println("stopping prompt thread");
//promptThread.stop();
//System.out.println("exiting prompt loop");
unprompt();
break;
} else {
try {
//System.out.println("inside prompt thread " +
//System.currentTimeMillis());
Thread.sleep(100);
} catch (InterruptedException e) { }
}
}
}
*/
public void prompt(String message) {
//System.out.println("prompting...");
@@ -176,11 +158,66 @@ public class PdeEditorStatus extends Panel
update();
//promptThread = new Thread(this);
//promptThread.start();
/*
Point upperLeft = new Point(getLocation());
//Point lowerRight = new Point(upperLeft.x + getBounds().width,
// upperLeft.y + getBounds().height);
SwingUtilities.convertPointToScreen(upperLeft, this);
//Dialog dialog = new JDialog(editor.base, "none", true);
Dialog dialog = new Dialog(editor.base, "none", true);
//System.out.println(dialog.isDisplayable());
//System.out.println(dialog.isDisplayable());
dialog.setBounds(upperLeft.x, upperLeft.y,
getBounds().width, getBounds().height);
//System.out.println(dialog.isDisplayable());
//dialog.setModal(true);
//dialog.undecorated = true;
dialog.setUndecorated(true);
System.out.println("showing");
dialog.show();
System.out.println(dialog.isDisplayable());
*/
/*
//System.out.println(pt);
System.out.println(Thread.currentThread());
promptThread = new Thread(this);
promptThread.start();
*/
}
/*
public void run() {
//while (Thread.currentThread() == promptThread) {
synchronized (promptThread) {
while (promptThread != null) {
if (response != 0) {
System.out.println("stopping prompt thread");
//promptThread.stop();
promptThread = null;
System.out.println("exiting prompt loop");
unprompt();
break;
} else {
try {
System.out.println("inside prompt thread " +
System.currentTimeMillis());
Thread.sleep(10);
} catch (InterruptedException e) { }
}
}
System.out.println("exiting prompt thread");
}
}
*/
/**
* Makes the Dialog visible. If the dialog and/or its owner
@@ -201,10 +238,13 @@ public class PdeEditorStatus extends Panel
* @see java.awt.Dialog#isModal
*/
/*
// Stores the app context on which event dispatch thread the dialog
// is being shown. Initialized in show(), used in hideAndDisposeHandler()
private AppContext showAppContext;
private boolean keepBlocking = false;
public void show() {
@@ -222,7 +262,7 @@ public class PdeEditorStatus extends Panel
// we wake it by any event from hideAndDisposeHandler().
showAppContext = AppContext.getAppContext();
if (conditionalShow()) {
//if (conditionalShow()) {
// We have two mechanisms for blocking: 1. If we're on the
// EventDispatchThread, start a new event pump. 2. If we're
// on any other thread, call wait() on the treelock.
@@ -259,19 +299,21 @@ public class PdeEditorStatus extends Panel
windowClosingException.fillInStackTrace();
throw windowClosingException;
}
}
//}
}
//}
void interruptBlocking() {
hideAndDisposeHandler(); // this is what impl did
//if (modal) {
//disposeImpl();
} else if (windowClosingException != null) {
windowClosingException.fillInStackTrace();
windowClosingException.printStackTrace();
windowClosingException = null;
}
}
//} else if (windowClosingException != null) {
// windowClosingException.fillInStackTrace();
// windowClosingException.printStackTrace();
// windowClosingException = null;
// }
}
final static class WakingRunnable implements Runnable {
public void run() {
+20 -10
View File
@@ -97,6 +97,10 @@ X though setting it differently hoses everything (clears everything)
X setup (200, 200) causes the default size to be used
X be able to draw something inside setup (?)
X http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1044689650;start=0
X no time to ask for "save changes" before quit
X PdeEditor, around line 910.. not blocking until input
X read up on how to properly block for input in a java app
X http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1061659700
fixes because of dmose parser
@@ -196,9 +200,7 @@ X param(), online(), and status() functions
HIGH (to be completed for 0060)
_ no time to ask for "save changes" before quit
_ PdeEditor, around line 910.. not blocking until input
_ read up on how to properly block for input in a java app
_ do not delete sketch folder if empty sketch but non-empty data dir
_ maybe needs to be a holding area for the current sketch
_ this is how the read-only examples would be used
@@ -232,6 +234,12 @@ _ if size() not found in export/compile, ask the user
_ need to use oro matcher when trying to grab the applet size (export?)
_ size(myWidth, myHeight) -> set static var in BGraphics
_ for the last size that was used, use as default for fill-in field
_ better support for running locally
_ code to read from properties file from param()
_ for application mode or while inside the environment
_ these properties will be written to html on export
_ fix link, loadStrings, saveBytes code once that's fixed
_ saveBytes not in proper dir is annoying
dh b _ ability to export 'applications' (not just applets)
dh b _ lock feature for present mode (part of export to application?)
@@ -250,13 +258,6 @@ bf b _ or even BApplet.main(new String[] { getClass().getName() });
bf b _ META-INF/MANIFEST.MF contains just "Main-Class: ClassName"
bf b _ main sticking point will be serial/qtjava in exports
better support for running locally
_ code to read from properties file from param()
_ for application mode or while inside the environment
_ these properties will be written to html on export
_ fix link, loadStrings, saveBytes code once that's fixed
_ saveBytes not in proper dir is annoying
LOWER (post beta tweaks, non-structural)
_ remove .DS_Store boogers, especially from win/linux distributions
@@ -315,6 +316,15 @@ _ build all releases from a clean cvs
_ tries to make work/ without bagel serial existing and blows up
_ b/c bagel checkout happens later
_ all code needs to be buildable from scratch
_ make PdeEditorStatus modal
_ problem on quit (using JOptionPane as a band-aid)
_ also a problem because user can use the ui while prompt is visible
_ needs proper blocking, the way Dialog.show() does
_ so that that status window can be used while quitting
_ (currently cannot because it quits before getting response)
_ tried to pop up a modal Dialog in exactly the same location
_ but couldn't remove the decoration from the window (jvm bug?)
_ because it just quit without finishing
VOLUNTEER TASKS