Skip to content

[file_selector] Fix Linux cancel regression #8051

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/file_selector/file_selector_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.3+1

* Fixes a regression in 0.9.3 with handling of canceled dialogs.

## 0.9.3

* Updates method channel implementation to use Pigeon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,15 @@ static FfsFileSelectorApiShowFileChooserResponse* handle_show_file_chooser(
return ffs_file_selector_api_show_file_chooser_response_new_error(
kBadArgumentsError, "Unable to create dialog from arguments", nullptr);
}
return show_file_chooser(GTK_FILE_CHOOSER_NATIVE(dialog),
gtk_native_dialog_run);
}

gint response = gtk_native_dialog_run(GTK_NATIVE_DIALOG(dialog));
g_autoptr(FlValue) result = nullptr;
FfsFileSelectorApiShowFileChooserResponse* show_file_chooser(
GtkFileChooserNative* dialog, gint (*run_dialog)(GtkNativeDialog*)) {
gint response = run_dialog(GTK_NATIVE_DIALOG(dialog));
g_autoptr(FlValue) result = fl_value_new_list();
if (response == GTK_RESPONSE_ACCEPT) {
result = fl_value_new_list();
g_autoptr(GSList) filenames =
gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
for (GSList* link = filenames; link != nullptr; link = link->next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include <flutter_linux/flutter_linux.h>
#include <gtk/gtk.h>

#include "include/file_selector_linux/file_selector_plugin.h"
#include "messages.g.h"
Expand All @@ -17,3 +18,9 @@
GtkFileChooserNative* create_dialog_of_type(
GtkWindow* window, FfsPlatformFileChooserActionType type,
FfsPlatformFileChooserOptions* options);

// TODO(stuartmorgan): Fold this into handle_show_file_chooser as part of the
// above TODO. This only exists to allow testing response generation without
// mocking out all of the GTK calls.
FfsFileSelectorApiShowFileChooserResponse* show_file_chooser(
GtkFileChooserNative* dialog, gint (*run_dialog)(GtkNativeDialog*));
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,25 @@ TEST(FileSelectorPlugin, TestGetMultipleDirectories) {
EXPECT_EQ(gtk_file_chooser_get_select_multiple(GTK_FILE_CHOOSER(dialog)),
true);
}

static gint mock_run_dialog_cancel(GtkNativeDialog* dialog) {
return GTK_RESPONSE_CANCEL;
}

TEST(FileSelectorPlugin, TestGetDirectoryCancel) {
g_autoptr(FfsPlatformFileChooserOptions) options =
ffs_platform_file_chooser_options_new(nullptr, nullptr, nullptr, nullptr,
nullptr);

g_autoptr(GtkFileChooserNative) dialog = create_dialog_of_type(
nullptr,
FILE_SELECTOR_LINUX_PLATFORM_FILE_CHOOSER_ACTION_TYPE_CHOOSE_DIRECTORY,
options);

ASSERT_NE(dialog, nullptr);

g_autoptr(FfsFileSelectorApiShowFileChooserResponse) response =
show_file_chooser(dialog, mock_run_dialog_cancel);

EXPECT_NE(response, nullptr);
}
2 changes: 1 addition & 1 deletion packages/file_selector/file_selector_linux/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: file_selector_linux
description: Liunx implementation of the file_selector plugin.
repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_linux
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
version: 0.9.3
version: 0.9.3+1

environment:
sdk: ^3.3.0
Expand Down