Skip to content

Commit

Permalink
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 Oct 24, 2024
1 parent 7901bee commit ff753de
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 ff753de

Please sign in to comment.