version_control_editor_plugin.h 8.3 KB

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