version_control_editor_plugin.cpp 65 KB

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