Skip to content

Commit

Permalink
Fixes : #1205
Browse files Browse the repository at this point in the history
Snippet99 requires modification as Command+Q is not implemented.
Currently, the snippet demonstrates a message box pop-up when attempting
to close the dialog window, but pressing Command+Q closes the window
without triggering this behavior. The snippet has been updated to
implement Command+Q functionality and to add an SWT dispose listener to
the display object.
  • Loading branch information
elsazac committed Sep 23, 2024
1 parent 02e20d6 commit 92dc6ff
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@ public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell (display);
shell.setText("Snippet 99");
shell.addListener (SWT.Close, event -> {
MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setText("Information");
messageBox.setMessage("Close the shell?");
messageBox.setButtonLabels(Map.of(SWT.YES, "Close"));
event.doit = messageBox.open () == SWT.YES;
});
// Listener for when the shell close button is clicked
shell.addListener (SWT.Close, event -> {
if (!shell.isDisposed()) {
MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setText("Information");
messageBox.setMessage("Close the shell?");
messageBox.setButtonLabels(Map.of(SWT.YES, "Close"));
event.doit = messageBox.open () == SWT.YES;
}
});
// Dispose listener to implement Cmd+Q (on macOS)
display.addListener(SWT.Dispose, event -> {
if (!shell.isDisposed()) {
MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setText("Information");
messageBox.setMessage("Close the application?");
messageBox.setButtonLabels(Map.of(SWT.YES, "Close"));
event.doit = messageBox.open() == SWT.YES;
}
});
shell.pack ();
shell.open();
while (!shell.isDisposed ()) {
Expand Down

0 comments on commit 92dc6ff

Please sign in to comment.