version_control_editor_plugin.cpp 65 KB

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