summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorTwarit <wtwarit@gmail.com>2019-09-03 20:01:14 +0530
committerTwarit <wtwarit@gmail.com>2019-09-03 20:01:14 +0530
commit97959a53df144222f468d1622a3cb7e2f7e48741 (patch)
tree39212df1719fb1c70d3ef59cab24ae550568629e /editor
parent07e3be3debe968dcffd3b62202e3862edb9a7d27 (diff)
Add an overridable VCS Interface for the editor
The VCS interface can be thought of like a proxy system, where any call to the API is redirected to the actual implementation of the VCS API which may be existing in the form of a GDNative plugin which is marked as a singleton and is not marked reloadable. If the implementation doesn't exist in the file system, it only returns the default responses which contain mostly empty containers of the data type that every API call returns. EditorVCSInterface is used like a Godot object with a script attached to it. The script is the implementation of the API and the object is the interface to the script, which returns default responses if the script doesn't exist or if the script doesn't define a function that handles that particular API call. The entire system has been implemented using Object::call() and its ability to switch to the script instance to handle the API call if the script exists. Look for VersionControlEditorPlugin::_initialize() for the essential API setup.
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_vcs_interface.cpp173
-rw-r--r--editor/editor_vcs_interface.h53
2 files changed, 226 insertions, 0 deletions
diff --git a/editor/editor_vcs_interface.cpp b/editor/editor_vcs_interface.cpp
new file mode 100644
index 0000000000..db1c289ec9
--- /dev/null
+++ b/editor/editor_vcs_interface.cpp
@@ -0,0 +1,173 @@
+#include "editor_vcs_interface.h"
+
+EditorVCSInterface *EditorVCSInterface::singleton = NULL;
+
+void EditorVCSInterface::_bind_methods() {
+
+ // Proxy end points that act as fallbacks to unavailability of a function in the VCS addon
+ ClassDB::bind_method(D_METHOD("_initialize", "project_root_path"), &EditorVCSInterface::_initialize);
+ ClassDB::bind_method(D_METHOD("_get_is_vcs_intialized"), &EditorVCSInterface::_get_is_vcs_intialized);
+ ClassDB::bind_method(D_METHOD("_get_vcs_name"), &EditorVCSInterface::_get_vcs_name);
+ ClassDB::bind_method(D_METHOD("_shut_down"), &EditorVCSInterface::_shut_down);
+ ClassDB::bind_method(D_METHOD("_get_project_name"), &EditorVCSInterface::_get_project_name);
+ ClassDB::bind_method(D_METHOD("_get_modified_files_data"), &EditorVCSInterface::_get_modified_files_data);
+ ClassDB::bind_method(D_METHOD("_commit", "msg"), &EditorVCSInterface::_commit);
+ ClassDB::bind_method(D_METHOD("_get_file_diff", "file_path"), &EditorVCSInterface::_get_file_diff);
+ ClassDB::bind_method(D_METHOD("_stage_file", "file_path"), &EditorVCSInterface::_stage_file);
+ ClassDB::bind_method(D_METHOD("_unstage_file", "file_path"), &EditorVCSInterface::_unstage_file);
+
+ ClassDB::bind_method(D_METHOD("is_addon_ready"), &EditorVCSInterface::is_addon_ready);
+
+ // API methods that redirect calls to the proxy end points
+ ClassDB::bind_method(D_METHOD("initialize", "project_root_path"), &EditorVCSInterface::initialize);
+ ClassDB::bind_method(D_METHOD("get_is_vcs_intialized"), &EditorVCSInterface::get_is_vcs_intialized);
+ ClassDB::bind_method(D_METHOD("get_modified_files_data"), &EditorVCSInterface::get_modified_files_data);
+ ClassDB::bind_method(D_METHOD("stage_file", "file_path"), &EditorVCSInterface::stage_file);
+ ClassDB::bind_method(D_METHOD("unstage_file", "file_path"), &EditorVCSInterface::unstage_file);
+ ClassDB::bind_method(D_METHOD("commit", "msg"), &EditorVCSInterface::commit);
+ ClassDB::bind_method(D_METHOD("get_file_diff", "file_path"), &EditorVCSInterface::get_file_diff);
+ ClassDB::bind_method(D_METHOD("shut_down"), &EditorVCSInterface::shut_down);
+ ClassDB::bind_method(D_METHOD("get_project_name"), &EditorVCSInterface::get_project_name);
+ ClassDB::bind_method(D_METHOD("get_vcs_name"), &EditorVCSInterface::get_vcs_name);
+}
+
+bool EditorVCSInterface::_initialize(String p_project_root_path) {
+
+ WARN_PRINT("Selected VCS addon does not implement an initialization function. This warning will be suppressed.")
+ return true;
+}
+
+bool EditorVCSInterface::_get_is_vcs_intialized() {
+
+ return false;
+}
+
+Dictionary EditorVCSInterface::_get_modified_files_data() {
+
+ return Dictionary();
+}
+
+void EditorVCSInterface::_stage_file(String p_file_path) {
+
+ return;
+}
+
+void EditorVCSInterface::_unstage_file(String p_file_path) {
+
+ return;
+}
+
+void EditorVCSInterface::_commit(String p_msg) {
+
+ return;
+}
+
+Array EditorVCSInterface::_get_file_diff(String p_file_path) {
+
+ return Array();
+}
+
+bool EditorVCSInterface::_shut_down() {
+
+ return false;
+}
+
+String EditorVCSInterface::_get_project_name() {
+
+ return String();
+}
+
+String EditorVCSInterface::_get_vcs_name() {
+
+ return "";
+}
+
+bool EditorVCSInterface::initialize(String p_project_root_path) {
+
+ is_initialized = call("_initialize", p_project_root_path);
+ return is_initialized;
+}
+
+bool EditorVCSInterface::get_is_vcs_intialized() {
+
+ return call("_get_is_vcs_intialized");
+}
+
+Dictionary EditorVCSInterface::get_modified_files_data() {
+
+ return call("_get_modified_files_data");
+}
+
+void EditorVCSInterface::stage_file(String p_file_path) {
+
+ if (is_addon_ready()) {
+
+ call("_stage_file", p_file_path);
+ }
+ return;
+}
+
+void EditorVCSInterface::unstage_file(String p_file_path) {
+
+ if (is_addon_ready()) {
+
+ call("_unstage_file", p_file_path);
+ }
+ return;
+}
+
+bool EditorVCSInterface::is_addon_ready() {
+
+ return is_initialized;
+}
+
+void EditorVCSInterface::commit(String p_msg) {
+
+ if (is_addon_ready()) {
+
+ call("_commit", p_msg);
+ }
+ return;
+}
+
+Array EditorVCSInterface::get_file_diff(String p_file_path) {
+
+ if (is_addon_ready()) {
+
+ return call("_get_file_diff", p_file_path);
+ }
+ return Array();
+}
+
+bool EditorVCSInterface::shut_down() {
+
+ return call("_shut_down");
+}
+
+String EditorVCSInterface::get_project_name() {
+
+ return call("_get_project_name");
+}
+
+String EditorVCSInterface::get_vcs_name() {
+
+ return call("_get_vcs_name");
+}
+
+EditorVCSInterface::EditorVCSInterface() {
+
+ is_initialized = false;
+}
+
+EditorVCSInterface::~EditorVCSInterface() {
+}
+
+EditorVCSInterface *EditorVCSInterface::get_singleton() {
+
+ return singleton;
+}
+
+void EditorVCSInterface::set_singleton(EditorVCSInterface *p_singleton) {
+
+ singleton = p_singleton;
+}
diff --git a/editor/editor_vcs_interface.h b/editor/editor_vcs_interface.h
new file mode 100644
index 0000000000..baf196de6e
--- /dev/null
+++ b/editor/editor_vcs_interface.h
@@ -0,0 +1,53 @@
+#ifndef EDITOR_VCS_INTERFACE_H
+#define EDITOR_VCS_INTERFACE_H
+
+#include "core/object.h"
+#include "core/ustring.h"
+#include "scene/gui/panel_container.h"
+
+class EditorVCSInterface : public Object {
+
+ GDCLASS(EditorVCSInterface, Object)
+
+ bool is_initialized;
+
+protected:
+ static EditorVCSInterface *singleton;
+
+ static void _bind_methods();
+
+ // Implemented by addons as end points for the proxy functions
+ bool _initialize(String p_project_root_path);
+ bool _get_is_vcs_intialized();
+ Dictionary _get_modified_files_data();
+ void _stage_file(String p_file_path);
+ void _unstage_file(String p_file_path);
+ void _commit(String p_msg);
+ Array _get_file_diff(String p_file_path);
+ bool _shut_down();
+ String _get_project_name();
+ String _get_vcs_name();
+
+public:
+ static EditorVCSInterface *get_singleton();
+ static void set_singleton(EditorVCSInterface *p_singleton);
+
+ bool is_addon_ready();
+
+ // Proxy functions to the editor for use
+ bool initialize(String p_project_root_path);
+ bool get_is_vcs_intialized();
+ Dictionary get_modified_files_data();
+ void stage_file(String p_file_path);
+ void unstage_file(String p_file_path);
+ void commit(String p_msg);
+ Array get_file_diff(String p_file_path);
+ bool shut_down();
+ String get_project_name();
+ String get_vcs_name();
+
+ EditorVCSInterface();
+ virtual ~EditorVCSInterface();
+};
+
+#endif // !EDITOR_VCS_INTERFACE_H