version_control_editor_plugin.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**************************************************************************/
  2. /* version_control_editor_plugin.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 VERSION_CONTROL_EDITOR_PLUGIN_H
  31. #define VERSION_CONTROL_EDITOR_PLUGIN_H
  32. #include "editor/editor_vcs_interface.h"
  33. #include "editor/plugins/editor_plugin.h"
  34. #include "scene/gui/check_button.h"
  35. #include "scene/gui/file_dialog.h"
  36. #include "scene/gui/menu_button.h"
  37. #include "scene/gui/rich_text_label.h"
  38. #include "scene/gui/text_edit.h"
  39. #include "scene/gui/tree.h"
  40. class VersionControlEditorPlugin : public EditorPlugin {
  41. GDCLASS(VersionControlEditorPlugin, EditorPlugin)
  42. public:
  43. enum ButtonType {
  44. BUTTON_TYPE_OPEN = 0,
  45. BUTTON_TYPE_DISCARD = 1,
  46. };
  47. enum DiffViewType {
  48. DIFF_VIEW_TYPE_SPLIT = 0,
  49. DIFF_VIEW_TYPE_UNIFIED = 1,
  50. };
  51. enum ExtraOption {
  52. EXTRA_OPTION_FORCE_PUSH,
  53. EXTRA_OPTION_CREATE_BRANCH,
  54. EXTRA_OPTION_CREATE_REMOTE,
  55. };
  56. private:
  57. static VersionControlEditorPlugin *singleton;
  58. List<StringName> available_plugins;
  59. PopupMenu *version_control_actions = nullptr;
  60. ConfirmationDialog *metadata_dialog = nullptr;
  61. OptionButton *metadata_selection = nullptr;
  62. AcceptDialog *set_up_dialog = nullptr;
  63. CheckButton *toggle_vcs_choice = nullptr;
  64. OptionButton *set_up_choice = nullptr;
  65. VBoxContainer *set_up_vbc = nullptr;
  66. VBoxContainer *set_up_settings_vbc = nullptr;
  67. LineEdit *set_up_username = nullptr;
  68. LineEdit *set_up_password = nullptr;
  69. LineEdit *set_up_ssh_public_key_path = nullptr;
  70. LineEdit *set_up_ssh_private_key_path = nullptr;
  71. LineEdit *set_up_ssh_passphrase = nullptr;
  72. FileDialog *set_up_ssh_public_key_file_dialog = nullptr;
  73. FileDialog *set_up_ssh_private_key_file_dialog = nullptr;
  74. Label *set_up_warning_text = nullptr;
  75. AcceptDialog *discard_all_confirm = nullptr;
  76. OptionButton *commit_list_size_button = nullptr;
  77. AcceptDialog *branch_create_confirm = nullptr;
  78. LineEdit *branch_create_name_input = nullptr;
  79. Button *branch_create_ok = nullptr;
  80. AcceptDialog *remote_create_confirm = nullptr;
  81. LineEdit *remote_create_name_input = nullptr;
  82. LineEdit *remote_create_url_input = nullptr;
  83. Button *remote_create_ok = nullptr;
  84. HashMap<EditorVCSInterface::ChangeType, String> change_type_to_strings;
  85. HashMap<EditorVCSInterface::ChangeType, Color> change_type_to_color;
  86. HashMap<EditorVCSInterface::ChangeType, Ref<Texture>> change_type_to_icon;
  87. VBoxContainer *version_commit_dock = nullptr;
  88. Tree *staged_files = nullptr;
  89. Tree *unstaged_files = nullptr;
  90. Tree *commit_list = nullptr;
  91. OptionButton *branch_select = nullptr;
  92. Button *branch_remove_button = nullptr;
  93. AcceptDialog *branch_remove_confirm = nullptr;
  94. Button *fetch_button = nullptr;
  95. Button *pull_button = nullptr;
  96. Button *push_button = nullptr;
  97. OptionButton *remote_select = nullptr;
  98. Button *remote_remove_button = nullptr;
  99. AcceptDialog *remote_remove_confirm = nullptr;
  100. MenuButton *extra_options = nullptr;
  101. PopupMenu *extra_options_remove_branch_list = nullptr;
  102. PopupMenu *extra_options_remove_remote_list = nullptr;
  103. String branch_to_remove;
  104. String remote_to_remove;
  105. Button *stage_all_button = nullptr;
  106. Button *unstage_all_button = nullptr;
  107. Button *discard_all_button = nullptr;
  108. Button *refresh_button = nullptr;
  109. TextEdit *commit_message = nullptr;
  110. Button *commit_button = nullptr;
  111. VBoxContainer *version_control_dock = nullptr;
  112. Button *version_control_dock_button = nullptr;
  113. Label *diff_title = nullptr;
  114. RichTextLabel *diff = nullptr;
  115. OptionButton *diff_view_type_select = nullptr;
  116. bool show_commit_diff_header = false;
  117. List<EditorVCSInterface::DiffFile> diff_content;
  118. void _notification(int p_what);
  119. void _initialize_vcs();
  120. void _set_vcs_ui_state(bool p_enabled);
  121. void _set_credentials();
  122. void _ssh_public_key_selected(const String &p_path);
  123. void _ssh_private_key_selected(const String &p_path);
  124. void _populate_available_vcs_names();
  125. void _update_remotes_list();
  126. void _update_set_up_warning(const String &p_new_text);
  127. void _update_opened_tabs();
  128. void _update_extra_options();
  129. bool _load_plugin(const String &p_name);
  130. void _pull();
  131. void _push();
  132. void _force_push();
  133. void _fetch();
  134. void _commit();
  135. void _confirm_discard_all();
  136. void _discard_all();
  137. void _refresh_stage_area();
  138. void _refresh_branch_list();
  139. void _set_commit_list_size(int p_index);
  140. void _refresh_commit_list();
  141. void _refresh_remote_list();
  142. void _display_diff(int p_idx);
  143. void _move_all(Object *p_tree);
  144. void _load_diff(Object *p_tree);
  145. void _clear_diff();
  146. int _get_item_count(Tree *p_tree);
  147. void _item_activated(Object *p_tree);
  148. void _create_branch();
  149. void _create_remote();
  150. void _update_branch_create_button(const String &p_new_text);
  151. void _update_remote_create_button(const String &p_new_text);
  152. void _branch_item_selected(int p_index);
  153. void _remote_selected(int p_index);
  154. void _remove_branch();
  155. void _remove_remote();
  156. void _popup_branch_remove_confirm(int p_index);
  157. void _popup_remote_remove_confirm(int p_index);
  158. void _move_item(Tree *p_tree, TreeItem *p_itme);
  159. void _display_diff_split_view(List<EditorVCSInterface::DiffLine> &p_diff_content);
  160. void _display_diff_unified_view(List<EditorVCSInterface::DiffLine> &p_diff_content);
  161. void _discard_file(const String &p_file_path, EditorVCSInterface::ChangeType p_change);
  162. void _cell_button_pressed(Object *p_item, int p_column, int p_id, int p_mouse_button_index);
  163. void _add_new_item(Tree *p_tree, const String &p_file_path, EditorVCSInterface::ChangeType p_change);
  164. void _update_commit_button();
  165. void _commit_message_gui_input(const Ref<InputEvent> &p_event);
  166. void _extra_option_selected(int p_index);
  167. bool _is_staging_area_empty();
  168. String _get_date_string_from(int64_t p_unix_timestamp, int64_t p_offset_minutes) const;
  169. void _create_vcs_metadata_files();
  170. void _popup_file_dialog(const Variant &p_file_dialog_variant);
  171. void _toggle_vcs_integration(bool p_toggled);
  172. friend class EditorVCSInterface;
  173. protected:
  174. static void _bind_methods();
  175. public:
  176. static VersionControlEditorPlugin *get_singleton();
  177. void popup_vcs_metadata_dialog();
  178. void popup_vcs_set_up_dialog(const Control *p_gui_base);
  179. PopupMenu *get_version_control_actions_panel() const { return version_control_actions; }
  180. void register_editor();
  181. void fetch_available_vcs_plugin_names();
  182. void shut_down();
  183. VersionControlEditorPlugin();
  184. ~VersionControlEditorPlugin();
  185. };
  186. #endif // VERSION_CONTROL_EDITOR_PLUGIN_H