diff --git a/packages/file_selector/file_selector_linux/CHANGELOG.md b/packages/file_selector/file_selector_linux/CHANGELOG.md index 74a5f6edc7d2..da19a0a8abd3 100644 --- a/packages/file_selector/file_selector_linux/CHANGELOG.md +++ b/packages/file_selector/file_selector_linux/CHANGELOG.md @@ -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. diff --git a/packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc b/packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc index db27d38c80c2..e8095d589eaa 100644 --- a/packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc +++ b/packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc @@ -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) { diff --git a/packages/file_selector/file_selector_linux/linux/file_selector_plugin_private.h b/packages/file_selector/file_selector_linux/linux/file_selector_plugin_private.h index d8ee91bdd8a7..3a8a9b109c7a 100644 --- a/packages/file_selector/file_selector_linux/linux/file_selector_plugin_private.h +++ b/packages/file_selector/file_selector_linux/linux/file_selector_plugin_private.h @@ -3,6 +3,7 @@ // found in the LICENSE file. #include +#include #include "include/file_selector_linux/file_selector_plugin.h" #include "messages.g.h" @@ -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*)); diff --git a/packages/file_selector/file_selector_linux/linux/test/file_selector_plugin_test.cc b/packages/file_selector/file_selector_linux/linux/test/file_selector_plugin_test.cc index bbd285a7ca12..3a3c8459e460 100644 --- a/packages/file_selector/file_selector_linux/linux/test/file_selector_plugin_test.cc +++ b/packages/file_selector/file_selector_linux/linux/test/file_selector_plugin_test.cc @@ -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); +} diff --git a/packages/file_selector/file_selector_linux/pubspec.yaml b/packages/file_selector/file_selector_linux/pubspec.yaml index 8a9d48b9ad0f..b7d91169ef69 100644 --- a/packages/file_selector/file_selector_linux/pubspec.yaml +++ b/packages/file_selector/file_selector_linux/pubspec.yaml @@ -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