Skip to content

Commit b39655a

Browse files
committed
[file_selector] Implement canCreateDirectories for macOS and Linux
1 parent 4385dea commit b39655a

File tree

24 files changed

+540
-32
lines changed

24 files changed

+540
-32
lines changed

packages/file_selector/file_selector_linux/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 0.9.4
22

3+
* Adds `getDirectoryPathWithOptions` and `getDirectoryPathsWithOptions` implementations.
34
* Updates minimum supported SDK version to Flutter 3.32/Dart 3.8.
45

56
## 0.9.3+2

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 (v22.6.2), do not edit directly.
4+
// Autogenerated from Pigeon (v22.7.4), 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

@@ -59,6 +59,7 @@ class PlatformFileChooserOptions {
5959
this.currentName,
6060
this.acceptButtonLabel,
6161
this.selectMultiple,
62+
this.createFolders,
6263
});
6364

6465
List<PlatformTypeGroup>? allowedFileTypes;
@@ -74,13 +75,19 @@ class PlatformFileChooserOptions {
7475
/// Nullable because it does not apply to the "save" action.
7576
bool? selectMultiple;
7677

78+
/// Whether to allow new folders creation.
79+
///
80+
/// Nullable because it does not apply to the "open" action.
81+
bool? createFolders;
82+
7783
Object encode() {
7884
return <Object?>[
7985
allowedFileTypes,
8086
currentFolderPath,
8187
currentName,
8288
acceptButtonLabel,
8389
selectMultiple,
90+
createFolders,
8491
];
8592
}
8693

@@ -93,6 +100,7 @@ class PlatformFileChooserOptions {
93100
currentName: result[2] as String?,
94101
acceptButtonLabel: result[3] as String?,
95102
selectMultiple: result[4] as bool?,
103+
createFolders: result[5] as bool?,
96104
);
97105
}
98106
}

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 (v22.6.2), do not edit directly.
4+
// Autogenerated from Pigeon (v22.7.4), 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 (v22.6.2), do not edit directly.
4+
// Autogenerated from Pigeon (v22.7.4), 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 folders 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)