filesystem_dock.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*************************************************************************/
  2. /* filesystem_dock.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 FileSystemDock : public VBoxContainer {
  53. GDCLASS(FileSystemDock, VBoxContainer);
  54. public:
  55. enum FileListDisplayMode {
  56. FILE_LIST_DISPLAY_THUMBNAILS,
  57. FILE_LIST_DISPLAY_LIST
  58. };
  59. enum DisplayMode {
  60. DISPLAY_MODE_TREE_ONLY,
  61. DISPLAY_MODE_SPLIT,
  62. };
  63. private:
  64. enum FileMenu {
  65. FILE_OPEN,
  66. FILE_INSTANCE,
  67. FILE_ADD_FAVORITE,
  68. FILE_REMOVE_FAVORITE,
  69. FILE_DEPENDENCIES,
  70. FILE_OWNERS,
  71. FILE_MOVE,
  72. FILE_RENAME,
  73. FILE_REMOVE,
  74. FILE_DUPLICATE,
  75. FILE_REIMPORT,
  76. FILE_INFO,
  77. FILE_NEW_FOLDER,
  78. FILE_NEW_SCRIPT,
  79. FILE_SHOW_IN_EXPLORER,
  80. FILE_COPY_PATH,
  81. FILE_NEW_RESOURCE,
  82. FOLDER_EXPAND_ALL,
  83. FOLDER_COLLAPSE_ALL,
  84. };
  85. VBoxContainer *scanning_vb;
  86. ProgressBar *scanning_progress;
  87. VSplitContainer *split_box;
  88. VBoxContainer *file_list_vb;
  89. EditorNode *editor;
  90. Set<String> favorites;
  91. Button *button_toggle_display_mode;
  92. Button *button_reload;
  93. Button *button_file_list_display_mode;
  94. Button *button_hist_next;
  95. Button *button_hist_prev;
  96. LineEdit *current_path;
  97. LineEdit *tree_search_box;
  98. LineEdit *file_list_search_box;
  99. String searched_string;
  100. Vector<String> uncollapsed_paths_before_search;
  101. TextureRect *search_icon;
  102. HBoxContainer *path_hb;
  103. FileListDisplayMode file_list_display_mode;
  104. DisplayMode display_mode;
  105. DisplayMode old_display_mode;
  106. PopupMenu *file_list_popup;
  107. PopupMenu *tree_popup;
  108. DependencyEditor *deps_editor;
  109. DependencyEditorOwners *owners_editor;
  110. DependencyRemoveDialog *remove_dialog;
  111. EditorDirDialog *move_dialog;
  112. ConfirmationDialog *rename_dialog;
  113. LineEdit *rename_dialog_text;
  114. ConfirmationDialog *duplicate_dialog;
  115. LineEdit *duplicate_dialog_text;
  116. ConfirmationDialog *make_dir_dialog;
  117. LineEdit *make_dir_dialog_text;
  118. ConfirmationDialog *overwrite_dialog;
  119. ScriptCreateDialog *make_script_dialog_text;
  120. CreateDialog *new_resource_dialog;
  121. bool always_show_folders;
  122. class FileOrFolder {
  123. public:
  124. String path;
  125. bool is_file;
  126. FileOrFolder() :
  127. path(""),
  128. is_file(false) {}
  129. FileOrFolder(const String &p_path, bool p_is_file) :
  130. path(p_path),
  131. is_file(p_is_file) {}
  132. };
  133. FileOrFolder to_rename;
  134. FileOrFolder to_duplicate;
  135. Vector<FileOrFolder> to_move;
  136. String to_move_path;
  137. Vector<String> history;
  138. int history_pos;
  139. int history_max_size;
  140. String path;
  141. bool initialized;
  142. bool updating_tree;
  143. int tree_update_id;
  144. Tree *tree; //directories
  145. ItemList *files;
  146. bool import_dock_needs_update;
  147. Ref<Texture> _get_tree_item_icon(EditorFileSystemDirectory *p_dir, int p_idx);
  148. bool _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites);
  149. Vector<String> _compute_uncollapsed_paths();
  150. void _update_tree(const Vector<String> p_uncollapsed_paths = Vector<String>(), bool p_uncollapse_root = false, bool p_select_in_favorites = false);
  151. void _navigate_to_path(const String &p_path, bool p_select_in_favorites = false);
  152. void _file_list_gui_input(Ref<InputEvent> p_event);
  153. void _tree_gui_input(Ref<InputEvent> p_event);
  154. void _update_file_list(bool p_keep_selection);
  155. void _toggle_file_display();
  156. void _set_file_display(bool p_active);
  157. void _fs_changed();
  158. void _tree_toggle_collapsed();
  159. void _select_file(const String p_path, bool p_select_in_favorites = false);
  160. void _tree_activate_file();
  161. void _file_list_activate_file(int p_idx);
  162. void _file_multi_selected(int p_index, bool p_selected);
  163. void _tree_multi_selected(Object *p_item, int p_column, bool p_selected);
  164. void _update_import_dock();
  165. void _get_all_items_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files, Vector<String> &folders) const;
  166. void _find_remaps(EditorFileSystemDirectory *efsd, const Map<String, String> &renames, Vector<String> &to_remaps) const;
  167. 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);
  168. void _try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const;
  169. void _update_dependencies_after_move(const Map<String, String> &p_renames) const;
  170. void _update_resource_paths_after_move(const Map<String, String> &p_renames) const;
  171. void _save_scenes_after_move(const Map<String, String> &p_renames) const;
  172. void _update_favorites_list_after_move(const Map<String, String> &p_files_renames, const Map<String, String> &p_folders_renames) const;
  173. void _update_project_settings_after_move(const Map<String, String> &p_folders_renames) const;
  174. void _file_deleted(String p_file);
  175. void _folder_deleted(String p_folder);
  176. void _files_moved(String p_old_file, String p_new_file);
  177. void _folder_moved(String p_old_folder, String p_new_folder);
  178. void _resource_created() const;
  179. void _make_dir_confirm();
  180. void _rename_operation_confirm();
  181. void _duplicate_operation_confirm();
  182. void _move_with_overwrite();
  183. bool _check_existing();
  184. void _move_operation_confirm(const String &p_to_path, bool overwrite = false);
  185. void _tree_rmb_option(int p_option);
  186. void _file_list_rmb_option(int p_option);
  187. void _file_option(int p_option, const Vector<String> p_selected);
  188. void _fw_history();
  189. void _bw_history();
  190. void _update_history();
  191. void _push_to_history();
  192. void _set_scanning_mode();
  193. void _rescan();
  194. void _toggle_split_mode(bool p_active);
  195. void _search_changed(const String &p_text, const Control *p_from);
  196. void _file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options = true);
  197. void _tree_rmb_select(const Vector2 &p_pos);
  198. void _file_list_rmb_select(int p_item, const Vector2 &p_pos);
  199. void _file_list_rmb_pressed(const Vector2 &p_pos);
  200. void _tree_empty_selected();
  201. struct FileInfo {
  202. String name;
  203. String path;
  204. StringName type;
  205. int import_status; //0 not imported, 1 - ok, 2- must reimport, 3- broken
  206. Vector<String> sources;
  207. bool import_broken;
  208. bool operator<(const FileInfo &fi) const {
  209. return NaturalNoCaseComparator()(name, fi.name);
  210. }
  211. };
  212. void _search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items);
  213. void _set_current_path_text(const String &p_path);
  214. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  215. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  216. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  217. void _get_drag_target_folder(String &target, bool &target_favorites, const Point2 &p_point, Control *p_from) const;
  218. void _preview_invalidated(const String &p_path);
  219. void _file_list_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
  220. void _tree_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
  221. void _update_display_mode(bool p_force = false);
  222. Vector<String> _tree_get_selected(bool remove_self_inclusion = true);
  223. protected:
  224. void _notification(int p_what);
  225. static void _bind_methods();
  226. public:
  227. String get_selected_path() const;
  228. String get_current_path() const;
  229. void navigate_to_path(const String &p_path);
  230. void focus_on_filter();
  231. void fix_dependencies(const String &p_for_file);
  232. int get_split_offset() { return split_box->get_split_offset(); }
  233. void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); }
  234. void select_file(const String &p_file);
  235. void set_display_mode(DisplayMode p_display_mode);
  236. DisplayMode get_display_mode() { return display_mode; }
  237. void set_file_list_display_mode(FileListDisplayMode p_mode);
  238. FileListDisplayMode get_file_list_display_mode() { return file_list_display_mode; };
  239. FileSystemDock(EditorNode *p_editor);
  240. ~FileSystemDock();
  241. };
  242. #endif // SCENES_DOCK_H