filesystem_dock.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. #ifndef FILESYSTEM_DOCK_H
  31. #define FILESYSTEM_DOCK_H
  32. #include "editor/dependency_editor.h"
  33. #include "editor/editor_file_system.h"
  34. #include "editor/plugins/script_editor_plugin.h"
  35. #include "editor/script_create_dialog.h"
  36. #include "scene/gui/box_container.h"
  37. #include "scene/gui/control.h"
  38. #include "scene/gui/dialogs.h"
  39. #include "scene/gui/menu_button.h"
  40. #include "scene/gui/split_container.h"
  41. #include "scene/gui/tree.h"
  42. class CreateDialog;
  43. class EditorDirDialog;
  44. class ItemList;
  45. class LineEdit;
  46. class ProgressBar;
  47. class SceneCreateDialog;
  48. class ShaderCreateDialog;
  49. class DirectoryCreateDialog;
  50. class EditorResourceTooltipPlugin;
  51. class FileSystemTree : public Tree {
  52. virtual Control *make_custom_tooltip(const String &p_text) const;
  53. };
  54. class FileSystemList : public ItemList {
  55. GDCLASS(FileSystemList, ItemList);
  56. VBoxContainer *popup_editor_vb = nullptr;
  57. Popup *popup_editor = nullptr;
  58. LineEdit *line_editor = nullptr;
  59. virtual Control *make_custom_tooltip(const String &p_text) const override;
  60. void _line_editor_submit(String p_text);
  61. void _text_editor_popup_modal_close();
  62. protected:
  63. static void _bind_methods();
  64. public:
  65. bool edit_selected();
  66. String get_edit_text();
  67. FileSystemList();
  68. };
  69. class FileSystemDock : public VBoxContainer {
  70. GDCLASS(FileSystemDock, VBoxContainer);
  71. public:
  72. enum FileListDisplayMode {
  73. FILE_LIST_DISPLAY_THUMBNAILS,
  74. FILE_LIST_DISPLAY_LIST
  75. };
  76. enum DisplayMode {
  77. DISPLAY_MODE_TREE_ONLY,
  78. DISPLAY_MODE_SPLIT,
  79. };
  80. enum FileSortOption {
  81. FILE_SORT_NAME = 0,
  82. FILE_SORT_NAME_REVERSE,
  83. FILE_SORT_TYPE,
  84. FILE_SORT_TYPE_REVERSE,
  85. FILE_SORT_MODIFIED_TIME,
  86. FILE_SORT_MODIFIED_TIME_REVERSE,
  87. FILE_SORT_MAX,
  88. };
  89. private:
  90. enum FileMenu {
  91. FILE_OPEN,
  92. FILE_INHERIT,
  93. FILE_MAIN_SCENE,
  94. FILE_INSTANTIATE,
  95. FILE_ADD_FAVORITE,
  96. FILE_REMOVE_FAVORITE,
  97. FILE_DEPENDENCIES,
  98. FILE_OWNERS,
  99. FILE_MOVE,
  100. FILE_RENAME,
  101. FILE_REMOVE,
  102. FILE_DUPLICATE,
  103. FILE_REIMPORT,
  104. FILE_INFO,
  105. FILE_NEW,
  106. FILE_SHOW_IN_EXPLORER,
  107. FILE_OPEN_EXTERNAL,
  108. FILE_COPY_PATH,
  109. FILE_COPY_UID,
  110. FOLDER_EXPAND_ALL,
  111. FOLDER_COLLAPSE_ALL,
  112. FILE_NEW_RESOURCE,
  113. FILE_NEW_TEXTFILE,
  114. FILE_NEW_FOLDER,
  115. FILE_NEW_SCRIPT,
  116. FILE_NEW_SCENE,
  117. };
  118. enum Overwrite {
  119. OVERWRITE_UNDECIDED,
  120. OVERWRITE_REPLACE,
  121. OVERWRITE_RENAME,
  122. };
  123. FileSortOption file_sort = FILE_SORT_NAME;
  124. VBoxContainer *scanning_vb = nullptr;
  125. ProgressBar *scanning_progress = nullptr;
  126. VSplitContainer *split_box = nullptr;
  127. VBoxContainer *file_list_vb = nullptr;
  128. HashSet<String> favorites;
  129. Button *button_toggle_display_mode = nullptr;
  130. Button *button_reload = nullptr;
  131. Button *button_file_list_display_mode = nullptr;
  132. Button *button_hist_next = nullptr;
  133. Button *button_hist_prev = nullptr;
  134. LineEdit *current_path_line_edit = nullptr;
  135. HBoxContainer *toolbar2_hbc = nullptr;
  136. LineEdit *tree_search_box = nullptr;
  137. MenuButton *tree_button_sort = nullptr;
  138. LineEdit *file_list_search_box = nullptr;
  139. MenuButton *file_list_button_sort = nullptr;
  140. String searched_string;
  141. Vector<String> uncollapsed_paths_before_search;
  142. TextureRect *search_icon = nullptr;
  143. HBoxContainer *path_hb = nullptr;
  144. FileListDisplayMode file_list_display_mode;
  145. DisplayMode display_mode;
  146. DisplayMode old_display_mode;
  147. PopupMenu *file_list_popup = nullptr;
  148. PopupMenu *tree_popup = nullptr;
  149. DependencyEditor *deps_editor = nullptr;
  150. DependencyEditorOwners *owners_editor = nullptr;
  151. DependencyRemoveDialog *remove_dialog = nullptr;
  152. EditorDirDialog *move_dialog = nullptr;
  153. ConfirmationDialog *duplicate_dialog = nullptr;
  154. LineEdit *duplicate_dialog_text = nullptr;
  155. DirectoryCreateDialog *make_dir_dialog = nullptr;
  156. ConfirmationDialog *overwrite_dialog = nullptr;
  157. ScrollContainer *overwrite_dialog_scroll = nullptr;
  158. Label *overwrite_dialog_header = nullptr;
  159. Label *overwrite_dialog_footer = nullptr;
  160. Label *overwrite_dialog_file_list = nullptr;
  161. SceneCreateDialog *make_scene_dialog = nullptr;
  162. ScriptCreateDialog *make_script_dialog = nullptr;
  163. ShaderCreateDialog *make_shader_dialog = nullptr;
  164. CreateDialog *new_resource_dialog = nullptr;
  165. bool always_show_folders = false;
  166. class FileOrFolder {
  167. public:
  168. String path;
  169. bool is_file = false;
  170. FileOrFolder() {}
  171. FileOrFolder(const String &p_path, bool p_is_file) :
  172. path(p_path),
  173. is_file(p_is_file) {}
  174. };
  175. FileOrFolder to_rename;
  176. FileOrFolder to_duplicate;
  177. Vector<FileOrFolder> to_move;
  178. String to_move_path;
  179. bool to_move_or_copy = false;
  180. Vector<String> history;
  181. int history_pos;
  182. int history_max_size;
  183. String current_path;
  184. bool initialized = false;
  185. bool updating_tree = false;
  186. int tree_update_id;
  187. FileSystemTree *tree = nullptr;
  188. FileSystemList *files = nullptr;
  189. bool import_dock_needs_update = false;
  190. bool holding_branch = false;
  191. Vector<TreeItem *> tree_items_selected_on_drag_begin;
  192. PackedInt32Array list_items_selected_on_drag_begin;
  193. LocalVector<Ref<EditorResourceTooltipPlugin>> tooltip_plugins;
  194. void _tree_mouse_exited();
  195. void _reselect_items_selected_on_drag_begin(bool reset = false);
  196. Ref<Texture2D> _get_tree_item_icon(bool p_is_valid, String p_file_type);
  197. bool _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites, bool p_unfold_path = false);
  198. void _update_tree(const Vector<String> &p_uncollapsed_paths = Vector<String>(), bool p_uncollapse_root = false, bool p_select_in_favorites = false, bool p_unfold_path = false);
  199. void _navigate_to_path(const String &p_path, bool p_select_in_favorites = false);
  200. void _file_list_gui_input(Ref<InputEvent> p_event);
  201. void _tree_gui_input(Ref<InputEvent> p_event);
  202. void _update_file_list(bool p_keep_selection);
  203. void _toggle_file_display();
  204. void _set_file_display(bool p_active);
  205. void _fs_changed();
  206. void _select_file(const String &p_path, bool p_select_in_favorites = false);
  207. void _tree_activate_file();
  208. void _file_list_activate_file(int p_idx);
  209. void _file_multi_selected(int p_index, bool p_selected);
  210. void _tree_multi_selected(Object *p_item, int p_column, bool p_selected);
  211. bool _get_imported_files(const String &p_path, String &r_extension, Vector<String> &r_files) const;
  212. void _update_import_dock();
  213. void _get_all_items_in_dir(EditorFileSystemDirectory *p_efsd, Vector<String> &r_files, Vector<String> &r_folders) const;
  214. void _find_remaps(EditorFileSystemDirectory *p_efsd, const HashMap<String, String> &r_renames, Vector<String> &r_to_remaps) const;
  215. 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);
  216. void _try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const;
  217. void _update_dependencies_after_move(const HashMap<String, String> &p_renames) const;
  218. void _update_resource_paths_after_move(const HashMap<String, String> &p_renames) const;
  219. void _save_scenes_after_move(const HashMap<String, String> &p_renames) const;
  220. void _update_favorites_list_after_move(const HashMap<String, String> &p_files_renames, const HashMap<String, String> &p_folders_renames) const;
  221. void _update_project_settings_after_move(const HashMap<String, String> &p_renames) const;
  222. String _get_unique_name(const FileOrFolder &p_entry, const String &p_at_path);
  223. void _resource_removed(const Ref<Resource> &p_resource);
  224. void _file_removed(String p_file);
  225. void _folder_removed(String p_folder);
  226. void _resource_created();
  227. void _make_scene_confirm();
  228. void _rename_operation_confirm();
  229. void _duplicate_operation_confirm();
  230. void _overwrite_dialog_action(bool p_overwrite);
  231. Vector<String> _check_existing();
  232. void _move_dialog_confirm(const String &p_path);
  233. void _move_operation_confirm(const String &p_to_path, bool p_copy = false, Overwrite p_overwrite = OVERWRITE_UNDECIDED);
  234. void _tree_rmb_option(int p_option);
  235. void _file_list_rmb_option(int p_option);
  236. void _file_option(int p_option, const Vector<String> &p_selected);
  237. void _fw_history();
  238. void _bw_history();
  239. void _update_history();
  240. void _push_to_history();
  241. void _set_scanning_mode();
  242. void _rescan();
  243. void _toggle_split_mode(bool p_active);
  244. void _search_changed(const String &p_text, const Control *p_from);
  245. MenuButton *_create_file_menu_button();
  246. void _file_sort_popup(int p_id);
  247. void _file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options = true);
  248. void _tree_rmb_select(const Vector2 &p_pos, MouseButton p_button);
  249. void _file_list_item_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);
  250. void _file_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
  251. void _tree_empty_click(const Vector2 &p_pos, MouseButton p_button);
  252. void _tree_empty_selected();
  253. struct FileInfo {
  254. String name;
  255. String path;
  256. StringName type;
  257. Vector<String> sources;
  258. bool import_broken = false;
  259. uint64_t modified_time = 0;
  260. bool operator<(const FileInfo &fi) const {
  261. return NaturalNoCaseComparator()(name, fi.name);
  262. }
  263. };
  264. struct FileInfoTypeComparator;
  265. struct FileInfoModifiedTimeComparator;
  266. void _sort_file_info_list(List<FileSystemDock::FileInfo> &r_file_list);
  267. void _search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items);
  268. void _set_current_path_line_edit_text(const String &p_path);
  269. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  270. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  271. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  272. void _get_drag_target_folder(String &target, bool &target_favorites, const Point2 &p_point, Control *p_from) const;
  273. void _preview_invalidated(const String &p_path);
  274. void _file_list_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
  275. void _tree_thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
  276. void _update_display_mode(bool p_force = false);
  277. Vector<String> _tree_get_selected(bool remove_self_inclusion = true) const;
  278. bool _is_file_type_disabled_by_feature_profile(const StringName &p_class);
  279. void _feature_profile_changed();
  280. static Vector<String> _remove_self_included_paths(Vector<String> selected_strings);
  281. private:
  282. static FileSystemDock *singleton;
  283. public:
  284. static FileSystemDock *get_singleton() { return singleton; }
  285. protected:
  286. void _notification(int p_what);
  287. static void _bind_methods();
  288. public:
  289. Vector<String> get_selected_paths() const;
  290. Vector<String> get_uncollapsed_paths() const;
  291. String get_current_path() const;
  292. String get_current_directory() const;
  293. void navigate_to_path(const String &p_path);
  294. void focus_on_filter();
  295. ScriptCreateDialog *get_script_create_dialog() const;
  296. void fix_dependencies(const String &p_for_file);
  297. int get_split_offset() { return split_box->get_split_offset(); }
  298. void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); }
  299. void select_file(const String &p_file);
  300. void set_display_mode(DisplayMode p_display_mode);
  301. DisplayMode get_display_mode() { return display_mode; }
  302. void set_file_sort(FileSortOption p_file_sort);
  303. FileSortOption get_file_sort() { return file_sort; }
  304. void set_file_list_display_mode(FileListDisplayMode p_mode);
  305. FileListDisplayMode get_file_list_display_mode() { return file_list_display_mode; };
  306. Tree *get_tree_control() { return tree; }
  307. void add_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin);
  308. void remove_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin);
  309. Control *create_tooltip_for_path(const String &p_path) const;
  310. FileSystemDock();
  311. ~FileSystemDock();
  312. };
  313. #endif // FILESYSTEM_DOCK_H