version_control_editor_plugin.cpp 64 KB

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