Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ public void handleOpenPrompt() {
// use the front-most window frame for placing file dialog
FileDialog openDialog =
new FileDialog(activeEditor, prompt, FileDialog.LOAD);
openDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);

// Only show .pde files as eligible bachelors
openDialog.setFilenameFilter((dir, name) -> {
Expand Down
38 changes: 18 additions & 20 deletions app/src/processing/app/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ import javax.swing.UIManager

class Messages {
companion object {

/**
* Shows a modal dialog that only blocks its parent window,
* not all windows in the application.
*/
private fun showModalDialog(message: Any, title: String, messageType: Int) {
val activeWindow = java.awt.KeyboardFocusManager
.getCurrentKeyboardFocusManager().activeWindow
val pane = JOptionPane(message, messageType)
val dialog = pane.createDialog(activeWindow, title)
dialog.modalityType = java.awt.Dialog.ModalityType.DOCUMENT_MODAL
dialog.isVisible = true
}
/**
* "No cookie for you" type messages. Nothing fatal or all that
* much of a bummer, but something to notify the user about.
Expand All @@ -57,10 +70,7 @@ class Messages {
if (Base.isCommandLine()) {
println("$title: $message")
} else {
JOptionPane.showMessageDialog(
Frame(), message, title,
JOptionPane.INFORMATION_MESSAGE
)
showModalDialog(message, title, JOptionPane.INFORMATION_MESSAGE)
}
}

Expand All @@ -77,10 +87,7 @@ class Messages {
if (Base.isCommandLine()) {
println("$title: $message")
} else {
JOptionPane.showMessageDialog(
Frame(), message, title,
JOptionPane.WARNING_MESSAGE
)
showModalDialog(message, title, JOptionPane.WARNING_MESSAGE)
}
e?.printStackTrace()
}
Expand All @@ -101,11 +108,7 @@ class Messages {
println("$title: $primary\n$secondary")
} else {
EventQueue.invokeLater {
JOptionPane.showMessageDialog(
JFrame(),
Toolkit.formatMessage(primary, secondary),
title, JOptionPane.WARNING_MESSAGE
)
showModalDialog(Toolkit.formatMessage(primary, secondary), title, JOptionPane.WARNING_MESSAGE)
}
}
e?.printStackTrace()
Expand All @@ -122,10 +125,7 @@ class Messages {
if (Base.isCommandLine()) {
System.err.println("$title: $message")
} else {
JOptionPane.showMessageDialog(
Frame(), message, title,
JOptionPane.ERROR_MESSAGE
)
showModalDialog(message, title, JOptionPane.ERROR_MESSAGE)
}
e?.printStackTrace()
System.exit(1)
Expand All @@ -151,9 +151,7 @@ class Messages {
val sw = StringWriter()
t!!.printStackTrace(PrintWriter(sw))

JOptionPane.showMessageDialog(
Frame(), // first <br/> clears to the next line
// second <br/> is a shorter height blank space before the trace
showModalDialog(
Toolkit.formatMessage("$message<br/><tt><br/>$sw</tt>"),
title,
if (fatal) JOptionPane.ERROR_MESSAGE else JOptionPane.WARNING_MESSAGE
Expand Down
3 changes: 3 additions & 0 deletions app/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.FileDialog;
import java.awt.Dialog;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
Expand Down Expand Up @@ -866,6 +867,7 @@ public boolean saveAs() throws IOException {
if (useNative) {
// get new name for folder
FileDialog fd = new FileDialog(editor, PROMPT, FileDialog.SAVE);
fd.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
if (isReadOnly() || isUntitled()) {
// default to the sketchbook folder
fd.setDirectory(Preferences.getSketchbookPath());
Expand Down Expand Up @@ -1387,6 +1389,7 @@ public void handleAddFile() {
String prompt = Language.text("file");
//FileDialog fd = new FileDialog(new Frame(), prompt, FileDialog.LOAD);
FileDialog fd = new FileDialog(editor, prompt, FileDialog.LOAD);
fd.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
fd.setVisible(true);

String directory = fd.getDirectory();
Expand Down
2 changes: 2 additions & 0 deletions core/src/processing/awt/ShimAWT.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ static public void selectImpl(final String prompt,

if (PApplet.useNativeSelect) {
FileDialog dialog = new FileDialog(parentFrame, prompt, mode);
dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
if (defaultSelection != null) {
dialog.setDirectory(defaultSelection.getParent());
dialog.setFile(defaultSelection.getName());
Expand Down Expand Up @@ -910,6 +911,7 @@ static public void selectFolderImpl(final String prompt,
if (PApplet.platform == PConstants.MACOS && PApplet.useNativeSelect) {
FileDialog fileDialog =
new FileDialog(parentFrame, prompt, FileDialog.LOAD);
fileDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
if (defaultSelection != null) {
fileDialog.setDirectory(defaultSelection.getAbsolutePath());
}
Expand Down