version_control_editor_plugin.cpp 61 KB

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