version_control_editor_plugin.cpp 63 KB

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