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