alt button option in editor, remove prompt mode from header, more cleaning

up
This commit is contained in:
benfry
2007-07-23 01:56:47 +00:00
parent 05666379b7
commit 474082ba31
8 changed files with 124 additions and 193 deletions
+43 -1
View File
@@ -295,11 +295,16 @@ public class Base {
Preferences.setInteger("last.screen.width", screen.width);
Preferences.setInteger("last.screen.height", screen.height);
String untitledPath = untitledFolder.getAbsolutePath();
// Save the sketch path and window placement for each open sketch
Preferences.setInteger("last.sketch.count", editorCount);
//System.out.println("saving sketch count " + editorCount);
for (int i = 0; i < editorCount; i++) {
String path = editors[i].sketch.getMainFilePath();
if (path.startsWith(untitledPath)) {
path = ""; // this will prevent it from opening
}
Preferences.set("last.sketch" + i + ".path", path);
int[] location = editors[i].getPlacement();
@@ -307,6 +312,37 @@ public class Base {
Preferences.set("last.sketch" + i + ".location", locationStr);
}
}
// If a sketch is untitled on quit, may need to store the new name
// rather than the location from the temp folder.
protected void storeSketchPath(Editor editor, int index) {
String path = editor.sketch.getMainFilePath();
String untitledPath = untitledFolder.getAbsolutePath();
if (path.startsWith(untitledPath)) {
path = "";
}
Preferences.set("last.sketch" + index + ".path", path);
}
/*
public void storeSketch(Editor editor) {
int index = -1;
for (int i = 0; i < editorCount; i++) {
if (editors[i] == editor) {
index = i;
break;
}
}
if (index == -1) {
System.err.println("Problem storing sketch " + editor.sketch.name);
} else {
String path = editor.sketch.getMainFilePath();
Preferences.set("last.sketch" + index + ".path", path);
}
}
*/
// .................................................................
@@ -528,9 +564,11 @@ public class Base {
}
/*
public void handleOpen(File file) {
handleOpen(file.getAbsolutePath());
}
*/
/**
@@ -614,9 +652,13 @@ public class Base {
boolean canceled = false;
for (int i = 0; i < editorCount; i++) {
if (!handleClose(editors[i], true)) {
Editor editor = editors[i];
if (!handleClose(editor, true)) {
canceled = true;
break;
} else {
// Update to the new/final sketch path for this fella
storeSketchPath(editor, i);
}
}
if (!canceled) {
+27 -135
View File
@@ -47,7 +47,7 @@ public class Editor extends JFrame {
Base base;
// yeah
static final String WINDOW_TITLE = "Processing" + " - " + Base.VERSION_NAME;
static final String WINDOW_TITLE = "Processing " + Base.VERSION_NAME;
// p5 icon for the window
static Image icon;
@@ -59,14 +59,19 @@ public class Editor extends JFrame {
" " +
" ";
/** Command on Mac OS X, Ctrl on Windows and Linux */
static final int SHORTCUT_KEY_MASK =
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
/** Command-W on Mac OS X, Ctrl-W on Windows and Linux */
static public final KeyStroke WINDOW_CLOSE_KEYSTROKE =
KeyStroke.getKeyStroke('W', SHORTCUT_KEY_MASK);
/** Command-Option on Mac OS X, Ctrl-Alt on Windows and Linux */
static public final int SHORTCUT_ALT_KEY_MASK = ActionEvent.ALT_MASK |
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
static final int HANDLE_NEW = 1;
static final int HANDLE_OPEN = 2;
static final int HANDLE_QUIT = 3;
//static final int HANDLE_NEW = 1;
//static final int HANDLE_OPEN = 2;
//static final int HANDLE_QUIT = 3;
//int checkModifiedMode;
//String handleOpenPath;
@@ -112,8 +117,6 @@ public class Editor extends JFrame {
// True if the sketchbook has changed since this Editor was last active.
boolean sketchbookUpdated;
//
boolean running;
boolean presenting;
@@ -125,8 +128,6 @@ public class Editor extends JFrame {
// used internally, and only briefly
CompoundEdit compoundEdit;
//
//SketchHistory history; // TODO re-enable history
//Sketchbook sketchbook;
FindReplace find;
@@ -280,7 +281,8 @@ public class Editor extends JFrame {
String name = filename.substring(0, filename.length() - 4);
File parent = file.getParentFile();
if (name.equals(parent.getName())) {
base.handleOpen(file);
base.handleOpen(file.getAbsolutePath());
// Only opens the first sketch dragged into the window
return true;
}
}
@@ -883,6 +885,15 @@ public class Editor extends JFrame {
return menuItem;
}
static public JMenuItem newJMenuItemAlt(String title, int what) {
JMenuItem menuItem = new JMenuItem(title);
//int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
//menuItem.setAccelerator(KeyStroke.getKeyStroke(what, modifiers));
menuItem.setAccelerator(KeyStroke.getKeyStroke(what, SHORTCUT_ALT_KEY_MASK));
return menuItem;
}
// ...................................................................
@@ -1314,111 +1325,6 @@ public class Editor extends JFrame {
}
/**
* Check to see if there have been changes. If so, prompt user
* whether or not to save first. If the user cancels, just ignore.
* Otherwise, one of the other methods will handle calling
* checkModified2() which will get on with business.
*/
/*
protected void checkModified(int checkModifiedMode) {
this.checkModifiedMode = checkModifiedMode;
if (!sketch.modified) {
checkModified2();
return;
}
String prompt = "Save changes to " + sketch.name + "? ";
if (checkModifiedMode != HANDLE_QUIT) {
// if the user is not quitting, then use simpler nicer
// dialog that's actually inside the p5 window.
status.prompt(prompt);
} else {
if (!Base.isMacOS() || PApplet.javaVersion < 1.5f) {
int result =
JOptionPane.showConfirmDialog(this, prompt, "Quit",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
handleSave(true);
checkModified2();
} else if (result == JOptionPane.NO_OPTION) {
checkModified2();
}
// cancel is ignored altogether
} else {
// This code is disabled unless Java 1.5 is being used on Mac OS X
// because of a Java bug that prevents the initial value of the
// dialog from being set properly (at least on my MacBook Pro).
// The bug causes the "Don't Save" option to be the highlighted,
// blinking, default. This sucks. But I'll tell you what doesn't
// suck--workarounds for the Mac and Apple's snobby attitude about it!
// adapted from the quaqua guide
// http://www.randelshofer.ch/quaqua/guide/joptionpane.html
JOptionPane pane =
new JOptionPane("<html> " +
"<head> <style type=\"text/css\">"+
"b { font: 13pt \"Lucida Grande\" }"+
"p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+
"</style> </head>" +
"<b>Do you want to save changes to this sketch<BR>" +
" before closing?</b>" +
"<p>If you don't save, your changes will be lost.",
JOptionPane.QUESTION_MESSAGE);
String[] options = new String[] {
"Save", "Cancel", "Don't Save"
};
pane.setOptions(options);
// highlight the safest option ala apple hig
pane.setInitialValue(options[0]);
// on macosx, setting the destructive property places this option
// away from the others at the lefthand side
pane.putClientProperty("Quaqua.OptionPane.destructiveOption",
new Integer(2));
JDialog dialog = pane.createDialog(this, null);
dialog.show();
Object result = pane.getValue();
if (result == options[0]) { // save (and quit)
handleSave(true);
checkModified2();
} else if (result == options[2]) { // don't save (still quit)
checkModified2();
}
}
}
}
*/
/**
* Called by EditorStatus to complete the job and re-dispatch
* to handleNew, handleOpen, handleQuit.
*/
/*
public void checkModified2() {
switch (checkModifiedMode) {
case HANDLE_NEW: handleNew2(false); break;
case HANDLE_OPEN: handleOpen2(handleOpenPath); break;
case HANDLE_QUIT: handleQuit2(); break;
}
checkModifiedMode = 0;
}
*/
/**
* Open a sketch given the full path to the .pde file.
* Pass in 'null' to prompt the user for the name of the sketch.
@@ -1452,8 +1358,8 @@ public class Editor extends JFrame {
* Open a sketch from a particular path, but don't check to save changes.
* Used by Sketch.saveAs() to re-open a sketch after the "Save As"
*/
public void handleOpenUnchecked(String path, int codeIndex,
int selStart, int selStop, int scrollPos) {
protected void handleOpenUnchecked(String path, int codeIndex,
int selStart, int selStop, int scrollPos) {
doClose();
handleOpen2(path);
@@ -1512,8 +1418,8 @@ public class Editor extends JFrame {
} else if (!path.endsWith(".pde")) {
Base.showWarning("Bad file selected",
"Processing can only open its own sketches\n" +
"and other files ending in .pde", null);
"Processing can only open its own sketches\n" +
"and other files ending in .pde", null);
return;
} else {
@@ -1564,14 +1470,13 @@ public class Editor extends JFrame {
}
sketch = new Sketch(this, path);
// TODO re-enable this once export application works
//exportAppItem.setEnabled(false);
//exportAppItem.setEnabled(false && !sketch.isLibrary());
//buttons.disableRun(sketch.isLibrary());
header.rebuild();
// TODO remove this, it's a moot point for separate windows
if (Preferences.getBoolean("console.auto_clear")) {
console.clear();
}
// Set the title of the window to "sketch_070752a - Processing 0126"
setTitle(sketch.name + " | " + WINDOW_TITLE);
} catch (Exception e) {
error(e);
@@ -1579,19 +1484,6 @@ public class Editor extends JFrame {
}
/*
public boolean handleClose() {
}
*/
/*
public void handleClose2() {
base.handleClose(this);
}
*/
/**
* Actually handle the save command. If 'immediately' is set to false,
* this will happen in another thread so that the message area
+7 -7
View File
@@ -292,7 +292,8 @@ public class EditorHeader extends JComponent {
menu.addSeparator();
*/
item = new JMenuItem("New Tab");
//item = new JMenuItem("New Tab");
item = Editor.newJMenuItemAlt("New Tab", 'N');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.sketch.newCode();
@@ -300,7 +301,7 @@ public class EditorHeader extends JComponent {
});
menu.add(item);
item = new JMenuItem("Rename");
item = Editor.newJMenuItemAlt("Rename", 'R');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.sketch.renameCode();
@@ -357,13 +358,11 @@ public class EditorHeader extends JComponent {
// KeyEvent.VK_LEFT and VK_RIGHT will make Windows beep
int ctrlAlt = ActionEvent.ALT_MASK |
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
//item = Editor.newJMenuItem("Previous Tab", '[', true);
item = new JMenuItem("Previous Tab");
//int shortcut = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
KeyStroke ctrlAltLeft = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ctrlAlt);
KeyStroke ctrlAltLeft =
KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Editor.SHORTCUT_ALT_KEY_MASK);
item.setAccelerator(ctrlAltLeft);
//int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
//KeyStroke tabby = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, modifiers);
@@ -380,7 +379,8 @@ public class EditorHeader extends JComponent {
//item = Editor.newJMenuItem("Next Tab", ']', true);
item = new JMenuItem("Next Tab");
KeyStroke ctrlAltRight = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ctrlAlt);
KeyStroke ctrlAltRight =
KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Editor.SHORTCUT_ALT_KEY_MASK);
item.setAccelerator(ctrlAltRight);
/*
item.addActionListener(new ActionListener() {
+27 -26
View File
@@ -37,8 +37,9 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
static final int NOTICE = 0;
static final int ERR = 1;
static final int PROMPT = 2;
static final int EDIT = 3;
//static final int PROMPT = 2;
//static final int EDIT = 3;
static final int EDIT = 2;
static final int YES = 1;
static final int NO = 2;
@@ -60,8 +61,8 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
int sizeW, sizeH;
int imageW, imageH;
JButton yesButton;
JButton noButton;
//JButton yesButton;
//JButton noButton;
JButton cancelButton;
JButton okButton;
JTextField editField;
@@ -75,17 +76,17 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
empty();
if (bgcolor == null) {
bgcolor = new Color[4];
bgcolor = new Color[3]; //4];
bgcolor[0] = Preferences.getColor("status.notice.bgcolor");
bgcolor[1] = Preferences.getColor("status.error.bgcolor");
bgcolor[2] = Preferences.getColor("status.prompt.bgcolor");
bgcolor[3] = Preferences.getColor("status.prompt.bgcolor");
bgcolor[2] = Preferences.getColor("status.edit.bgcolor");
//bgcolor[3] = Preferences.getColor("status.prompt.bgcolor");
fgcolor = new Color[4];
fgcolor = new Color[3]; //4];
fgcolor[0] = Preferences.getColor("status.notice.fgcolor");
fgcolor[1] = Preferences.getColor("status.error.fgcolor");
fgcolor[2] = Preferences.getColor("status.prompt.fgcolor");
fgcolor[3] = Preferences.getColor("status.prompt.fgcolor");
fgcolor[2] = Preferences.getColor("status.edit.fgcolor");
//fgcolor[3] = Preferences.getColor("status.prompt.fgcolor");
}
}
@@ -182,7 +183,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
public void paintComponent(Graphics screen) {
//if (screen == null) return;
if (yesButton == null) setup();
if (okButton == null) setup();
//System.out.println("status.paintComponent");
@@ -234,9 +235,9 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
protected void setup() {
if (yesButton == null) {
yesButton = new JButton(Preferences.PROMPT_YES);
noButton = new JButton(Preferences.PROMPT_NO);
if (okButton == null) {
//yesButton = new JButton(Preferences.PROMPT_YES);
//noButton = new JButton(Preferences.PROMPT_NO);
cancelButton = new JButton(Preferences.PROMPT_CANCEL);
okButton = new JButton(Preferences.PROMPT_OK);
@@ -263,10 +264,10 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
// !@#(* aqua ui #($*(( that turtle-neck wearing #(** (#$@)(
// os9 seems to work if bg of component is set, but x still a bastard
if (Base.isMacOS()) {
yesButton.setBackground(bgcolor[PROMPT]);
noButton.setBackground(bgcolor[PROMPT]);
cancelButton.setBackground(bgcolor[PROMPT]);
okButton.setBackground(bgcolor[PROMPT]);
//yesButton.setBackground(bgcolor[EDIT]);
//noButton.setBackground(bgcolor[EDIT]);
cancelButton.setBackground(bgcolor[EDIT]);
okButton.setBackground(bgcolor[EDIT]);
}
setLayout(null);
@@ -277,13 +278,13 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
okButton.addActionListener(this);
*/
add(yesButton);
add(noButton);
//add(yesButton);
//add(noButton);
add(cancelButton);
add(okButton);
yesButton.setVisible(false);
noButton.setVisible(false);
//yesButton.setVisible(false);
//noButton.setVisible(false);
cancelButton.setVisible(false);
okButton.setVisible(false);
@@ -398,13 +399,13 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
int noLeft = cancelLeft - eachButton;
int yesLeft = noLeft - eachButton;
yesButton.setLocation(yesLeft, top);
noButton.setLocation(noLeft, top);
//yesButton.setLocation(yesLeft, top);
//noButton.setLocation(noLeft, top);
cancelButton.setLocation(cancelLeft, top);
okButton.setLocation(noLeft, top);
yesButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
noButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
//yesButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
//noButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
cancelButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
okButton.setSize(Preferences.BUTTON_WIDTH, Preferences.BUTTON_HEIGHT);
+5 -5
View File
@@ -99,11 +99,11 @@ public class Sketch {
// get the name of the sketch by chopping .pde or .java
// off of the main file name
if (mainFilename.endsWith(".pde")) {
name = mainFilename.substring(0, mainFilename.length() - 4);
} else if (mainFilename.endsWith(".java")) {
name = mainFilename.substring(0, mainFilename.length() - 5);
}
//if (mainFilename.endsWith(".pde")) {
name = mainFilename.substring(0, mainFilename.length() - 4);
//} else if (mainFilename.endsWith(".java")) {
//name = mainFilename.substring(0, mainFilename.length() - 5);
//}
// lib/build must exist when the application is started
// it is added to the CLASSPATH by default, but if it doesn't
-8
View File
@@ -98,8 +98,6 @@ cd ../app
### -- BUILD PARSER ---------------------------------------------
#BUILD_PREPROC=true
echo app is now
ls
if $BUILD_PREPROC
then
@@ -115,9 +113,6 @@ then
-glib src/antlr/java/java.g src/processing/app/preproc/pde.g
fi
echo app is now
ls
### -- BUILD PDE ------------------------------------------------
echo Building the PDE...
@@ -131,9 +126,6 @@ echo Building the PDE...
# version that follows includes jalopy.jar and log4j.jar
#../build/macosx/work/jikes -target 1.3 +D -classpath ../build/macosx/work/classes:../build/macosx/work/lib/core.jar:../build/macosx/work/lib/antlr.jar:../build/macosx/work/lib/oro.jar:../build/macosx/work/lib/registry.jar:../build/macosx/work/lib/jalopy.jar:../build/macosx/work/lib/log4j.jar:$CLASSPATH -d ../build/macosx/work/classes tools/*.java preproc/*.java syntax/*.java *.java
echo app is now
ls
cd ../build/macosx/work/classes
rm -f ../lib/pde.jar
zip -0rq ../lib/pde.jar .
+4 -2
View File
@@ -172,8 +172,10 @@ status.notice.fgcolor = #000000
status.notice.bgcolor = #bbbbaa
status.error.fgcolor = #ffffff
status.error.bgcolor = #662000
status.prompt.fgcolor = #000000
status.prompt.bgcolor = #cc9900
status.edit.fgcolor = #000000
status.edit.bgcolor = #cc9900
#status.prompt.fgcolor = #000000
#status.prompt.bgcolor = #cc9900
status.font = SansSerif,plain,12
# convert tabs to spaces? how many spaces?
+11 -9
View File
@@ -18,22 +18,24 @@ X if quitting when zero windows are open, mark as such and use untitled
X first untitled sketch not being marked as modified
X move untitled sketches to the tmp folder
X then on save, do a save as that defaults to the sketch folder
X clean up number of new/open/close functions in editor and in base
X make sure drag and drop to open sketch is still working
o make sure double-click pde to open is launching in p5
X on first save, ask for the name of the project (with default)
X set title of window to the sketch name
X cmd-opt-r for rename, cmd-opt-n for new tab
X save/saveas should use modal dialog
X only use the bottom bar for name, rename, new tab
X remove prompt mode (yes/no/cancel) from EditorStatus
_ improve speed of "new", which is calling the rebuild menus
_ keep one static list of all pairs of names/files in sketchbook
_ tough to do with the multiple directories/submenus
_ add methods for "add" and "remove" for sketches
_ also a rename method, which could just be a remove and add
_ libraries and examples won't be rebuilt during the session
_ test on windows
_ test on linux
_ make sure quit being handled properly on windows/linux
_ clean up number of new/open/close functions in editor and in base
_ make sure drag and drop to open sketch is still working
_ make sure double-click pde to open is launching in p5
_ would also help the opening multiple files thing
_ set title of window to the sketch name
_ on first save, ask for the name of the project (with default)
_ cmd-opt-r for rename?
_ save/saveas should use modal dialog
_ only use the bottom bar for name, rename, new tab
_ make editor buttons light up and clear properly
_ don't bug the user about new release of p5 when they have it