version_control_editor_plugin.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. #include "version_control_editor_plugin.h"
  31. #include "core/object/script_language.h"
  32. #include "editor/editor_file_system.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_scale.h"
  35. VersionControlEditorPlugin *VersionControlEditorPlugin::singleton = nullptr;
  36. void VersionControlEditorPlugin::_bind_methods() {
  37. ClassDB::bind_method(D_METHOD("popup_vcs_set_up_dialog"), &VersionControlEditorPlugin::popup_vcs_set_up_dialog);
  38. // Used to track the status of files in the staging area
  39. BIND_ENUM_CONSTANT(CHANGE_TYPE_NEW);
  40. BIND_ENUM_CONSTANT(CHANGE_TYPE_MODIFIED);
  41. BIND_ENUM_CONSTANT(CHANGE_TYPE_RENAMED);
  42. BIND_ENUM_CONSTANT(CHANGE_TYPE_DELETED);
  43. BIND_ENUM_CONSTANT(CHANGE_TYPE_TYPECHANGE);
  44. }
  45. void VersionControlEditorPlugin::_selected_a_vcs(int p_id) {
  46. List<StringName> available_addons = get_available_vcs_names();
  47. const StringName selected_vcs = set_up_choice->get_item_text(p_id);
  48. }
  49. void VersionControlEditorPlugin::_populate_available_vcs_names() {
  50. static bool called = false;
  51. if (!called) {
  52. List<StringName> available_addons = get_available_vcs_names();
  53. for (int i = 0; i < available_addons.size(); i++) {
  54. set_up_choice->add_item(available_addons[i]);
  55. }
  56. called = true;
  57. }
  58. }
  59. VersionControlEditorPlugin *VersionControlEditorPlugin::get_singleton() {
  60. return singleton ? singleton : memnew(VersionControlEditorPlugin);
  61. }
  62. void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_base) {
  63. fetch_available_vcs_addon_names();
  64. List<StringName> available_addons = get_available_vcs_names();
  65. if (available_addons.size() >= 1) {
  66. Size2 popup_size = Size2(400, 100);
  67. Size2 window_size = p_gui_base->get_viewport_rect().size;
  68. popup_size.x = MIN(window_size.x * 0.5, popup_size.x);
  69. popup_size.y = MIN(window_size.y * 0.5, popup_size.y);
  70. _populate_available_vcs_names();
  71. set_up_dialog->popup_centered_clamped(popup_size * EDSCALE);
  72. } else {
  73. EditorNode::get_singleton()->show_warning(TTR("No VCS addons are available."), TTR("Error"));
  74. }
  75. }
  76. void VersionControlEditorPlugin::_initialize_vcs() {
  77. register_editor();
  78. ERR_FAIL_COND_MSG(EditorVCSInterface::get_singleton(), EditorVCSInterface::get_singleton()->get_vcs_name() + " is already active");
  79. const int id = set_up_choice->get_selected_id();
  80. String selected_addon = set_up_choice->get_item_text(id);
  81. String path = ScriptServer::get_global_class_path(selected_addon);
  82. Ref<Script> script = ResourceLoader::load(path);
  83. ERR_FAIL_COND_MSG(!script.is_valid(), "VCS Addon path is invalid");
  84. EditorVCSInterface *vcs_interface = memnew(EditorVCSInterface);
  85. ScriptInstance *addon_script_instance = script->instance_create(vcs_interface);
  86. ERR_FAIL_COND_MSG(!addon_script_instance, "Failed to create addon script instance.");
  87. // The addon is attached as a script to the VCS interface as a proxy end-point
  88. vcs_interface->set_script_and_instance(script, addon_script_instance);
  89. EditorVCSInterface::set_singleton(vcs_interface);
  90. EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area));
  91. String res_dir = OS::get_singleton()->get_resource_dir();
  92. ERR_FAIL_COND_MSG(!EditorVCSInterface::get_singleton()->initialize(res_dir), "VCS was not initialized");
  93. _refresh_stage_area();
  94. }
  95. void VersionControlEditorPlugin::_send_commit_msg() {
  96. if (EditorVCSInterface::get_singleton()) {
  97. if (staged_files_count == 0) {
  98. commit_status->set_text(TTR("No files added to stage"));
  99. return;
  100. }
  101. EditorVCSInterface::get_singleton()->commit(commit_message->get_text());
  102. commit_message->set_text("");
  103. version_control_dock_button->set_pressed(false);
  104. } else {
  105. WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu");
  106. }
  107. _update_commit_status();
  108. _refresh_stage_area();
  109. _clear_file_diff();
  110. }
  111. void VersionControlEditorPlugin::_refresh_stage_area() {
  112. if (EditorVCSInterface::get_singleton()) {
  113. staged_files_count = 0;
  114. clear_stage_area();
  115. Dictionary modified_file_paths = EditorVCSInterface::get_singleton()->get_modified_files_data();
  116. String file_path;
  117. for (int i = 0; i < modified_file_paths.size(); i++) {
  118. file_path = modified_file_paths.get_key_at_index(i);
  119. TreeItem *found = stage_files->search_item_text(file_path, nullptr, true);
  120. if (!found) {
  121. ChangeType change_index = (ChangeType)(int)modified_file_paths.get_value_at_index(i);
  122. String change_text = file_path + " (" + change_type_to_strings[change_index] + ")";
  123. Color &change_color = change_type_to_color[change_index];
  124. TreeItem *new_item = stage_files->create_item(stage_files->get_root());
  125. new_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  126. new_item->set_text(0, change_text);
  127. new_item->set_metadata(0, file_path);
  128. new_item->set_custom_color(0, change_color);
  129. new_item->set_checked(0, true);
  130. new_item->set_editable(0, true);
  131. } else {
  132. if (found->get_metadata(0) == diff_file_name->get_text()) {
  133. _refresh_file_diff();
  134. }
  135. }
  136. commit_status->set_text("New changes detected");
  137. }
  138. } else {
  139. WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu.");
  140. }
  141. }
  142. void VersionControlEditorPlugin::_stage_selected() {
  143. if (!EditorVCSInterface::get_singleton()) {
  144. WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu");
  145. return;
  146. }
  147. staged_files_count = 0;
  148. TreeItem *root = stage_files->get_root();
  149. if (root) {
  150. TreeItem *file_entry = root->get_first_child();
  151. while (file_entry) {
  152. if (file_entry->is_checked(0)) {
  153. EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0));
  154. file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_theme_color("success_color", "Editor"));
  155. staged_files_count++;
  156. } else {
  157. EditorVCSInterface::get_singleton()->unstage_file(file_entry->get_metadata(0));
  158. file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_theme_color("error_color", "Editor"));
  159. }
  160. file_entry = file_entry->get_next();
  161. }
  162. }
  163. _update_stage_status();
  164. }
  165. void VersionControlEditorPlugin::_stage_all() {
  166. if (!EditorVCSInterface::get_singleton()) {
  167. WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu");
  168. return;
  169. }
  170. staged_files_count = 0;
  171. TreeItem *root = stage_files->get_root();
  172. if (root) {
  173. TreeItem *file_entry = root->get_first_child();
  174. while (file_entry) {
  175. EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0));
  176. file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_theme_color("success_color", "Editor"));
  177. file_entry->set_checked(0, true);
  178. staged_files_count++;
  179. file_entry = file_entry->get_next();
  180. }
  181. }
  182. _update_stage_status();
  183. }
  184. void VersionControlEditorPlugin::_view_file_diff() {
  185. version_control_dock_button->set_pressed(true);
  186. String file_path = stage_files->get_selected()->get_metadata(0);
  187. _display_file_diff(file_path);
  188. }
  189. void VersionControlEditorPlugin::_display_file_diff(String p_file_path) {
  190. Array diff_content = EditorVCSInterface::get_singleton()->get_file_diff(p_file_path);
  191. diff_file_name->set_text(p_file_path);
  192. diff->clear();
  193. diff->push_font(EditorNode::get_singleton()->get_gui_base()->get_theme_font("source", "EditorFonts"));
  194. for (int i = 0; i < diff_content.size(); i++) {
  195. Dictionary line_result = diff_content[i];
  196. if (line_result["status"] == "+") {
  197. diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_theme_color("success_color", "Editor"));
  198. } else if (line_result["status"] == "-") {
  199. diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_theme_color("error_color", "Editor"));
  200. } else {
  201. diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_theme_color("font_color", "Label"));
  202. }
  203. diff->add_text((String)line_result["content"]);
  204. diff->pop();
  205. }
  206. diff->pop();
  207. }
  208. void VersionControlEditorPlugin::_refresh_file_diff() {
  209. String open_file = diff_file_name->get_text();
  210. if (open_file != "") {
  211. _display_file_diff(diff_file_name->get_text());
  212. }
  213. }
  214. void VersionControlEditorPlugin::_clear_file_diff() {
  215. diff->clear();
  216. diff_file_name->set_text("");
  217. version_control_dock_button->set_pressed(false);
  218. }
  219. void VersionControlEditorPlugin::_update_stage_status() {
  220. String status;
  221. if (staged_files_count == 1) {
  222. status = "Stage contains 1 file";
  223. } else {
  224. status = "Stage contains " + String::num_int64(staged_files_count) + " files";
  225. }
  226. commit_status->set_text(status);
  227. }
  228. void VersionControlEditorPlugin::_update_commit_status() {
  229. String status;
  230. if (staged_files_count == 1) {
  231. status = "Committed 1 file";
  232. } else {
  233. status = "Committed " + String::num_int64(staged_files_count) + " files ";
  234. }
  235. commit_status->set_text(status);
  236. staged_files_count = 0;
  237. }
  238. void VersionControlEditorPlugin::_update_commit_button() {
  239. commit_button->set_disabled(commit_message->get_text().strip_edges() == "");
  240. }
  241. void VersionControlEditorPlugin::register_editor() {
  242. if (!EditorVCSInterface::get_singleton()) {
  243. EditorNode::get_singleton()->add_control_to_dock(EditorNode::DOCK_SLOT_RIGHT_UL, version_commit_dock);
  244. TabContainer *dock_vbc = (TabContainer *)version_commit_dock->get_parent_control();
  245. dock_vbc->set_tab_title(version_commit_dock->get_index(), TTR("Commit"));
  246. Button *vc = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Version Control"), version_control_dock);
  247. set_version_control_tool_button(vc);
  248. }
  249. }
  250. void VersionControlEditorPlugin::fetch_available_vcs_addon_names() {
  251. List<StringName> global_classes;
  252. ScriptServer::get_global_class_list(&global_classes);
  253. for (int i = 0; i != global_classes.size(); i++) {
  254. String path = ScriptServer::get_global_class_path(global_classes[i]);
  255. Ref<Script> script = ResourceLoader::load(path);
  256. ERR_FAIL_COND(script.is_null());
  257. if (script->get_instance_base_type() == "EditorVCSInterface") {
  258. available_addons.push_back(global_classes[i]);
  259. }
  260. }
  261. }
  262. void VersionControlEditorPlugin::clear_stage_area() {
  263. stage_files->get_root()->clear_children();
  264. }
  265. void VersionControlEditorPlugin::shut_down() {
  266. if (EditorVCSInterface::get_singleton()) {
  267. if (EditorFileSystem::get_singleton()->is_connected("filesystem_changed", callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area))) {
  268. EditorFileSystem::get_singleton()->disconnect("filesystem_changed", callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area));
  269. }
  270. EditorVCSInterface::get_singleton()->shut_down();
  271. memdelete(EditorVCSInterface::get_singleton());
  272. EditorVCSInterface::set_singleton(nullptr);
  273. EditorNode::get_singleton()->remove_control_from_dock(version_commit_dock);
  274. EditorNode::get_singleton()->remove_bottom_panel_item(version_control_dock);
  275. }
  276. }
  277. bool VersionControlEditorPlugin::is_vcs_initialized() const {
  278. return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->is_vcs_initialized() : false;
  279. }
  280. const String VersionControlEditorPlugin::get_vcs_name() const {
  281. return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->get_vcs_name() : "";
  282. }
  283. VersionControlEditorPlugin::VersionControlEditorPlugin() {
  284. singleton = this;
  285. staged_files_count = 0;
  286. version_control_actions = memnew(PopupMenu);
  287. set_up_dialog = memnew(AcceptDialog);
  288. set_up_dialog->set_title(TTR("Set Up Version Control"));
  289. set_up_dialog->set_min_size(Size2(400, 100));
  290. version_control_actions->add_child(set_up_dialog);
  291. set_up_ok_button = set_up_dialog->get_ok_button();
  292. set_up_ok_button->set_text(TTR("Close"));
  293. set_up_vbc = memnew(VBoxContainer);
  294. set_up_vbc->set_alignment(VBoxContainer::ALIGN_CENTER);
  295. set_up_dialog->add_child(set_up_vbc);
  296. set_up_hbc = memnew(HBoxContainer);
  297. set_up_hbc->set_h_size_flags(HBoxContainer::SIZE_EXPAND_FILL);
  298. set_up_vbc->add_child(set_up_hbc);
  299. set_up_vcs_status = memnew(RichTextLabel);
  300. set_up_vcs_status->set_text(TTR("VCS Addon is not initialized"));
  301. set_up_vbc->add_child(set_up_vcs_status);
  302. set_up_vcs_label = memnew(Label);
  303. set_up_vcs_label->set_text(TTR("Version Control System"));
  304. set_up_hbc->add_child(set_up_vcs_label);
  305. set_up_choice = memnew(OptionButton);
  306. set_up_choice->set_h_size_flags(HBoxContainer::SIZE_EXPAND_FILL);
  307. set_up_choice->connect("item_selected", callable_mp(this, &VersionControlEditorPlugin::_selected_a_vcs));
  308. set_up_hbc->add_child(set_up_choice);
  309. set_up_init_settings = nullptr;
  310. set_up_init_button = memnew(Button);
  311. set_up_init_button->set_text(TTR("Initialize"));
  312. set_up_init_button->connect("pressed", callable_mp(this, &VersionControlEditorPlugin::_initialize_vcs));
  313. set_up_vbc->add_child(set_up_init_button);
  314. version_commit_dock = memnew(VBoxContainer);
  315. version_commit_dock->set_visible(false);
  316. commit_box_vbc = memnew(VBoxContainer);
  317. commit_box_vbc->set_alignment(VBoxContainer::ALIGN_BEGIN);
  318. commit_box_vbc->set_h_size_flags(VBoxContainer::SIZE_EXPAND_FILL);
  319. commit_box_vbc->set_v_size_flags(VBoxContainer::SIZE_EXPAND_FILL);
  320. version_commit_dock->add_child(commit_box_vbc);
  321. stage_tools = memnew(HSplitContainer);
  322. stage_tools->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED);
  323. commit_box_vbc->add_child(stage_tools);
  324. staging_area_label = memnew(Label);
  325. staging_area_label->set_h_size_flags(Label::SIZE_EXPAND_FILL);
  326. staging_area_label->set_text(TTR("Staging area"));
  327. stage_tools->add_child(staging_area_label);
  328. refresh_button = memnew(Button);
  329. refresh_button->set_tooltip(TTR("Detect new changes"));
  330. refresh_button->set_text(TTR("Refresh"));
  331. refresh_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Reload", "EditorIcons"));
  332. refresh_button->connect("pressed", callable_mp(this, &VersionControlEditorPlugin::_refresh_stage_area));
  333. stage_tools->add_child(refresh_button);
  334. stage_files = memnew(Tree);
  335. stage_files->set_h_size_flags(Tree::SIZE_EXPAND_FILL);
  336. stage_files->set_v_size_flags(Tree::SIZE_EXPAND_FILL);
  337. stage_files->set_columns(1);
  338. stage_files->set_column_title(0, TTR("Changes"));
  339. stage_files->set_column_titles_visible(true);
  340. stage_files->set_allow_reselect(true);
  341. stage_files->set_allow_rmb_select(true);
  342. stage_files->set_select_mode(Tree::SelectMode::SELECT_MULTI);
  343. stage_files->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
  344. stage_files->connect("cell_selected", callable_mp(this, &VersionControlEditorPlugin::_view_file_diff));
  345. stage_files->create_item();
  346. stage_files->set_hide_root(true);
  347. commit_box_vbc->add_child(stage_files);
  348. change_type_to_strings[CHANGE_TYPE_NEW] = TTR("New");
  349. change_type_to_strings[CHANGE_TYPE_MODIFIED] = TTR("Modified");
  350. change_type_to_strings[CHANGE_TYPE_RENAMED] = TTR("Renamed");
  351. change_type_to_strings[CHANGE_TYPE_DELETED] = TTR("Deleted");
  352. change_type_to_strings[CHANGE_TYPE_TYPECHANGE] = TTR("Typechange");
  353. change_type_to_color[CHANGE_TYPE_NEW] = EditorNode::get_singleton()->get_gui_base()->get_theme_color("success_color", "Editor");
  354. change_type_to_color[CHANGE_TYPE_MODIFIED] = EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor");
  355. change_type_to_color[CHANGE_TYPE_RENAMED] = EditorNode::get_singleton()->get_gui_base()->get_theme_color("disabled_font_color", "Editor");
  356. change_type_to_color[CHANGE_TYPE_DELETED] = EditorNode::get_singleton()->get_gui_base()->get_theme_color("error_color", "Editor");
  357. change_type_to_color[CHANGE_TYPE_TYPECHANGE] = EditorNode::get_singleton()->get_gui_base()->get_theme_color("font_color", "Editor");
  358. stage_buttons = memnew(HSplitContainer);
  359. stage_buttons->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED);
  360. commit_box_vbc->add_child(stage_buttons);
  361. stage_selected_button = memnew(Button);
  362. stage_selected_button->set_h_size_flags(Button::SIZE_EXPAND_FILL);
  363. stage_selected_button->set_text(TTR("Stage Selected"));
  364. stage_selected_button->connect("pressed", callable_mp(this, &VersionControlEditorPlugin::_stage_selected));
  365. stage_buttons->add_child(stage_selected_button);
  366. stage_all_button = memnew(Button);
  367. stage_all_button->set_text(TTR("Stage All"));
  368. stage_all_button->connect("pressed", callable_mp(this, &VersionControlEditorPlugin::_stage_all));
  369. stage_buttons->add_child(stage_all_button);
  370. commit_box_vbc->add_child(memnew(HSeparator));
  371. commit_message = memnew(TextEdit);
  372. commit_message->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  373. commit_message->set_h_grow_direction(Control::GrowDirection::GROW_DIRECTION_BEGIN);
  374. commit_message->set_v_grow_direction(Control::GrowDirection::GROW_DIRECTION_END);
  375. commit_message->set_custom_minimum_size(Size2(200, 100));
  376. commit_message->set_wrap_enabled(true);
  377. commit_message->connect("text_changed", callable_mp(this, &VersionControlEditorPlugin::_update_commit_button));
  378. commit_box_vbc->add_child(commit_message);
  379. commit_button = memnew(Button);
  380. commit_button->set_text(TTR("Commit Changes"));
  381. commit_button->set_disabled(true);
  382. commit_button->connect("pressed", callable_mp(this, &VersionControlEditorPlugin::_send_commit_msg));
  383. commit_box_vbc->add_child(commit_button);
  384. commit_status = memnew(Label);
  385. commit_status->set_align(Label::ALIGN_CENTER);
  386. commit_box_vbc->add_child(commit_status);
  387. version_control_dock = memnew(PanelContainer);
  388. version_control_dock->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  389. version_control_dock->set_custom_minimum_size(Size2(0, 300) * EDSCALE);
  390. version_control_dock->hide();
  391. diff_vbc = memnew(VBoxContainer);
  392. diff_vbc->set_h_size_flags(HBoxContainer::SIZE_FILL);
  393. diff_vbc->set_v_size_flags(HBoxContainer::SIZE_FILL);
  394. version_control_dock->add_child(diff_vbc);
  395. diff_hbc = memnew(HBoxContainer);
  396. diff_hbc->set_h_size_flags(HBoxContainer::SIZE_FILL);
  397. diff_vbc->add_child(diff_hbc);
  398. diff_heading = memnew(Label);
  399. diff_heading->set_text(TTR("Status"));
  400. diff_heading->set_tooltip(TTR("View file diffs before committing them to the latest version"));
  401. diff_hbc->add_child(diff_heading);
  402. diff_file_name = memnew(Label);
  403. diff_file_name->set_text(TTR("No file diff is active"));
  404. diff_file_name->set_h_size_flags(Label::SIZE_EXPAND_FILL);
  405. diff_file_name->set_align(Label::ALIGN_RIGHT);
  406. diff_hbc->add_child(diff_file_name);
  407. diff_refresh_button = memnew(Button);
  408. diff_refresh_button->set_tooltip(TTR("Detect changes in file diff"));
  409. diff_refresh_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Reload", "EditorIcons"));
  410. diff_refresh_button->connect("pressed", callable_mp(this, &VersionControlEditorPlugin::_refresh_file_diff));
  411. diff_hbc->add_child(diff_refresh_button);
  412. diff = memnew(RichTextLabel);
  413. diff->set_h_size_flags(TextEdit::SIZE_EXPAND_FILL);
  414. diff->set_v_size_flags(TextEdit::SIZE_EXPAND_FILL);
  415. diff->set_selection_enabled(true);
  416. diff_vbc->add_child(diff);
  417. }
  418. VersionControlEditorPlugin::~VersionControlEditorPlugin() {
  419. shut_down();
  420. memdelete(version_control_dock);
  421. memdelete(version_commit_dock);
  422. memdelete(version_control_actions);
  423. }