filesystem_dock.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*************************************************************************/
  2. /* filesystem_dock.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 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 "os/dir_access.h"
  45. #include "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. private:
  60. enum DisplayMode {
  61. DISPLAY_TREE_ONLY,
  62. DISPLAY_FILE_LIST_ONLY,
  63. DISPLAY_SPLIT,
  64. };
  65. enum FileMenu {
  66. FILE_OPEN,
  67. FILE_INSTANCE,
  68. FILE_DEPENDENCIES,
  69. FILE_OWNERS,
  70. FILE_MOVE,
  71. FILE_RENAME,
  72. FILE_REMOVE,
  73. FILE_DUPLICATE,
  74. FILE_REIMPORT,
  75. FILE_INFO,
  76. FILE_NEW_FOLDER,
  77. FILE_NEW_SCRIPT,
  78. FILE_SHOW_IN_EXPLORER,
  79. FILE_COPY_PATH,
  80. FILE_NEW_RESOURCE
  81. };
  82. enum FolderMenu {
  83. FOLDER_EXPAND_ALL,
  84. FOLDER_COLLAPSE_ALL,
  85. FOLDER_MOVE,
  86. FOLDER_RENAME,
  87. FOLDER_REMOVE,
  88. FOLDER_NEW_FOLDER,
  89. FOLDER_SHOW_IN_EXPLORER,
  90. FOLDER_COPY_PATH
  91. };
  92. VBoxContainer *scanning_vb;
  93. ProgressBar *scanning_progress;
  94. VSplitContainer *split_box;
  95. VBoxContainer *file_list_vb;
  96. EditorNode *editor;
  97. Set<String> favorites;
  98. Button *button_reload;
  99. Button *button_favorite;
  100. Button *button_tree;
  101. Button *button_file_list_display_mode;
  102. Button *button_hist_next;
  103. Button *button_hist_prev;
  104. Button *button_show;
  105. LineEdit *current_path;
  106. LineEdit *search_box;
  107. TextureRect *search_icon;
  108. HBoxContainer *path_hb;
  109. FileListDisplayMode file_list_display_mode;
  110. DisplayMode display_mode;
  111. bool file_list_view;
  112. PopupMenu *file_options;
  113. PopupMenu *folder_options;
  114. DependencyEditor *deps_editor;
  115. DependencyEditorOwners *owners_editor;
  116. DependencyRemoveDialog *remove_dialog;
  117. EditorDirDialog *move_dialog;
  118. ConfirmationDialog *rename_dialog;
  119. LineEdit *rename_dialog_text;
  120. ConfirmationDialog *duplicate_dialog;
  121. LineEdit *duplicate_dialog_text;
  122. ConfirmationDialog *make_dir_dialog;
  123. LineEdit *make_dir_dialog_text;
  124. ConfirmationDialog *overwrite_dialog;
  125. ScriptCreateDialog *make_script_dialog_text;
  126. CreateDialog *new_resource_dialog;
  127. class FileOrFolder {
  128. public:
  129. String path;
  130. bool is_file;
  131. FileOrFolder() :
  132. path(""),
  133. is_file(false) {}
  134. FileOrFolder(const String &p_path, bool p_is_file) :
  135. path(p_path),
  136. is_file(p_is_file) {}
  137. };
  138. FileOrFolder to_rename;
  139. FileOrFolder to_duplicate;
  140. Vector<FileOrFolder> to_move;
  141. String to_move_path;
  142. Vector<String> history;
  143. int history_pos;
  144. int history_max_size;
  145. String path;
  146. bool initialized;
  147. bool updating_tree;
  148. Tree *tree; //directories
  149. ItemList *files;
  150. bool import_dock_needs_update;
  151. bool _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths);
  152. void _update_tree(bool keep_collapse_state, bool p_uncollapse_root = false);
  153. void _files_gui_input(Ref<InputEvent> p_event);
  154. void _update_files(bool p_keep_selection);
  155. void _update_file_list_display_mode_button();
  156. void _change_file_display();
  157. void _fs_changed();
  158. void _go_to_tree();
  159. void _go_to_file_list();
  160. void _select_file(int p_idx);
  161. void _file_multi_selected(int p_index, bool p_selected);
  162. void _update_import_dock();
  163. void _file_selected();
  164. void _dir_selected();
  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) const;
  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 _update_favorite_dirs_list_after_move(const Map<String, String> &p_renames) const;
  172. void _update_project_settings_after_move(const Map<String, String> &p_renames) const;
  173. void _resource_created() const;
  174. void _make_dir_confirm();
  175. void _rename_operation_confirm();
  176. void _duplicate_operation_confirm();
  177. void _move_with_overwrite();
  178. bool _check_existing();
  179. void _move_operation_confirm(const String &p_to_path, bool overwrite = false);
  180. void _file_option(int p_option);
  181. void _folder_option(int p_option);
  182. void _fw_history();
  183. void _bw_history();
  184. void _update_history();
  185. void _push_to_history();
  186. void _set_scanning_mode();
  187. void _rescan();
  188. void _favorites_pressed();
  189. void _show_current_scene_file();
  190. void _search_changed(const String &p_text);
  191. void _dir_rmb_pressed(const Vector2 &p_pos);
  192. void _files_list_rmb_select(int p_item, const Vector2 &p_pos);
  193. void _rmb_pressed(const Vector2 &p_pos);
  194. struct FileInfo {
  195. String name;
  196. String path;
  197. StringName type;
  198. int import_status; //0 not imported, 1 - ok, 2- must reimport, 3- broken
  199. Vector<String> sources;
  200. bool import_broken;
  201. bool operator<(const FileInfo &fi) const {
  202. return name < fi.name;
  203. }
  204. };
  205. void _search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items);
  206. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  207. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  208. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  209. String _get_drag_target_folder(const Point2 &p_point, Control *p_from) const;
  210. void _preview_invalidated(const String &p_path);
  211. void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
  212. void _update_display_mode();
  213. protected:
  214. void _notification(int p_what);
  215. static void _bind_methods();
  216. public:
  217. String get_selected_path() const;
  218. String get_current_path() const;
  219. void navigate_to_path(const String &p_path);
  220. void focus_on_filter();
  221. void fix_dependencies(const String &p_for_file);
  222. void set_file_list_display_mode(int p_mode);
  223. int get_split_offset() { return split_box->get_split_offset(); }
  224. void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); }
  225. void select_file(const String &p_file);
  226. FileSystemDock(EditorNode *p_editor);
  227. ~FileSystemDock();
  228. };
  229. #endif // SCENES_DOCK_H