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