-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GTK4] Migrate DirectoryDialog from GtkFileChooser to GtkFileDialog #1421
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat Inc. and others. | ||
* Copyright (c) 2020, 2024 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -14,7 +14,9 @@ | |
package org.eclipse.swt.internal; | ||
|
||
import java.lang.reflect.*; | ||
import java.util.function.*; | ||
|
||
import org.eclipse.swt.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this unused import. |
||
import org.eclipse.swt.internal.gtk.*; | ||
import org.eclipse.swt.widgets.*; | ||
|
||
|
@@ -28,6 +30,41 @@ | |
public class SyncDialogUtil { | ||
static int responseID; | ||
static Callback dialogResponseCallback; | ||
static Function<Long, Long> dialogAsyncFinish; | ||
static Long dialogAsyncValue; | ||
|
||
/** | ||
* This method implements the {@code AsyncReadyCallback} mechanism that is | ||
* used in GTK4. Most operations within GTK4 are executed asynchronously, | ||
* where the user is given the option to respond to the completion of such | ||
* an operation via a callback method, in order to e.g. process the result | ||
* or to apply additional cleanup tasks.<br> | ||
* When calling this method, the asynchronous operation is initiated via the | ||
* {code asyncOpen} parameter. Callers have to ensure that the callback | ||
* address is used as argument for the {@code AsyncReadyCallback} parameter. | ||
* From within the callback routine, the {@code asyncFinish} function is | ||
* called, receiving the {@code AsyncResult} of the callback as argument and | ||
* returning the {@code long} value of the callback function.<br> | ||
* This method blocks until the callback method has been called. It is | ||
* therefore essential that callers use the address of the {@link Callback} | ||
* as address for the {@code AsyncReadyCallback} object. | ||
*/ | ||
static public long run(Display display, Consumer<Long> asyncOpen, Function<Long, Long> asyncFinish) { | ||
initializeResponseCallback(); | ||
|
||
dialogAsyncFinish = asyncFinish; | ||
asyncOpen.accept(dialogResponseCallback.getAddress()); | ||
|
||
while (!display.isDisposed()) { | ||
if (dialogAsyncValue != null) { | ||
break; | ||
} | ||
display.readAndDispatch(); | ||
} | ||
|
||
disposeResponseCallback(); | ||
return dialogAsyncValue; | ||
} | ||
|
||
/** | ||
* A blocking call that waits for the handling of the signal before returning | ||
|
@@ -53,21 +90,23 @@ static public int run(Display display, long handle, boolean isNativeDialog) { | |
} | ||
|
||
disposeResponseCallback(); | ||
return responseID; | ||
return (int) responseID; | ||
} | ||
|
||
/** | ||
* Initializes the response callback and resets the responseID of the dialog to the default value. | ||
* This function should be called before connect the dialog to the "response" signal, as this sets up the callback. | ||
*/ | ||
static void initializeResponseCallback() { | ||
dialogResponseCallback = new Callback(SyncDialogUtil.class, "dialogResponseProc", void.class, new Type[] {long.class, int.class, long.class}); | ||
dialogResponseCallback = new Callback(SyncDialogUtil.class, "dialogResponseProc", void.class, new Type[] {long.class, long.class, long.class}); | ||
dialogAsyncValue = null; | ||
responseID = -1; | ||
} | ||
|
||
static void disposeResponseCallback() { | ||
dialogResponseCallback.dispose(); | ||
dialogResponseCallback = null; | ||
dialogAsyncFinish = null; | ||
} | ||
|
||
/** | ||
|
@@ -77,7 +116,10 @@ static void disposeResponseCallback() { | |
* | ||
* Note: Native dialogs are platform dialogs that don't use GtkDialog or GtkWindow. | ||
*/ | ||
static void dialogResponseProc(long dialog, int response_id, long user_data) { | ||
responseID = response_id; | ||
static void dialogResponseProc(long dialog, long response_id, long user_data) { | ||
if (dialogAsyncFinish != null) { | ||
dialogAsyncValue = dialogAsyncFinish.apply(response_id); | ||
} | ||
responseID = (int) response_id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be '(GError **)'. What you have here fails with