Skip to content

Commit e67b6be

Browse files
authored
[file_selector] Implement canCreateDirectories on macos and linux (#10443)
Updates macos and linux `file_selector` platforms to implement the new `canCreateDirectories` parameter from platform interface Until now, only macos and linux are able to override this parameter This is the "platform implementations" step for #9965 Part of: flutter/flutter#141339 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 22c6056 commit e67b6be

File tree

24 files changed

+542
-31
lines changed

24 files changed

+542
-31
lines changed

packages/file_selector/file_selector_linux/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.4
2+
3+
* Adds `getDirectoryPathWithOptions` and `getDirectoryPathsWithOptions` implementations.
4+
15
## 0.9.3+3
26

37
* Updates to Pigeon 26.

packages/file_selector/file_selector_linux/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ environment:
1010
dependencies:
1111
file_selector_linux:
1212
path: ../
13-
file_selector_platform_interface: ^2.6.0
13+
file_selector_platform_interface: ^2.7.0
1414
flutter:
1515
sdk: flutter
1616

packages/file_selector/file_selector_linux/lib/file_selector_linux.dart

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class FileSelectorLinux extends FileSelectorPlatform {
9494
currentFolderPath: options.initialDirectory,
9595
currentName: options.suggestedName,
9696
acceptButtonLabel: options.confirmButtonText,
97+
createFolders: options.canCreateDirectories,
9798
),
9899
);
99100
return paths.isEmpty ? null : FileSaveLocation(paths.first);
@@ -104,11 +105,22 @@ class FileSelectorLinux extends FileSelectorPlatform {
104105
String? initialDirectory,
105106
String? confirmButtonText,
106107
}) async {
108+
return getDirectoryPathWithOptions(
109+
FileDialogOptions(
110+
initialDirectory: initialDirectory,
111+
confirmButtonText: confirmButtonText,
112+
),
113+
);
114+
}
115+
116+
@override
117+
Future<String?> getDirectoryPathWithOptions(FileDialogOptions options) async {
107118
final List<String> paths = await _hostApi.showFileChooser(
108119
PlatformFileChooserActionType.chooseDirectory,
109120
PlatformFileChooserOptions(
110-
currentFolderPath: initialDirectory,
111-
acceptButtonLabel: confirmButtonText,
121+
currentFolderPath: options.initialDirectory,
122+
acceptButtonLabel: options.confirmButtonText,
123+
createFolders: options.canCreateDirectories,
112124
selectMultiple: false,
113125
),
114126
);
@@ -120,11 +132,24 @@ class FileSelectorLinux extends FileSelectorPlatform {
120132
String? initialDirectory,
121133
String? confirmButtonText,
122134
}) async {
135+
return getDirectoryPathsWithOptions(
136+
FileDialogOptions(
137+
initialDirectory: initialDirectory,
138+
confirmButtonText: confirmButtonText,
139+
),
140+
);
141+
}
142+
143+
@override
144+
Future<List<String>> getDirectoryPathsWithOptions(
145+
FileDialogOptions options,
146+
) async {
123147
return _hostApi.showFileChooser(
124148
PlatformFileChooserActionType.chooseDirectory,
125149
PlatformFileChooserOptions(
126-
currentFolderPath: initialDirectory,
127-
acceptButtonLabel: confirmButtonText,
150+
currentFolderPath: options.initialDirectory,
151+
acceptButtonLabel: options.confirmButtonText,
152+
createFolders: options.canCreateDirectories,
128153
selectMultiple: true,
129154
),
130155
);

packages/file_selector/file_selector_linux/lib/src/messages.g.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v26.1.0), do not edit directly.
4+
// Autogenerated from Pigeon (v26.1.1), do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers
77

@@ -97,6 +97,7 @@ class PlatformFileChooserOptions {
9797
this.currentName,
9898
this.acceptButtonLabel,
9999
this.selectMultiple,
100+
this.createFolders,
100101
});
101102

102103
List<PlatformTypeGroup>? allowedFileTypes;
@@ -112,13 +113,19 @@ class PlatformFileChooserOptions {
112113
/// Nullable because it does not apply to the "save" action.
113114
bool? selectMultiple;
114115

116+
/// Whether to allow new folder creation.
117+
///
118+
/// Nullable because it does not apply to the "open" action.
119+
bool? createFolders;
120+
115121
List<Object?> _toList() {
116122
return <Object?>[
117123
allowedFileTypes,
118124
currentFolderPath,
119125
currentName,
120126
acceptButtonLabel,
121127
selectMultiple,
128+
createFolders,
122129
];
123130
}
124131

@@ -135,6 +142,7 @@ class PlatformFileChooserOptions {
135142
currentName: result[2] as String?,
136143
acceptButtonLabel: result[3] as String?,
137144
selectMultiple: result[4] as bool?,
145+
createFolders: result[5] as bool?,
138146
);
139147
}
140148

packages/file_selector/file_selector_linux/linux/file_selector_plugin.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ static GtkFileChooserNative* create_dialog(
9494
}
9595
}
9696

97+
const gboolean* create_folders =
98+
ffs_platform_file_chooser_options_get_create_folders(options);
99+
if (create_folders != nullptr) {
100+
gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(dialog),
101+
*create_folders);
102+
}
103+
97104
return GTK_FILE_CHOOSER_NATIVE(g_object_ref(dialog));
98105
}
99106

packages/file_selector/file_selector_linux/linux/messages.g.cc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v26.1.0), do not edit directly.
4+
// Autogenerated from Pigeon (v26.1.1), do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
#include "messages.g.h"
@@ -84,6 +84,7 @@ struct _FfsPlatformFileChooserOptions {
8484
gchar* current_name;
8585
gchar* accept_button_label;
8686
gboolean* select_multiple;
87+
gboolean* create_folders;
8788
};
8889

8990
G_DEFINE_TYPE(FfsPlatformFileChooserOptions, ffs_platform_file_chooser_options,
@@ -97,6 +98,7 @@ static void ffs_platform_file_chooser_options_dispose(GObject* object) {
9798
g_clear_pointer(&self->current_name, g_free);
9899
g_clear_pointer(&self->accept_button_label, g_free);
99100
g_clear_pointer(&self->select_multiple, g_free);
101+
g_clear_pointer(&self->create_folders, g_free);
100102
G_OBJECT_CLASS(ffs_platform_file_chooser_options_parent_class)
101103
->dispose(object);
102104
}
@@ -112,7 +114,7 @@ static void ffs_platform_file_chooser_options_class_init(
112114
FfsPlatformFileChooserOptions* ffs_platform_file_chooser_options_new(
113115
FlValue* allowed_file_types, const gchar* current_folder_path,
114116
const gchar* current_name, const gchar* accept_button_label,
115-
gboolean* select_multiple) {
117+
gboolean* select_multiple, gboolean* create_folders) {
116118
FfsPlatformFileChooserOptions* self = FFS_PLATFORM_FILE_CHOOSER_OPTIONS(
117119
g_object_new(ffs_platform_file_chooser_options_get_type(), nullptr));
118120
if (allowed_file_types != nullptr) {
@@ -141,6 +143,12 @@ FfsPlatformFileChooserOptions* ffs_platform_file_chooser_options_new(
141143
} else {
142144
self->select_multiple = nullptr;
143145
}
146+
if (create_folders != nullptr) {
147+
self->create_folders = static_cast<gboolean*>(malloc(sizeof(gboolean)));
148+
*self->create_folders = *create_folders;
149+
} else {
150+
self->create_folders = nullptr;
151+
}
144152
return self;
145153
}
146154

@@ -174,6 +182,12 @@ gboolean* ffs_platform_file_chooser_options_get_select_multiple(
174182
return self->select_multiple;
175183
}
176184

185+
gboolean* ffs_platform_file_chooser_options_get_create_folders(
186+
FfsPlatformFileChooserOptions* self) {
187+
g_return_val_if_fail(FFS_IS_PLATFORM_FILE_CHOOSER_OPTIONS(self), nullptr);
188+
return self->create_folders;
189+
}
190+
177191
static FlValue* ffs_platform_file_chooser_options_to_list(
178192
FfsPlatformFileChooserOptions* self) {
179193
FlValue* values = fl_value_new_list();
@@ -194,6 +208,9 @@ static FlValue* ffs_platform_file_chooser_options_to_list(
194208
fl_value_append_take(values, self->select_multiple != nullptr
195209
? fl_value_new_bool(*self->select_multiple)
196210
: fl_value_new_null());
211+
fl_value_append_take(values, self->create_folders != nullptr
212+
? fl_value_new_bool(*self->create_folders)
213+
: fl_value_new_null());
197214
return values;
198215
}
199216

@@ -226,9 +243,16 @@ ffs_platform_file_chooser_options_new_from_list(FlValue* values) {
226243
select_multiple_value = fl_value_get_bool(value4);
227244
select_multiple = &select_multiple_value;
228245
}
246+
FlValue* value5 = fl_value_get_list_value(values, 5);
247+
gboolean* create_folders = nullptr;
248+
gboolean create_folders_value;
249+
if (fl_value_get_type(value5) != FL_VALUE_TYPE_NULL) {
250+
create_folders_value = fl_value_get_bool(value5);
251+
create_folders = &create_folders_value;
252+
}
229253
return ffs_platform_file_chooser_options_new(
230254
allowed_file_types, current_folder_path, current_name,
231-
accept_button_label, select_multiple);
255+
accept_button_label, select_multiple, create_folders);
232256
}
233257

234258
struct _FfsMessageCodec {

packages/file_selector/file_selector_linux/linux/messages.g.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v26.1.0), do not edit directly.
4+
// Autogenerated from Pigeon (v26.1.1), do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
#ifndef PIGEON_MESSAGES_G_H_
@@ -97,6 +97,7 @@ G_DECLARE_FINAL_TYPE(FfsPlatformFileChooserOptions,
9797
* current_name: field in this object.
9898
* accept_button_label: field in this object.
9999
* select_multiple: field in this object.
100+
* create_folders: field in this object.
100101
*
101102
* Creates a new #PlatformFileChooserOptions object.
102103
*
@@ -105,7 +106,7 @@ G_DECLARE_FINAL_TYPE(FfsPlatformFileChooserOptions,
105106
FfsPlatformFileChooserOptions* ffs_platform_file_chooser_options_new(
106107
FlValue* allowed_file_types, const gchar* current_folder_path,
107108
const gchar* current_name, const gchar* accept_button_label,
108-
gboolean* select_multiple);
109+
gboolean* select_multiple, gboolean* create_folders);
109110

110111
/**
111112
* ffs_platform_file_chooser_options_get_allowed_file_types
@@ -164,6 +165,19 @@ const gchar* ffs_platform_file_chooser_options_get_accept_button_label(
164165
gboolean* ffs_platform_file_chooser_options_get_select_multiple(
165166
FfsPlatformFileChooserOptions* object);
166167

168+
/**
169+
* ffs_platform_file_chooser_options_get_create_folders
170+
* @object: a #FfsPlatformFileChooserOptions.
171+
*
172+
* Whether to allow new folder creation.
173+
*
174+
* Nullable because it does not apply to the "open" action.
175+
*
176+
* Returns: the field value.
177+
*/
178+
gboolean* ffs_platform_file_chooser_options_get_create_folders(
179+
FfsPlatformFileChooserOptions* object);
180+
167181
G_DECLARE_FINAL_TYPE(FfsMessageCodec, ffs_message_codec, FFS, MESSAGE_CODEC,
168182
FlStandardMessageCodec)
169183

0 commit comments

Comments
 (0)