Debian Codegraph @

editor/version_control/version_control_editor_plugin.cpp

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