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) 2007-2020 Juan Linietsky, Ariel Manzur. */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
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/script_language.h"
34 #include "editor/editor_file_system.h"
35 #include "editor/editor_node.h"
36 #include "editor/editor_scale.h"
37
38 VersionControlEditorPlugin *VersionControlEditorPlugin::singleton = NULL;
39
_bind_methods()40 void VersionControlEditorPlugin::_bind_methods() {
41
42 ClassDB::bind_method(D_METHOD("_selected_a_vcs"), &VersionControlEditorPlugin::_selected_a_vcs);
43 ClassDB::bind_method(D_METHOD("_initialize_vcs"), &VersionControlEditorPlugin::_initialize_vcs);
44 ClassDB::bind_method(D_METHOD("_send_commit_msg"), &VersionControlEditorPlugin::_send_commit_msg);
45 ClassDB::bind_method(D_METHOD("_refresh_stage_area"), &VersionControlEditorPlugin::_refresh_stage_area);
46 ClassDB::bind_method(D_METHOD("_stage_all"), &VersionControlEditorPlugin::_stage_all);
47 ClassDB::bind_method(D_METHOD("_stage_selected"), &VersionControlEditorPlugin::_stage_selected);
48 ClassDB::bind_method(D_METHOD("_view_file_diff"), &VersionControlEditorPlugin::_view_file_diff);
49 ClassDB::bind_method(D_METHOD("_refresh_file_diff"), &VersionControlEditorPlugin::_refresh_file_diff);
50 ClassDB::bind_method(D_METHOD("popup_vcs_set_up_dialog"), &VersionControlEditorPlugin::popup_vcs_set_up_dialog);
51
52 // Used to track the status of files in the staging area
53 BIND_ENUM_CONSTANT(CHANGE_TYPE_NEW);
54 BIND_ENUM_CONSTANT(CHANGE_TYPE_MODIFIED);
55 BIND_ENUM_CONSTANT(CHANGE_TYPE_RENAMED);
56 BIND_ENUM_CONSTANT(CHANGE_TYPE_DELETED);
57 BIND_ENUM_CONSTANT(CHANGE_TYPE_TYPECHANGE);
58 }
59
_selected_a_vcs(int p_id)60 void VersionControlEditorPlugin::_selected_a_vcs(int p_id) {
61
62 List<StringName> available_addons = get_available_vcs_names();
63 const StringName selected_vcs = set_up_choice->get_item_text(p_id);
64 }
65
_populate_available_vcs_names()66 void VersionControlEditorPlugin::_populate_available_vcs_names() {
67
68 static bool called = false;
69
70 if (!called) {
71
72 List<StringName> available_addons = get_available_vcs_names();
73 for (int i = 0; i < available_addons.size(); i++) {
74
75 set_up_choice->add_item(available_addons[i]);
76 }
77
78 called = true;
79 }
80 }
81
get_singleton()82 VersionControlEditorPlugin *VersionControlEditorPlugin::get_singleton() {
83
84 return singleton ? singleton : memnew(VersionControlEditorPlugin);
85 }
86
popup_vcs_set_up_dialog(const Control * p_gui_base)87 void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_base) {
88
89 fetch_available_vcs_addon_names();
90 List<StringName> available_addons = get_available_vcs_names();
91 if (available_addons.size() >= 1) {
92
93 Size2 popup_size = Size2(400, 100);
94 Size2 window_size = p_gui_base->get_viewport_rect().size;
95 popup_size.x = MIN(window_size.x * 0.5, popup_size.x);
96 popup_size.y = MIN(window_size.y * 0.5, popup_size.y);
97
98 _populate_available_vcs_names();
99
100 set_up_dialog->popup_centered_clamped(popup_size * EDSCALE);
101 } else {
102
103 EditorNode::get_singleton()->show_warning(TTR("No VCS addons are available."), TTR("Error"));
104 }
105 }
106
_initialize_vcs()107 void VersionControlEditorPlugin::_initialize_vcs() {
108
109 register_editor();
110
111 ERR_FAIL_COND_MSG(EditorVCSInterface::get_singleton(), EditorVCSInterface::get_singleton()->get_vcs_name() + " is already active");
112
113 const int id = set_up_choice->get_selected_id();
114 String selected_addon = set_up_choice->get_item_text(id);
115
116 String path = ScriptServer::get_global_class_path(selected_addon);
117 Ref<Script> script = ResourceLoader::load(path);
118
119 ERR_FAIL_COND_MSG(!script.is_valid(), "VCS Addon path is invalid");
120
121 EditorVCSInterface *vcs_interface = memnew(EditorVCSInterface);
122 ScriptInstance *addon_script_instance = script->instance_create(vcs_interface);
123
124 ERR_FAIL_COND_MSG(!addon_script_instance, "Failed to create addon script instance.");
125
126 // The addon is attached as a script to the VCS interface as a proxy end-point
127 vcs_interface->set_script_and_instance(script.get_ref_ptr(), addon_script_instance);
128
129 EditorVCSInterface::set_singleton(vcs_interface);
130 EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_refresh_stage_area");
131
132 String res_dir = OS::get_singleton()->get_resource_dir();
133
134 ERR_FAIL_COND_MSG(!EditorVCSInterface::get_singleton()->initialize(res_dir), "VCS was not initialized");
135
136 _refresh_stage_area();
137 }
138
_send_commit_msg()139 void VersionControlEditorPlugin::_send_commit_msg() {
140
141 String msg = commit_message->get_text();
142 if (msg == "") {
143
144 commit_status->set_text(TTR("No commit message was provided"));
145 return;
146 }
147
148 if (EditorVCSInterface::get_singleton()) {
149
150 if (staged_files_count == 0) {
151
152 commit_status->set_text(TTR("No files added to stage"));
153 return;
154 }
155
156 EditorVCSInterface::get_singleton()->commit(msg);
157
158 commit_message->set_text("");
159 version_control_dock_button->set_pressed(false);
160 } else {
161
162 WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu");
163 }
164
165 _update_commit_status();
166 _refresh_stage_area();
167 _clear_file_diff();
168 }
169
_refresh_stage_area()170 void VersionControlEditorPlugin::_refresh_stage_area() {
171
172 if (EditorVCSInterface::get_singleton()) {
173
174 staged_files_count = 0;
175 clear_stage_area();
176
177 Dictionary modified_file_paths = EditorVCSInterface::get_singleton()->get_modified_files_data();
178 String file_path;
179 for (int i = 0; i < modified_file_paths.size(); i++) {
180
181 file_path = modified_file_paths.get_key_at_index(i);
182 TreeItem *found = stage_files->search_item_text(file_path, 0, true);
183 if (!found) {
184
185 ChangeType change_index = (ChangeType)(int)modified_file_paths.get_value_at_index(i);
186 String change_text = file_path + " (" + change_type_to_strings[change_index] + ")";
187 Color &change_color = change_type_to_color[change_index];
188 TreeItem *new_item = stage_files->create_item(stage_files->get_root());
189 new_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
190 new_item->set_text(0, change_text);
191 new_item->set_metadata(0, file_path);
192 new_item->set_custom_color(0, change_color);
193 new_item->set_checked(0, true);
194 new_item->set_editable(0, true);
195 } else {
196
197 if (found->get_metadata(0) == diff_file_name->get_text()) {
198
199 _refresh_file_diff();
200 }
201 }
202 commit_status->set_text("New changes detected");
203 }
204 } else {
205
206 WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu.")
207 }
208 }
209
_stage_selected()210 void VersionControlEditorPlugin::_stage_selected() {
211
212 if (!EditorVCSInterface::get_singleton()) {
213
214 WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu");
215 return;
216 }
217
218 staged_files_count = 0;
219 TreeItem *root = stage_files->get_root();
220 if (root) {
221
222 TreeItem *file_entry = root->get_children();
223 while (file_entry) {
224
225 if (file_entry->is_checked(0)) {
226
227 EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0));
228 file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor"));
229 staged_files_count++;
230 } else {
231
232 EditorVCSInterface::get_singleton()->unstage_file(file_entry->get_metadata(0));
233 file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
234 }
235
236 file_entry = file_entry->get_next();
237 }
238 }
239
240 _update_stage_status();
241 }
242
_stage_all()243 void VersionControlEditorPlugin::_stage_all() {
244
245 if (!EditorVCSInterface::get_singleton()) {
246
247 WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu");
248 return;
249 }
250
251 staged_files_count = 0;
252 TreeItem *root = stage_files->get_root();
253 if (root) {
254
255 TreeItem *file_entry = root->get_children();
256 while (file_entry) {
257
258 EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0));
259 file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor"));
260 file_entry->set_checked(0, true);
261 staged_files_count++;
262
263 file_entry = file_entry->get_next();
264 }
265 }
266
267 _update_stage_status();
268 }
269
_view_file_diff()270 void VersionControlEditorPlugin::_view_file_diff() {
271
272 version_control_dock_button->set_pressed(true);
273
274 String file_path = stage_files->get_selected()->get_metadata(0);
275
276 _display_file_diff(file_path);
277 }
278
_display_file_diff(String p_file_path)279 void VersionControlEditorPlugin::_display_file_diff(String p_file_path) {
280
281 Array diff_content = EditorVCSInterface::get_singleton()->get_file_diff(p_file_path);
282
283 diff_file_name->set_text(p_file_path);
284
285 diff->clear();
286 diff->push_font(EditorNode::get_singleton()->get_gui_base()->get_font("source", "EditorFonts"));
287 for (int i = 0; i < diff_content.size(); i++) {
288
289 Dictionary line_result = diff_content[i];
290
291 if (line_result["status"] == "+") {
292
293 diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor"));
294 } else if (line_result["status"] == "-") {
295
296 diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
297 } else {
298
299 diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("font_color", "Label"));
300 }
301
302 diff->add_text((String)line_result["content"]);
303
304 diff->pop();
305 }
306 diff->pop();
307 }
308
_refresh_file_diff()309 void VersionControlEditorPlugin::_refresh_file_diff() {
310
311 String open_file = diff_file_name->get_text();
312 if (open_file != "") {
313
314 _display_file_diff(diff_file_name->get_text());
315 }
316 }
317
_clear_file_diff()318 void VersionControlEditorPlugin::_clear_file_diff() {
319
320 diff->clear();
321 diff_file_name->set_text("");
322 version_control_dock_button->set_pressed(false);
323 }
324
_update_stage_status()325 void VersionControlEditorPlugin::_update_stage_status() {
326
327 String status;
328 if (staged_files_count == 1) {
329
330 status = "Stage contains 1 file";
331 } else {
332
333 status = "Stage contains " + String::num_int64(staged_files_count) + " files";
334 }
335 commit_status->set_text(status);
336 }
337
_update_commit_status()338 void VersionControlEditorPlugin::_update_commit_status() {
339
340 String status;
341 if (staged_files_count == 1) {
342
343 status = "Committed 1 file";
344 } else {
345
346 status = "Committed " + String::num_int64(staged_files_count) + " files ";
347 }
348 commit_status->set_text(status);
349 staged_files_count = 0;
350 }
351
register_editor()352 void VersionControlEditorPlugin::register_editor() {
353
354 if (!EditorVCSInterface::get_singleton()) {
355
356 EditorNode::get_singleton()->add_control_to_dock(EditorNode::DOCK_SLOT_RIGHT_UL, version_commit_dock);
357 TabContainer *dock_vbc = (TabContainer *)version_commit_dock->get_parent_control();
358 dock_vbc->set_tab_title(version_commit_dock->get_index(), TTR("Commit"));
359
360 ToolButton *vc = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Version Control"), version_control_dock);
361 set_version_control_tool_button(vc);
362 }
363 }
364
fetch_available_vcs_addon_names()365 void VersionControlEditorPlugin::fetch_available_vcs_addon_names() {
366
367 List<StringName> global_classes;
368 ScriptServer::get_global_class_list(&global_classes);
369
370 for (int i = 0; i != global_classes.size(); i++) {
371
372 String path = ScriptServer::get_global_class_path(global_classes[i]);
373 Ref<Script> script = ResourceLoader::load(path);
374 ERR_FAIL_COND(script.is_null());
375
376 if (script->get_instance_base_type() == "EditorVCSInterface") {
377
378 available_addons.push_back(global_classes[i]);
379 }
380 }
381 }
382
clear_stage_area()383 void VersionControlEditorPlugin::clear_stage_area() {
384
385 stage_files->get_root()->clear_children();
386 }
387
shut_down()388 void VersionControlEditorPlugin::shut_down() {
389
390 if (EditorVCSInterface::get_singleton()) {
391 if (EditorFileSystem::get_singleton()->is_connected("filesystem_changed", this, "_refresh_stage_area")) {
392 EditorFileSystem::get_singleton()->disconnect("filesystem_changed", this, "_refresh_stage_area");
393 }
394 EditorVCSInterface::get_singleton()->shut_down();
395 memdelete(EditorVCSInterface::get_singleton());
396 EditorVCSInterface::set_singleton(NULL);
397
398 EditorNode::get_singleton()->remove_control_from_dock(version_commit_dock);
399 EditorNode::get_singleton()->remove_bottom_panel_item(version_control_dock);
400 }
401 }
402
is_vcs_initialized() const403 bool VersionControlEditorPlugin::is_vcs_initialized() const {
404
405 return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->is_vcs_initialized() : false;
406 }
407
get_vcs_name() const408 const String VersionControlEditorPlugin::get_vcs_name() const {
409
410 return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->get_vcs_name() : "";
411 }
412
VersionControlEditorPlugin()413 VersionControlEditorPlugin::VersionControlEditorPlugin() {
414
415 singleton = this;
416 staged_files_count = 0;
417
418 version_control_actions = memnew(PopupMenu);
419 version_control_actions->set_v_size_flags(BoxContainer::SIZE_SHRINK_CENTER);
420
421 set_up_dialog = memnew(AcceptDialog);
422 set_up_dialog->set_title(TTR("Set Up Version Control"));
423 set_up_dialog->set_custom_minimum_size(Size2(400, 100));
424 version_control_actions->add_child(set_up_dialog);
425
426 set_up_ok_button = set_up_dialog->get_ok();
427 set_up_ok_button->set_text(TTR("Close"));
428
429 set_up_vbc = memnew(VBoxContainer);
430 set_up_vbc->set_alignment(VBoxContainer::ALIGN_CENTER);
431 set_up_dialog->add_child(set_up_vbc);
432
433 set_up_hbc = memnew(HBoxContainer);
434 set_up_hbc->set_h_size_flags(HBoxContainer::SIZE_EXPAND_FILL);
435 set_up_vbc->add_child(set_up_hbc);
436
437 set_up_vcs_status = memnew(RichTextLabel);
438 set_up_vcs_status->set_text(TTR("VCS Addon is not initialized"));
439 set_up_vbc->add_child(set_up_vcs_status);
440
441 set_up_vcs_label = memnew(Label);
442 set_up_vcs_label->set_text(TTR("Version Control System"));
443 set_up_hbc->add_child(set_up_vcs_label);
444
445 set_up_choice = memnew(OptionButton);
446 set_up_choice->set_h_size_flags(HBoxContainer::SIZE_EXPAND_FILL);
447 set_up_choice->connect("item_selected", this, "_selected_a_vcs");
448 set_up_hbc->add_child(set_up_choice);
449
450 set_up_init_settings = NULL;
451
452 set_up_init_button = memnew(Button);
453 set_up_init_button->set_text(TTR("Initialize"));
454 set_up_init_button->connect("pressed", this, "_initialize_vcs");
455 set_up_vbc->add_child(set_up_init_button);
456
457 version_control_actions->set_v_size_flags(PopupMenu::SIZE_EXPAND_FILL);
458 version_control_actions->set_h_size_flags(PopupMenu::SIZE_EXPAND_FILL);
459
460 version_commit_dock = memnew(VBoxContainer);
461 version_commit_dock->set_visible(false);
462
463 commit_box_vbc = memnew(VBoxContainer);
464 commit_box_vbc->set_alignment(VBoxContainer::ALIGN_BEGIN);
465 commit_box_vbc->set_h_size_flags(VBoxContainer::SIZE_EXPAND_FILL);
466 commit_box_vbc->set_v_size_flags(VBoxContainer::SIZE_EXPAND_FILL);
467 version_commit_dock->add_child(commit_box_vbc);
468
469 stage_tools = memnew(HSplitContainer);
470 stage_tools->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED);
471 commit_box_vbc->add_child(stage_tools);
472
473 staging_area_label = memnew(Label);
474 staging_area_label->set_h_size_flags(Label::SIZE_EXPAND_FILL);
475 staging_area_label->set_text(TTR("Staging area"));
476 stage_tools->add_child(staging_area_label);
477
478 refresh_button = memnew(Button);
479 refresh_button->set_tooltip(TTR("Detect new changes"));
480 refresh_button->set_text(TTR("Refresh"));
481 refresh_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Reload", "EditorIcons"));
482 refresh_button->connect("pressed", this, "_refresh_stage_area");
483 stage_tools->add_child(refresh_button);
484
485 stage_files = memnew(Tree);
486 stage_files->set_h_size_flags(Tree::SIZE_EXPAND_FILL);
487 stage_files->set_v_size_flags(Tree::SIZE_EXPAND_FILL);
488 stage_files->set_columns(1);
489 stage_files->set_column_title(0, TTR("Changes"));
490 stage_files->set_column_titles_visible(true);
491 stage_files->set_allow_reselect(true);
492 stage_files->set_allow_rmb_select(true);
493 stage_files->set_select_mode(Tree::SelectMode::SELECT_MULTI);
494 stage_files->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
495 stage_files->connect("cell_selected", this, "_view_file_diff");
496 stage_files->create_item();
497 stage_files->set_hide_root(true);
498 commit_box_vbc->add_child(stage_files);
499
500 change_type_to_strings[CHANGE_TYPE_NEW] = TTR("New");
501 change_type_to_strings[CHANGE_TYPE_MODIFIED] = TTR("Modified");
502 change_type_to_strings[CHANGE_TYPE_RENAMED] = TTR("Renamed");
503 change_type_to_strings[CHANGE_TYPE_DELETED] = TTR("Deleted");
504 change_type_to_strings[CHANGE_TYPE_TYPECHANGE] = TTR("Typechange");
505
506 change_type_to_color[CHANGE_TYPE_NEW] = EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor");
507 change_type_to_color[CHANGE_TYPE_MODIFIED] = EditorNode::get_singleton()->get_gui_base()->get_color("warning_color", "Editor");
508 change_type_to_color[CHANGE_TYPE_RENAMED] = EditorNode::get_singleton()->get_gui_base()->get_color("disabled_font_color", "Editor");
509 change_type_to_color[CHANGE_TYPE_DELETED] = EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor");
510 change_type_to_color[CHANGE_TYPE_TYPECHANGE] = EditorNode::get_singleton()->get_gui_base()->get_color("font_color", "Editor");
511
512 stage_buttons = memnew(HSplitContainer);
513 stage_buttons->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED);
514 commit_box_vbc->add_child(stage_buttons);
515
516 stage_selected_button = memnew(Button);
517 stage_selected_button->set_h_size_flags(Button::SIZE_EXPAND_FILL);
518 stage_selected_button->set_text(TTR("Stage Selected"));
519 stage_selected_button->connect("pressed", this, "_stage_selected");
520 stage_buttons->add_child(stage_selected_button);
521
522 stage_all_button = memnew(Button);
523 stage_all_button->set_text(TTR("Stage All"));
524 stage_all_button->connect("pressed", this, "_stage_all");
525 stage_buttons->add_child(stage_all_button);
526
527 commit_box_vbc->add_child(memnew(HSeparator));
528
529 commit_message = memnew(TextEdit);
530 commit_message->set_h_size_flags(Control::SIZE_EXPAND_FILL);
531 commit_message->set_h_grow_direction(Control::GrowDirection::GROW_DIRECTION_BEGIN);
532 commit_message->set_v_grow_direction(Control::GrowDirection::GROW_DIRECTION_END);
533 commit_message->set_custom_minimum_size(Size2(200, 100));
534 commit_message->set_wrap_enabled(true);
535 commit_message->set_text(TTR("Add a commit message"));
536 commit_box_vbc->add_child(commit_message);
537
538 commit_button = memnew(Button);
539 commit_button->set_text(TTR("Commit Changes"));
540 commit_button->connect("pressed", this, "_send_commit_msg");
541 commit_box_vbc->add_child(commit_button);
542
543 commit_status = memnew(Label);
544 commit_status->set_align(Label::ALIGN_CENTER);
545 commit_box_vbc->add_child(commit_status);
546
547 version_control_dock = memnew(PanelContainer);
548 version_control_dock->set_v_size_flags(Control::SIZE_EXPAND_FILL);
549 version_control_dock->hide();
550
551 diff_vbc = memnew(VBoxContainer);
552 diff_vbc->set_h_size_flags(HBoxContainer::SIZE_FILL);
553 diff_vbc->set_v_size_flags(HBoxContainer::SIZE_FILL);
554 version_control_dock->add_child(diff_vbc);
555
556 diff_hbc = memnew(HBoxContainer);
557 diff_hbc->set_h_size_flags(HBoxContainer::SIZE_FILL);
558 diff_vbc->add_child(diff_hbc);
559
560 diff_heading = memnew(Label);
561 diff_heading->set_text(TTR("Status"));
562 diff_heading->set_tooltip(TTR("View file diffs before committing them to the latest version"));
563 diff_hbc->add_child(diff_heading);
564
565 diff_file_name = memnew(Label);
566 diff_file_name->set_text(TTR("No file diff is active"));
567 diff_file_name->set_h_size_flags(Label::SIZE_EXPAND_FILL);
568 diff_file_name->set_align(Label::ALIGN_RIGHT);
569 diff_hbc->add_child(diff_file_name);
570
571 diff_refresh_button = memnew(Button);
572 diff_refresh_button->set_tooltip(TTR("Detect changes in file diff"));
573 diff_refresh_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Reload", "EditorIcons"));
574 diff_refresh_button->connect("pressed", this, "_refresh_file_diff");
575 diff_hbc->add_child(diff_refresh_button);
576
577 diff = memnew(RichTextLabel);
578 diff->set_h_size_flags(TextEdit::SIZE_EXPAND_FILL);
579 diff->set_v_size_flags(TextEdit::SIZE_EXPAND_FILL);
580 diff->set_selection_enabled(true);
581 diff_vbc->add_child(diff);
582 }
583
~VersionControlEditorPlugin()584 VersionControlEditorPlugin::~VersionControlEditorPlugin() {
585
586 shut_down();
587 memdelete(version_control_dock);
588 memdelete(version_commit_dock);
589 memdelete(version_control_actions);
590 }
591