version_control_editor_plugin.cpp 21 KB

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