| 1 | /**************************************************************************/ |
| 2 | /* version_control_editor_plugin.h */ |
| 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 | #ifndef VERSION_CONTROL_EDITOR_PLUGIN_H |
| 32 | #define VERSION_CONTROL_EDITOR_PLUGIN_H |
| 33 | |
| 34 | #include "editor/editor_plugin.h" |
| 35 | #include "editor/editor_vcs_interface.h" |
| 36 | #include "scene/gui/check_button.h" |
| 37 | #include "scene/gui/container.h" |
| 38 | #include "scene/gui/file_dialog.h" |
| 39 | #include "scene/gui/menu_button.h" |
| 40 | #include "scene/gui/rich_text_label.h" |
| 41 | #include "scene/gui/tab_container.h" |
| 42 | #include "scene/gui/text_edit.h" |
| 43 | #include "scene/gui/tree.h" |
| 44 | |
| 45 | class VersionControlEditorPlugin : public EditorPlugin { |
| 46 | GDCLASS(VersionControlEditorPlugin, EditorPlugin) |
| 47 | |
| 48 | public: |
| 49 | enum ButtonType { |
| 50 | BUTTON_TYPE_OPEN = 0, |
| 51 | BUTTON_TYPE_DISCARD = 1, |
| 52 | }; |
| 53 | |
| 54 | enum DiffViewType { |
| 55 | DIFF_VIEW_TYPE_SPLIT = 0, |
| 56 | DIFF_VIEW_TYPE_UNIFIED = 1, |
| 57 | }; |
| 58 | |
| 59 | enum { |
| 60 | , |
| 61 | , |
| 62 | , |
| 63 | }; |
| 64 | |
| 65 | private: |
| 66 | static VersionControlEditorPlugin *singleton; |
| 67 | |
| 68 | List<StringName> available_plugins; |
| 69 | |
| 70 | PopupMenu *version_control_actions = nullptr; |
| 71 | ConfirmationDialog *metadata_dialog = nullptr; |
| 72 | OptionButton *metadata_selection = nullptr; |
| 73 | AcceptDialog *set_up_dialog = nullptr; |
| 74 | CheckButton *toggle_vcs_choice = nullptr; |
| 75 | OptionButton *set_up_choice = nullptr; |
| 76 | VBoxContainer *set_up_vbc = nullptr; |
| 77 | VBoxContainer *set_up_settings_vbc = nullptr; |
| 78 | LineEdit *set_up_username = nullptr; |
| 79 | LineEdit *set_up_password = nullptr; |
| 80 | LineEdit *set_up_ssh_public_key_path = nullptr; |
| 81 | LineEdit *set_up_ssh_private_key_path = nullptr; |
| 82 | LineEdit *set_up_ssh_passphrase = nullptr; |
| 83 | FileDialog *set_up_ssh_public_key_file_dialog = nullptr; |
| 84 | FileDialog *set_up_ssh_private_key_file_dialog = nullptr; |
| 85 | Label *set_up_warning_text = nullptr; |
| 86 | |
| 87 | AcceptDialog *discard_all_confirm = nullptr; |
| 88 | |
| 89 | OptionButton *commit_list_size_button = nullptr; |
| 90 | |
| 91 | AcceptDialog *branch_create_confirm = nullptr; |
| 92 | LineEdit *branch_create_name_input = nullptr; |
| 93 | Button *branch_create_ok = nullptr; |
| 94 | |
| 95 | AcceptDialog *remote_create_confirm = nullptr; |
| 96 | LineEdit *remote_create_name_input = nullptr; |
| 97 | LineEdit *remote_create_url_input = nullptr; |
| 98 | Button *remote_create_ok = nullptr; |
| 99 | |
| 100 | HashMap<EditorVCSInterface::ChangeType, String> change_type_to_strings; |
| 101 | HashMap<EditorVCSInterface::ChangeType, Color> change_type_to_color; |
| 102 | HashMap<EditorVCSInterface::ChangeType, Ref<Texture>> change_type_to_icon; |
| 103 | |
| 104 | VBoxContainer *version_commit_dock = nullptr; |
| 105 | Tree *staged_files = nullptr; |
| 106 | Tree *unstaged_files = nullptr; |
| 107 | Tree *commit_list = nullptr; |
| 108 | |
| 109 | OptionButton *branch_select = nullptr; |
| 110 | Button *branch_remove_button = nullptr; |
| 111 | AcceptDialog *branch_remove_confirm = nullptr; |
| 112 | |
| 113 | Button *fetch_button = nullptr; |
| 114 | Button *pull_button = nullptr; |
| 115 | Button *push_button = nullptr; |
| 116 | OptionButton *remote_select = nullptr; |
| 117 | Button *remote_remove_button = nullptr; |
| 118 | AcceptDialog *remote_remove_confirm = nullptr; |
| 119 | MenuButton * = nullptr; |
| 120 | PopupMenu * = nullptr; |
| 121 | PopupMenu * = nullptr; |
| 122 | |
| 123 | String branch_to_remove; |
| 124 | String remote_to_remove; |
| 125 | |
| 126 | Button *stage_all_button = nullptr; |
| 127 | Button *unstage_all_button = nullptr; |
| 128 | Button *discard_all_button = nullptr; |
| 129 | Button *refresh_button = nullptr; |
| 130 | TextEdit *commit_message = nullptr; |
| 131 | Button *commit_button = nullptr; |
| 132 | |
| 133 | VBoxContainer *version_control_dock = nullptr; |
| 134 | Button *version_control_dock_button = nullptr; |
| 135 | Label *diff_title = nullptr; |
| 136 | RichTextLabel *diff = nullptr; |
| 137 | OptionButton *diff_view_type_select = nullptr; |
| 138 | bool = false; |
| 139 | List<EditorVCSInterface::DiffFile> diff_content; |
| 140 | |
| 141 | void _notification(int p_what); |
| 142 | void _initialize_vcs(); |
| 143 | void _set_vcs_ui_state(bool p_enabled); |
| 144 | void _set_credentials(); |
| 145 | void _ssh_public_key_selected(String p_path); |
| 146 | void _ssh_private_key_selected(String p_path); |
| 147 | void _populate_available_vcs_names(); |
| 148 | void _update_remotes_list(); |
| 149 | void _update_set_up_warning(String p_new_text); |
| 150 | void _update_opened_tabs(); |
| 151 | void (); |
| 152 | |
| 153 | bool _load_plugin(String p_name); |
| 154 | |
| 155 | void _pull(); |
| 156 | void _push(); |
| 157 | void _force_push(); |
| 158 | void _fetch(); |
| 159 | void _commit(); |
| 160 | void _confirm_discard_all(); |
| 161 | void _discard_all(); |
| 162 | void _refresh_stage_area(); |
| 163 | void _refresh_branch_list(); |
| 164 | void _set_commit_list_size(int p_index); |
| 165 | void _refresh_commit_list(); |
| 166 | void _refresh_remote_list(); |
| 167 | void _display_diff(int p_idx); |
| 168 | void _move_all(Object *p_tree); |
| 169 | void _load_diff(Object *p_tree); |
| 170 | void _clear_diff(); |
| 171 | int _get_item_count(Tree *p_tree); |
| 172 | void _item_activated(Object *p_tree); |
| 173 | void _create_branch(); |
| 174 | void _create_remote(); |
| 175 | void _update_branch_create_button(String p_new_text); |
| 176 | void _update_remote_create_button(String p_new_text); |
| 177 | void _branch_item_selected(int p_index); |
| 178 | void _remote_selected(int p_index); |
| 179 | void _remove_branch(); |
| 180 | void _remove_remote(); |
| 181 | void (int p_index); |
| 182 | void (int p_index); |
| 183 | void _move_item(Tree *p_tree, TreeItem *p_itme); |
| 184 | void _display_diff_split_view(List<EditorVCSInterface::DiffLine> &p_diff_content); |
| 185 | void _display_diff_unified_view(List<EditorVCSInterface::DiffLine> &p_diff_content); |
| 186 | void _discard_file(String p_file_path, EditorVCSInterface::ChangeType p_change); |
| 187 | void _cell_button_pressed(Object *p_item, int p_column, int p_id, int p_mouse_button_index); |
| 188 | void _add_new_item(Tree *p_tree, String p_file_path, EditorVCSInterface::ChangeType p_change); |
| 189 | void _update_commit_button(); |
| 190 | void _commit_message_gui_input(const Ref<InputEvent> &p_event); |
| 191 | void (int p_index); |
| 192 | bool _is_staging_area_empty(); |
| 193 | String _get_date_string_from(int64_t p_unix_timestamp, int64_t p_offset_minutes) const; |
| 194 | void _create_vcs_metadata_files(); |
| 195 | void (Variant p_file_dialog_variant); |
| 196 | void _toggle_vcs_integration(bool p_toggled); |
| 197 | |
| 198 | friend class EditorVCSInterface; |
| 199 | |
| 200 | protected: |
| 201 | static void _bind_methods(); |
| 202 | |
| 203 | public: |
| 204 | static VersionControlEditorPlugin *get_singleton(); |
| 205 | |
| 206 | void (); |
| 207 | void (const Control *p_gui_base); |
| 208 | |
| 209 | PopupMenu *get_version_control_actions_panel() const { return version_control_actions; } |
| 210 | |
| 211 | void register_editor(); |
| 212 | void fetch_available_vcs_plugin_names(); |
| 213 | void shut_down(); |
| 214 | |
| 215 | VersionControlEditorPlugin(); |
| 216 | ~VersionControlEditorPlugin(); |
| 217 | }; |
| 218 | |
| 219 | #endif // VERSION_CONTROL_EDITOR_PLUGIN_H |
| 220 | |