version_control_editor_plugin.cpp 63 KB

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