Merge pull request #42447 from aaronfranke/gitignore-create
This commit is contained in:
commit
c5ab537617
7 changed files with 120 additions and 18 deletions
|
@ -383,6 +383,9 @@ void EditorNode::_update_scene_tabs() {
|
|||
|
||||
void EditorNode::_version_control_menu_option(int p_idx) {
|
||||
switch (vcs_actions_menu->get_item_id(p_idx)) {
|
||||
case RUN_VCS_METADATA: {
|
||||
VersionControlEditorPlugin::get_singleton()->popup_vcs_metadata_dialog();
|
||||
} break;
|
||||
case RUN_VCS_SETTINGS: {
|
||||
VersionControlEditorPlugin::get_singleton()->popup_vcs_set_up_dialog(gui_base);
|
||||
} break;
|
||||
|
@ -6432,6 +6435,7 @@ EditorNode::EditorNode() {
|
|||
p->add_separator();
|
||||
p->add_child(vcs_actions_menu);
|
||||
p->add_submenu_item(TTR("Version Control"), "Version Control");
|
||||
vcs_actions_menu->add_item(TTR("Create Version Control Metadata"), RUN_VCS_METADATA);
|
||||
vcs_actions_menu->add_item(TTR("Set Up Version Control"), RUN_VCS_SETTINGS);
|
||||
vcs_actions_menu->add_item(TTR("Shut Down Version Control"), RUN_VCS_SHUT_DOWN);
|
||||
|
||||
|
|
|
@ -170,6 +170,7 @@ private:
|
|||
RUN_PROJECT_DATA_FOLDER,
|
||||
RUN_RELOAD_CURRENT_PROJECT,
|
||||
RUN_PROJECT_MANAGER,
|
||||
RUN_VCS_METADATA,
|
||||
RUN_VCS_SETTINGS,
|
||||
RUN_VCS_SHUT_DOWN,
|
||||
SETTINGS_UPDATE_CONTINUOUSLY,
|
||||
|
|
|
@ -166,3 +166,24 @@ EditorVCSInterface *EditorVCSInterface::get_singleton() {
|
|||
void EditorVCSInterface::set_singleton(EditorVCSInterface *p_singleton) {
|
||||
singleton = p_singleton;
|
||||
}
|
||||
|
||||
void EditorVCSInterface::create_vcs_metadata_files(VCSMetadata p_vcs_metadata_type, String &p_dir) {
|
||||
if (p_vcs_metadata_type == VCSMetadata::GIT) {
|
||||
FileAccess *f = FileAccess::open(p_dir.plus_file(".gitignore"), FileAccess::WRITE);
|
||||
if (!f) {
|
||||
ERR_FAIL_MSG(TTR("Couldn't create .gitignore in project path."));
|
||||
} else {
|
||||
f->store_line("# Godot 4+ specific ignores");
|
||||
f->store_line(".godot/");
|
||||
memdelete(f);
|
||||
}
|
||||
f = FileAccess::open(p_dir.plus_file(".gitattributes"), FileAccess::WRITE);
|
||||
if (!f) {
|
||||
ERR_FAIL_MSG(TTR("Couldn't create .gitattributes in project path."));
|
||||
} else {
|
||||
f->store_line("# Normalize EOL for all files that Git considers text files.");
|
||||
f->store_line("* text=auto eol=lf");
|
||||
memdelete(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,12 @@ public:
|
|||
static EditorVCSInterface *get_singleton();
|
||||
static void set_singleton(EditorVCSInterface *p_singleton);
|
||||
|
||||
enum class VCSMetadata {
|
||||
NONE,
|
||||
GIT,
|
||||
};
|
||||
static void create_vcs_metadata_files(VCSMetadata p_vcs_metadata_type, String &p_dir);
|
||||
|
||||
bool is_addon_ready();
|
||||
|
||||
// Proxy functions to the editor for use
|
||||
|
|
|
@ -49,6 +49,11 @@ void VersionControlEditorPlugin::_bind_methods() {
|
|||
BIND_ENUM_CONSTANT(CHANGE_TYPE_TYPECHANGE);
|
||||
}
|
||||
|
||||
void VersionControlEditorPlugin::_create_vcs_metadata_files() {
|
||||
String dir = "res://";
|
||||
EditorVCSInterface::create_vcs_metadata_files(EditorVCSInterface::VCSMetadata(metadata_selection->get_selected()), dir);
|
||||
}
|
||||
|
||||
void VersionControlEditorPlugin::_selected_a_vcs(int p_id) {
|
||||
List<StringName> available_addons = get_available_vcs_names();
|
||||
const StringName selected_vcs = set_up_choice->get_item_text(p_id);
|
||||
|
@ -71,6 +76,10 @@ VersionControlEditorPlugin *VersionControlEditorPlugin::get_singleton() {
|
|||
return singleton ? singleton : memnew(VersionControlEditorPlugin);
|
||||
}
|
||||
|
||||
void VersionControlEditorPlugin::popup_vcs_metadata_dialog() {
|
||||
metadata_dialog->popup_centered();
|
||||
}
|
||||
|
||||
void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_base) {
|
||||
fetch_available_vcs_addon_names();
|
||||
List<StringName> available_addons = get_available_vcs_names();
|
||||
|
@ -374,6 +383,30 @@ VersionControlEditorPlugin::VersionControlEditorPlugin() {
|
|||
|
||||
version_control_actions = memnew(PopupMenu);
|
||||
|
||||
metadata_dialog = memnew(ConfirmationDialog);
|
||||
metadata_dialog->set_title(TTR("Create Version Control Metadata"));
|
||||
metadata_dialog->set_min_size(Size2(200, 40));
|
||||
version_control_actions->add_child(metadata_dialog);
|
||||
|
||||
VBoxContainer *metadata_vb = memnew(VBoxContainer);
|
||||
HBoxContainer *metadata_hb = memnew(HBoxContainer);
|
||||
metadata_hb->set_custom_minimum_size(Size2(200, 20));
|
||||
Label *l = memnew(Label);
|
||||
l->set_text(TTR("Create VCS metadata files for:"));
|
||||
metadata_hb->add_child(l);
|
||||
metadata_selection = memnew(OptionButton);
|
||||
metadata_selection->set_custom_minimum_size(Size2(100, 20));
|
||||
metadata_selection->add_item("None", (int)EditorVCSInterface::VCSMetadata::NONE);
|
||||
metadata_selection->add_item("Git", (int)EditorVCSInterface::VCSMetadata::GIT);
|
||||
metadata_selection->select((int)EditorVCSInterface::VCSMetadata::GIT);
|
||||
metadata_dialog->get_ok_button()->connect("pressed", callable_mp(this, &VersionControlEditorPlugin::_create_vcs_metadata_files));
|
||||
metadata_hb->add_child(metadata_selection);
|
||||
metadata_vb->add_child(metadata_hb);
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("Existing VCS metadata files will be overwritten."));
|
||||
metadata_vb->add_child(l);
|
||||
metadata_dialog->add_child(metadata_vb);
|
||||
|
||||
set_up_dialog = memnew(AcceptDialog);
|
||||
set_up_dialog->set_title(TTR("Set Up Version Control"));
|
||||
set_up_dialog->set_min_size(Size2(400, 100));
|
||||
|
|
|
@ -57,6 +57,8 @@ private:
|
|||
List<StringName> available_addons;
|
||||
|
||||
PopupMenu *version_control_actions;
|
||||
ConfirmationDialog *metadata_dialog;
|
||||
OptionButton *metadata_selection;
|
||||
AcceptDialog *set_up_dialog;
|
||||
VBoxContainer *set_up_vbc;
|
||||
HBoxContainer *set_up_hbc;
|
||||
|
@ -98,6 +100,7 @@ private:
|
|||
RichTextLabel *diff;
|
||||
|
||||
void _populate_available_vcs_names();
|
||||
void _create_vcs_metadata_files();
|
||||
void _selected_a_vcs(int p_id);
|
||||
void _initialize_vcs();
|
||||
void _send_commit_msg();
|
||||
|
@ -121,6 +124,7 @@ protected:
|
|||
public:
|
||||
static VersionControlEditorPlugin *get_singleton();
|
||||
|
||||
void popup_vcs_metadata_dialog();
|
||||
void popup_vcs_set_up_dialog(const Control *p_gui_base);
|
||||
void set_version_control_tool_button(Button *p_button) { version_control_dock_button = p_button; }
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "core/string/translation.h"
|
||||
#include "core/version.h"
|
||||
#include "core/version_hash.gen.h"
|
||||
#include "editor/editor_vcs_interface.h"
|
||||
#include "editor_scale.h"
|
||||
#include "editor_settings.h"
|
||||
#include "editor_themes.h"
|
||||
|
@ -67,19 +68,19 @@ public:
|
|||
MODE_NEW,
|
||||
MODE_IMPORT,
|
||||
MODE_INSTALL,
|
||||
MODE_RENAME
|
||||
MODE_RENAME,
|
||||
};
|
||||
|
||||
private:
|
||||
enum MessageType {
|
||||
MESSAGE_ERROR,
|
||||
MESSAGE_WARNING,
|
||||
MESSAGE_SUCCESS
|
||||
MESSAGE_SUCCESS,
|
||||
};
|
||||
|
||||
enum InputType {
|
||||
PROJECT_PATH,
|
||||
INSTALL_PATH
|
||||
INSTALL_PATH,
|
||||
};
|
||||
|
||||
Mode mode;
|
||||
|
@ -90,6 +91,7 @@ private:
|
|||
Container *path_container;
|
||||
Container *install_path_container;
|
||||
Container *rasterizer_container;
|
||||
HBoxContainer *default_files_container;
|
||||
Ref<ButtonGroup> rasterizer_button_group;
|
||||
Label *msg;
|
||||
LineEdit *project_path;
|
||||
|
@ -99,6 +101,8 @@ private:
|
|||
TextureRect *install_status_rect;
|
||||
FileDialog *fdialog;
|
||||
FileDialog *fdialog_install;
|
||||
OptionButton *vcs_metadata_selection;
|
||||
CheckBox *create_default_environment;
|
||||
String zip_path;
|
||||
String zip_title;
|
||||
AcceptDialog *dialog_error;
|
||||
|
@ -478,28 +482,34 @@ private:
|
|||
initial_settings["rendering/vulkan/rendering/back_end"] = rasterizer_button_group->get_pressed_button()->get_meta(SNAME("driver_name"));
|
||||
initial_settings["application/config/name"] = project_name->get_text().strip_edges();
|
||||
initial_settings["application/config/icon"] = "res://icon.png";
|
||||
initial_settings["rendering/environment/defaults/default_environment"] = "res://default_env.tres";
|
||||
|
||||
if (create_default_environment->is_pressed()) {
|
||||
initial_settings["rendering/environment/defaults/default_environment"] = "res://default_env.tres";
|
||||
}
|
||||
|
||||
if (ProjectSettings::get_singleton()->save_custom(dir.plus_file("project.godot"), initial_settings, Vector<String>(), false) != OK) {
|
||||
set_message(TTR("Couldn't create project.godot in project path."), MESSAGE_ERROR);
|
||||
} else {
|
||||
ResourceSaver::save(dir.plus_file("icon.png"), create_unscaled_default_project_icon());
|
||||
|
||||
FileAccess *f = FileAccess::open(dir.plus_file("default_env.tres"), FileAccess::WRITE);
|
||||
if (!f) {
|
||||
set_message(TTR("Couldn't create project.godot in project path."), MESSAGE_ERROR);
|
||||
} else {
|
||||
f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=3]");
|
||||
f->store_line("");
|
||||
f->store_line("[sub_resource type=\"Sky\" id=\"1\"]");
|
||||
f->store_line("");
|
||||
f->store_line("[resource]");
|
||||
f->store_line("background_mode = 2");
|
||||
f->store_line("sky = SubResource( \"1\" )");
|
||||
memdelete(f);
|
||||
FileAccess *f;
|
||||
if (create_default_environment->is_pressed()) {
|
||||
f = FileAccess::open(dir.plus_file("default_env.tres"), FileAccess::WRITE);
|
||||
if (!f) {
|
||||
set_message(TTR("Couldn't create default_env.tres in project path."), MESSAGE_ERROR);
|
||||
} else {
|
||||
f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=2]");
|
||||
f->store_line("");
|
||||
f->store_line("[sub_resource type=\"Sky\" id=\"1\"]");
|
||||
f->store_line("");
|
||||
f->store_line("[resource]");
|
||||
f->store_line("background_mode = 2");
|
||||
f->store_line("sky = SubResource( \"1\" )");
|
||||
memdelete(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorVCSInterface::create_vcs_metadata_files(EditorVCSInterface::VCSMetadata(vcs_metadata_selection->get_selected()), dir);
|
||||
}
|
||||
} else if (mode == MODE_INSTALL) {
|
||||
if (project_path->get_text().ends_with(".zip")) {
|
||||
dir = install_path->get_text();
|
||||
|
@ -694,6 +704,7 @@ public:
|
|||
install_path_container->hide();
|
||||
install_status_rect->hide();
|
||||
rasterizer_container->hide();
|
||||
default_files_container->hide();
|
||||
get_ok_button()->set_disabled(false);
|
||||
|
||||
ProjectSettings *current = memnew(ProjectSettings);
|
||||
|
@ -745,6 +756,7 @@ public:
|
|||
name_container->hide();
|
||||
install_path_container->hide();
|
||||
rasterizer_container->hide();
|
||||
default_files_container->hide();
|
||||
project_path->grab_focus();
|
||||
|
||||
} else if (mode == MODE_NEW) {
|
||||
|
@ -753,6 +765,7 @@ public:
|
|||
name_container->show();
|
||||
install_path_container->hide();
|
||||
rasterizer_container->show();
|
||||
default_files_container->show();
|
||||
project_name->call_deferred(SNAME("grab_focus"));
|
||||
project_name->call_deferred(SNAME("select_all"));
|
||||
|
||||
|
@ -763,6 +776,7 @@ public:
|
|||
name_container->show();
|
||||
install_path_container->hide();
|
||||
rasterizer_container->hide();
|
||||
default_files_container->hide();
|
||||
project_path->grab_focus();
|
||||
}
|
||||
|
||||
|
@ -905,6 +919,25 @@ public:
|
|||
l->set_modulate(Color(1, 1, 1, 0.7));
|
||||
rasterizer_container->add_child(l);
|
||||
|
||||
default_files_container = memnew(HBoxContainer);
|
||||
vb->add_child(default_files_container);
|
||||
l = memnew(Label);
|
||||
l->set_text(TTR("Version Control Metadata:"));
|
||||
default_files_container->add_child(l);
|
||||
vcs_metadata_selection = memnew(OptionButton);
|
||||
vcs_metadata_selection->set_custom_minimum_size(Size2(100, 20));
|
||||
vcs_metadata_selection->add_item("None", (int)EditorVCSInterface::VCSMetadata::NONE);
|
||||
vcs_metadata_selection->add_item("Git", (int)EditorVCSInterface::VCSMetadata::GIT);
|
||||
vcs_metadata_selection->select((int)EditorVCSInterface::VCSMetadata::GIT);
|
||||
default_files_container->add_child(vcs_metadata_selection);
|
||||
Control *spacer = memnew(Control);
|
||||
spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
default_files_container->add_child(spacer);
|
||||
create_default_environment = memnew(CheckBox);
|
||||
create_default_environment->set_text("Create Default Environment");
|
||||
create_default_environment->set_pressed(true);
|
||||
default_files_container->add_child(create_default_environment);
|
||||
|
||||
fdialog = memnew(FileDialog);
|
||||
fdialog->set_access(FileDialog::ACCESS_FILESYSTEM);
|
||||
fdialog_install = memnew(FileDialog);
|
||||
|
|
Loading…
Reference in a new issue