filesystem_dock.h 7.2 KB

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