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