Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/gui/editor_file_dialog.h
9896 views
1
/**************************************************************************/
2
/* editor_file_dialog.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/io/dir_access.h"
34
#include "editor/file_system/file_info.h"
35
#include "scene/gui/dialogs.h"
36
#include "scene/property_list_helper.h"
37
38
class DependencyRemoveDialog;
39
class GridContainer;
40
class HSplitContainer;
41
class HFlowContainer;
42
class ItemList;
43
class MenuButton;
44
class OptionButton;
45
class PopupMenu;
46
class TextureRect;
47
class VSeparator;
48
49
class EditorFileDialog : public ConfirmationDialog {
50
GDCLASS(EditorFileDialog, ConfirmationDialog);
51
52
public:
53
enum DisplayMode {
54
DISPLAY_THUMBNAILS,
55
DISPLAY_LIST
56
};
57
58
enum Access {
59
ACCESS_RESOURCES,
60
ACCESS_USERDATA,
61
ACCESS_FILESYSTEM
62
};
63
64
enum FileMode {
65
FILE_MODE_OPEN_FILE,
66
FILE_MODE_OPEN_FILES,
67
FILE_MODE_OPEN_DIR,
68
FILE_MODE_OPEN_ANY,
69
FILE_MODE_SAVE_FILE
70
};
71
72
typedef Ref<Texture2D> (*GetIconFunc)(const String &);
73
typedef void (*RegisterFunc)(EditorFileDialog *);
74
75
static inline GetIconFunc get_icon_func = nullptr;
76
static inline GetIconFunc get_thumbnail_func = nullptr;
77
static inline RegisterFunc register_func = nullptr;
78
static inline RegisterFunc unregister_func = nullptr;
79
80
private:
81
enum ItemMenu {
82
ITEM_MENU_COPY_PATH,
83
ITEM_MENU_DELETE,
84
ITEM_MENU_REFRESH,
85
ITEM_MENU_NEW_FOLDER,
86
ITEM_MENU_SHOW_IN_EXPLORER,
87
ITEM_MENU_SHOW_BUNDLE_CONTENT,
88
};
89
90
ConfirmationDialog *makedialog = nullptr;
91
LineEdit *makedirname = nullptr;
92
93
VSeparator *makedir_sep = nullptr;
94
Button *makedir = nullptr;
95
Access access = ACCESS_RESOURCES;
96
97
HFlowContainer *flow_checkbox_options = nullptr;
98
GridContainer *grid_select_options = nullptr;
99
VBoxContainer *vbox = nullptr;
100
FileMode mode = FILE_MODE_SAVE_FILE;
101
bool can_create_dir = false;
102
LineEdit *dir = nullptr;
103
104
Button *dir_prev = nullptr;
105
Button *dir_next = nullptr;
106
Button *dir_up = nullptr;
107
108
HBoxContainer *drives_container = nullptr;
109
HBoxContainer *shortcuts_container = nullptr;
110
OptionButton *drives = nullptr;
111
ItemList *item_list = nullptr;
112
PopupMenu *item_menu = nullptr;
113
TextureRect *preview = nullptr;
114
VBoxContainer *preview_vb = nullptr;
115
HSplitContainer *body_hsplit = nullptr;
116
HSplitContainer *list_hb = nullptr;
117
HBoxContainer *file_box = nullptr;
118
LineEdit *file = nullptr;
119
OptionButton *filter = nullptr;
120
AcceptDialog *error_dialog = nullptr;
121
Ref<DirAccess> dir_access;
122
ConfirmationDialog *confirm_save = nullptr;
123
DependencyRemoveDialog *dep_remove_dialog = nullptr;
124
ConfirmationDialog *global_remove_dialog = nullptr;
125
VBoxContainer *side_vbox = nullptr;
126
VBoxContainer *vbc = nullptr;
127
HBoxContainer *pathhb = nullptr;
128
129
Button *mode_thumbnails = nullptr;
130
Button *mode_list = nullptr;
131
132
Button *refresh = nullptr;
133
Button *favorite = nullptr;
134
Button *show_hidden = nullptr;
135
Button *show_search_filter_button = nullptr;
136
137
String search_string;
138
bool show_search_filter = false;
139
HBoxContainer *filter_hb = nullptr;
140
LineEdit *filter_box = nullptr;
141
FileSortOption file_sort = FileSortOption::FILE_SORT_NAME;
142
MenuButton *file_sort_button = nullptr;
143
144
Button *fav_up = nullptr;
145
Button *fav_down = nullptr;
146
147
ItemList *favorites = nullptr;
148
ItemList *recent = nullptr;
149
150
Vector<String> local_history;
151
int local_history_pos = 0;
152
void _push_history();
153
154
Vector<String> filters;
155
Vector<String> processed_filters;
156
157
bool previews_enabled = true;
158
bool preview_waiting = false;
159
int preview_wheel_index = 0;
160
float preview_wheel_timeout = 0.0f;
161
162
static inline bool default_show_hidden_files = false;
163
static inline DisplayMode default_display_mode = DISPLAY_THUMBNAILS;
164
bool show_hidden_files;
165
DisplayMode display_mode;
166
167
bool disable_overwrite_warning = false;
168
bool is_invalidating = false;
169
170
struct ThemeCache {
171
Ref<Texture2D> parent_folder;
172
Ref<Texture2D> forward_folder;
173
Ref<Texture2D> back_folder;
174
Ref<Texture2D> open_folder;
175
Ref<Texture2D> reload;
176
Ref<Texture2D> toggle_hidden;
177
Ref<Texture2D> toggle_filename_filter;
178
Ref<Texture2D> favorite;
179
Ref<Texture2D> mode_thumbnails;
180
Ref<Texture2D> mode_list;
181
Ref<Texture2D> create_folder;
182
Ref<Texture2D> favorites_up;
183
Ref<Texture2D> favorites_down;
184
185
Ref<Texture2D> filter_box;
186
Ref<Texture2D> file_sort_button;
187
188
Ref<Texture2D> folder;
189
Color folder_icon_color;
190
191
Ref<Texture2D> action_copy;
192
Ref<Texture2D> action_delete;
193
Ref<Texture2D> filesystem;
194
195
Ref<Texture2D> folder_medium_thumbnail;
196
Ref<Texture2D> file_medium_thumbnail;
197
Ref<Texture2D> folder_big_thumbnail;
198
Ref<Texture2D> file_big_thumbnail;
199
200
Ref<Texture2D> progress[8]{};
201
} theme_cache;
202
203
struct Option {
204
String name;
205
Vector<String> values;
206
int default_idx = 0;
207
};
208
209
static inline PropertyListHelper base_property_helper;
210
PropertyListHelper property_helper;
211
212
Vector<Option> options;
213
Dictionary selected_options;
214
bool options_dirty = false;
215
String full_dir;
216
217
void update_dir();
218
void update_file_name();
219
void update_file_list();
220
void update_search_filter_gui();
221
void update_filters();
222
223
void _focus_file_text();
224
225
void _update_favorites();
226
void _favorite_pressed();
227
void _favorite_selected(int p_idx);
228
void _favorite_move_up();
229
void _favorite_move_down();
230
231
void _update_recent();
232
void _recent_selected(int p_idx);
233
234
void _item_selected(int p_item);
235
void _multi_selected(int p_item, bool p_selected);
236
void _items_clear_selection(const Vector2 &p_pos, MouseButton p_mouse_button_index);
237
void _item_dc_selected(int p_item);
238
239
void _item_list_item_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);
240
void _item_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
241
void _item_menu_id_pressed(int p_option);
242
243
void _select_drive(int p_idx);
244
void _dir_submitted(const String &p_dir);
245
void _action_pressed();
246
void _save_confirm_pressed();
247
void _cancel_pressed();
248
void _filter_selected(int);
249
void _make_dir();
250
void _make_dir_confirm();
251
252
void _focus_filter_box();
253
void _filter_changed(const String &p_text);
254
void _search_filter_selected();
255
void _file_sort_popup(int p_id);
256
257
void _delete_items();
258
void _delete_files_global();
259
260
void _update_drives(bool p_select = true);
261
void _update_icons();
262
263
void _go_up();
264
void _go_back();
265
void _go_forward();
266
267
void _invalidate();
268
269
virtual void _post_popup() override;
270
271
void _save_to_recent();
272
// Callback function is callback(String p_path,Ref<Texture2D> preview,Variant udata) preview null if could not load.
273
274
void _thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
275
void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
276
void _request_single_thumbnail(const String &p_path);
277
278
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
279
280
bool _is_open_should_be_disabled();
281
282
void _update_side_menu_visibility(bool p_native_dlg);
283
284
void _native_popup();
285
void _native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options);
286
287
TypedArray<Dictionary> _get_options() const;
288
void _update_option_controls();
289
void _option_changed_checkbox_toggled(bool p_pressed, const String &p_name);
290
void _option_changed_item_selected(int p_idx, const String &p_name);
291
292
protected:
293
virtual void _update_theme_item_cache() override;
294
295
void _notification(int p_what);
296
bool _set(const StringName &p_name, const Variant &p_value) { return property_helper.property_set_value(p_name, p_value); }
297
bool _get(const StringName &p_name, Variant &r_ret) const { return property_helper.property_get_value(p_name, r_ret); }
298
void _get_property_list(List<PropertyInfo> *p_list) const { property_helper.get_property_list(p_list); }
299
bool _property_can_revert(const StringName &p_name) const { return property_helper.property_can_revert(p_name); }
300
bool _property_get_revert(const StringName &p_name, Variant &r_property) const { return property_helper.property_get_revert(p_name, r_property); }
301
static void _bind_methods();
302
303
public:
304
virtual void set_visible(bool p_visible) override;
305
virtual void popup(const Rect2i &p_rect = Rect2i()) override;
306
307
// Public for use with callable_mp.
308
void _file_submitted(const String &p_file);
309
310
void popup_file_dialog();
311
void clear_filters();
312
void add_filter(const String &p_filter, const String &p_description = "");
313
void set_filters(const Vector<String> &p_filters);
314
Vector<String> get_filters() const;
315
void clear_search_filter();
316
void set_search_filter(const String &p_search_filter);
317
String get_search_filter() const;
318
319
void set_enable_multiple_selection(bool p_enable);
320
Vector<String> get_selected_files() const;
321
322
String get_current_dir() const;
323
String get_current_file() const;
324
String get_current_path() const;
325
void set_current_dir(const String &p_dir);
326
void set_current_file(const String &p_file);
327
void set_current_path(const String &p_path);
328
329
String get_option_name(int p_option) const;
330
Vector<String> get_option_values(int p_option) const;
331
int get_option_default(int p_option) const;
332
void set_option_name(int p_option, const String &p_name);
333
void set_option_values(int p_option, const Vector<String> &p_values);
334
void set_option_default(int p_option, int p_index);
335
336
void add_option(const String &p_name, const Vector<String> &p_values, int p_index);
337
338
void set_option_count(int p_count);
339
int get_option_count() const;
340
341
Dictionary get_selected_options() const;
342
343
void set_display_mode(DisplayMode p_mode);
344
DisplayMode get_display_mode() const;
345
346
void set_file_mode(FileMode p_mode);
347
FileMode get_file_mode() const;
348
349
VBoxContainer *get_vbox();
350
LineEdit *get_line_edit() { return file; }
351
352
void set_access(Access p_access);
353
Access get_access() const;
354
355
static void set_default_show_hidden_files(bool p_show);
356
static void set_default_display_mode(DisplayMode p_mode);
357
void set_show_hidden_files(bool p_show);
358
void set_show_search_filter(bool p_show);
359
bool is_showing_hidden_files() const;
360
361
void invalidate();
362
363
void set_disable_overwrite_warning(bool p_disable);
364
bool is_overwrite_warning_disabled() const;
365
366
void set_previews_enabled(bool p_enabled);
367
bool are_previews_enabled();
368
369
void add_side_menu(Control *p_menu, const String &p_title = "");
370
371
EditorFileDialog();
372
~EditorFileDialog();
373
};
374
375
VARIANT_ENUM_CAST(EditorFileDialog::FileMode);
376
VARIANT_ENUM_CAST(EditorFileDialog::Access);
377
VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode);
378
379