project_manager.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /**************************************************************************/
  2. /* project_manager.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #pragma once
  31. #include "scene/gui/dialogs.h"
  32. #include "scene/gui/scroll_container.h"
  33. class CheckBox;
  34. class EditorAbout;
  35. class EditorAssetLibrary;
  36. class EditorFileDialog;
  37. class EditorTitleBar;
  38. class HFlowContainer;
  39. class LineEdit;
  40. class MarginContainer;
  41. class OptionButton;
  42. class PanelContainer;
  43. class PopupMenu;
  44. class ProjectDialog;
  45. class ProjectList;
  46. class QuickSettingsDialog;
  47. class RichTextLabel;
  48. class TabContainer;
  49. class VBoxContainer;
  50. class ProjectManager : public Control {
  51. GDCLASS(ProjectManager, Control);
  52. static ProjectManager *singleton;
  53. // Utility data.
  54. static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
  55. static Ref<Texture2D> _file_dialog_get_thumbnail(const String &p_path);
  56. HashMap<String, Ref<Texture2D>> icon_type_cache;
  57. void _build_icon_type_cache(Ref<Theme> p_theme);
  58. enum PostDuplicateAction {
  59. POST_DUPLICATE_ACTION_NONE,
  60. POST_DUPLICATE_ACTION_OPEN,
  61. POST_DUPLICATE_ACTION_FULL_CONVERSION,
  62. };
  63. PostDuplicateAction post_duplicate_action = POST_DUPLICATE_ACTION_NONE;
  64. // Main layout.
  65. Ref<Theme> theme;
  66. void _update_size_limits();
  67. void _update_theme(bool p_skip_creation = false);
  68. void _titlebar_resized();
  69. MarginContainer *root_container = nullptr;
  70. Panel *background_panel = nullptr;
  71. VBoxContainer *main_vbox = nullptr;
  72. EditorTitleBar *title_bar = nullptr;
  73. Control *left_menu_spacer = nullptr;
  74. Control *left_spacer = nullptr;
  75. Control *right_menu_spacer = nullptr;
  76. Control *right_spacer = nullptr;
  77. Button *title_bar_logo = nullptr;
  78. HBoxContainer *main_view_toggles = nullptr;
  79. Button *quick_settings_button = nullptr;
  80. enum MainViewTab {
  81. MAIN_VIEW_PROJECTS,
  82. MAIN_VIEW_ASSETLIB,
  83. MAIN_VIEW_MAX
  84. };
  85. MainViewTab current_main_view = MAIN_VIEW_PROJECTS;
  86. HashMap<MainViewTab, Control *> main_view_map;
  87. HashMap<MainViewTab, Button *> main_view_toggle_map;
  88. PanelContainer *main_view_container = nullptr;
  89. Ref<ButtonGroup> main_view_toggles_group;
  90. Button *_add_main_view(MainViewTab p_id, const String &p_name, const Ref<Texture2D> &p_icon, Control *p_view_control);
  91. void _set_main_view_icon(MainViewTab p_id, const Ref<Texture2D> &p_icon);
  92. void _select_main_view(int p_id);
  93. VBoxContainer *local_projects_vb = nullptr;
  94. EditorAssetLibrary *asset_library = nullptr;
  95. EditorAbout *about_dialog = nullptr;
  96. void _show_about();
  97. void _open_asset_library_confirmed();
  98. AcceptDialog *error_dialog = nullptr;
  99. void _show_error(const String &p_message, const Size2 &p_min_size = Size2());
  100. void _dim_window();
  101. // Quick settings.
  102. QuickSettingsDialog *quick_settings_dialog = nullptr;
  103. void _show_quick_settings();
  104. void _restart_confirmed();
  105. // Project list.
  106. VBoxContainer *empty_list_placeholder = nullptr;
  107. RichTextLabel *empty_list_message = nullptr;
  108. Button *empty_list_create_project = nullptr;
  109. Button *empty_list_import_project = nullptr;
  110. Button *empty_list_open_assetlib = nullptr;
  111. Label *empty_list_online_warning = nullptr;
  112. void _update_list_placeholder();
  113. ProjectList *project_list = nullptr;
  114. bool initialized = false;
  115. LineEdit *search_box = nullptr;
  116. Label *loading_label = nullptr;
  117. Label *sort_label = nullptr;
  118. OptionButton *filter_option = nullptr;
  119. PanelContainer *project_list_panel = nullptr;
  120. Button *create_btn = nullptr;
  121. Button *import_btn = nullptr;
  122. Button *scan_btn = nullptr;
  123. Button *open_btn = nullptr;
  124. Button *open_options_btn = nullptr;
  125. Button *run_btn = nullptr;
  126. Button *rename_btn = nullptr;
  127. Button *duplicate_btn = nullptr;
  128. Button *manage_tags_btn = nullptr;
  129. Button *erase_btn = nullptr;
  130. Button *erase_missing_btn = nullptr;
  131. HBoxContainer *open_btn_container = nullptr;
  132. PopupMenu *open_options_popup = nullptr;
  133. EditorFileDialog *scan_dir = nullptr;
  134. ConfirmationDialog *erase_ask = nullptr;
  135. Label *erase_ask_label = nullptr;
  136. // Comment out for now until we have a better warning system to
  137. // ensure users delete their project only.
  138. //CheckBox *delete_project_contents = nullptr;
  139. ConfirmationDialog *erase_missing_ask = nullptr;
  140. ConfirmationDialog *multi_open_ask = nullptr;
  141. ConfirmationDialog *multi_run_ask = nullptr;
  142. ConfirmationDialog *open_recovery_mode_ask = nullptr;
  143. ProjectDialog *project_dialog = nullptr;
  144. void _scan_projects();
  145. void _run_project();
  146. void _run_project_confirm();
  147. void _open_selected_projects();
  148. void _open_selected_projects_with_migration();
  149. void _open_selected_projects_check_warnings();
  150. void _open_selected_projects_check_recovery_mode();
  151. void _install_project(const String &p_zip_path, const String &p_title);
  152. void _import_project();
  153. void _new_project();
  154. void _rename_project();
  155. void _duplicate_project();
  156. void _duplicate_project_with_action(PostDuplicateAction p_action);
  157. void _erase_project();
  158. void _erase_missing_projects();
  159. void _erase_project_confirm();
  160. void _erase_missing_projects_confirm();
  161. void _update_project_buttons();
  162. void _open_options_popup();
  163. void _open_recovery_mode_ask(bool manual = false);
  164. void _on_project_created(const String &dir, bool edit);
  165. void _on_project_duplicated(const String &p_original_path, const String &p_duplicate_path, bool p_edit);
  166. void _on_projects_updated();
  167. void _on_open_options_selected(int p_option);
  168. void _on_recovery_mode_popup_open_normal();
  169. void _on_recovery_mode_popup_open_recovery();
  170. void _on_order_option_changed(int p_idx);
  171. void _on_search_term_changed(const String &p_term);
  172. void _on_search_term_submitted(const String &p_text);
  173. // Project tag management.
  174. HashSet<String> tag_set;
  175. PackedStringArray current_project_tags;
  176. PackedStringArray forbidden_tag_characters{ "/", "\\", "-" };
  177. ConfirmationDialog *tag_manage_dialog = nullptr;
  178. HFlowContainer *project_tags = nullptr;
  179. HFlowContainer *all_tags = nullptr;
  180. Label *tag_edit_error = nullptr;
  181. Button *create_tag_btn = nullptr;
  182. ConfirmationDialog *create_tag_dialog = nullptr;
  183. LineEdit *new_tag_name = nullptr;
  184. Label *tag_error = nullptr;
  185. void _manage_project_tags();
  186. void _add_project_tag(const String &p_tag);
  187. void _delete_project_tag(const String &p_tag);
  188. void _apply_project_tags();
  189. void _set_new_tag_name(const String p_name);
  190. void _create_new_tag();
  191. // Project converter/migration tool.
  192. ConfirmationDialog *ask_full_convert_dialog = nullptr;
  193. ConfirmationDialog *ask_update_settings = nullptr;
  194. VBoxContainer *ask_update_vb = nullptr;
  195. Label *ask_update_label = nullptr;
  196. CheckBox *ask_update_backup = nullptr;
  197. Button *full_convert_button = nullptr;
  198. Button *migration_guide_button = nullptr;
  199. String version_convert_feature;
  200. bool open_in_recovery_mode = false;
  201. bool open_in_verbose_mode = false;
  202. #ifndef DISABLE_DEPRECATED
  203. void _minor_project_migrate();
  204. #endif
  205. void _full_convert_button_pressed();
  206. void _migration_guide_button_pressed();
  207. void _perform_full_project_conversion();
  208. // Input and I/O.
  209. virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
  210. void _files_dropped(PackedStringArray p_files);
  211. protected:
  212. void _notification(int p_what);
  213. public:
  214. static ProjectManager *get_singleton() { return singleton; }
  215. static constexpr int DEFAULT_WINDOW_WIDTH = 1152;
  216. static constexpr int DEFAULT_WINDOW_HEIGHT = 800;
  217. // Project list.
  218. bool is_initialized() const { return initialized; }
  219. LineEdit *get_search_box();
  220. // Project tag management.
  221. void add_new_tag(const String &p_tag);
  222. ProjectManager();
  223. ~ProjectManager();
  224. };