project_manager.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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. #ifndef PROJECT_MANAGER_H
  31. #define PROJECT_MANAGER_H
  32. #include "core/io/config_file.h"
  33. #include "editor/editor_about.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/file_dialog.h"
  36. #include "scene/gui/scroll_container.h"
  37. class CheckBox;
  38. class EditorAssetLibrary;
  39. class EditorFileDialog;
  40. class HFlowContainer;
  41. class PanelContainer;
  42. class ProjectList;
  43. class ProjectDialog : public ConfirmationDialog {
  44. GDCLASS(ProjectDialog, ConfirmationDialog);
  45. public:
  46. enum Mode {
  47. MODE_NEW,
  48. MODE_IMPORT,
  49. MODE_INSTALL,
  50. MODE_RENAME,
  51. };
  52. private:
  53. enum MessageType {
  54. MESSAGE_ERROR,
  55. MESSAGE_WARNING,
  56. MESSAGE_SUCCESS,
  57. };
  58. enum InputType {
  59. PROJECT_PATH,
  60. INSTALL_PATH,
  61. };
  62. Mode mode = MODE_NEW;
  63. bool is_folder_empty = true;
  64. Button *browse = nullptr;
  65. Button *install_browse = nullptr;
  66. Button *create_dir = nullptr;
  67. Container *name_container = nullptr;
  68. Container *path_container = nullptr;
  69. Container *install_path_container = nullptr;
  70. Container *renderer_container = nullptr;
  71. Label *renderer_info = nullptr;
  72. HBoxContainer *default_files_container = nullptr;
  73. Ref<ButtonGroup> renderer_button_group;
  74. Label *msg = nullptr;
  75. LineEdit *project_path = nullptr;
  76. LineEdit *project_name = nullptr;
  77. LineEdit *install_path = nullptr;
  78. TextureRect *status_rect = nullptr;
  79. TextureRect *install_status_rect = nullptr;
  80. OptionButton *vcs_metadata_selection = nullptr;
  81. EditorFileDialog *fdialog = nullptr;
  82. EditorFileDialog *fdialog_install = nullptr;
  83. AcceptDialog *dialog_error = nullptr;
  84. String zip_path;
  85. String zip_title;
  86. String fav_dir;
  87. String created_folder_path;
  88. void _set_message(const String &p_msg, MessageType p_type = MESSAGE_SUCCESS, InputType input_type = PROJECT_PATH);
  89. String _test_path();
  90. void _path_text_changed(const String &p_path);
  91. void _path_selected(const String &p_path);
  92. void _file_selected(const String &p_path);
  93. void _install_path_selected(const String &p_path);
  94. void _browse_path();
  95. void _browse_install_path();
  96. void _create_folder();
  97. void _text_changed(const String &p_text);
  98. void _nonempty_confirmation_ok_pressed();
  99. void _renderer_selected();
  100. void _remove_created_folder();
  101. void ok_pressed() override;
  102. void cancel_pressed() override;
  103. protected:
  104. void _notification(int p_what);
  105. static void _bind_methods();
  106. public:
  107. void set_zip_path(const String &p_path);
  108. void set_zip_title(const String &p_title);
  109. void set_mode(Mode p_mode);
  110. void set_project_path(const String &p_path);
  111. void show_dialog();
  112. ProjectDialog();
  113. };
  114. class ProjectListItemControl : public HBoxContainer {
  115. GDCLASS(ProjectListItemControl, HBoxContainer)
  116. VBoxContainer *main_vbox = nullptr;
  117. TextureButton *favorite_button = nullptr;
  118. Button *explore_button = nullptr;
  119. TextureRect *project_icon = nullptr;
  120. Label *project_title = nullptr;
  121. Label *project_path = nullptr;
  122. TextureRect *project_unsupported_features = nullptr;
  123. HBoxContainer *tag_container = nullptr;
  124. bool project_is_missing = false;
  125. bool icon_needs_reload = true;
  126. bool is_selected = false;
  127. bool is_hovering = false;
  128. void _favorite_button_pressed();
  129. void _explore_button_pressed();
  130. protected:
  131. void _notification(int p_what);
  132. static void _bind_methods();
  133. public:
  134. void set_project_title(const String &p_title);
  135. void set_project_path(const String &p_path);
  136. void set_tags(const PackedStringArray &p_tags, ProjectList *p_parent_list);
  137. void set_project_icon(const Ref<Texture2D> &p_icon);
  138. void set_unsupported_features(PackedStringArray p_features);
  139. bool should_load_project_icon() const;
  140. void set_selected(bool p_selected);
  141. void set_is_favorite(bool p_favorite);
  142. void set_is_missing(bool p_missing);
  143. void set_is_grayed(bool p_grayed);
  144. ProjectListItemControl();
  145. };
  146. class ProjectList : public ScrollContainer {
  147. GDCLASS(ProjectList, ScrollContainer)
  148. friend class ProjectManager;
  149. public:
  150. enum FilterOption {
  151. EDIT_DATE,
  152. NAME,
  153. PATH,
  154. TAGS,
  155. };
  156. // Can often be passed by copy
  157. struct Item {
  158. String project_name;
  159. String description;
  160. PackedStringArray tags;
  161. String tag_sort_string;
  162. String path;
  163. String icon;
  164. String main_scene;
  165. PackedStringArray unsupported_features;
  166. uint64_t last_edited = 0;
  167. bool favorite = false;
  168. bool grayed = false;
  169. bool missing = false;
  170. int version = 0;
  171. ProjectListItemControl *control = nullptr;
  172. Item() {}
  173. Item(const String &p_name,
  174. const String &p_description,
  175. const PackedStringArray &p_tags,
  176. const String &p_path,
  177. const String &p_icon,
  178. const String &p_main_scene,
  179. const PackedStringArray &p_unsupported_features,
  180. uint64_t p_last_edited,
  181. bool p_favorite,
  182. bool p_grayed,
  183. bool p_missing,
  184. int p_version) {
  185. project_name = p_name;
  186. description = p_description;
  187. tags = p_tags;
  188. path = p_path;
  189. icon = p_icon;
  190. main_scene = p_main_scene;
  191. unsupported_features = p_unsupported_features;
  192. last_edited = p_last_edited;
  193. favorite = p_favorite;
  194. grayed = p_grayed;
  195. missing = p_missing;
  196. version = p_version;
  197. control = nullptr;
  198. PackedStringArray sorted_tags = tags;
  199. sorted_tags.sort();
  200. tag_sort_string = String().join(sorted_tags);
  201. }
  202. _FORCE_INLINE_ bool operator==(const Item &l) const {
  203. return path == l.path;
  204. }
  205. };
  206. private:
  207. bool project_opening_initiated = false;
  208. String _search_term;
  209. FilterOption _order_option = FilterOption::EDIT_DATE;
  210. HashSet<String> _selected_project_paths;
  211. String _last_clicked; // Project key
  212. VBoxContainer *_scroll_children = nullptr;
  213. int _icon_load_index = 0;
  214. Vector<Item> _projects;
  215. ConfigFile _config;
  216. String _config_path;
  217. void _panel_input(const Ref<InputEvent> &p_ev, Node *p_hb);
  218. void _favorite_pressed(Node *p_hb);
  219. void _show_project(const String &p_path);
  220. void _clear_project_selection();
  221. void _toggle_project(int p_index);
  222. void _select_project_nocheck(int p_index);
  223. void _deselect_project_nocheck(int p_index);
  224. void _select_project_range(int p_begin, int p_end);
  225. void _create_project_item_control(int p_index);
  226. void _remove_project(int p_index, bool p_update_settings);
  227. static Item load_project_data(const String &p_property_key, bool p_favorite);
  228. void _update_icons_async();
  229. void _load_project_icon(int p_index);
  230. void _global_menu_new_window(const Variant &p_tag);
  231. void _global_menu_open_project(const Variant &p_tag);
  232. protected:
  233. void _notification(int p_what);
  234. static void _bind_methods();
  235. public:
  236. static const char *SIGNAL_SELECTION_CHANGED;
  237. static const char *SIGNAL_PROJECT_ASK_OPEN;
  238. void load_projects();
  239. int get_project_count() const;
  240. void sort_projects();
  241. void add_project(const String &dir_path, bool favorite);
  242. void set_project_version(const String &p_project_path, int version);
  243. int refresh_project(const String &dir_path);
  244. void ensure_project_visible(int p_index);
  245. void select_project(int p_index);
  246. void select_first_visible_project();
  247. void erase_selected_projects(bool p_delete_project_contents);
  248. Vector<Item> get_selected_projects() const;
  249. const HashSet<String> &get_selected_project_keys() const;
  250. int get_single_selected_index() const;
  251. bool is_any_project_missing() const;
  252. void erase_missing_projects();
  253. void set_search_term(String p_search_term);
  254. void add_search_tag(const String &p_tag);
  255. void set_order_option(int p_option);
  256. void update_dock_menu();
  257. void migrate_config();
  258. void save_config();
  259. ProjectList();
  260. };
  261. class ProjectManager : public Control {
  262. GDCLASS(ProjectManager, Control);
  263. HashMap<String, Ref<Texture2D>> icon_type_cache;
  264. void _build_icon_type_cache(Ref<Theme> p_theme);
  265. static ProjectManager *singleton;
  266. Panel *background_panel = nullptr;
  267. TabContainer *tabs = nullptr;
  268. ProjectList *_project_list = nullptr;
  269. LineEdit *search_box = nullptr;
  270. Label *loading_label = nullptr;
  271. OptionButton *filter_option = nullptr;
  272. PanelContainer *search_panel = nullptr;
  273. Button *create_btn = nullptr;
  274. Button *import_btn = nullptr;
  275. Button *scan_btn = nullptr;
  276. Button *open_btn = nullptr;
  277. Button *run_btn = nullptr;
  278. Button *rename_btn = nullptr;
  279. Button *manage_tags_btn = nullptr;
  280. Button *erase_btn = nullptr;
  281. Button *erase_missing_btn = nullptr;
  282. Button *about_btn = nullptr;
  283. HBoxContainer *local_projects_hb = nullptr;
  284. EditorAssetLibrary *asset_library = nullptr;
  285. Ref<StyleBox> tag_stylebox;
  286. EditorFileDialog *scan_dir = nullptr;
  287. ConfirmationDialog *language_restart_ask = nullptr;
  288. ConfirmationDialog *erase_ask = nullptr;
  289. Label *erase_ask_label = nullptr;
  290. // Comment out for now until we have a better warning system to
  291. // ensure users delete their project only.
  292. //CheckBox *delete_project_contents = nullptr;
  293. ConfirmationDialog *erase_missing_ask = nullptr;
  294. ConfirmationDialog *multi_open_ask = nullptr;
  295. ConfirmationDialog *multi_run_ask = nullptr;
  296. ConfirmationDialog *multi_scan_ask = nullptr;
  297. ConfirmationDialog *ask_full_convert_dialog = nullptr;
  298. ConfirmationDialog *ask_update_settings = nullptr;
  299. ConfirmationDialog *open_templates = nullptr;
  300. EditorAbout *about = nullptr;
  301. HBoxContainer *settings_hb = nullptr;
  302. AcceptDialog *run_error_diag = nullptr;
  303. AcceptDialog *dialog_error = nullptr;
  304. ProjectDialog *npdialog = nullptr;
  305. Button *full_convert_button = nullptr;
  306. OptionButton *language_btn = nullptr;
  307. LinkButton *version_btn = nullptr;
  308. HashSet<String> tag_set;
  309. PackedStringArray current_project_tags;
  310. PackedStringArray forbidden_tag_characters{ "/", "\\", "-" };
  311. ConfirmationDialog *tag_manage_dialog = nullptr;
  312. HFlowContainer *project_tags = nullptr;
  313. HFlowContainer *all_tags = nullptr;
  314. Label *tag_edit_error = nullptr;
  315. Button *create_tag_btn = nullptr;
  316. ConfirmationDialog *create_tag_dialog = nullptr;
  317. LineEdit *new_tag_name = nullptr;
  318. Label *tag_error = nullptr;
  319. void _open_asset_library();
  320. void _scan_projects();
  321. void _run_project();
  322. void _run_project_confirm();
  323. void _open_selected_projects();
  324. void _open_selected_projects_ask();
  325. void _full_convert_button_pressed();
  326. void _perform_full_project_conversion();
  327. void _import_project();
  328. void _new_project();
  329. void _rename_project();
  330. void _erase_project();
  331. void _erase_missing_projects();
  332. void _erase_project_confirm();
  333. void _erase_missing_projects_confirm();
  334. void _show_about();
  335. void _update_project_buttons();
  336. void _language_selected(int p_id);
  337. void _restart_confirm();
  338. void _confirm_update_settings();
  339. void _manage_project_tags();
  340. void _add_project_tag(const String &p_tag);
  341. void _delete_project_tag(const String &p_tag);
  342. void _apply_project_tags();
  343. void _set_new_tag_name(const String p_name);
  344. void _create_new_tag();
  345. void _load_recent_projects();
  346. void _on_project_created(const String &dir);
  347. void _on_projects_updated();
  348. void _scan_multiple_folders(PackedStringArray p_files);
  349. void _scan_begin(const String &p_base);
  350. void _scan_dir(const String &path);
  351. void _install_project(const String &p_zip_path, const String &p_title);
  352. void _dim_window();
  353. virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
  354. void _files_dropped(PackedStringArray p_files);
  355. void _version_button_pressed();
  356. void _on_order_option_changed(int p_idx);
  357. void _on_tab_changed(int p_tab);
  358. void _on_search_term_changed(const String &p_term);
  359. static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
  360. static Ref<Texture2D> _file_dialog_get_thumbnail(const String &p_path);
  361. protected:
  362. void _notification(int p_what);
  363. static void _bind_methods();
  364. public:
  365. static ProjectManager *get_singleton() { return singleton; }
  366. LineEdit *get_search_box();
  367. void add_new_tag(const String &p_tag);
  368. ProjectManager();
  369. ~ProjectManager();
  370. };
  371. class ProjectTag : public HBoxContainer {
  372. GDCLASS(ProjectTag, HBoxContainer);
  373. String tag_string;
  374. Button *button = nullptr;
  375. bool display_close = false;
  376. protected:
  377. void _notification(int p_what);
  378. public:
  379. ProjectTag(const String &p_text, bool p_display_close = false);
  380. void connect_button_to(const Callable &p_callable);
  381. const String get_tag() const;
  382. };
  383. #endif // PROJECT_MANAGER_H