version_control_editor_plugin.cpp 64 KB

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