Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/version_control/version_control_editor_plugin.cpp
20983 views
1
/**************************************************************************/
2
/* version_control_editor_plugin.cpp */
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
#include "version_control_editor_plugin.h"
32
33
#include "core/config/project_settings.h"
34
#include "core/os/keyboard.h"
35
#include "core/os/time.h"
36
#include "editor/docks/editor_dock.h"
37
#include "editor/docks/editor_dock_manager.h"
38
#include "editor/docks/filesystem_dock.h"
39
#include "editor/editor_interface.h"
40
#include "editor/editor_node.h"
41
#include "editor/editor_string_names.h"
42
#include "editor/file_system/editor_file_system.h"
43
#include "editor/gui/editor_bottom_panel.h"
44
#include "editor/gui/editor_file_dialog.h"
45
#include "editor/script/script_editor_plugin.h"
46
#include "editor/settings/editor_command_palette.h"
47
#include "editor/settings/editor_settings.h"
48
#include "editor/themes/editor_scale.h"
49
#include "scene/gui/flow_container.h"
50
#include "scene/gui/line_edit.h"
51
#include "scene/gui/separator.h"
52
53
#define CHECK_PLUGIN_INITIALIZED() \
54
ERR_FAIL_NULL_MSG(EditorVCSInterface::get_singleton(), "No VCS plugin is initialized. Select a Version Control Plugin from Project menu.");
55
56
VersionControlEditorPlugin *VersionControlEditorPlugin::singleton = nullptr;
57
58
void VersionControlEditorPlugin::_bind_methods() {
59
// No binds required so far.
60
}
61
62
void VersionControlEditorPlugin::_create_vcs_metadata_files() {
63
String dir = "res://";
64
EditorVCSInterface::create_vcs_metadata_files(EditorVCSInterface::VCSMetadata(metadata_selection->get_selected_id()), dir);
65
}
66
67
void VersionControlEditorPlugin::_notification(int p_what) {
68
if (p_what == NOTIFICATION_READY) {
69
String installed_plugin = GLOBAL_GET("editor/version_control/plugin_name");
70
bool has_autoload_enable = GLOBAL_GET("editor/version_control/autoload_on_startup");
71
72
if (installed_plugin != "" && has_autoload_enable) {
73
if (_load_plugin(installed_plugin)) {
74
_set_credentials();
75
}
76
}
77
}
78
}
79
80
void VersionControlEditorPlugin::_update_theme() {
81
change_type_to_color[EditorVCSInterface::CHANGE_TYPE_NEW] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("success_color"), EditorStringName(Editor));
82
change_type_to_color[EditorVCSInterface::CHANGE_TYPE_MODIFIED] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("warning_color"), EditorStringName(Editor));
83
change_type_to_color[EditorVCSInterface::CHANGE_TYPE_RENAMED] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("warning_color"), EditorStringName(Editor));
84
change_type_to_color[EditorVCSInterface::CHANGE_TYPE_DELETED] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor));
85
change_type_to_color[EditorVCSInterface::CHANGE_TYPE_TYPECHANGE] = EditorNode::get_singleton()->get_editor_theme()->get_color(SceneStringName(font_color), EditorStringName(Editor));
86
change_type_to_color[EditorVCSInterface::CHANGE_TYPE_UNMERGED] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("warning_color"), EditorStringName(Editor));
87
88
change_type_to_icon[EditorVCSInterface::CHANGE_TYPE_NEW] = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("StatusSuccess"), EditorStringName(EditorIcons));
89
change_type_to_icon[EditorVCSInterface::CHANGE_TYPE_MODIFIED] = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("StatusWarning"), EditorStringName(EditorIcons));
90
change_type_to_icon[EditorVCSInterface::CHANGE_TYPE_RENAMED] = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("StatusWarning"), EditorStringName(EditorIcons));
91
change_type_to_icon[EditorVCSInterface::CHANGE_TYPE_TYPECHANGE] = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("StatusWarning"), EditorStringName(EditorIcons));
92
change_type_to_icon[EditorVCSInterface::CHANGE_TYPE_DELETED] = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("StatusError"), EditorStringName(EditorIcons));
93
change_type_to_icon[EditorVCSInterface::CHANGE_TYPE_UNMERGED] = EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("StatusWarning"), EditorStringName(EditorIcons));
94
95
select_public_path_button->set_button_icon(EditorNode::get_singleton()->get_gui_base()->get_editor_theme_icon("Folder"));
96
select_private_path_button->set_button_icon(EditorNode::get_singleton()->get_gui_base()->get_editor_theme_icon("Folder"));
97
refresh_button->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Reload"), EditorStringName(EditorIcons)));
98
discard_all_button->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Close"), EditorStringName(EditorIcons)));
99
stage_all_button->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("MoveDown"), EditorStringName(EditorIcons)));
100
unstage_all_button->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("MoveUp"), EditorStringName(EditorIcons)));
101
fetch_button->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Reload"), EditorStringName(EditorIcons)));
102
pull_button->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("MoveDown"), EditorStringName(EditorIcons)));
103
push_button->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("MoveUp"), EditorStringName(EditorIcons)));
104
extra_options->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GuiTabMenuHl"), EditorStringName(EditorIcons)));
105
106
if (EditorVCSInterface::get_singleton()) {
107
_refresh_stage_area();
108
}
109
}
110
111
void VersionControlEditorPlugin::_populate_available_vcs_names() {
112
set_up_choice->clear();
113
for (const StringName &available_plugin : available_plugins) {
114
set_up_choice->add_item(available_plugin);
115
}
116
}
117
118
VersionControlEditorPlugin *VersionControlEditorPlugin::get_singleton() {
119
return singleton ? singleton : memnew(VersionControlEditorPlugin);
120
}
121
122
void VersionControlEditorPlugin::popup_vcs_metadata_dialog() {
123
metadata_dialog->popup_centered();
124
}
125
126
void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_base) {
127
fetch_available_vcs_plugin_names();
128
if (!available_plugins.is_empty()) {
129
Size2 popup_size = Size2(400, 100);
130
Size2 window_size = p_gui_base->get_viewport_rect().size;
131
popup_size = popup_size.min(window_size * 0.5);
132
133
_populate_available_vcs_names();
134
135
set_up_dialog->popup_centered_clamped(popup_size * EDSCALE);
136
} else {
137
// TODO: Give info to user on how to fix this error.
138
EditorNode::get_singleton()->show_warning(TTR("No VCS plugins are available in the project. Install a VCS plugin to use VCS integration features."), TTR("Error"));
139
}
140
}
141
142
void VersionControlEditorPlugin::_initialize_vcs() {
143
ERR_FAIL_COND_MSG(EditorVCSInterface::get_singleton(), EditorVCSInterface::get_singleton()->get_vcs_name() + " is already active.");
144
145
const int id = set_up_choice->get_selected_id();
146
String selected_plugin = set_up_choice->get_item_text(id);
147
148
if (_load_plugin(selected_plugin)) {
149
ProjectSettings::get_singleton()->set("editor/version_control/autoload_on_startup", true);
150
ProjectSettings::get_singleton()->set("editor/version_control/plugin_name", selected_plugin);
151
ProjectSettings::get_singleton()->save();
152
}
153
}
154
155
void VersionControlEditorPlugin::_set_vcs_ui_state(bool p_enabled) {
156
set_up_dialog->get_ok_button()->set_disabled(!p_enabled);
157
set_up_choice->set_disabled(p_enabled);
158
toggle_vcs_choice->set_pressed_no_signal(p_enabled);
159
}
160
161
void VersionControlEditorPlugin::_set_credentials() {
162
CHECK_PLUGIN_INITIALIZED();
163
164
String username = set_up_username->get_text();
165
String password = set_up_password->get_text();
166
String ssh_public_key = set_up_ssh_public_key_path->get_text();
167
String ssh_private_key = set_up_ssh_private_key_path->get_text();
168
String ssh_passphrase = set_up_ssh_passphrase->get_text();
169
170
EditorVCSInterface::get_singleton()->set_credentials(
171
username,
172
password,
173
ssh_public_key,
174
ssh_private_key,
175
ssh_passphrase);
176
177
EditorSettings::get_singleton()->set_setting("version_control/username", username);
178
EditorSettings::get_singleton()->set_setting("version_control/ssh_public_key_path", ssh_public_key);
179
EditorSettings::get_singleton()->set_setting("version_control/ssh_private_key_path", ssh_private_key);
180
}
181
182
bool VersionControlEditorPlugin::_load_plugin(const String &p_name) {
183
Object *extension_instance = ClassDB::instantiate(p_name);
184
ERR_FAIL_NULL_V_MSG(extension_instance, false, "Received a nullptr VCS extension instance during construction.");
185
186
EditorVCSInterface *vcs_plugin = Object::cast_to<EditorVCSInterface>(extension_instance);
187
ERR_FAIL_NULL_V_MSG(vcs_plugin, false, vformat("Could not cast VCS extension instance to %s.", EditorVCSInterface::get_class_static()));
188
189
String res_dir = OS::get_singleton()->get_resource_dir();
190
191
ERR_FAIL_COND_V_MSG(!vcs_plugin->initialize(res_dir), false, "Could not initialize " + p_name);
192
193
EditorVCSInterface::set_singleton(vcs_plugin);
194
195
register_editor();
196
EditorFileSystem::get_singleton()->connect(SNAME("filesystem_changed"), callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area));
197
198
_refresh_stage_area();
199
_refresh_commit_list();
200
_refresh_branch_list();
201
_refresh_remote_list();
202
203
return true;
204
}
205
206
void VersionControlEditorPlugin::_update_set_up_warning(const String &p_new_text) {
207
bool empty_settings = set_up_username->get_text().strip_edges().is_empty() &&
208
set_up_password->get_text().is_empty() &&
209
set_up_ssh_public_key_path->get_text().strip_edges().is_empty() &&
210
set_up_ssh_private_key_path->get_text().strip_edges().is_empty() &&
211
set_up_ssh_passphrase->get_text().is_empty();
212
213
if (empty_settings) {
214
set_up_warning_text->add_theme_color_override(SceneStringName(font_color), EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("warning_color"), EditorStringName(Editor)));
215
set_up_warning_text->set_text(TTR("Remote settings are empty. VCS features that use the network may not work."));
216
} else {
217
set_up_warning_text->set_text("");
218
}
219
}
220
221
void VersionControlEditorPlugin::_refresh_branch_list() {
222
CHECK_PLUGIN_INITIALIZED();
223
224
List<String> branch_list = EditorVCSInterface::get_singleton()->get_branch_list();
225
branch_select->clear();
226
227
branch_select->set_disabled(branch_list.is_empty());
228
229
String current_branch = EditorVCSInterface::get_singleton()->get_current_branch_name();
230
231
int i = 0;
232
for (List<String>::ConstIterator itr = branch_list.begin(); itr != branch_list.end(); ++itr, ++i) {
233
branch_select->add_icon_item(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("VcsBranches"), EditorStringName(EditorIcons)), *itr, i);
234
235
if (*itr == current_branch) {
236
branch_select->select(i);
237
}
238
}
239
}
240
241
String VersionControlEditorPlugin::_get_date_string_from(int64_t p_unix_timestamp, int64_t p_offset_minutes) const {
242
return vformat(
243
"%s %s",
244
Time::get_singleton()->get_datetime_string_from_unix_time(p_unix_timestamp + p_offset_minutes * 60, true),
245
Time::get_singleton()->get_offset_string_from_offset_minutes(p_offset_minutes));
246
}
247
248
void VersionControlEditorPlugin::_set_commit_list_size(int p_index) {
249
_refresh_commit_list();
250
}
251
252
void VersionControlEditorPlugin::_refresh_commit_list() {
253
CHECK_PLUGIN_INITIALIZED();
254
255
commit_list->get_root()->clear_children();
256
257
List<EditorVCSInterface::Commit> commit_info_list = EditorVCSInterface::get_singleton()->get_previous_commits(commit_list_size_button->get_selected_metadata());
258
259
for (const EditorVCSInterface::Commit &commit : commit_info_list) {
260
TreeItem *item = commit_list->create_item();
261
262
// Only display the first line of a commit message
263
int line_ending = commit.msg.find_char('\n');
264
String commit_display_msg = commit.msg.substr(0, line_ending);
265
String commit_date_string = _get_date_string_from(commit.unix_timestamp, commit.offset_minutes);
266
267
Dictionary meta_data;
268
meta_data[SNAME("commit_id")] = commit.id;
269
meta_data[SNAME("commit_title")] = commit_display_msg;
270
meta_data[SNAME("commit_subtitle")] = commit.msg.substr(line_ending).strip_edges();
271
meta_data[SNAME("commit_unix_timestamp")] = commit.unix_timestamp;
272
meta_data[SNAME("commit_author")] = commit.author;
273
meta_data[SNAME("commit_date_string")] = commit_date_string;
274
275
item->set_text(0, commit_display_msg);
276
item->set_text(1, commit.author.strip_edges());
277
item->set_metadata(0, meta_data);
278
}
279
}
280
281
void VersionControlEditorPlugin::_refresh_remote_list() {
282
CHECK_PLUGIN_INITIALIZED();
283
284
List<String> remotes = EditorVCSInterface::get_singleton()->get_remotes();
285
286
String current_remote = remote_select->get_selected_metadata();
287
remote_select->clear();
288
289
remote_select->set_disabled(remotes.is_empty());
290
291
int i = 0;
292
for (List<String>::ConstIterator itr = remotes.begin(); itr != remotes.end(); ++itr, ++i) {
293
remote_select->add_icon_item(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ArrowUp"), EditorStringName(EditorIcons)), *itr, i);
294
remote_select->set_item_metadata(i, *itr);
295
296
if (*itr == current_remote) {
297
remote_select->select(i);
298
}
299
}
300
}
301
302
void VersionControlEditorPlugin::_commit() {
303
CHECK_PLUGIN_INITIALIZED();
304
305
String msg = commit_message->get_text().strip_edges();
306
307
ERR_FAIL_COND_MSG(msg.is_empty(), "No commit message was provided.");
308
309
EditorVCSInterface::get_singleton()->commit(msg);
310
311
if (version_control_dock->get_current_layout() == EditorDock::DOCK_LAYOUT_HORIZONTAL) {
312
version_control_dock->hide();
313
}
314
315
commit_message->release_focus();
316
commit_button->release_focus();
317
commit_message->set_text("");
318
319
_refresh_stage_area();
320
_refresh_commit_list();
321
_refresh_branch_list();
322
_clear_diff();
323
}
324
325
void VersionControlEditorPlugin::_branch_item_selected(int p_index) {
326
CHECK_PLUGIN_INITIALIZED();
327
328
String branch_name = branch_select->get_item_text(p_index);
329
EditorVCSInterface::get_singleton()->checkout_branch(branch_name);
330
331
EditorFileSystem::get_singleton()->scan_changes();
332
ScriptEditor::get_singleton()->reload_scripts();
333
334
_refresh_branch_list();
335
_refresh_commit_list();
336
_refresh_stage_area();
337
_clear_diff();
338
339
_update_opened_tabs();
340
}
341
342
void VersionControlEditorPlugin::_remote_selected(int p_index) {
343
_refresh_remote_list();
344
}
345
346
void VersionControlEditorPlugin::_ssh_public_key_selected(const String &p_path) {
347
set_up_ssh_public_key_path->set_text(p_path);
348
}
349
350
void VersionControlEditorPlugin::_ssh_private_key_selected(const String &p_path) {
351
set_up_ssh_private_key_path->set_text(p_path);
352
}
353
354
void VersionControlEditorPlugin::_popup_file_dialog(const Variant &p_file_dialog_variant) {
355
FileDialog *file_dialog = Object::cast_to<FileDialog>(p_file_dialog_variant);
356
ERR_FAIL_NULL(file_dialog);
357
358
file_dialog->popup_centered_ratio();
359
}
360
361
void VersionControlEditorPlugin::_create_branch() {
362
CHECK_PLUGIN_INITIALIZED();
363
364
String new_branch_name = branch_create_name_input->get_text().strip_edges();
365
366
EditorVCSInterface::get_singleton()->create_branch(new_branch_name);
367
EditorVCSInterface::get_singleton()->checkout_branch(new_branch_name);
368
369
branch_create_name_input->clear();
370
_refresh_branch_list();
371
}
372
373
void VersionControlEditorPlugin::_create_remote() {
374
CHECK_PLUGIN_INITIALIZED();
375
376
String new_remote_name = remote_create_name_input->get_text().strip_edges();
377
String new_remote_url = remote_create_url_input->get_text().strip_edges();
378
379
EditorVCSInterface::get_singleton()->create_remote(new_remote_name, new_remote_url);
380
381
remote_create_name_input->clear();
382
remote_create_url_input->clear();
383
_refresh_remote_list();
384
}
385
386
void VersionControlEditorPlugin::_update_branch_create_button(const String &p_new_text) {
387
branch_create_ok->set_disabled(p_new_text.strip_edges().is_empty());
388
}
389
390
void VersionControlEditorPlugin::_update_remote_create_button(const String &p_new_text) {
391
remote_create_ok->set_disabled(p_new_text.strip_edges().is_empty());
392
}
393
394
int VersionControlEditorPlugin::_get_item_count(Tree *p_tree) {
395
if (!p_tree->get_root()) {
396
return 0;
397
}
398
return p_tree->get_root()->get_children().size();
399
}
400
401
void VersionControlEditorPlugin::_refresh_stage_area() {
402
CHECK_PLUGIN_INITIALIZED();
403
404
staged_files->get_root()->clear_children();
405
unstaged_files->get_root()->clear_children();
406
407
List<EditorVCSInterface::StatusFile> status_files = EditorVCSInterface::get_singleton()->get_modified_files_data();
408
for (const EditorVCSInterface::StatusFile &sf : status_files) {
409
if (sf.area == EditorVCSInterface::TREE_AREA_STAGED) {
410
_add_new_item(staged_files, sf.file_path, sf.change_type);
411
} else if (sf.area == EditorVCSInterface::TREE_AREA_UNSTAGED) {
412
_add_new_item(unstaged_files, sf.file_path, sf.change_type);
413
}
414
}
415
416
staged_files->queue_redraw();
417
unstaged_files->queue_redraw();
418
419
int total_changes = status_files.size();
420
String commit_tab_title = TTR("Commit") + (total_changes > 0 ? " (" + itos(total_changes) + ")" : "");
421
version_commit_dock->set_name(commit_tab_title);
422
}
423
424
void VersionControlEditorPlugin::_discard_file(const String &p_file_path, EditorVCSInterface::ChangeType p_change) {
425
CHECK_PLUGIN_INITIALIZED();
426
427
if (p_change == EditorVCSInterface::CHANGE_TYPE_NEW) {
428
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
429
dir->remove(p_file_path);
430
} else {
431
CHECK_PLUGIN_INITIALIZED();
432
EditorVCSInterface::get_singleton()->discard_file(p_file_path);
433
}
434
// FIXIT: The project.godot file shows weird behavior
435
EditorFileSystem::get_singleton()->update_file(p_file_path);
436
}
437
438
void VersionControlEditorPlugin::_confirm_discard_all() {
439
discard_all_confirm->popup_centered();
440
}
441
442
void VersionControlEditorPlugin::_discard_all() {
443
TreeItem *file_entry = unstaged_files->get_root()->get_first_child();
444
while (file_entry) {
445
String file_path = file_entry->get_meta(SNAME("file_path"));
446
EditorVCSInterface::ChangeType change = (EditorVCSInterface::ChangeType)(int)file_entry->get_meta(SNAME("change_type"));
447
_discard_file(file_path, change);
448
449
file_entry = file_entry->get_next();
450
}
451
_refresh_stage_area();
452
}
453
454
void VersionControlEditorPlugin::_add_new_item(Tree *p_tree, const String &p_file_path, EditorVCSInterface::ChangeType p_change) {
455
String change_text = p_file_path + " (" + change_type_to_strings[p_change] + ")";
456
457
TreeItem *new_item = p_tree->create_item();
458
new_item->set_text(0, change_text);
459
new_item->set_icon(0, change_type_to_icon[p_change]);
460
new_item->set_meta(SNAME("file_path"), p_file_path);
461
new_item->set_meta(SNAME("change_type"), p_change);
462
new_item->set_custom_color(0, change_type_to_color[p_change]);
463
464
new_item->add_button(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("File"), EditorStringName(EditorIcons)), BUTTON_TYPE_OPEN, false, TTR("Open in editor"));
465
if (p_tree == unstaged_files) {
466
new_item->add_button(0, EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Close"), EditorStringName(EditorIcons)), BUTTON_TYPE_DISCARD, false, TTR("Discard changes"));
467
}
468
}
469
470
void VersionControlEditorPlugin::_fetch() {
471
CHECK_PLUGIN_INITIALIZED();
472
473
EditorVCSInterface::get_singleton()->fetch(remote_select->get_selected_metadata());
474
_refresh_branch_list();
475
}
476
477
void VersionControlEditorPlugin::_pull() {
478
CHECK_PLUGIN_INITIALIZED();
479
480
EditorVCSInterface::get_singleton()->pull(remote_select->get_selected_metadata());
481
_refresh_stage_area();
482
_refresh_branch_list();
483
_refresh_commit_list();
484
_clear_diff();
485
_update_opened_tabs();
486
}
487
488
void VersionControlEditorPlugin::_push() {
489
CHECK_PLUGIN_INITIALIZED();
490
491
EditorVCSInterface::get_singleton()->push(remote_select->get_selected_metadata(), false);
492
}
493
494
void VersionControlEditorPlugin::_force_push() {
495
CHECK_PLUGIN_INITIALIZED();
496
497
EditorVCSInterface::get_singleton()->push(remote_select->get_selected_metadata(), true);
498
}
499
500
void VersionControlEditorPlugin::_update_opened_tabs() {
501
Vector<EditorData::EditedScene> open_scenes = EditorNode::get_editor_data().get_edited_scenes();
502
for (int i = 0; i < open_scenes.size(); i++) {
503
if (open_scenes[i].root == nullptr) {
504
continue;
505
}
506
EditorNode::get_singleton()->reload_scene(open_scenes[i].path);
507
}
508
}
509
510
void VersionControlEditorPlugin::_move_all(Object *p_tree) {
511
Tree *tree = Object::cast_to<Tree>(p_tree);
512
513
TreeItem *file_entry = tree->get_root()->get_first_child();
514
while (file_entry) {
515
_move_item(tree, file_entry);
516
517
file_entry = file_entry->get_next();
518
}
519
_refresh_stage_area();
520
}
521
522
void VersionControlEditorPlugin::_load_diff(Object *p_tree) {
523
CHECK_PLUGIN_INITIALIZED();
524
525
version_control_dock->make_visible();
526
527
Tree *tree = Object::cast_to<Tree>(p_tree);
528
if (tree == staged_files) {
529
show_commit_diff_header = false;
530
String file_path = tree->get_selected()->get_meta(SNAME("file_path"));
531
diff_title->set_text(TTR("Staged Changes"));
532
diff_content = EditorVCSInterface::get_singleton()->get_diff(file_path, EditorVCSInterface::TREE_AREA_STAGED);
533
} else if (tree == unstaged_files) {
534
show_commit_diff_header = false;
535
String file_path = tree->get_selected()->get_meta(SNAME("file_path"));
536
diff_title->set_text(TTR("Unstaged Changes"));
537
diff_content = EditorVCSInterface::get_singleton()->get_diff(file_path, EditorVCSInterface::TREE_AREA_UNSTAGED);
538
} else if (tree == commit_list) {
539
show_commit_diff_header = true;
540
Dictionary meta_data = tree->get_selected()->get_metadata(0);
541
String commit_id = meta_data[SNAME("commit_id")];
542
String commit_title = meta_data[SNAME("commit_title")];
543
diff_title->set_text(commit_title);
544
diff_content = EditorVCSInterface::get_singleton()->get_diff(commit_id, EditorVCSInterface::TREE_AREA_COMMIT);
545
}
546
_display_diff(0);
547
}
548
549
void VersionControlEditorPlugin::_clear_diff() {
550
diff->clear();
551
diff_content.clear();
552
diff_title->set_text("");
553
}
554
555
void VersionControlEditorPlugin::_item_activated(Object *p_tree) {
556
Tree *tree = Object::cast_to<Tree>(p_tree);
557
558
_move_item(tree, tree->get_selected());
559
_refresh_stage_area();
560
}
561
562
void VersionControlEditorPlugin::_move_item(Tree *p_tree, TreeItem *p_item) {
563
CHECK_PLUGIN_INITIALIZED();
564
565
if (p_tree == staged_files) {
566
EditorVCSInterface::get_singleton()->unstage_file(p_item->get_meta(SNAME("file_path")));
567
} else {
568
EditorVCSInterface::get_singleton()->stage_file(p_item->get_meta(SNAME("file_path")));
569
}
570
}
571
572
void VersionControlEditorPlugin::_cell_button_pressed(Object *p_item, int p_column, int p_id, int p_mouse_button_index) {
573
TreeItem *item = Object::cast_to<TreeItem>(p_item);
574
String file_path = item->get_meta(SNAME("file_path"));
575
EditorVCSInterface::ChangeType change = (EditorVCSInterface::ChangeType)(int)item->get_meta(SNAME("change_type"));
576
577
if (p_id == BUTTON_TYPE_OPEN && change != EditorVCSInterface::CHANGE_TYPE_DELETED) {
578
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
579
if (!dir->file_exists(file_path)) {
580
return;
581
}
582
583
file_path = "res://" + file_path;
584
if (ResourceLoader::get_resource_type(file_path) == "PackedScene") {
585
EditorNode::get_singleton()->load_scene(file_path);
586
} else if (file_path.ends_with(".gd")) {
587
EditorNode::get_singleton()->load_resource(file_path);
588
ScriptEditor::get_singleton()->reload_scripts();
589
} else {
590
FileSystemDock::get_singleton()->navigate_to_path(file_path);
591
}
592
593
} else if (p_id == BUTTON_TYPE_DISCARD) {
594
_discard_file(file_path, change);
595
_refresh_stage_area();
596
}
597
}
598
599
void VersionControlEditorPlugin::_display_diff(int p_idx) {
600
DiffViewType diff_view = (DiffViewType)diff_view_type_select->get_selected();
601
602
diff->clear();
603
604
if (show_commit_diff_header) {
605
Dictionary meta_data = commit_list->get_selected()->get_metadata(0);
606
String commit_id = meta_data[SNAME("commit_id")];
607
String commit_subtitle = meta_data[SNAME("commit_subtitle")];
608
String commit_date = meta_data[SNAME("commit_date")];
609
String commit_author = meta_data[SNAME("commit_author")];
610
String commit_date_string = meta_data[SNAME("commit_date_string")];
611
612
diff->push_font(EditorNode::get_singleton()->get_editor_theme()->get_font(SNAME("doc_bold"), EditorStringName(EditorFonts)));
613
diff->push_color(EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("accent_color"), EditorStringName(Editor)));
614
diff->add_text(TTR("Commit:") + " " + commit_id);
615
diff->add_newline();
616
diff->add_text(TTR("Author:") + " " + commit_author);
617
diff->add_newline();
618
diff->add_text(TTR("Date:") + " " + commit_date_string);
619
diff->add_newline();
620
if (!commit_subtitle.is_empty()) {
621
diff->add_text(TTR("Subtitle:") + " " + commit_subtitle);
622
diff->add_newline();
623
}
624
diff->add_newline();
625
diff->pop();
626
diff->pop();
627
}
628
629
for (const EditorVCSInterface::DiffFile &diff_file : diff_content) {
630
diff->push_font(EditorNode::get_singleton()->get_editor_theme()->get_font(SNAME("doc_bold"), EditorStringName(EditorFonts)));
631
diff->push_color(EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("accent_color"), EditorStringName(Editor)));
632
diff->add_text(TTR("File:") + " " + diff_file.new_file);
633
diff->pop();
634
diff->pop();
635
636
diff->push_font(EditorNode::get_singleton()->get_editor_theme()->get_font(SNAME("status_source"), EditorStringName(EditorFonts)));
637
for (EditorVCSInterface::DiffHunk hunk : diff_file.diff_hunks) {
638
String old_start = String::num_int64(hunk.old_start);
639
String new_start = String::num_int64(hunk.new_start);
640
String old_lines = String::num_int64(hunk.old_lines);
641
String new_lines = String::num_int64(hunk.new_lines);
642
643
diff->add_newline();
644
diff->append_text("[center]@@ " + old_start + "," + old_lines + " " + new_start + "," + new_lines + " @@[/center]");
645
diff->add_newline();
646
647
switch (diff_view) {
648
case DIFF_VIEW_TYPE_SPLIT:
649
_display_diff_split_view(hunk.diff_lines);
650
break;
651
case DIFF_VIEW_TYPE_UNIFIED:
652
_display_diff_unified_view(hunk.diff_lines);
653
break;
654
}
655
diff->add_newline();
656
}
657
diff->pop();
658
659
diff->add_newline();
660
}
661
}
662
663
void VersionControlEditorPlugin::_display_diff_split_view(List<EditorVCSInterface::DiffLine> &p_diff_content) {
664
LocalVector<EditorVCSInterface::DiffLine> parsed_diff;
665
666
for (EditorVCSInterface::DiffLine diff_line : p_diff_content) {
667
String line = diff_line.content.strip_edges(false, true);
668
669
if (diff_line.new_line_no >= 0 && diff_line.old_line_no >= 0) {
670
diff_line.new_text = line;
671
diff_line.old_text = line;
672
parsed_diff.push_back(diff_line);
673
} else if (diff_line.new_line_no == -1) {
674
diff_line.new_text = "";
675
diff_line.old_text = line;
676
parsed_diff.push_back(diff_line);
677
} else if (diff_line.old_line_no == -1) {
678
int32_t j = parsed_diff.size() - 1;
679
while (j >= 0 && parsed_diff[j].new_line_no == -1) {
680
j--;
681
}
682
683
if (j == (int32_t)parsed_diff.size() - 1) {
684
// no lines are modified
685
diff_line.new_text = line;
686
diff_line.old_text = "";
687
parsed_diff.push_back(diff_line);
688
} else {
689
// lines are modified
690
EditorVCSInterface::DiffLine modified_line = parsed_diff[j + 1];
691
modified_line.new_text = line;
692
modified_line.new_line_no = diff_line.new_line_no;
693
parsed_diff[j + 1] = modified_line;
694
}
695
}
696
}
697
698
diff->push_table(6);
699
/*
700
[cell]Old Line No[/cell]
701
[cell]prefix[/cell]
702
[cell]Old Code[/cell]
703
704
[cell]New Line No[/cell]
705
[cell]prefix[/cell]
706
[cell]New Line[/cell]
707
*/
708
709
diff->set_table_column_expand(2, true);
710
diff->set_table_column_expand(5, true);
711
712
for (uint32_t i = 0; i < parsed_diff.size(); i++) {
713
EditorVCSInterface::DiffLine diff_line = parsed_diff[i];
714
715
bool has_change = diff_line.status != " ";
716
static const Color red = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor));
717
static const Color green = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("success_color"), EditorStringName(Editor));
718
static const Color white = EditorNode::get_singleton()->get_editor_theme()->get_color(SceneStringName(font_color), SNAME("Label")) * Color(1, 1, 1, 0.6);
719
720
if (diff_line.old_line_no >= 0) {
721
diff->push_cell();
722
diff->push_color(has_change ? red : white);
723
diff->add_text(String::num_int64(diff_line.old_line_no));
724
diff->pop();
725
diff->pop();
726
727
diff->push_cell();
728
diff->push_color(has_change ? red : white);
729
diff->add_text(has_change ? "-|" : " |");
730
diff->pop();
731
diff->pop();
732
733
diff->push_cell();
734
diff->push_color(has_change ? red : white);
735
diff->add_text(diff_line.old_text);
736
diff->pop();
737
diff->pop();
738
739
} else {
740
diff->push_cell();
741
diff->pop();
742
743
diff->push_cell();
744
diff->pop();
745
746
diff->push_cell();
747
diff->pop();
748
}
749
750
if (diff_line.new_line_no >= 0) {
751
diff->push_cell();
752
diff->push_color(has_change ? green : white);
753
diff->add_text(String::num_int64(diff_line.new_line_no));
754
diff->pop();
755
diff->pop();
756
757
diff->push_cell();
758
diff->push_color(has_change ? green : white);
759
diff->add_text(has_change ? "+|" : " |");
760
diff->pop();
761
diff->pop();
762
763
diff->push_cell();
764
diff->push_color(has_change ? green : white);
765
diff->add_text(diff_line.new_text);
766
diff->pop();
767
diff->pop();
768
} else {
769
diff->push_cell();
770
diff->pop();
771
772
diff->push_cell();
773
diff->pop();
774
775
diff->push_cell();
776
diff->pop();
777
}
778
}
779
diff->pop();
780
}
781
782
void VersionControlEditorPlugin::_display_diff_unified_view(List<EditorVCSInterface::DiffLine> &p_diff_content) {
783
diff->push_table(4);
784
diff->set_table_column_expand(3, true);
785
786
/*
787
[cell]Old Line No[/cell]
788
[cell]New Line No[/cell]
789
[cell]status[/cell]
790
[cell]code[/cell]
791
*/
792
for (const EditorVCSInterface::DiffLine &diff_line : p_diff_content) {
793
String line = diff_line.content.strip_edges(false, true);
794
795
Color color;
796
if (diff_line.status == "+") {
797
color = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("success_color"), EditorStringName(Editor));
798
} else if (diff_line.status == "-") {
799
color = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor));
800
} else {
801
color = EditorNode::get_singleton()->get_editor_theme()->get_color(SceneStringName(font_color), SNAME("Label"));
802
color *= Color(1, 1, 1, 0.6);
803
}
804
805
diff->push_cell();
806
diff->push_color(color);
807
diff->push_indent(1);
808
diff->add_text(diff_line.old_line_no >= 0 ? String::num_int64(diff_line.old_line_no) : "");
809
diff->pop();
810
diff->pop();
811
diff->pop();
812
813
diff->push_cell();
814
diff->push_color(color);
815
diff->push_indent(1);
816
diff->add_text(diff_line.new_line_no >= 0 ? String::num_int64(diff_line.new_line_no) : "");
817
diff->pop();
818
diff->pop();
819
diff->pop();
820
821
diff->push_cell();
822
diff->push_color(color);
823
diff->add_text(diff_line.status != "" ? diff_line.status + "|" : " |");
824
diff->pop();
825
diff->pop();
826
827
diff->push_cell();
828
diff->push_color(color);
829
diff->add_text(line);
830
diff->pop();
831
diff->pop();
832
}
833
834
diff->pop();
835
}
836
837
void VersionControlEditorPlugin::_update_commit_button() {
838
commit_button->set_disabled(commit_message->get_text().strip_edges().is_empty());
839
}
840
841
void VersionControlEditorPlugin::_remove_branch() {
842
CHECK_PLUGIN_INITIALIZED();
843
844
EditorVCSInterface::get_singleton()->remove_branch(branch_to_remove);
845
branch_to_remove.clear();
846
847
_refresh_branch_list();
848
}
849
850
void VersionControlEditorPlugin::_remove_remote() {
851
CHECK_PLUGIN_INITIALIZED();
852
853
EditorVCSInterface::get_singleton()->remove_remote(remote_to_remove);
854
remote_to_remove.clear();
855
856
_refresh_remote_list();
857
}
858
859
void VersionControlEditorPlugin::_extra_option_selected(int p_index) {
860
CHECK_PLUGIN_INITIALIZED();
861
862
switch ((ExtraOption)p_index) {
863
case EXTRA_OPTION_FORCE_PUSH:
864
_force_push();
865
break;
866
case EXTRA_OPTION_CREATE_BRANCH:
867
branch_create_confirm->popup_centered();
868
break;
869
case EXTRA_OPTION_CREATE_REMOTE:
870
remote_create_confirm->popup_centered();
871
break;
872
}
873
}
874
875
void VersionControlEditorPlugin::_popup_branch_remove_confirm(int p_index) {
876
branch_to_remove = extra_options_remove_branch_list->get_item_text(p_index);
877
878
branch_remove_confirm->set_text(vformat(TTR("Do you want to remove the %s branch?"), branch_to_remove));
879
branch_remove_confirm->popup_centered();
880
}
881
882
void VersionControlEditorPlugin::_popup_remote_remove_confirm(int p_index) {
883
remote_to_remove = extra_options_remove_remote_list->get_item_text(p_index);
884
885
remote_remove_confirm->set_text(vformat(TTR("Do you want to remove the %s remote?"), branch_to_remove));
886
remote_remove_confirm->popup_centered();
887
}
888
889
void VersionControlEditorPlugin::_update_extra_options() {
890
extra_options_remove_branch_list->clear();
891
for (int i = 0; i < branch_select->get_item_count(); i++) {
892
extra_options_remove_branch_list->add_icon_item(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("VcsBranches"), EditorStringName(EditorIcons)), branch_select->get_item_text(branch_select->get_item_id(i)));
893
}
894
extra_options_remove_branch_list->update_canvas_items();
895
896
extra_options_remove_remote_list->clear();
897
for (int i = 0; i < remote_select->get_item_count(); i++) {
898
extra_options_remove_remote_list->add_icon_item(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ArrowUp"), EditorStringName(EditorIcons)), remote_select->get_item_text(remote_select->get_item_id(i)));
899
}
900
extra_options_remove_remote_list->update_canvas_items();
901
}
902
903
bool VersionControlEditorPlugin::_is_staging_area_empty() {
904
return staged_files->get_root()->get_child_count() == 0;
905
}
906
907
void VersionControlEditorPlugin::_commit_message_gui_input(const Ref<InputEvent> &p_event) {
908
if (!commit_message->has_focus()) {
909
return;
910
}
911
if (commit_message->get_text().strip_edges().is_empty()) {
912
// Do not allow empty commit messages.
913
return;
914
}
915
const Ref<InputEventKey> k = p_event;
916
917
if (k.is_valid() && k->is_pressed()) {
918
if (ED_IS_SHORTCUT("version_control/commit", p_event)) {
919
if (_is_staging_area_empty()) {
920
// Stage all files only when no files were previously staged.
921
_move_all(unstaged_files);
922
}
923
924
_commit();
925
926
commit_message->accept_event();
927
}
928
}
929
}
930
931
void VersionControlEditorPlugin::_toggle_vcs_integration(bool p_toggled) {
932
if (p_toggled) {
933
_initialize_vcs();
934
} else {
935
shut_down();
936
}
937
}
938
939
void VersionControlEditorPlugin::fetch_available_vcs_plugin_names() {
940
available_plugins.clear();
941
ClassDB::get_direct_inheriters_from_class(EditorVCSInterface::get_class_static(), &available_plugins);
942
}
943
944
void VersionControlEditorPlugin::register_editor() {
945
EditorDockManager::get_singleton()->add_dock(version_commit_dock);
946
EditorDockManager::get_singleton()->add_dock(version_control_dock);
947
948
_set_vcs_ui_state(true);
949
}
950
951
void VersionControlEditorPlugin::shut_down() {
952
if (!EditorVCSInterface::get_singleton()) {
953
return;
954
}
955
956
if (EditorFileSystem::get_singleton()->is_connected(SNAME("filesystem_changed"), callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area))) {
957
EditorFileSystem::get_singleton()->disconnect(SNAME("filesystem_changed"), callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area));
958
}
959
960
EditorVCSInterface::get_singleton()->shut_down();
961
memdelete(EditorVCSInterface::get_singleton());
962
EditorVCSInterface::set_singleton(nullptr);
963
964
EditorDockManager::get_singleton()->remove_dock(version_commit_dock);
965
EditorDockManager::get_singleton()->remove_dock(version_control_dock);
966
967
_set_vcs_ui_state(false);
968
}
969
970
VersionControlEditorPlugin::VersionControlEditorPlugin() {
971
singleton = this;
972
973
version_control_actions = memnew(PopupMenu);
974
975
metadata_dialog = memnew(ConfirmationDialog);
976
metadata_dialog->set_title(TTR("Create Version Control Metadata"));
977
metadata_dialog->set_min_size(Size2(200, 40));
978
metadata_dialog->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_create_vcs_metadata_files));
979
EditorInterface::get_singleton()->get_base_control()->add_child(metadata_dialog);
980
981
VBoxContainer *metadata_vb = memnew(VBoxContainer);
982
metadata_dialog->add_child(metadata_vb);
983
984
HBoxContainer *metadata_hb = memnew(HBoxContainer);
985
metadata_hb->set_custom_minimum_size(Size2(200, 20));
986
metadata_vb->add_child(metadata_hb);
987
988
Label *l = memnew(Label);
989
l->set_text(TTR("Create VCS metadata files for:"));
990
metadata_hb->add_child(l);
991
992
metadata_selection = memnew(OptionButton);
993
metadata_selection->set_custom_minimum_size(Size2(100, 20));
994
metadata_selection->add_item("Git", (int)EditorVCSInterface::VCSMetadata::GIT);
995
metadata_selection->select(metadata_selection->get_item_index((int)EditorVCSInterface::VCSMetadata::GIT));
996
metadata_hb->add_child(metadata_selection);
997
998
l = memnew(Label);
999
l->set_text(TTR("Existing VCS metadata files will be overwritten."));
1000
metadata_vb->add_child(l);
1001
1002
set_up_dialog = memnew(AcceptDialog);
1003
set_up_dialog->set_title(TTR("Local Settings"));
1004
set_up_dialog->set_min_size(Size2(600, 100));
1005
set_up_dialog->add_cancel_button("Cancel");
1006
set_up_dialog->set_hide_on_ok(true);
1007
EditorInterface::get_singleton()->get_base_control()->add_child(set_up_dialog);
1008
1009
Button *set_up_apply_button = set_up_dialog->get_ok_button();
1010
set_up_apply_button->set_text(TTR("Apply"));
1011
set_up_apply_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_set_credentials));
1012
1013
set_up_vbc = memnew(VBoxContainer);
1014
set_up_vbc->set_alignment(BoxContainer::ALIGNMENT_CENTER);
1015
set_up_dialog->add_child(set_up_vbc);
1016
1017
HBoxContainer *set_up_hbc = memnew(HBoxContainer);
1018
set_up_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1019
set_up_vbc->add_child(set_up_hbc);
1020
1021
Label *set_up_vcs_label = memnew(Label);
1022
set_up_vcs_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1023
set_up_vcs_label->set_text(TTR("VCS Provider"));
1024
set_up_hbc->add_child(set_up_vcs_label);
1025
1026
set_up_choice = memnew(OptionButton);
1027
set_up_choice->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1028
set_up_hbc->add_child(set_up_choice);
1029
1030
HBoxContainer *toggle_vcs_hbc = memnew(HBoxContainer);
1031
toggle_vcs_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1032
set_up_vbc->add_child(toggle_vcs_hbc);
1033
1034
Label *toggle_vcs_label = memnew(Label);
1035
toggle_vcs_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1036
toggle_vcs_label->set_text(TTR("Connect to VCS"));
1037
toggle_vcs_hbc->add_child(toggle_vcs_label);
1038
1039
toggle_vcs_choice = memnew(CheckButton);
1040
toggle_vcs_choice->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1041
toggle_vcs_choice->set_pressed_no_signal(false);
1042
toggle_vcs_choice->connect(SceneStringName(toggled), callable_mp(this, &VersionControlEditorPlugin::_toggle_vcs_integration));
1043
toggle_vcs_hbc->add_child(toggle_vcs_choice);
1044
1045
set_up_vbc->add_child(memnew(HSeparator));
1046
1047
set_up_settings_vbc = memnew(VBoxContainer);
1048
set_up_settings_vbc->set_alignment(BoxContainer::ALIGNMENT_CENTER);
1049
set_up_vbc->add_child(set_up_settings_vbc);
1050
1051
Label *remote_login = memnew(Label);
1052
remote_login->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1053
remote_login->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
1054
remote_login->set_text(TTR("Remote Login"));
1055
set_up_settings_vbc->add_child(remote_login);
1056
1057
HBoxContainer *set_up_username_input = memnew(HBoxContainer);
1058
set_up_username_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1059
set_up_settings_vbc->add_child(set_up_username_input);
1060
1061
Label *set_up_username_label = memnew(Label);
1062
set_up_username_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1063
set_up_username_label->set_text(TTR("Username"));
1064
set_up_username_input->add_child(set_up_username_label);
1065
1066
set_up_username = memnew(LineEdit);
1067
set_up_username->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1068
set_up_username->set_text(EDITOR_GET("version_control/username"));
1069
set_up_username->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_set_up_warning));
1070
set_up_username_input->add_child(set_up_username);
1071
1072
HBoxContainer *set_up_password_input = memnew(HBoxContainer);
1073
set_up_password_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1074
set_up_settings_vbc->add_child(set_up_password_input);
1075
1076
Label *set_up_password_label = memnew(Label);
1077
set_up_password_label->set_text(TTR("Password"));
1078
set_up_password_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1079
set_up_password_input->add_child(set_up_password_label);
1080
1081
set_up_password = memnew(LineEdit);
1082
set_up_password->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1083
set_up_password->set_secret(true);
1084
set_up_password->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_set_up_warning));
1085
set_up_password_input->add_child(set_up_password);
1086
1087
const String home_dir = OS::get_singleton()->has_environment("HOME") ? OS::get_singleton()->get_environment("HOME") : OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS);
1088
1089
HBoxContainer *set_up_ssh_public_key_input = memnew(HBoxContainer);
1090
set_up_ssh_public_key_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1091
set_up_settings_vbc->add_child(set_up_ssh_public_key_input);
1092
1093
Label *set_up_ssh_public_key_label = memnew(Label);
1094
set_up_ssh_public_key_label->set_text(TTR("SSH Public Key Path"));
1095
set_up_ssh_public_key_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1096
set_up_ssh_public_key_input->add_child(set_up_ssh_public_key_label);
1097
1098
HBoxContainer *set_up_ssh_public_key_input_hbc = memnew(HBoxContainer);
1099
set_up_ssh_public_key_input_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1100
set_up_ssh_public_key_input->add_child(set_up_ssh_public_key_input_hbc);
1101
1102
set_up_ssh_public_key_path = memnew(LineEdit);
1103
set_up_ssh_public_key_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1104
set_up_ssh_public_key_path->set_accessibility_name(TTRC("SSH Public Key Path"));
1105
set_up_ssh_public_key_path->set_text(EDITOR_GET("version_control/ssh_public_key_path"));
1106
set_up_ssh_public_key_path->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_set_up_warning));
1107
set_up_ssh_public_key_input_hbc->add_child(set_up_ssh_public_key_path);
1108
1109
set_up_ssh_public_key_file_dialog = memnew(EditorFileDialog);
1110
set_up_ssh_public_key_file_dialog->set_access(FileDialog::ACCESS_FILESYSTEM);
1111
set_up_ssh_public_key_file_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_FILE);
1112
set_up_ssh_public_key_file_dialog->set_show_hidden_files(true);
1113
set_up_ssh_public_key_file_dialog->set_current_dir(home_dir);
1114
set_up_ssh_public_key_file_dialog->connect(SNAME("file_selected"), callable_mp(this, &VersionControlEditorPlugin::_ssh_public_key_selected));
1115
set_up_ssh_public_key_input_hbc->add_child(set_up_ssh_public_key_file_dialog);
1116
1117
select_public_path_button = memnew(Button);
1118
select_public_path_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_popup_file_dialog).bind(set_up_ssh_public_key_file_dialog));
1119
select_public_path_button->set_tooltip_text(TTR("Select SSH public key path"));
1120
select_public_path_button->set_accessibility_name(TTRC("Select SSH public key path"));
1121
set_up_ssh_public_key_input_hbc->add_child(select_public_path_button);
1122
1123
HBoxContainer *set_up_ssh_private_key_input = memnew(HBoxContainer);
1124
set_up_ssh_private_key_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1125
set_up_settings_vbc->add_child(set_up_ssh_private_key_input);
1126
1127
Label *set_up_ssh_private_key_label = memnew(Label);
1128
set_up_ssh_private_key_label->set_text(TTR("SSH Private Key Path"));
1129
set_up_ssh_private_key_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1130
set_up_ssh_private_key_input->add_child(set_up_ssh_private_key_label);
1131
1132
HBoxContainer *set_up_ssh_private_key_input_hbc = memnew(HBoxContainer);
1133
set_up_ssh_private_key_input_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1134
set_up_ssh_private_key_input->add_child(set_up_ssh_private_key_input_hbc);
1135
1136
set_up_ssh_private_key_path = memnew(LineEdit);
1137
set_up_ssh_private_key_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1138
set_up_ssh_private_key_path->set_text(EDITOR_GET("version_control/ssh_private_key_path"));
1139
set_up_ssh_private_key_path->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_set_up_warning));
1140
set_up_ssh_private_key_path->set_accessibility_name(TTRC("SSH Private Key Path"));
1141
set_up_ssh_private_key_input_hbc->add_child(set_up_ssh_private_key_path);
1142
1143
set_up_ssh_private_key_file_dialog = memnew(EditorFileDialog);
1144
set_up_ssh_private_key_file_dialog->set_access(FileDialog::ACCESS_FILESYSTEM);
1145
set_up_ssh_private_key_file_dialog->set_file_mode(FileDialog::FILE_MODE_OPEN_FILE);
1146
set_up_ssh_private_key_file_dialog->set_show_hidden_files(true);
1147
set_up_ssh_private_key_file_dialog->set_current_dir(home_dir);
1148
set_up_ssh_private_key_file_dialog->connect("file_selected", callable_mp(this, &VersionControlEditorPlugin::_ssh_private_key_selected));
1149
set_up_ssh_private_key_input_hbc->add_child(set_up_ssh_private_key_file_dialog);
1150
1151
select_private_path_button = memnew(Button);
1152
select_private_path_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_popup_file_dialog).bind(set_up_ssh_private_key_file_dialog));
1153
select_private_path_button->set_tooltip_text(TTR("Select SSH private key path"));
1154
set_up_ssh_private_key_input_hbc->add_child(select_private_path_button);
1155
1156
HBoxContainer *set_up_ssh_passphrase_input = memnew(HBoxContainer);
1157
set_up_ssh_passphrase_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1158
set_up_settings_vbc->add_child(set_up_ssh_passphrase_input);
1159
1160
Label *set_up_ssh_passphrase_label = memnew(Label);
1161
set_up_ssh_passphrase_label->set_text(TTR("SSH Passphrase"));
1162
set_up_ssh_passphrase_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1163
set_up_ssh_passphrase_input->add_child(set_up_ssh_passphrase_label);
1164
1165
set_up_ssh_passphrase = memnew(LineEdit);
1166
set_up_ssh_passphrase->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1167
set_up_ssh_passphrase->set_secret(true);
1168
set_up_ssh_passphrase->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_set_up_warning));
1169
set_up_ssh_passphrase->set_accessibility_name(TTRC("SSH Passphrase"));
1170
set_up_ssh_passphrase_input->add_child(set_up_ssh_passphrase);
1171
1172
set_up_warning_text = memnew(Label);
1173
set_up_warning_text->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
1174
set_up_warning_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
1175
set_up_warning_text->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1176
set_up_settings_vbc->add_child(set_up_warning_text);
1177
1178
version_commit_dock = memnew(EditorDock);
1179
version_commit_dock->set_visible(false);
1180
version_commit_dock->set_name(TTRC("Commit"));
1181
version_commit_dock->set_layout_key("VersionCommit");
1182
version_commit_dock->set_icon_name("VCSCommit");
1183
version_commit_dock->set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("docks/open_version_control", TTRC("Open Version Control Dock")));
1184
version_commit_dock->set_default_slot(EditorDock::DOCK_SLOT_RIGHT_UL);
1185
1186
VBoxContainer *dock_vb = memnew(VBoxContainer);
1187
version_commit_dock->add_child(dock_vb);
1188
1189
VBoxContainer *unstage_area = memnew(VBoxContainer);
1190
unstage_area->set_v_size_flags(Control::SIZE_EXPAND_FILL);
1191
unstage_area->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1192
dock_vb->add_child(unstage_area);
1193
1194
HBoxContainer *unstage_title = memnew(HBoxContainer);
1195
unstage_area->add_child(unstage_title);
1196
1197
Label *unstage_label = memnew(Label);
1198
unstage_label->set_text(TTR("Unstaged Changes"));
1199
unstage_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1200
unstage_title->add_child(unstage_label);
1201
1202
refresh_button = memnew(Button);
1203
refresh_button->set_tooltip_text(TTR("Detect new changes"));
1204
refresh_button->set_theme_type_variation(SceneStringName(FlatButton));
1205
refresh_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area));
1206
refresh_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_refresh_commit_list));
1207
refresh_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_refresh_branch_list));
1208
refresh_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_refresh_remote_list));
1209
unstage_title->add_child(refresh_button);
1210
1211
discard_all_confirm = memnew(AcceptDialog);
1212
discard_all_confirm->set_title(TTR("Discard all changes"));
1213
discard_all_confirm->set_min_size(Size2i(400, 50));
1214
discard_all_confirm->set_text(TTR("This operation is IRREVERSIBLE. Your changes will be deleted FOREVER."));
1215
discard_all_confirm->set_hide_on_ok(true);
1216
discard_all_confirm->set_ok_button_text(TTR("Permanentally delete my changes"));
1217
discard_all_confirm->add_cancel_button();
1218
dock_vb->add_child(discard_all_confirm);
1219
1220
discard_all_confirm->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_discard_all));
1221
1222
discard_all_button = memnew(Button);
1223
discard_all_button->set_tooltip_text(TTR("Discard all changes"));
1224
discard_all_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_confirm_discard_all));
1225
discard_all_button->set_theme_type_variation(SceneStringName(FlatButton));
1226
unstage_title->add_child(discard_all_button);
1227
1228
stage_all_button = memnew(Button);
1229
stage_all_button->set_accessibility_name(TTRC("Stage all changes"));
1230
stage_all_button->set_theme_type_variation(SceneStringName(FlatButton));
1231
stage_all_button->set_tooltip_text(TTR("Stage all changes"));
1232
unstage_title->add_child(stage_all_button);
1233
1234
MarginContainer *mc = memnew(MarginContainer);
1235
mc->set_v_size_flags(Tree::SIZE_EXPAND_FILL);
1236
mc->set_theme_type_variation("NoBorderHorizontal");
1237
unstage_area->add_child(mc);
1238
1239
unstaged_files = memnew(Tree);
1240
unstaged_files->set_select_mode(Tree::SELECT_ROW);
1241
unstaged_files->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_load_diff).bind(unstaged_files));
1242
unstaged_files->connect(SNAME("item_activated"), callable_mp(this, &VersionControlEditorPlugin::_item_activated).bind(unstaged_files));
1243
unstaged_files->connect(SNAME("button_clicked"), callable_mp(this, &VersionControlEditorPlugin::_cell_button_pressed));
1244
unstaged_files->create_item();
1245
unstaged_files->set_hide_root(true);
1246
unstaged_files->set_scroll_hint_mode(Tree::SCROLL_HINT_MODE_BOTH);
1247
mc->add_child(unstaged_files);
1248
1249
VBoxContainer *stage_area = memnew(VBoxContainer);
1250
stage_area->set_v_size_flags(Control::SIZE_EXPAND_FILL);
1251
stage_area->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1252
dock_vb->add_child(stage_area);
1253
1254
HBoxContainer *stage_title = memnew(HBoxContainer);
1255
stage_area->add_child(stage_title);
1256
1257
Label *stage_label = memnew(Label);
1258
stage_label->set_text(TTR("Staged Changes"));
1259
stage_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1260
stage_title->add_child(stage_label);
1261
1262
unstage_all_button = memnew(Button);
1263
unstage_all_button->set_accessibility_name(TTRC("Unstage all changes"));
1264
unstage_all_button->set_theme_type_variation(SceneStringName(FlatButton));
1265
unstage_all_button->set_tooltip_text(TTR("Unstage all changes"));
1266
stage_title->add_child(unstage_all_button);
1267
1268
mc = memnew(MarginContainer);
1269
mc->set_v_size_flags(Tree::SIZE_EXPAND_FILL);
1270
mc->set_theme_type_variation("NoBorderHorizontal");
1271
stage_area->add_child(mc);
1272
1273
staged_files = memnew(Tree);
1274
staged_files->set_select_mode(Tree::SELECT_ROW);
1275
staged_files->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_load_diff).bind(staged_files));
1276
staged_files->connect(SNAME("button_clicked"), callable_mp(this, &VersionControlEditorPlugin::_cell_button_pressed));
1277
staged_files->connect(SNAME("item_activated"), callable_mp(this, &VersionControlEditorPlugin::_item_activated).bind(staged_files));
1278
staged_files->create_item();
1279
staged_files->set_hide_root(true);
1280
staged_files->set_scroll_hint_mode(Tree::SCROLL_HINT_MODE_BOTH);
1281
mc->add_child(staged_files);
1282
1283
// Editor crashes if bind is null
1284
unstage_all_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_move_all).bind(staged_files));
1285
stage_all_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_move_all).bind(unstaged_files));
1286
1287
VBoxContainer *commit_area = memnew(VBoxContainer);
1288
dock_vb->add_child(commit_area);
1289
1290
Label *commit_label = memnew(Label);
1291
commit_label->set_text(TTR("Commit Message"));
1292
commit_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1293
commit_area->add_child(commit_label);
1294
1295
commit_message = memnew(TextEdit);
1296
commit_message->set_accessibility_name(TTRC("Commit Message"));
1297
commit_message->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1298
commit_message->set_h_grow_direction(Control::GrowDirection::GROW_DIRECTION_BEGIN);
1299
commit_message->set_v_grow_direction(Control::GrowDirection::GROW_DIRECTION_END);
1300
commit_message->set_custom_minimum_size(Size2(200, 100));
1301
commit_message->set_line_wrapping_mode(TextEdit::LINE_WRAPPING_BOUNDARY);
1302
commit_message->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_commit_button));
1303
commit_message->connect(SceneStringName(gui_input), callable_mp(this, &VersionControlEditorPlugin::_commit_message_gui_input));
1304
commit_area->add_child(commit_message);
1305
1306
ED_SHORTCUT("version_control/commit", TTRC("Commit"), KeyModifierMask::CMD_OR_CTRL | Key::ENTER);
1307
1308
commit_button = memnew(Button);
1309
commit_button->set_text(TTR("Commit Changes"));
1310
commit_button->set_disabled(true);
1311
commit_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_commit));
1312
commit_area->add_child(commit_button);
1313
1314
dock_vb->add_child(memnew(HSeparator));
1315
1316
HBoxContainer *commit_list_hbc = memnew(HBoxContainer);
1317
dock_vb->add_child(commit_list_hbc);
1318
1319
Label *commit_list_label = memnew(Label);
1320
commit_list_label->set_text(TTR("Commit List"));
1321
commit_list_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1322
commit_list_hbc->add_child(commit_list_label);
1323
1324
commit_list_size_button = memnew(OptionButton);
1325
commit_list_size_button->set_tooltip_text(TTR("Commit list size"));
1326
commit_list_size_button->add_item("10");
1327
commit_list_size_button->set_item_metadata(0, 10);
1328
commit_list_size_button->add_item("20");
1329
commit_list_size_button->set_item_metadata(1, 20);
1330
commit_list_size_button->add_item("30");
1331
commit_list_size_button->set_item_metadata(2, 30);
1332
commit_list_size_button->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_set_commit_list_size));
1333
commit_list_hbc->add_child(commit_list_size_button);
1334
1335
mc = memnew(MarginContainer);
1336
mc->set_v_grow_direction(Control::GrowDirection::GROW_DIRECTION_END);
1337
mc->set_theme_type_variation("NoBorderHorizontal");
1338
dock_vb->add_child(mc);
1339
1340
commit_list = memnew(Tree);
1341
commit_list->set_custom_minimum_size(Size2(200, 160));
1342
commit_list->create_item();
1343
commit_list->set_hide_root(true);
1344
commit_list->set_select_mode(Tree::SELECT_ROW);
1345
commit_list->set_columns(2); // Commit message and author.
1346
commit_list->set_column_custom_minimum_width(0, 40);
1347
commit_list->set_column_custom_minimum_width(1, 20);
1348
commit_list->set_scroll_hint_mode(Tree::SCROLL_HINT_MODE_BOTH);
1349
commit_list->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_load_diff).bind(commit_list));
1350
mc->add_child(commit_list);
1351
1352
HFlowContainer *menu_bar = memnew(HFlowContainer);
1353
menu_bar->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1354
menu_bar->set_v_size_flags(Control::SIZE_FILL);
1355
dock_vb->add_child(menu_bar);
1356
1357
branch_select = memnew(OptionButton);
1358
branch_select->set_tooltip_text(TTR("Branches"));
1359
branch_select->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1360
branch_select->set_clip_text(true);
1361
branch_select->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_branch_item_selected));
1362
branch_select->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_refresh_branch_list));
1363
menu_bar->add_child(branch_select);
1364
1365
branch_create_confirm = memnew(AcceptDialog);
1366
branch_create_confirm->set_title(TTR("Create New Branch"));
1367
branch_create_confirm->set_min_size(Size2(400, 100));
1368
branch_create_confirm->set_hide_on_ok(true);
1369
version_commit_dock->add_child(branch_create_confirm);
1370
1371
branch_create_ok = branch_create_confirm->get_ok_button();
1372
branch_create_ok->set_text(TTR("Create"));
1373
branch_create_ok->set_disabled(true);
1374
branch_create_ok->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_create_branch));
1375
1376
branch_remove_confirm = memnew(AcceptDialog);
1377
branch_remove_confirm->set_title(TTR("Remove Branch"));
1378
branch_remove_confirm->add_cancel_button();
1379
version_commit_dock->add_child(branch_remove_confirm);
1380
1381
Button *branch_remove_ok = branch_remove_confirm->get_ok_button();
1382
branch_remove_ok->set_text(TTR("Remove"));
1383
branch_remove_ok->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_remove_branch));
1384
1385
VBoxContainer *branch_create_vbc = memnew(VBoxContainer);
1386
branch_create_vbc->set_alignment(BoxContainer::ALIGNMENT_CENTER);
1387
branch_create_confirm->add_child(branch_create_vbc);
1388
1389
HBoxContainer *branch_create_hbc = memnew(HBoxContainer);
1390
branch_create_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1391
branch_create_vbc->add_child(branch_create_hbc);
1392
1393
Label *branch_create_name_label = memnew(Label);
1394
branch_create_name_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1395
branch_create_name_label->set_text(TTR("Branch Name"));
1396
branch_create_hbc->add_child(branch_create_name_label);
1397
1398
branch_create_name_input = memnew(LineEdit);
1399
branch_create_name_input->set_accessibility_name(TTRC("Branch Name"));
1400
branch_create_name_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1401
branch_create_name_input->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_branch_create_button));
1402
branch_create_hbc->add_child(branch_create_name_input);
1403
1404
remote_select = memnew(OptionButton);
1405
remote_select->set_tooltip_text(TTR("Remotes"));
1406
remote_select->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1407
remote_select->set_clip_text(true);
1408
remote_select->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_remote_selected));
1409
remote_select->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_refresh_remote_list));
1410
menu_bar->add_child(remote_select);
1411
1412
remote_create_confirm = memnew(AcceptDialog);
1413
remote_create_confirm->set_title(TTR("Create New Remote"));
1414
remote_create_confirm->set_min_size(Size2(400, 100));
1415
remote_create_confirm->set_hide_on_ok(true);
1416
version_commit_dock->add_child(remote_create_confirm);
1417
1418
remote_create_ok = remote_create_confirm->get_ok_button();
1419
remote_create_ok->set_text(TTR("Create"));
1420
remote_create_ok->set_disabled(true);
1421
remote_create_ok->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_create_remote));
1422
1423
remote_remove_confirm = memnew(AcceptDialog);
1424
remote_remove_confirm->set_title(TTR("Remove Remote"));
1425
remote_remove_confirm->add_cancel_button();
1426
version_commit_dock->add_child(remote_remove_confirm);
1427
1428
Button *remote_remove_ok = remote_remove_confirm->get_ok_button();
1429
remote_remove_ok->set_text(TTR("Remove"));
1430
remote_remove_ok->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_remove_remote));
1431
1432
VBoxContainer *remote_create_vbc = memnew(VBoxContainer);
1433
remote_create_vbc->set_alignment(BoxContainer::ALIGNMENT_CENTER);
1434
remote_create_confirm->add_child(remote_create_vbc);
1435
1436
HBoxContainer *remote_create_name_hbc = memnew(HBoxContainer);
1437
remote_create_name_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1438
remote_create_vbc->add_child(remote_create_name_hbc);
1439
1440
Label *remote_create_name_label = memnew(Label);
1441
remote_create_name_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1442
remote_create_name_label->set_text(TTR("Remote Name"));
1443
remote_create_name_hbc->add_child(remote_create_name_label);
1444
1445
remote_create_name_input = memnew(LineEdit);
1446
remote_create_name_input->set_accessibility_name(TTRC("Remote Name"));
1447
remote_create_name_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1448
remote_create_name_input->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_remote_create_button));
1449
remote_create_name_hbc->add_child(remote_create_name_input);
1450
1451
HBoxContainer *remote_create_hbc = memnew(HBoxContainer);
1452
remote_create_hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1453
remote_create_vbc->add_child(remote_create_hbc);
1454
1455
Label *remote_create_url_label = memnew(Label);
1456
remote_create_url_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1457
remote_create_url_label->set_text(TTR("Remote URL"));
1458
remote_create_hbc->add_child(remote_create_url_label);
1459
1460
remote_create_url_input = memnew(LineEdit);
1461
remote_create_url_input->set_accessibility_name(TTRC("Remote URL"));
1462
remote_create_url_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1463
remote_create_url_input->connect(SceneStringName(text_changed), callable_mp(this, &VersionControlEditorPlugin::_update_remote_create_button));
1464
remote_create_hbc->add_child(remote_create_url_input);
1465
1466
fetch_button = memnew(Button);
1467
fetch_button->set_theme_type_variation(SceneStringName(FlatButton));
1468
fetch_button->set_tooltip_text(TTR("Fetch"));
1469
fetch_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_fetch));
1470
menu_bar->add_child(fetch_button);
1471
1472
pull_button = memnew(Button);
1473
pull_button->set_theme_type_variation(SceneStringName(FlatButton));
1474
pull_button->set_tooltip_text(TTR("Pull"));
1475
pull_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_pull));
1476
menu_bar->add_child(pull_button);
1477
1478
push_button = memnew(Button);
1479
push_button->set_theme_type_variation(SceneStringName(FlatButton));
1480
push_button->set_tooltip_text(TTR("Push"));
1481
push_button->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_push));
1482
menu_bar->add_child(push_button);
1483
1484
extra_options = memnew(MenuButton);
1485
extra_options->set_accessibility_name(TTRC("Extra options"));
1486
extra_options->get_popup()->connect(SNAME("about_to_popup"), callable_mp(this, &VersionControlEditorPlugin::_update_extra_options));
1487
extra_options->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &VersionControlEditorPlugin::_extra_option_selected));
1488
menu_bar->add_child(extra_options);
1489
1490
extra_options->get_popup()->add_item(TTR("Force Push"), EXTRA_OPTION_FORCE_PUSH);
1491
extra_options->get_popup()->add_separator();
1492
extra_options->get_popup()->add_item(TTR("Create New Branch"), EXTRA_OPTION_CREATE_BRANCH);
1493
1494
extra_options_remove_branch_list = memnew(PopupMenu);
1495
extra_options_remove_branch_list->connect(SceneStringName(id_pressed), callable_mp(this, &VersionControlEditorPlugin::_popup_branch_remove_confirm));
1496
extra_options->get_popup()->add_submenu_node_item(TTR("Remove Branch"), extra_options_remove_branch_list);
1497
1498
extra_options->get_popup()->add_separator();
1499
extra_options->get_popup()->add_item(TTR("Create New Remote"), EXTRA_OPTION_CREATE_REMOTE);
1500
1501
extra_options_remove_remote_list = memnew(PopupMenu);
1502
extra_options_remove_remote_list->connect(SceneStringName(id_pressed), callable_mp(this, &VersionControlEditorPlugin::_popup_remote_remove_confirm));
1503
extra_options->get_popup()->add_submenu_node_item(TTR("Remove Remote"), extra_options_remove_remote_list);
1504
1505
change_type_to_strings[EditorVCSInterface::CHANGE_TYPE_NEW] = TTR("New");
1506
change_type_to_strings[EditorVCSInterface::CHANGE_TYPE_MODIFIED] = TTR("Modified");
1507
change_type_to_strings[EditorVCSInterface::CHANGE_TYPE_RENAMED] = TTR("Renamed");
1508
change_type_to_strings[EditorVCSInterface::CHANGE_TYPE_DELETED] = TTR("Deleted");
1509
change_type_to_strings[EditorVCSInterface::CHANGE_TYPE_TYPECHANGE] = TTR("Typechange");
1510
change_type_to_strings[EditorVCSInterface::CHANGE_TYPE_UNMERGED] = TTR("Unmerged");
1511
1512
version_control_dock = memnew(EditorDock);
1513
version_control_dock->set_name(TTRC("Version Control"));
1514
version_control_dock->set_icon_name("VcsBranches");
1515
version_control_dock->set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_version_control_bottom_panel", TTRC("Toggle Version Control Dock")));
1516
version_control_dock->set_default_slot(EditorDock::DOCK_SLOT_BOTTOM);
1517
version_control_dock->set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING);
1518
version_control_dock->set_global(false);
1519
version_control_dock->set_transient(true);
1520
version_control_dock->set_custom_minimum_size(Size2(0, 300) * EDSCALE);
1521
version_commit_dock->connect("opened", callable_mp(EditorDockManager::get_singleton(), &EditorDockManager::open_dock).bind(version_control_dock, false));
1522
version_commit_dock->connect("closed", callable_mp(EditorDockManager::get_singleton(), &EditorDockManager::close_dock).bind(version_control_dock));
1523
1524
VBoxContainer *vbc = memnew(VBoxContainer);
1525
version_control_dock->add_child(vbc);
1526
1527
HBoxContainer *diff_heading = memnew(HBoxContainer);
1528
diff_heading->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1529
diff_heading->set_tooltip_text(TTR("View file diffs before committing them to the latest version"));
1530
vbc->add_child(diff_heading);
1531
1532
diff_title = memnew(Label);
1533
diff_title->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
1534
diff_title->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1535
diff_heading->add_child(diff_title);
1536
1537
Label *view = memnew(Label);
1538
view->set_text(TTR("View:"));
1539
diff_heading->add_child(view);
1540
1541
diff_view_type_select = memnew(OptionButton);
1542
diff_view_type_select->set_accessibility_name(TTRC("View:"));
1543
diff_view_type_select->add_item(TTR("Split"), DIFF_VIEW_TYPE_SPLIT);
1544
diff_view_type_select->add_item(TTR("Unified"), DIFF_VIEW_TYPE_UNIFIED);
1545
diff_view_type_select->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_display_diff));
1546
diff_heading->add_child(diff_view_type_select);
1547
1548
diff = memnew(RichTextLabel);
1549
diff->set_h_size_flags(TextEdit::SIZE_EXPAND_FILL);
1550
diff->set_v_size_flags(TextEdit::SIZE_EXPAND_FILL);
1551
diff->set_use_bbcode(true);
1552
diff->set_selection_enabled(true);
1553
diff->set_context_menu_enabled(true);
1554
vbc->add_child(diff);
1555
1556
_update_set_up_warning("");
1557
EditorNode::get_singleton()->get_gui_base()->connect(SceneStringName(theme_changed), callable_mp(this, &VersionControlEditorPlugin::_update_theme));
1558
}
1559
1560
VersionControlEditorPlugin::~VersionControlEditorPlugin() {
1561
shut_down();
1562
memdelete(version_commit_dock);
1563
memdelete(version_control_dock);
1564
memdelete(version_control_actions);
1565
}
1566
1567