Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/docks/filesystem_dock.h
9896 views
1
/**************************************************************************/
2
/* filesystem_dock.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 "editor/file_system/dependency_editor.h"
34
#include "editor/file_system/editor_file_system.h"
35
#include "editor/file_system/file_info.h"
36
#include "editor/script/script_create_dialog.h"
37
#include "editor/script/script_editor_plugin.h"
38
#include "scene/gui/box_container.h"
39
#include "scene/gui/control.h"
40
#include "scene/gui/dialogs.h"
41
#include "scene/gui/menu_button.h"
42
#include "scene/gui/split_container.h"
43
#include "scene/gui/tree.h"
44
45
class CreateDialog;
46
class EditorDirDialog;
47
class ItemList;
48
class LineEdit;
49
class ProgressBar;
50
class SceneCreateDialog;
51
class ShaderCreateDialog;
52
class DirectoryCreateDialog;
53
class EditorResourceTooltipPlugin;
54
55
class FileSystemTree : public Tree {
56
virtual Control *make_custom_tooltip(const String &p_text) const;
57
};
58
59
class FileSystemList : public ItemList {
60
GDCLASS(FileSystemList, ItemList);
61
62
bool popup_edit_committed = true;
63
VBoxContainer *popup_editor_vb = nullptr;
64
Popup *popup_editor = nullptr;
65
LineEdit *line_editor = nullptr;
66
67
virtual Control *make_custom_tooltip(const String &p_text) const override;
68
void _line_editor_submit(const String &p_text);
69
void _text_editor_popup_modal_close();
70
71
protected:
72
static void _bind_methods();
73
74
public:
75
bool edit_selected();
76
String get_edit_text();
77
78
FileSystemList();
79
};
80
81
class FileSystemDock : public VBoxContainer {
82
GDCLASS(FileSystemDock, VBoxContainer);
83
84
public:
85
enum FileListDisplayMode {
86
FILE_LIST_DISPLAY_THUMBNAILS,
87
FILE_LIST_DISPLAY_LIST
88
};
89
90
enum DisplayMode {
91
DISPLAY_MODE_TREE_ONLY,
92
DISPLAY_MODE_VSPLIT,
93
DISPLAY_MODE_HSPLIT,
94
};
95
96
enum Overwrite {
97
OVERWRITE_UNDECIDED,
98
OVERWRITE_REPLACE,
99
OVERWRITE_RENAME,
100
};
101
102
private:
103
enum FileMenu {
104
FILE_MENU_OPEN,
105
FILE_MENU_INHERIT,
106
FILE_MENU_MAIN_SCENE,
107
FILE_MENU_INSTANTIATE,
108
FILE_MENU_ADD_FAVORITE,
109
FILE_MENU_REMOVE_FAVORITE,
110
FILE_MENU_SHOW_IN_FILESYSTEM,
111
FILE_MENU_DEPENDENCIES,
112
FILE_MENU_OWNERS,
113
FILE_MENU_MOVE,
114
FILE_MENU_RENAME,
115
FILE_MENU_REMOVE,
116
FILE_MENU_DUPLICATE,
117
FILE_MENU_REIMPORT,
118
FILE_MENU_NEW,
119
FILE_MENU_SHOW_IN_EXPLORER,
120
FILE_MENU_OPEN_EXTERNAL,
121
FILE_MENU_OPEN_IN_TERMINAL,
122
FILE_MENU_COPY_PATH,
123
FILE_MENU_COPY_ABSOLUTE_PATH,
124
FILE_MENU_COPY_UID,
125
FILE_MENU_EXPAND_ALL,
126
FILE_MENU_COLLAPSE_ALL,
127
FILE_MENU_NEW_RESOURCE,
128
FILE_MENU_NEW_TEXTFILE,
129
FILE_MENU_NEW_FOLDER,
130
FILE_MENU_NEW_SCRIPT,
131
FILE_MENU_NEW_SCENE,
132
FILE_MENU_RUN_SCRIPT,
133
FILE_MENU_MAX,
134
// Extra shortcuts that don't exist in the menu.
135
EXTRA_FOCUS_PATH,
136
EXTRA_FOCUS_FILTER,
137
138
CONVERT_BASE_ID = 1000,
139
};
140
141
HashMap<String, TreeItem *> folder_map;
142
HashMap<String, Color> folder_colors;
143
Dictionary assigned_folder_colors;
144
145
FileSortOption file_sort = FileSortOption::FILE_SORT_NAME;
146
147
VBoxContainer *scanning_vb = nullptr;
148
ProgressBar *scanning_progress = nullptr;
149
SplitContainer *split_box = nullptr;
150
VBoxContainer *file_list_vb = nullptr;
151
152
int split_box_offset_h = 0;
153
int split_box_offset_v = 0;
154
155
HashSet<String> favorites;
156
157
Button *button_dock_placement = nullptr;
158
159
Button *button_toggle_display_mode = nullptr;
160
Button *button_file_list_display_mode = nullptr;
161
Button *button_hist_next = nullptr;
162
Button *button_hist_prev = nullptr;
163
LineEdit *current_path_line_edit = nullptr;
164
165
HBoxContainer *toolbar2_hbc = nullptr;
166
LineEdit *tree_search_box = nullptr;
167
MenuButton *tree_button_sort = nullptr;
168
169
LineEdit *file_list_search_box = nullptr;
170
MenuButton *file_list_button_sort = nullptr;
171
172
PackedStringArray searched_tokens;
173
Vector<String> uncollapsed_paths_before_search;
174
175
TextureRect *search_icon = nullptr;
176
HBoxContainer *path_hb = nullptr;
177
178
FileListDisplayMode file_list_display_mode;
179
DisplayMode display_mode;
180
DisplayMode old_display_mode;
181
182
PopupMenu *file_list_popup = nullptr;
183
PopupMenu *tree_popup = nullptr;
184
185
DependencyEditor *deps_editor = nullptr;
186
DependencyEditorOwners *owners_editor = nullptr;
187
DependencyRemoveDialog *remove_dialog = nullptr;
188
189
EditorDirDialog *move_dialog = nullptr;
190
DirectoryCreateDialog *make_dir_dialog = nullptr;
191
192
ConfirmationDialog *overwrite_dialog = nullptr;
193
ScrollContainer *overwrite_dialog_scroll = nullptr;
194
Label *overwrite_dialog_header = nullptr;
195
Label *overwrite_dialog_footer = nullptr;
196
Label *overwrite_dialog_file_list = nullptr;
197
198
ConfirmationDialog *conversion_dialog = nullptr;
199
200
SceneCreateDialog *make_scene_dialog = nullptr;
201
ScriptCreateDialog *make_script_dialog = nullptr;
202
ShaderCreateDialog *make_shader_dialog = nullptr;
203
CreateDialog *new_resource_dialog = nullptr;
204
205
bool always_show_folders = false;
206
int thumbnail_size_setting = 0;
207
208
bool editor_is_dark_theme = false;
209
210
class FileOrFolder {
211
public:
212
String path;
213
bool is_file = false;
214
215
FileOrFolder() {}
216
FileOrFolder(const String &p_path, bool p_is_file) :
217
path(p_path),
218
is_file(p_is_file) {}
219
};
220
FileOrFolder to_rename;
221
FileOrFolder to_duplicate;
222
Vector<FileOrFolder> to_move;
223
String to_move_path;
224
bool to_move_or_copy = false;
225
226
Vector<String> to_convert;
227
int selected_conversion_id = 0;
228
229
Vector<String> history;
230
int history_pos;
231
int history_max_size;
232
233
String current_path;
234
String select_after_scan;
235
236
bool updating_tree = false;
237
int tree_update_id;
238
FileSystemTree *tree = nullptr;
239
FileSystemList *files = nullptr;
240
bool import_dock_needs_update = false;
241
TreeItem *resources_item = nullptr;
242
TreeItem *favorites_item = nullptr;
243
Control *had_focus = nullptr;
244
245
bool holding_branch = false;
246
Vector<TreeItem *> tree_items_selected_on_drag_begin;
247
PackedInt32Array list_items_selected_on_drag_begin;
248
249
LocalVector<Ref<EditorResourceTooltipPlugin>> tooltip_plugins;
250
251
HashSet<String> cached_valid_conversion_targets;
252
253
void _tree_mouse_exited();
254
void _reselect_items_selected_on_drag_begin(bool reset = false);
255
256
Ref<Texture2D> _get_tree_item_icon(bool p_is_valid, const String &p_file_type, const String &p_icon_path);
257
void _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites, bool p_unfold_path = false);
258
void _update_tree(const Vector<String> &p_uncollapsed_paths = Vector<String>(), bool p_uncollapse_root = false, bool p_scroll_to_selected = true);
259
void _navigate_to_path(const String &p_path, bool p_select_in_favorites = false, bool p_grab_focus = false);
260
bool _update_filtered_items(TreeItem *p_tree_item = nullptr);
261
262
void _file_list_gui_input(Ref<InputEvent> p_event);
263
void _tree_gui_input(Ref<InputEvent> p_event);
264
265
HashSet<String> _get_valid_conversions_for_file_paths(const Vector<String> &p_paths);
266
267
void _update_file_list(bool p_keep_selection);
268
void _toggle_file_display();
269
void _set_file_display(bool p_active);
270
void _fs_changed();
271
272
void _select_file(const String &p_path, bool p_select_in_favorites = false, bool p_navigate = true);
273
void _tree_activate_file();
274
void _file_list_activate_file(int p_idx);
275
void _file_multi_selected(int p_index, bool p_selected);
276
void _tree_multi_selected(Object *p_item, int p_column, bool p_selected);
277
278
bool _get_imported_files(const String &p_path, String &r_extension, Vector<String> &r_files) const;
279
void _update_import_dock();
280
281
void _get_all_items_in_dir(EditorFileSystemDirectory *p_efsd, Vector<String> &r_files, Vector<String> &r_folders) const;
282
void _find_file_owners(EditorFileSystemDirectory *p_efsd, const HashSet<String> &p_renames, HashSet<String> &r_file_owners) const;
283
void _try_move_item(const FileOrFolder &p_item, const String &p_new_path, HashMap<String, String> &p_file_renames, HashMap<String, String> &p_folder_renames);
284
void _try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const;
285
void _before_move(HashMap<String, ResourceUID::ID> &r_uids, HashSet<String> &r_file_owners) const;
286
void _update_dependencies_after_move(const HashMap<String, String> &p_renames, const HashSet<String> &p_file_owners) const;
287
void _update_resource_paths_after_move(const HashMap<String, String> &p_renames, const HashMap<String, ResourceUID::ID> &p_uids) const;
288
void _update_favorites_after_move(const HashMap<String, String> &p_files_renames, const HashMap<String, String> &p_folders_renames) const;
289
void _update_project_settings_after_move(const HashMap<String, String> &p_renames, const HashMap<String, String> &p_folders_renames);
290
String _get_unique_name(const FileOrFolder &p_entry, const String &p_at_path);
291
292
void _update_folder_colors_setting();
293
294
void _resource_removed(const Ref<Resource> &p_resource);
295
void _file_removed(const String &p_file);
296
void _folder_removed(const String &p_folder);
297
298
void _resource_created();
299
void _make_scene_confirm();
300
void _rename_operation_confirm();
301
void _duplicate_operation_confirm(const String &p_path);
302
void _overwrite_dialog_action(bool p_overwrite);
303
void _convert_dialog_action();
304
Vector<String> _check_existing();
305
void _move_operation_confirm(const String &p_to_path, bool p_copy = false, Overwrite p_overwrite = OVERWRITE_UNDECIDED);
306
307
void _tree_rmb_option(int p_option);
308
void _file_list_rmb_option(int p_option);
309
void _generic_rmb_option_selected(int p_option);
310
void _file_option(int p_option, const Vector<String> &p_selected);
311
int _get_menu_option_from_key(const Ref<InputEventKey> &p_key);
312
313
void _fw_history();
314
void _bw_history();
315
void _update_history();
316
void _push_to_history();
317
318
void _set_scanning_mode();
319
void _rescan();
320
321
void _change_split_mode();
322
void _split_dragged(int p_offset);
323
324
void _search_changed(const String &p_text, const Control *p_from);
325
bool _matches_all_search_tokens(const String &p_text);
326
327
MenuButton *_create_file_menu_button();
328
void _file_sort_popup(int p_id);
329
330
void _folder_color_index_pressed(int p_index, PopupMenu *p_menu);
331
void _file_and_folders_fill_popup(PopupMenu *p_popup, const Vector<String> &p_paths, bool p_display_path_dependent_options = true);
332
void _tree_rmb_select(const Vector2 &p_pos, MouseButton p_button);
333
void _file_list_item_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);
334
void _file_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
335
void _tree_empty_click(const Vector2 &p_pos, MouseButton p_button);
336
void _tree_empty_selected();
337
338
void _search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items);
339
340
void _set_current_path_line_edit_text(const String &p_path);
341
342
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
343
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
344
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
345
void _get_drag_target_folder(String &target, bool &target_favorites, const Point2 &p_point, Control *p_from) const;
346
347
void _preview_invalidated(const String &p_path);
348
void _file_list_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
349
void _tree_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
350
351
void _update_display_mode(bool p_force = false);
352
353
Vector<String> _tree_get_selected(bool remove_self_inclusion = true, bool p_include_unselected_cursor = false) const;
354
Vector<String> _file_list_get_selected() const;
355
356
bool _is_file_type_disabled_by_feature_profile(const StringName &p_class);
357
358
void _feature_profile_changed();
359
void _project_settings_changed();
360
static Vector<String> _remove_self_included_paths(Vector<String> selected_strings);
361
362
void _change_bottom_dock_placement();
363
364
bool _can_dock_horizontal() const;
365
void _set_dock_horizontal(bool p_enable);
366
367
void _save_layout_to_config(Ref<ConfigFile> p_layout, const String &p_section) const;
368
void _load_layout_from_config(Ref<ConfigFile> p_layout, const String &p_section);
369
370
private:
371
inline static FileSystemDock *singleton = nullptr;
372
373
public:
374
static FileSystemDock *get_singleton() { return singleton; }
375
376
protected:
377
void _notification(int p_what);
378
static void _bind_methods();
379
380
public:
381
static constexpr double ITEM_COLOR_SCALE = 1.75;
382
static constexpr double ITEM_ALPHA_MIN = 0.1;
383
static constexpr double ITEM_ALPHA_MAX = 0.15;
384
static constexpr double ITEM_BG_DARK_SCALE = 0.3;
385
386
static Color get_dir_icon_color(const String &p_dir_path, const Color &p_default);
387
388
const HashMap<String, Color> &get_folder_colors() const;
389
Dictionary get_assigned_folder_colors() const;
390
391
Vector<String> get_selected_paths() const;
392
Vector<String> get_uncollapsed_paths() const;
393
394
String get_current_path() const;
395
String get_current_directory() const;
396
String get_folder_path_at_mouse_position() const;
397
398
void navigate_to_path(const String &p_path);
399
void focus_on_path();
400
void focus_on_filter();
401
void create_directory(const String &p_path, const String &p_base_dir);
402
403
ScriptCreateDialog *get_script_create_dialog() const;
404
405
void fix_dependencies(const String &p_for_file);
406
void update_all();
407
408
int get_h_split_offset() const { return split_box_offset_h; }
409
void set_h_split_offset(int p_offset) { split_box_offset_h = p_offset; }
410
int get_v_split_offset() const { return split_box_offset_v; }
411
void set_v_split_offset(int p_offset) { split_box_offset_v = p_offset; }
412
void select_file(const String &p_file);
413
414
void set_display_mode(DisplayMode p_display_mode);
415
DisplayMode get_display_mode() const { return display_mode; }
416
417
void set_file_sort(FileSortOption p_file_sort);
418
FileSortOption get_file_sort() const { return file_sort; }
419
420
void set_file_list_display_mode(FileListDisplayMode p_mode);
421
FileListDisplayMode get_file_list_display_mode() const { return file_list_display_mode; }
422
423
Tree *get_tree_control() { return tree; }
424
425
void add_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin);
426
void remove_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin);
427
Control *create_tooltip_for_path(const String &p_path) const;
428
429
FileSystemDock();
430
~FileSystemDock();
431
};
432
433
VARIANT_ENUM_CAST(FileSystemDock::Overwrite);
434
435