editor_vcs_interface.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*************************************************************************/
  2. /* editor_vcs_interface.cpp */
  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. #include "editor_vcs_interface.h"
  31. EditorVCSInterface *EditorVCSInterface::singleton = NULL;
  32. void EditorVCSInterface::_bind_methods() {
  33. // Proxy end points that act as fallbacks to unavailability of a function in the VCS addon
  34. ClassDB::bind_method(D_METHOD("_initialize", "project_root_path"), &EditorVCSInterface::_initialize);
  35. ClassDB::bind_method(D_METHOD("_is_vcs_initialized"), &EditorVCSInterface::_is_vcs_initialized);
  36. ClassDB::bind_method(D_METHOD("_get_vcs_name"), &EditorVCSInterface::_get_vcs_name);
  37. ClassDB::bind_method(D_METHOD("_shut_down"), &EditorVCSInterface::_shut_down);
  38. ClassDB::bind_method(D_METHOD("_get_project_name"), &EditorVCSInterface::_get_project_name);
  39. ClassDB::bind_method(D_METHOD("_get_modified_files_data"), &EditorVCSInterface::_get_modified_files_data);
  40. ClassDB::bind_method(D_METHOD("_commit", "msg"), &EditorVCSInterface::_commit);
  41. ClassDB::bind_method(D_METHOD("_get_file_diff", "file_path"), &EditorVCSInterface::_get_file_diff);
  42. ClassDB::bind_method(D_METHOD("_stage_file", "file_path"), &EditorVCSInterface::_stage_file);
  43. ClassDB::bind_method(D_METHOD("_unstage_file", "file_path"), &EditorVCSInterface::_unstage_file);
  44. ClassDB::bind_method(D_METHOD("is_addon_ready"), &EditorVCSInterface::is_addon_ready);
  45. // API methods that redirect calls to the proxy end points
  46. ClassDB::bind_method(D_METHOD("initialize", "project_root_path"), &EditorVCSInterface::initialize);
  47. ClassDB::bind_method(D_METHOD("is_vcs_initialized"), &EditorVCSInterface::is_vcs_initialized);
  48. ClassDB::bind_method(D_METHOD("get_modified_files_data"), &EditorVCSInterface::get_modified_files_data);
  49. ClassDB::bind_method(D_METHOD("stage_file", "file_path"), &EditorVCSInterface::stage_file);
  50. ClassDB::bind_method(D_METHOD("unstage_file", "file_path"), &EditorVCSInterface::unstage_file);
  51. ClassDB::bind_method(D_METHOD("commit", "msg"), &EditorVCSInterface::commit);
  52. ClassDB::bind_method(D_METHOD("get_file_diff", "file_path"), &EditorVCSInterface::get_file_diff);
  53. ClassDB::bind_method(D_METHOD("shut_down"), &EditorVCSInterface::shut_down);
  54. ClassDB::bind_method(D_METHOD("get_project_name"), &EditorVCSInterface::get_project_name);
  55. ClassDB::bind_method(D_METHOD("get_vcs_name"), &EditorVCSInterface::get_vcs_name);
  56. }
  57. bool EditorVCSInterface::_initialize(String p_project_root_path) {
  58. WARN_PRINT("Selected VCS addon does not implement an initialization function. This warning will be suppressed.")
  59. return true;
  60. }
  61. bool EditorVCSInterface::_is_vcs_initialized() {
  62. return false;
  63. }
  64. Dictionary EditorVCSInterface::_get_modified_files_data() {
  65. return Dictionary();
  66. }
  67. void EditorVCSInterface::_stage_file(String p_file_path) {
  68. }
  69. void EditorVCSInterface::_unstage_file(String p_file_path) {
  70. }
  71. void EditorVCSInterface::_commit(String p_msg) {
  72. }
  73. Array EditorVCSInterface::_get_file_diff(String p_file_path) {
  74. return Array();
  75. }
  76. bool EditorVCSInterface::_shut_down() {
  77. return false;
  78. }
  79. String EditorVCSInterface::_get_project_name() {
  80. return String();
  81. }
  82. String EditorVCSInterface::_get_vcs_name() {
  83. return "";
  84. }
  85. bool EditorVCSInterface::initialize(String p_project_root_path) {
  86. is_initialized = call("_initialize", p_project_root_path);
  87. return is_initialized;
  88. }
  89. bool EditorVCSInterface::is_vcs_initialized() {
  90. return call("_is_vcs_initialized");
  91. }
  92. Dictionary EditorVCSInterface::get_modified_files_data() {
  93. return call("_get_modified_files_data");
  94. }
  95. void EditorVCSInterface::stage_file(String p_file_path) {
  96. if (is_addon_ready()) {
  97. call("_stage_file", p_file_path);
  98. }
  99. }
  100. void EditorVCSInterface::unstage_file(String p_file_path) {
  101. if (is_addon_ready()) {
  102. call("_unstage_file", p_file_path);
  103. }
  104. }
  105. bool EditorVCSInterface::is_addon_ready() {
  106. return is_initialized;
  107. }
  108. void EditorVCSInterface::commit(String p_msg) {
  109. if (is_addon_ready()) {
  110. call("_commit", p_msg);
  111. }
  112. }
  113. Array EditorVCSInterface::get_file_diff(String p_file_path) {
  114. if (is_addon_ready()) {
  115. return call("_get_file_diff", p_file_path);
  116. }
  117. return Array();
  118. }
  119. bool EditorVCSInterface::shut_down() {
  120. return call("_shut_down");
  121. }
  122. String EditorVCSInterface::get_project_name() {
  123. return call("_get_project_name");
  124. }
  125. String EditorVCSInterface::get_vcs_name() {
  126. return call("_get_vcs_name");
  127. }
  128. EditorVCSInterface::EditorVCSInterface() {
  129. is_initialized = false;
  130. }
  131. EditorVCSInterface::~EditorVCSInterface() {
  132. }
  133. EditorVCSInterface *EditorVCSInterface::get_singleton() {
  134. return singleton;
  135. }
  136. void EditorVCSInterface::set_singleton(EditorVCSInterface *p_singleton) {
  137. singleton = p_singleton;
  138. }