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