filesystem_dock.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*************************************************************************/
  2. /* scenes_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/item_list.h"
  35. #include "scene/gui/label.h"
  36. #include "scene/gui/menu_button.h"
  37. #include "scene/gui/option_button.h"
  38. #include "scene/gui/progress_bar.h"
  39. #include "scene/gui/split_container.h"
  40. #include "scene/gui/tool_button.h"
  41. #include "scene/gui/tree.h"
  42. #include "scene/main/timer.h"
  43. #include "os/dir_access.h"
  44. #include "os/thread.h"
  45. #include "dependency_editor.h"
  46. #include "editor_dir_dialog.h"
  47. #include "editor_file_system.h"
  48. class EditorNode;
  49. class FileSystemDock : public VBoxContainer {
  50. OBJ_TYPE(FileSystemDock, VBoxContainer);
  51. public:
  52. enum DisplayMode {
  53. DISPLAY_THUMBNAILS,
  54. DISPLAY_LIST
  55. };
  56. private:
  57. enum FileMenu {
  58. FILE_OPEN,
  59. FILE_INSTANCE,
  60. FILE_DEPENDENCIES,
  61. FILE_OWNERS,
  62. FILE_MOVE,
  63. FILE_REMOVE,
  64. FILE_REIMPORT,
  65. FILE_INFO,
  66. FILE_SHOW_IN_EXPLORER,
  67. FILE_COPY_PATH
  68. };
  69. enum FolderMenu {
  70. FOLDER_EXPAND_ALL,
  71. FOLDER_COLLAPSE_ALL,
  72. FOLDER_MOVE,
  73. FOLDER_RENAME,
  74. FOLDER_REMOVE,
  75. FOLDER_NEW_FOLDER,
  76. FOLDER_SHOW_IN_EXPLORER,
  77. FOLDER_COPY_PATH
  78. };
  79. VBoxContainer *scanning_vb;
  80. ProgressBar *scanning_progress;
  81. VSplitContainer *split_box;
  82. VBoxContainer *file_list_vb;
  83. EditorNode *editor;
  84. Set<String> favorites;
  85. Button *button_reload;
  86. Button *button_favorite;
  87. Button *button_back;
  88. Button *button_display_mode;
  89. Button *button_hist_next;
  90. Button *button_hist_prev;
  91. LineEdit *current_path;
  92. LineEdit *search_box;
  93. TextureFrame *search_icon;
  94. HBoxContainer *path_hb;
  95. class FileOrFolder {
  96. public:
  97. String path;
  98. bool is_file;
  99. FileOrFolder() :
  100. path(""),
  101. is_file(false) {}
  102. FileOrFolder(const String &p_path, bool p_is_file) :
  103. path(p_path),
  104. is_file(p_is_file) {}
  105. };
  106. FileOrFolder to_rename;
  107. Vector<FileOrFolder> to_move;
  108. bool split_mode;
  109. DisplayMode display_mode;
  110. PopupMenu *file_options;
  111. PopupMenu *folder_options;
  112. DependencyEditor *deps_editor;
  113. DependencyEditorOwners *owners_editor;
  114. DependencyRemoveDialog *remove_dialog;
  115. EditorDirDialog *move_dialog;
  116. EditorDirDialog *move_dir_dialog;
  117. EditorFileDialog *rename_dialog;
  118. ConfirmationDialog *make_dir_dialog;
  119. ConfirmationDialog *rename_dir_dialog;
  120. LineEdit *rename_dialog_text;
  121. LineEdit *make_dir_dialog_text;
  122. Vector<String> move_dirs;
  123. Vector<String> move_files;
  124. Vector<String> history;
  125. int history_pos;
  126. String path;
  127. bool initialized;
  128. bool updating_tree;
  129. Tree *tree; //directories
  130. ItemList *files;
  131. void _go_to_tree();
  132. void _go_to_dir(const String &p_dir);
  133. void _select_file(int p_idx);
  134. bool _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir);
  135. void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
  136. void _find_inside_move_files(EditorFileSystemDirectory *efsd, Vector<String> &files);
  137. void _find_remaps(EditorFileSystemDirectory *efsd, Map<String, String> &renames, List<String> &to_remaps);
  138. void _rename_operation(const String &p_to_path);
  139. void _move_operation(const String &p_to_path);
  140. void _file_option(int p_option);
  141. void _folder_option(int p_option);
  142. void _update_files(bool p_keep_selection);
  143. void _change_file_display();
  144. void _fs_changed();
  145. void _fw_history();
  146. void _bw_history();
  147. void _push_to_history();
  148. void _dir_selected();
  149. void _dir_rmb_pressed(const Vector2 &p_pos);
  150. void _make_dir_confirm();
  151. void _rename_operation_confirm();
  152. void _move_operation_confirm(const String &p_to_path);
  153. void _try_move_item(const FileOrFolder &p_item, const String &p_new_path, Map<String, String> &p_renames);
  154. void _get_all_files_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files);
  155. void _update_dependencies_after_move(Map<String, String> &p_renames);
  156. void _update_tree();
  157. void _rescan();
  158. void _set_scanning_mode();
  159. void _favorites_pressed();
  160. void _open_pressed();
  161. void _search_changed(const String &p_text);
  162. void _files_list_rmb_select(int p_item, const Vector2 &p_pos);
  163. struct FileInfo {
  164. String name;
  165. String path;
  166. StringName type;
  167. int import_status; //0 not imported, 1 - ok, 2- must reimport, 3- broken
  168. Vector<String> sources;
  169. bool operator<(const FileInfo &fi) const {
  170. return name < fi.name;
  171. }
  172. };
  173. void _search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items);
  174. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  175. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  176. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  177. void _preview_invalidated(const String &p_path);
  178. protected:
  179. void _notification(int p_what);
  180. static void _bind_methods();
  181. public:
  182. String get_selected_path() const;
  183. void navigate_to_path(const String &p_path);
  184. String get_current_path() const;
  185. void focus_on_filter();
  186. void fix_dependencies(const String &p_for_file);
  187. void set_display_mode(int p_mode);
  188. int get_split_offset() { return split_box->get_split_offset(); }
  189. void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); }
  190. FileSystemDock(EditorNode *p_editor);
  191. ~FileSystemDock();
  192. };
  193. #endif // SCENES_DOCK_H