Skip to content

Commit 8458367

Browse files
committed
Added the ability to make a shell close on escape, but it defaults to false.
1 parent 28ab4c1 commit 8458367

File tree

1 file changed

+16
-5
lines changed
  • durian-swt/src/main/java/com/diffplug/common/swt

1 file changed

+16
-5
lines changed

durian-swt/src/main/java/com/diffplug/common/swt/Shells.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class Shells {
5454
private boolean positionIncludesTrim = true;
5555
private Map.Entry<Corner, Point> location = null;
5656
private boolean dontOpen = false;
57+
private boolean closeOnEscape = false;
5758

5859
private Shells(int style, Coat coat) {
5960
this.style = style;
@@ -184,6 +185,14 @@ public Shells setDontOpen(boolean dontOpen) {
184185
return this;
185186
}
186187

188+
/**
189+
* Determines whether the shell will close on escape, defaults to false.
190+
*/
191+
public Shells setCloseOnEscape(boolean closeOnEscape) {
192+
this.closeOnEscape = closeOnEscape;
193+
return this;
194+
}
195+
187196
/** Opens the shell on this parent shell. */
188197
public Shell openOn(Shell parent) {
189198
Preconditions.checkNotNull(parent);
@@ -352,11 +361,13 @@ private void setupShell(Shell shell) {
352361
shell.setAlpha(alpha);
353362
}
354363
// disable close on ESCAPE
355-
shell.addListener(SWT.Traverse, e -> {
356-
if (e.detail == SWT.TRAVERSE_ESCAPE) {
357-
e.doit = false;
358-
}
359-
});
364+
if (!closeOnEscape) {
365+
shell.addListener(SWT.Traverse, e -> {
366+
if (e.detail == SWT.TRAVERSE_ESCAPE) {
367+
e.doit = false;
368+
}
369+
});
370+
}
360371
// find the composite we're going to draw on
361372
coat.putOn(shell);
362373

0 commit comments

Comments
 (0)