mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 10:55:38 +01:00
make editor buttons properly highlight whether called by clicking or by
menu items. fix for bug #242
This commit is contained in:
@@ -119,6 +119,9 @@ public class Base {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// use native popups so they don't look so crappy on osx
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
|
||||
// build the editor object
|
||||
editor = new Editor();
|
||||
|
||||
|
||||
199
app/Editor.java
199
app/Editor.java
@@ -527,7 +527,11 @@ public class Editor extends JFrame
|
||||
exportAppItem = newJMenuItem("Export Application", 'E', true);
|
||||
exportAppItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//buttons.activate(EditorButtons.EXPORT);
|
||||
//SwingUtilities.invokeLater(new Runnable() {
|
||||
//public void run() {
|
||||
handleExportApplication();
|
||||
//}});
|
||||
}
|
||||
});
|
||||
menu.add(exportAppItem);
|
||||
@@ -1063,7 +1067,7 @@ public class Editor extends JFrame
|
||||
public void handleRun(boolean present) {
|
||||
doClose();
|
||||
running = true;
|
||||
buttons.run();
|
||||
buttons.activate(EditorButtons.RUN);
|
||||
|
||||
// do this for the terminal window / dos prompt / etc
|
||||
for (int i = 0; i < 10; i++) System.out.println();
|
||||
@@ -1178,6 +1182,7 @@ public class Editor extends JFrame
|
||||
} else {
|
||||
doStop();
|
||||
}
|
||||
buttons.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -1310,15 +1315,20 @@ public class Editor extends JFrame
|
||||
/**
|
||||
* New was called (by buttons or by menu), first check modified
|
||||
* and if things work out ok, handleNew2() will be called.
|
||||
*
|
||||
* <p/>
|
||||
* If shift is pressed when clicking the toolbar button, then
|
||||
* force the opposite behavior from sketchbook.prompt's setting
|
||||
*/
|
||||
public void handleNew(boolean shift) {
|
||||
doStop();
|
||||
handleNewShift = shift;
|
||||
handleNewLibrary = false;
|
||||
checkModified(HANDLE_NEW);
|
||||
public void handleNew(final boolean shift) {
|
||||
buttons.activate(EditorButtons.NEW);
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
doStop();
|
||||
handleNewShift = shift;
|
||||
handleNewLibrary = false;
|
||||
checkModified(HANDLE_NEW);
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
@@ -1369,6 +1379,7 @@ public class Editor extends JFrame
|
||||
"An error occurred while creating\n" +
|
||||
"a new sketch. Processing must now quit.", e);
|
||||
}
|
||||
buttons.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -1386,15 +1397,22 @@ public class Editor extends JFrame
|
||||
* Open a sketch given the full path to the .pde file.
|
||||
* Pass in 'null' to prompt the user for the name of the sketch.
|
||||
*/
|
||||
public void handleOpen(String path) {
|
||||
if (path == null) { // "open..." selected from the menu
|
||||
path = sketchbook.handleOpen();
|
||||
if (path == null) return;
|
||||
}
|
||||
doClose();
|
||||
//doStop();
|
||||
handleOpenPath = path;
|
||||
checkModified(HANDLE_OPEN);
|
||||
public void handleOpen(final String ipath) {
|
||||
// haven't run across a case where i can verify that this works
|
||||
// because open is usually very fast.
|
||||
buttons.activate(EditorButtons.OPEN);
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
String path = ipath;
|
||||
if (path == null) { // "open..." selected from the menu
|
||||
path = sketchbook.handleOpen();
|
||||
if (path == null) return;
|
||||
}
|
||||
doClose();
|
||||
handleOpenPath = path;
|
||||
checkModified(HANDLE_OPEN);
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
@@ -1523,96 +1541,120 @@ public class Editor extends JFrame
|
||||
|
||||
// there is no handleSave1 since there's never a need to prompt
|
||||
public void handleSave() {
|
||||
message("Saving...");
|
||||
try {
|
||||
if (sketch.save()) {
|
||||
message("Done Saving.");
|
||||
} else {
|
||||
message(EMPTY);
|
||||
}
|
||||
// rebuild sketch menu in case a save-as was forced
|
||||
sketchbook.rebuildMenus();
|
||||
doStop();
|
||||
buttons.activate(EditorButtons.SAVE);
|
||||
|
||||
} catch (Exception e) {
|
||||
// show the error as a message in the window
|
||||
error(e);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
message("Saving...");
|
||||
try {
|
||||
if (sketch.save()) {
|
||||
message("Done Saving.");
|
||||
} else {
|
||||
message(EMPTY);
|
||||
}
|
||||
// rebuild sketch menu in case a save-as was forced
|
||||
sketchbook.rebuildMenus();
|
||||
|
||||
// zero out the current action,
|
||||
// so that checkModified2 will just do nothing
|
||||
checkModifiedMode = 0;
|
||||
// this is used when another operation calls a save
|
||||
}
|
||||
buttons.clear();
|
||||
} catch (Exception e) {
|
||||
// show the error as a message in the window
|
||||
error(e);
|
||||
|
||||
// zero out the current action,
|
||||
// so that checkModified2 will just do nothing
|
||||
checkModifiedMode = 0;
|
||||
// this is used when another operation calls a save
|
||||
}
|
||||
buttons.clear();
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
public void handleSaveAs() {
|
||||
doStop();
|
||||
buttons.activate(EditorButtons.SAVE);
|
||||
|
||||
message("Saving...");
|
||||
try {
|
||||
if (sketch.saveAs()) {
|
||||
message("Done Saving.");
|
||||
sketchbook.rebuildMenus();
|
||||
} else {
|
||||
message("Save Cancelled.");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// show the error as a message in the window
|
||||
error(e);
|
||||
}
|
||||
buttons.clear();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
message("Saving...");
|
||||
try {
|
||||
if (sketch.saveAs()) {
|
||||
message("Done Saving.");
|
||||
sketchbook.rebuildMenus();
|
||||
} else {
|
||||
message("Save Cancelled.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// show the error as a message in the window
|
||||
error(e);
|
||||
}
|
||||
buttons.clear();
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles calling the export() function on sketch, and
|
||||
* queues all the gui status stuff that comes along with it.
|
||||
*
|
||||
* <p/>
|
||||
* Made synchronized to (hopefully) avoid problems of people
|
||||
* hitting export twice, quickly, and horking things up.
|
||||
*/
|
||||
synchronized public void handleExport() {
|
||||
if (!handleExportCheckModified()) return;
|
||||
buttons.activate(EditorButtons.EXPORT);
|
||||
|
||||
try {
|
||||
boolean success = sketch.exportApplet();
|
||||
if (success) {
|
||||
File appletFolder = new File(sketch.folder, "applet");
|
||||
Base.openFolder(appletFolder);
|
||||
message("Done exporting.");
|
||||
} else {
|
||||
// error message will already be visible
|
||||
}
|
||||
} catch (Exception e) {
|
||||
error(e);
|
||||
}
|
||||
buttons.clear();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
boolean success = sketch.exportApplet();
|
||||
if (success) {
|
||||
File appletFolder = new File(sketch.folder, "applet");
|
||||
Base.openFolder(appletFolder);
|
||||
message("Done exporting.");
|
||||
} else {
|
||||
// error message will already be visible
|
||||
}
|
||||
} catch (Exception e) {
|
||||
error(e);
|
||||
}
|
||||
buttons.clear();
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
synchronized public void handleExportApplication() {
|
||||
if (!handleExportCheckModified()) return;
|
||||
buttons.activate(EditorButtons.EXPORT);
|
||||
|
||||
message("Exporting application...");
|
||||
try {
|
||||
if (sketch.exportApplication(PConstants.WINDOWS) &&
|
||||
sketch.exportApplication(PConstants.MACOSX) &&
|
||||
sketch.exportApplication(PConstants.LINUX)) {
|
||||
Base.openFolder(sketch.folder);
|
||||
message("Done exporting.");
|
||||
} else {
|
||||
// error message will already be visible
|
||||
}
|
||||
} catch (Exception e) {
|
||||
message("Error during export.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
buttons.clear();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
message("Exporting application...");
|
||||
try {
|
||||
if (sketch.exportApplication(PConstants.WINDOWS) &&
|
||||
sketch.exportApplication(PConstants.MACOSX) &&
|
||||
sketch.exportApplication(PConstants.LINUX)) {
|
||||
Base.openFolder(sketch.folder);
|
||||
message("Done exporting.");
|
||||
} else {
|
||||
// error message will already be visible
|
||||
}
|
||||
} catch (Exception e) {
|
||||
message("Error during export.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
buttons.clear();
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks to see if the sketch has been modified, and if so,
|
||||
* asks the user to save the sketch or cancel the export.
|
||||
* This prevents issues where an incomplete version of the sketch
|
||||
* would be exported, and is a fix for
|
||||
* <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=157">Bug 157</A>
|
||||
*/
|
||||
public boolean handleExportCheckModified() {
|
||||
if (!sketch.modified) return true;
|
||||
|
||||
@@ -1772,7 +1814,8 @@ public class Editor extends JFrame
|
||||
}
|
||||
error(mess);
|
||||
|
||||
buttons.clearRun();
|
||||
//buttons.clearRun();
|
||||
buttons.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class EditorButtons extends JComponent implements MouseInputListener {
|
||||
static final int ACTIVE = 2;
|
||||
|
||||
Editor editor;
|
||||
boolean disableRun;
|
||||
//boolean disableRun; // this was for library
|
||||
//Label status;
|
||||
|
||||
Image offscreen;
|
||||
@@ -73,7 +73,7 @@ public class EditorButtons extends JComponent implements MouseInputListener {
|
||||
Image rollover[];
|
||||
Image active[];
|
||||
int currentRollover;
|
||||
int currentSelection;
|
||||
//int currentSelection;
|
||||
|
||||
JPopupMenu popup;
|
||||
|
||||
@@ -231,10 +231,10 @@ public class EditorButtons extends JComponent implements MouseInputListener {
|
||||
if (sel == -1) return;
|
||||
|
||||
if (state[sel] != ACTIVE) {
|
||||
if (!(disableRun && ((sel == RUN) || (sel == STOP)))) {
|
||||
setState(sel, ROLLOVER, true);
|
||||
currentRollover = sel;
|
||||
}
|
||||
//if (!(disableRun && ((sel == RUN) || (sel == STOP)))) {
|
||||
setState(sel, ROLLOVER, true);
|
||||
currentRollover = sel;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,6 +281,10 @@ public class EditorButtons extends JComponent implements MouseInputListener {
|
||||
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// if the popup menu for is visible, don't register this,
|
||||
// because the popup being set visible will fire a mouseExited() event
|
||||
if ((popup != null) && popup.isVisible()) return;
|
||||
|
||||
if (state[OPEN] != INACTIVE) {
|
||||
setState(OPEN, INACTIVE, true);
|
||||
}
|
||||
@@ -292,26 +296,77 @@ public class EditorButtons extends JComponent implements MouseInputListener {
|
||||
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
int x = e.getX();
|
||||
int y = e.getY();
|
||||
final int x = e.getX();
|
||||
final int y = e.getY();
|
||||
|
||||
int sel = findSelection(x, y);
|
||||
///if (sel == -1) return false;
|
||||
if (sel == -1) return;
|
||||
currentRollover = -1;
|
||||
currentSelection = sel;
|
||||
if (!(disableRun && ((sel == RUN) || (sel == STOP)))) {
|
||||
setState(sel, ACTIVE, true);
|
||||
}
|
||||
//int currentSelection = sel;
|
||||
//if (!(disableRun && ((sel == RUN) || (sel == STOP)))) {
|
||||
// moving the handling of this over into the editor
|
||||
//setState(sel, ACTIVE, true);
|
||||
//}
|
||||
|
||||
if (currentSelection == OPEN) {
|
||||
//if (currentSelection == OPEN) {
|
||||
//switch (currentSelection) {
|
||||
switch (sel) {
|
||||
case RUN:
|
||||
//if (!disableRun) {
|
||||
editor.handleRun(e.isShiftDown());
|
||||
//}
|
||||
break;
|
||||
|
||||
case STOP:
|
||||
//if (!disableRun) {
|
||||
//setState(RUN, INACTIVE, true);
|
||||
//setInactive();
|
||||
editor.handleStop();
|
||||
//}
|
||||
break;
|
||||
|
||||
case OPEN:
|
||||
if (popup == null) {
|
||||
//popup = new JPopupMenu();
|
||||
popup = editor.sketchbook.getPopupMenu();
|
||||
// no events properly being fired, so nevermind
|
||||
/*
|
||||
popup.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("action " + e);
|
||||
}
|
||||
});
|
||||
popup.addComponentListener(new ComponentAdapter() {
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
System.out.println("hidden " + e);
|
||||
}
|
||||
});
|
||||
*/
|
||||
add(popup);
|
||||
}
|
||||
//editor.sketchbook.rebuildPopup(popup);
|
||||
popup.show(this, x, y);
|
||||
//activate(OPEN);
|
||||
//SwingUtilities.invokeLater(new Runnable() {
|
||||
//public void run() {
|
||||
popup.show(EditorButtons.this, x, y);
|
||||
//}});
|
||||
break;
|
||||
|
||||
case NEW:
|
||||
editor.handleNew(e.isShiftDown());
|
||||
break;
|
||||
|
||||
case SAVE:
|
||||
editor.handleSave();
|
||||
break;
|
||||
|
||||
case EXPORT:
|
||||
if (e.isShiftDown()) {
|
||||
editor.handleExportApplication();
|
||||
} else {
|
||||
editor.handleExport();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,49 +375,53 @@ public class EditorButtons extends JComponent implements MouseInputListener {
|
||||
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
/*
|
||||
switch (currentSelection) {
|
||||
case RUN:
|
||||
if (!disableRun) {
|
||||
editor.handleRun(e.isShiftDown());
|
||||
}
|
||||
break;
|
||||
|
||||
case STOP:
|
||||
if (!disableRun) {
|
||||
setState(RUN, INACTIVE, true);
|
||||
editor.handleStop();
|
||||
}
|
||||
break;
|
||||
|
||||
case OPEN:
|
||||
setState(OPEN, INACTIVE, true);
|
||||
break;
|
||||
|
||||
case NEW:
|
||||
editor.handleNew(e.isShiftDown());
|
||||
break;
|
||||
|
||||
case SAVE:
|
||||
editor.handleSave();
|
||||
break;
|
||||
|
||||
case EXPORT:
|
||||
if (e.isShiftDown()) {
|
||||
editor.handleExportApplication();
|
||||
} else {
|
||||
editor.handleExport();
|
||||
}
|
||||
break;
|
||||
}
|
||||
currentSelection = -1;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
public void disableRun(boolean what) {
|
||||
disableRun = what;
|
||||
//public void disableRun(boolean what) {
|
||||
//disableRun = what;
|
||||
//}
|
||||
|
||||
|
||||
/*
|
||||
public void run() {
|
||||
if (inactive == null) return;
|
||||
clear();
|
||||
setState(RUN, ACTIVE, true);
|
||||
}
|
||||
*/
|
||||
|
||||
public void running(boolean yesno) {
|
||||
setState(RUN, yesno ? ACTIVE : INACTIVE, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a particular button to be active.
|
||||
*/
|
||||
public void activate(int what) {
|
||||
if (inactive == null) return;
|
||||
setState(what, ACTIVE, true);
|
||||
}
|
||||
|
||||
//public void clearRun() {
|
||||
//if (inactive == null) return;
|
||||
//setState(RUN, INACTIVE, true);
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
* Clear all the state of all buttons.
|
||||
*/
|
||||
public void clear() { // (int button) {
|
||||
if (inactive == null) return;
|
||||
|
||||
@@ -374,24 +433,6 @@ public class EditorButtons extends JComponent implements MouseInputListener {
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
if (inactive == null) return;
|
||||
clear();
|
||||
setState(RUN, ACTIVE, true);
|
||||
}
|
||||
|
||||
|
||||
public void running(boolean yesno) {
|
||||
setState(RUN, yesno ? ACTIVE : INACTIVE, true);
|
||||
}
|
||||
|
||||
|
||||
public void clearRun() {
|
||||
if (inactive == null) return;
|
||||
setState(RUN, INACTIVE, true);
|
||||
}
|
||||
|
||||
|
||||
public void message(String msg) {
|
||||
//status.setText(msg + " "); // don't mind the hack
|
||||
status = msg;
|
||||
|
||||
8
todo.txt
8
todo.txt
@@ -18,11 +18,9 @@ X hack to fix non-terminated multi-line comments
|
||||
X http://dev.processing.org/bugs/show_bug.cgi?id=16
|
||||
X improved error message for bad sketch names to include the sketch path
|
||||
X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1134466565
|
||||
|
||||
casey priorities
|
||||
_ make editor save button highlight on ctrl-s
|
||||
_ same goes for the other editor buttons
|
||||
_ http://dev.processing.org/bugs/show_bug.cgi?id=242
|
||||
X make editor save button highlight on ctrl-s
|
||||
X same goes for the other editor buttons
|
||||
X http://dev.processing.org/bugs/show_bug.cgi?id=242
|
||||
|
||||
_ deal with "could not delete stderr.txt" messages
|
||||
_ probably screwed up the temp folder stuff
|
||||
|
||||
Reference in New Issue
Block a user