filesystem_dock.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 "scene/gui/box_container.h"
  33. #include "scene/gui/control.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/item_list.h"
  36. #include "scene/gui/label.h"
  37. #include "scene/gui/menu_button.h"
  38. #include "scene/gui/option_button.h"
  39. #include "scene/gui/progress_bar.h"
  40. #include "scene/gui/split_container.h"
  41. #include "scene/gui/tool_button.h"
  42. #include "scene/gui/tree.h"
  43. #include "scene/main/timer.h"
  44. #include "core/os/dir_access.h"
  45. #include "core/os/thread.h"
  46. #include "create_dialog.h"
  47. #include "dependency_editor.h"
  48. #include "editor_dir_dialog.h"
  49. #include "editor_file_system.h"
  50. #include "script_create_dialog.h"
  51. class EditorNode;
  52. class SceneCreateDialog;
  53. class DirectoryCreateDialog;
  54. class FileSystemDock : public VBoxContainer {
  55. GDCLASS(FileSystemDock, VBoxContainer);
  56. public:
  57. enum FileListDisplayMode {
  58. FILE_LIST_DISPLAY_THUMBNAILS,
  59. FILE_LIST_DISPLAY_LIST
  60. };
  61. enum DisplayMode {
  62. DISPLAY_MODE_TREE_ONLY,
  63. DISPLAY_MODE_SPLIT,
  64. };
  65. enum FileSortOption {
  66. FILE_SORT_NAME = 0,
  67. FILE_SORT_NAME_REVERSE,
  68. FILE_SORT_TYPE,
  69. FILE_SORT_TYPE_REVERSE,
  70. FILE_SORT_MODIFIED_TIME,
  71. FILE_SORT_MODIFIED_TIME_REVERSE,
  72. FILE_SORT_MAX,
  73. };
  74. private:
  75. enum FileMenu {
  76. FILE_OPEN,
  77. FILE_INHERIT,
  78. FILE_MAIN_SCENE,
  79. FILE_INSTANCE,
  80. FILE_ADD_FAVORITE,
  81. FILE_REMOVE_FAVORITE,
  82. FILE_DEPENDENCIES,
  83. FILE_OWNERS,
  84. FILE_MOVE,
  85. FILE_RENAME,
  86. FILE_REMOVE,
  87. FILE_DUPLICATE,
  88. FILE_REIMPORT,
  89. FILE_INFO,
  90. FILE_NEW_FOLDER,
  91. FILE_NEW_SCRIPT,
  92. FILE_NEW_SCENE,
  93. FILE_SHOW_IN_EXPLORER,
  94. FILE_COPY_PATH,
  95. FILE_NEW_RESOURCE,
  96. FOLDER_EXPAND_ALL,
  97. FOLDER_COLLAPSE_ALL,
  98. };
  99. FileSortOption file_sort = FILE_SORT_NAME;
  100. VBoxContainer *scanning_vb;
  101. ProgressBar *scanning_progress;
  102. VSplitContainer *split_box;
  103. VBoxContainer *file_list_vb;
  104. EditorNode *editor;
  105. Set<String> favorites;
  106. Button *button_toggle_display_mode;
  107. Button *button_reload;
  108. Button *button_file_list_display_mode;
  109. Button *button_hist_next;
  110. Button *button_hist_prev;
  111. LineEdit *current_path;
  112. HBoxContainer *toolbar2_hbc;
  113. LineEdit *tree_search_box;
  114. MenuButton *tree_button_sort;
  115. LineEdit *file_list_search_box;
  116. MenuButton *file_list_button_sort;
  117. String searched_string;
  118. Vector<String> uncollapsed_paths_before_search;
  119. TextureRect *search_icon;
  120. HBoxContainer *path_hb;
  121. FileListDisplayMode file_list_display_mode;
  122. DisplayMode display_mode;
  123. DisplayMode old_display_mode;
  124. PopupMenu *file_list_popup;
  125. PopupMenu *tree_popup;
  126. DependencyEditor *deps_editor;
  127. DependencyEditorOwners *owners_editor;
  128. DependencyRemoveDialog *remove_dialog;
  129. EditorDirDialog *move_dialog;
  130. ConfirmationDialog *rename_dialog;
  131. LineEdit *rename_dialog_text;
  132. ConfirmationDialog *duplicate_dialog;
  133. LineEdit *duplicate_dialog_text;
  134. DirectoryCreateDialog *make_dir_dialog = nullptr;
  135. ConfirmationDialog *overwrite_dialog;
  136. SceneCreateDialog *make_scene_dialog = nullptr;
  137. ScriptCreateDialog *make_script_dialog;
  138. CreateDialog *new_resource_dialog;
  139. bool always_show_folders;
  140. class FileOrFolder {
  141. public:
  142. String path;
  143. bool is_file;
  144. FileOrFolder() :
  145. path(""),
  146. is_file(false) {}
  147. FileOrFolder(const String &p_path, bool p_is_file) :
  148. path(p_path),
  149. is_file(p_is_file) {}
  150. };
  151. FileOrFolder to_rename;
  152. FileOrFolder to_duplicate;
  153. Vector<FileOrFolder> to_move;
  154. String to_move_path;
  155. Vector<String> history;
  156. int history_pos;
  157. int history_max_size;
  158. String path;
  159. bool initialized;
  160. bool updating_tree;
  161. int tree_update_id;
  162. Tree *tree;
  163. ItemList *files;
  164. bool import_dock_needs_update;
  165. Ref<Texture> _get_tree_item_icon(bool p_is_valid, String p_file_type);
  166. bool _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites, bool p_unfold_path = false);
  167. Vector<String> _compute_uncollapsed_paths();
  168. 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);
  169. void _navigate_to_path(const String &p_path, bool p_select_in_favorites = false);
  170. void _file_list_gui_input(Ref<InputEvent> p_event);
  171. void _tree_gui_input(Ref<InputEvent> p_event);
  172. void _update_file_list(bool p_keep_selection);
  173. void _toggle_file_display();
  174. void _set_file_display(bool p_active);
  175. void _fs_changed();
  176. void _select_file(const String &p_path, bool p_select_in_favorites = false);
  177. void _tree_activate_file();
  178. void _file_list_activate_file(int p_idx);
  179. void _file_multi_selected(int p_index, bool p_selected);
  180. void _tree_multi_selected(Object *p_item, int p_column, bool p_selected);
  181. void _update_import_dock();
  182. void _get_all_items_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files, Vector<String> &folders) const;
  183. void _find_remaps(EditorFileSystemDirectory *efsd, const Map<String, String> &renames, Vector<String> &to_remaps) const;
  184. void _try_move_item(const FileOrFolder &p_item, const String &p_new_path, Map<String, String> &p_file_renames, Map<String, String> &p_folder_renames);
  185. void _try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const;
  186. void _update_dependencies_after_move(const Map<String, String> &p_renames) const;
  187. void _update_resource_paths_after_move(const Map<String, String> &p_renames) const;
  188. void _save_scenes_after_move(const Map<String, String> &p_renames) const;
  189. void _update_favorites_list_after_move(const Map<String, String> &p_files_renames, const Map<String, String> &p_folders_renames) const;
  190. void _update_project_settings_after_move(const Map<String, String> &p_renames) const;
  191. void _file_removed(String p_file);
  192. void _folder_removed(String p_folder);
  193. void _resource_created() const;
  194. void _make_scene_confirm();
  195. void _rename_operation_confirm();
  196. void _duplicate_operation_confirm();
  197. void _move_with_overwrite();
  198. Vector<String> _check_existing();
  199. void _move_operation_confirm(const String &p_to_path, bool overwrite = false);
  200. void _tree_rmb_option(int p_option);
  201. void _file_list_rmb_option(int p_option);
  202. void _file_option(int p_option, const Vector<String> &p_selected);
  203. void _fw_history();
  204. void _bw_history();
  205. void _update_history();
  206. void _push_to_history();
  207. void _set_scanning_mode();
  208. void _rescan();
  209. void _toggle_split_mode(bool p_active);
  210. void _focus_current_search_box();
  211. void _search_changed(const String &p_text, const Control *p_from);
  212. MenuButton *_create_file_menu_button();
  213. void _file_sort_popup(int p_id);
  214. void _file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options = true);
  215. void _tree_rmb_select(const Vector2 &p_pos);
  216. void _tree_rmb_empty(const Vector2 &p_pos);
  217. void _file_list_rmb_select(int p_item, const Vector2 &p_pos);
  218. void _file_list_rmb_pressed(const Vector2 &p_pos);
  219. void _tree_empty_selected();
  220. struct FileInfo {
  221. String name;
  222. String path;
  223. StringName type;
  224. Vector<String> sources;
  225. bool import_broken;
  226. uint64_t modified_time;
  227. bool operator<(const FileInfo &fi) const {
  228. return NaturalNoCaseComparator()(name, fi.name);
  229. }
  230. };
  231. struct FileInfoTypeComparator;
  232. struct FileInfoModifiedTimeComparator;
  233. void _sort_file_info_list(List<FileSystemDock::FileInfo> &r_file_list);
  234. void _search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items);
  235. void _set_current_path_text(const String &p_path);
  236. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  237. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  238. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  239. void _get_drag_target_folder(String &target, bool &target_favorites, const Point2 &p_point, Control *p_from) const;
  240. void _preview_invalidated(const String &p_path);
  241. void _file_list_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
  242. void _tree_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
  243. void _update_display_mode(bool p_force = false);
  244. Vector<String> _tree_get_selected(bool remove_self_inclusion = true);
  245. bool _is_file_type_disabled_by_feature_profile(const StringName &p_class);
  246. void _feature_profile_changed();
  247. Vector<String> _remove_self_included_paths(Vector<String> selected_strings);
  248. protected:
  249. void _notification(int p_what);
  250. static void _bind_methods();
  251. public:
  252. String get_selected_path() const;
  253. String get_current_path() const;
  254. void navigate_to_path(const String &p_path);
  255. void focus_on_filter();
  256. void fix_dependencies(const String &p_for_file);
  257. int get_split_offset() { return split_box->get_split_offset(); }
  258. void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); }
  259. void select_file(const String &p_file);
  260. void set_display_mode(DisplayMode p_display_mode);
  261. DisplayMode get_display_mode() { return display_mode; }
  262. void set_file_sort(FileSortOption p_file_sort);
  263. FileSortOption get_file_sort() { return file_sort; }
  264. void set_file_list_display_mode(FileListDisplayMode p_mode);
  265. FileListDisplayMode get_file_list_display_mode() { return file_list_display_mode; };
  266. FileSystemDock(EditorNode *p_editor);
  267. ~FileSystemDock();
  268. };
  269. #endif // FILESYSTEM_DOCK_H