|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2024 Andrey Loskutov ([email protected]) and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * Andrey Loskutov ([email protected]) - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.swt.tests.gtk.snippets; |
| 15 | + |
| 16 | +/* |
| 17 | + * A handy snippet to test hanging File/Directory dialogs |
| 18 | + */ |
| 19 | +import org.eclipse.swt.SWT; |
| 20 | +import org.eclipse.swt.events.SelectionAdapter; |
| 21 | +import org.eclipse.swt.events.SelectionEvent; |
| 22 | +import org.eclipse.swt.layout.FillLayout; |
| 23 | +import org.eclipse.swt.widgets.Button; |
| 24 | +import org.eclipse.swt.widgets.DirectoryDialog; |
| 25 | +import org.eclipse.swt.widgets.Display; |
| 26 | +import org.eclipse.swt.widgets.FileDialog; |
| 27 | +import org.eclipse.swt.widgets.Label; |
| 28 | +import org.eclipse.swt.widgets.Shell; |
| 29 | + |
| 30 | +public class Issue1062_FileChooserNativeDialog { |
| 31 | + |
| 32 | + public static void main(String[] args) { |
| 33 | + Display display = new Display(); |
| 34 | + Shell shell = new Shell(display); |
| 35 | + shell.setText("Issue1062_FileChooserNativeDialog"); |
| 36 | + shell.setLayout(new FillLayout(SWT.VERTICAL)); |
| 37 | + Label label = new Label(shell, SWT.WRAP); |
| 38 | + label.setText("Click to open dialog, then right click on some file to open a menu and after that close dialog." |
| 39 | + + " The shell should not 'hang' after closing dialogs."); |
| 40 | + |
| 41 | + Button button = new Button(shell, 0); |
| 42 | + button.setText("Open File Dialog"); |
| 43 | + button.addSelectionListener(new SelectionAdapter() { |
| 44 | + @Override |
| 45 | + public void widgetSelected(SelectionEvent e) { |
| 46 | + FileDialog dialog = new FileDialog(shell, SWT.OPEN); |
| 47 | + dialog.setText("Right click to open a menu and after that try to close dialog"); |
| 48 | + String string = dialog.open(); |
| 49 | + System.out.println("Selected: " + string); |
| 50 | + } |
| 51 | + }); |
| 52 | + |
| 53 | + button = new Button(shell, 0); |
| 54 | + button.setText("Open Directory Dialog"); |
| 55 | + button.addSelectionListener(new SelectionAdapter() { |
| 56 | + @Override |
| 57 | + public void widgetSelected(SelectionEvent e) { |
| 58 | + DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN); |
| 59 | + dialog.setText("Right click to open a menu and after that try to close dialog"); |
| 60 | + String string = dialog.open(); |
| 61 | + System.out.println("Selected: " + string); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + shell.setSize(400, 200); |
| 66 | + shell.open(); |
| 67 | + while (!shell.isDisposed()) { |
| 68 | + if (!display.readAndDispatch()) |
| 69 | + display.sleep(); |
| 70 | + } |
| 71 | + display.dispose(); |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments