Skip to content

Commit d2bb303

Browse files
committed
FileDialog & DirectoryDialog hang after closing them with opened menu
`gtk_file_chooser_native_new handle()` should be dereferenced after use as proposed in https://docs.gtk.org/gtk3/class.FileChooserNative.html. Otherwise `gtk_native_dialog_run()` seem to continue to run (probably because the opened menu still references the dialog), with the effect that: `the recursive main loop gives the effect of a modal dialog (it prevents the user from interacting with other windows in the same window group while the dialog is run)`. See https://docs.gtk.org/gtk3/method.NativeDialog.run.html Fixes #1062
1 parent bd900fb commit d2bb303

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ Optional<String> openNativeChooserDialog () {
254254
result = Optional.ofNullable(selectedPath);
255255
}
256256
display.removeIdleProc ();
257+
OS.g_object_unref(handle);
257258
if (result.isPresent() || response == GTK.GTK_RESPONSE_CANCEL) {
258259
return result;
259260
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ Optional<String> openNativeChooserDialog () {
412412
result = Optional.ofNullable(computeResultChooserDialog ());
413413
}
414414
display.removeIdleProc ();
415+
OS.g_object_unref(handle);
415416
if (result.isPresent() || response == GTK.GTK_RESPONSE_CANCEL) {
416417
return result;
417418
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)