version_control_editor_plugin.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 VERSION_CONTROL_EDITOR_PLUGIN_H
  31. #define VERSION_CONTROL_EDITOR_PLUGIN_H
  32. #include "editor/editor_plugin.h"
  33. #include "editor/editor_vcs_interface.h"
  34. #include "scene/gui/container.h"
  35. #include "scene/gui/rich_text_label.h"
  36. #include "scene/gui/text_edit.h"
  37. #include "scene/gui/tree.h"
  38. class VersionControlEditorPlugin : public EditorPlugin {
  39. GDCLASS(VersionControlEditorPlugin, EditorPlugin)
  40. public:
  41. enum ChangeType {
  42. CHANGE_TYPE_NEW = 0,
  43. CHANGE_TYPE_MODIFIED = 1,
  44. CHANGE_TYPE_RENAMED = 2,
  45. CHANGE_TYPE_DELETED = 3,
  46. CHANGE_TYPE_TYPECHANGE = 4
  47. };
  48. private:
  49. static VersionControlEditorPlugin *singleton;
  50. int staged_files_count;
  51. List<StringName> available_addons;
  52. PopupMenu *version_control_actions;
  53. AcceptDialog *set_up_dialog;
  54. VBoxContainer *set_up_vbc;
  55. HBoxContainer *set_up_hbc;
  56. Label *set_up_vcs_label;
  57. OptionButton *set_up_choice;
  58. PanelContainer *set_up_init_settings;
  59. Button *set_up_init_button;
  60. RichTextLabel *set_up_vcs_status;
  61. Button *set_up_ok_button;
  62. HashMap<ChangeType, String> change_type_to_strings;
  63. HashMap<ChangeType, Color> change_type_to_color;
  64. VBoxContainer *version_commit_dock;
  65. VBoxContainer *commit_box_vbc;
  66. HSplitContainer *stage_tools;
  67. Tree *stage_files;
  68. TreeItem *new_files;
  69. TreeItem *modified_files;
  70. TreeItem *renamed_files;
  71. TreeItem *deleted_files;
  72. TreeItem *typechange_files;
  73. Label *staging_area_label;
  74. HSplitContainer *stage_buttons;
  75. Button *stage_all_button;
  76. Button *stage_selected_button;
  77. Button *refresh_button;
  78. TextEdit *commit_message;
  79. Button *commit_button;
  80. Label *commit_status;
  81. PanelContainer *version_control_dock;
  82. ToolButton *version_control_dock_button;
  83. VBoxContainer *diff_vbc;
  84. HBoxContainer *diff_hbc;
  85. Button *diff_refresh_button;
  86. Label *diff_file_name;
  87. Label *diff_heading;
  88. RichTextLabel *diff;
  89. void _populate_available_vcs_names();
  90. void _selected_a_vcs(int p_id);
  91. void _initialize_vcs();
  92. void _send_commit_msg();
  93. void _refresh_stage_area();
  94. void _stage_selected();
  95. void _stage_all();
  96. void _view_file_diff();
  97. void _display_file_diff(String p_file_path);
  98. void _refresh_file_diff();
  99. void _clear_file_diff();
  100. void _update_stage_status();
  101. void _update_commit_status();
  102. void _update_commit_button();
  103. friend class EditorVCSInterface;
  104. protected:
  105. static void _bind_methods();
  106. public:
  107. static VersionControlEditorPlugin *get_singleton();
  108. void popup_vcs_set_up_dialog(const Control *p_gui_base);
  109. void set_version_control_tool_button(ToolButton *p_button) { version_control_dock_button = p_button; }
  110. PopupMenu *get_version_control_actions_panel() const { return version_control_actions; }
  111. VBoxContainer *get_version_commit_dock() const { return version_commit_dock; }
  112. PanelContainer *get_version_control_dock() const { return version_control_dock; }
  113. List<StringName> get_available_vcs_names() const { return available_addons; }
  114. bool is_vcs_initialized() const;
  115. const String get_vcs_name() const;
  116. void register_editor();
  117. void fetch_available_vcs_addon_names();
  118. void clear_stage_area();
  119. void shut_down();
  120. VersionControlEditorPlugin();
  121. ~VersionControlEditorPlugin();
  122. };
  123. VARIANT_ENUM_CAST(VersionControlEditorPlugin::ChangeType);
  124. #endif // !VERSION_CONTROL_EDITOR_PLUGIN_H