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) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 
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/container.h"
37 #include "scene/gui/rich_text_label.h"
38 #include "scene/gui/text_edit.h"
39 #include "scene/gui/tree.h"
40 
41 class VersionControlEditorPlugin : public EditorPlugin {
42 
43 	GDCLASS(VersionControlEditorPlugin, EditorPlugin)
44 
45 public:
46 	enum ChangeType {
47 
48 		CHANGE_TYPE_NEW = 0,
49 		CHANGE_TYPE_MODIFIED = 1,
50 		CHANGE_TYPE_RENAMED = 2,
51 		CHANGE_TYPE_DELETED = 3,
52 		CHANGE_TYPE_TYPECHANGE = 4
53 	};
54 
55 private:
56 	static VersionControlEditorPlugin *singleton;
57 
58 	int staged_files_count;
59 	List<StringName> available_addons;
60 
61 	PopupMenu *version_control_actions;
62 	AcceptDialog *set_up_dialog;
63 	VBoxContainer *set_up_vbc;
64 	HBoxContainer *set_up_hbc;
65 	Label *set_up_vcs_label;
66 	OptionButton *set_up_choice;
67 	PanelContainer *set_up_init_settings;
68 	Button *set_up_init_button;
69 	RichTextLabel *set_up_vcs_status;
70 	Button *set_up_ok_button;
71 
72 	HashMap<ChangeType, String> change_type_to_strings;
73 	HashMap<ChangeType, Color> change_type_to_color;
74 
75 	VBoxContainer *version_commit_dock;
76 	VBoxContainer *commit_box_vbc;
77 	HSplitContainer *stage_tools;
78 	Tree *stage_files;
79 	TreeItem *new_files;
80 	TreeItem *modified_files;
81 	TreeItem *renamed_files;
82 	TreeItem *deleted_files;
83 	TreeItem *typechange_files;
84 	Label *staging_area_label;
85 	HSplitContainer *stage_buttons;
86 	Button *stage_all_button;
87 	Button *stage_selected_button;
88 	Button *refresh_button;
89 	TextEdit *commit_message;
90 	Button *commit_button;
91 	Label *commit_status;
92 
93 	PanelContainer *version_control_dock;
94 	ToolButton *version_control_dock_button;
95 	VBoxContainer *diff_vbc;
96 	HBoxContainer *diff_hbc;
97 	Button *diff_refresh_button;
98 	Label *diff_file_name;
99 	Label *diff_heading;
100 	RichTextLabel *diff;
101 
102 	void _populate_available_vcs_names();
103 	void _selected_a_vcs(int p_id);
104 	void _initialize_vcs();
105 	void _send_commit_msg();
106 	void _refresh_stage_area();
107 	void _stage_selected();
108 	void _stage_all();
109 	void _view_file_diff();
110 	void _display_file_diff(String p_file_path);
111 	void _refresh_file_diff();
112 	void _clear_file_diff();
113 	void _update_stage_status();
114 	void _update_commit_status();
115 
116 	friend class EditorVCSInterface;
117 
118 protected:
119 	static void _bind_methods();
120 
121 public:
122 	static VersionControlEditorPlugin *get_singleton();
123 
124 	void popup_vcs_set_up_dialog(const Control *p_gui_base);
set_version_control_tool_button(ToolButton * p_button)125 	void set_version_control_tool_button(ToolButton *p_button) { version_control_dock_button = p_button; }
126 
get_version_control_actions_panel()127 	PopupMenu *get_version_control_actions_panel() const { return version_control_actions; }
get_version_commit_dock()128 	VBoxContainer *get_version_commit_dock() const { return version_commit_dock; }
get_version_control_dock()129 	PanelContainer *get_version_control_dock() const { return version_control_dock; }
130 
get_available_vcs_names()131 	List<StringName> get_available_vcs_names() const { return available_addons; }
132 	bool is_vcs_initialized() const;
133 	const String get_vcs_name() const;
134 
135 	void register_editor();
136 	void fetch_available_vcs_addon_names();
137 	void clear_stage_area();
138 	void shut_down();
139 
140 	VersionControlEditorPlugin();
141 	~VersionControlEditorPlugin();
142 };
143 
144 VARIANT_ENUM_CAST(VersionControlEditorPlugin::ChangeType);
145 
146 #endif // !VERSION_CONTROL_EDITOR_PLUGIN_H
147