filesystem_dock.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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/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. GDCLASS(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_SHOW_IN_EXPLORER,
  73. FOLDER_COPY_PATH
  74. };
  75. VBoxContainer *scanning_vb;
  76. ProgressBar *scanning_progress;
  77. VSplitContainer *split_box;
  78. VBoxContainer *file_list_vb;
  79. EditorNode *editor;
  80. Set<String> favorites;
  81. Button *button_reload;
  82. Button *button_favorite;
  83. Button *button_back;
  84. Button *button_display_mode;
  85. Button *button_hist_next;
  86. Button *button_hist_prev;
  87. LineEdit *current_path;
  88. LineEdit *search_box;
  89. TextureRect *search_icon;
  90. HBoxContainer *path_hb;
  91. bool split_mode;
  92. DisplayMode display_mode;
  93. PopupMenu *file_options;
  94. PopupMenu *folder_options;
  95. DependencyEditor *deps_editor;
  96. DependencyEditorOwners *owners_editor;
  97. DependencyRemoveDialog *remove_dialog;
  98. EditorDirDialog *move_dialog;
  99. EditorFileDialog *rename_dialog;
  100. Vector<String> move_dirs;
  101. Vector<String> move_files;
  102. Vector<String> history;
  103. int history_pos;
  104. String path;
  105. bool initialized;
  106. bool updating_tree;
  107. Tree *tree; //directories
  108. ItemList *files;
  109. void _file_multi_selected(int p_index, bool p_selected);
  110. void _file_selected();
  111. void _go_to_tree();
  112. void _go_to_dir(const String &p_dir);
  113. void _select_file(int p_idx);
  114. bool _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir);
  115. void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
  116. void _find_inside_move_files(EditorFileSystemDirectory *efsd, Vector<String> &files);
  117. void _find_remaps(EditorFileSystemDirectory *efsd, Map<String, String> &renames, List<String> &to_remaps);
  118. void _rename_operation(const String &p_to_path);
  119. void _move_operation(const String &p_to_path);
  120. void _file_option(int p_option);
  121. void _folder_option(int p_option);
  122. void _update_files(bool p_keep_selection);
  123. void _update_file_display_toggle_button();
  124. void _change_file_display();
  125. void _fs_changed();
  126. void _fw_history();
  127. void _bw_history();
  128. void _push_to_history();
  129. void _dir_selected();
  130. void _update_tree();
  131. void _rescan();
  132. void _set_scanning_mode();
  133. void _favorites_pressed();
  134. void _open_pressed();
  135. void _dir_rmb_pressed(const Vector2 &p_pos);
  136. void _search_changed(const String &p_text);
  137. void _files_list_rmb_select(int p_item, const Vector2 &p_pos);
  138. struct FileInfo {
  139. String name;
  140. String path;
  141. StringName type;
  142. int import_status; //0 not imported, 1 - ok, 2- must reimport, 3- broken
  143. Vector<String> sources;
  144. bool import_broken;
  145. bool operator<(const FileInfo &fi) const {
  146. return name < fi.name;
  147. }
  148. };
  149. void _search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items);
  150. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  151. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  152. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  153. void _preview_invalidated(const String &p_path);
  154. protected:
  155. void _notification(int p_what);
  156. static void _bind_methods();
  157. public:
  158. String get_selected_path() const;
  159. String get_current_path() const;
  160. void navigate_to_path(const String &p_path);
  161. void focus_on_filter();
  162. void fix_dependencies(const String &p_for_file);
  163. void set_display_mode(int p_mode);
  164. int get_split_offset() { return split_box->get_split_offset(); }
  165. void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); }
  166. void select_file(const String &p_file);
  167. FileSystemDock(EditorNode *p_editor);
  168. ~FileSystemDock();
  169. };
  170. #endif // SCENES_DOCK_H