version_control_editor_plugin.cpp 66 KB

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