Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creating .gitignore and .gitattributes when creating a new project #42447

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
@@ -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;
@@ -6431,6 +6434,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);

1 change: 1 addition & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
@@ -170,6 +170,7 @@ class EditorNode : public Node {
RUN_PROJECT_DATA_FOLDER,
RUN_RELOAD_CURRENT_PROJECT,
RUN_PROJECT_MANAGER,
RUN_VCS_METADATA,
RUN_VCS_SETTINGS,
RUN_VCS_SHUT_DOWN,
SETTINGS_UPDATE_CONTINUOUSLY,
21 changes: 21 additions & 0 deletions editor/editor_vcs_interface.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
6 changes: 6 additions & 0 deletions editor/editor_vcs_interface.h
Original file line number Diff line number Diff line change
@@ -61,6 +61,12 @@ class EditorVCSInterface : public Object {
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
33 changes: 33 additions & 0 deletions editor/plugins/version_control_editor_plugin.cpp
Original file line number Diff line number Diff line change
@@ -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));
4 changes: 4 additions & 0 deletions editor/plugins/version_control_editor_plugin.h
Original file line number Diff line number Diff line change
@@ -57,6 +57,8 @@ class VersionControlEditorPlugin : public EditorPlugin {
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 @@ class VersionControlEditorPlugin : public EditorPlugin {
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 @@ class VersionControlEditorPlugin : public EditorPlugin {
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; }

69 changes: 51 additions & 18 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
@@ -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"
@@ -66,19 +67,19 @@ class ProjectDialog : public ConfirmationDialog {
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;
@@ -89,6 +90,7 @@ class ProjectDialog : public ConfirmationDialog {
Container *path_container;
Container *install_path_container;
Container *rasterizer_container;
HBoxContainer *default_files_container;
Ref<ButtonGroup> rasterizer_button_group;
Label *msg;
LineEdit *project_path;
@@ -98,6 +100,8 @@ class ProjectDialog : public ConfirmationDialog {
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;
@@ -477,28 +481,34 @@ class ProjectDialog : public ConfirmationDialog {
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();
@@ -693,6 +703,7 @@ class ProjectDialog : public ConfirmationDialog {
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);
@@ -744,6 +755,7 @@ class ProjectDialog : public ConfirmationDialog {
name_container->hide();
install_path_container->hide();
rasterizer_container->hide();
default_files_container->hide();
project_path->grab_focus();

} else if (mode == MODE_NEW) {
@@ -752,6 +764,7 @@ class ProjectDialog : public ConfirmationDialog {
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"));

@@ -762,6 +775,7 @@ class ProjectDialog : public ConfirmationDialog {
name_container->show();
install_path_container->hide();
rasterizer_container->hide();
default_files_container->hide();
project_path->grab_focus();
}

@@ -904,6 +918,25 @@ class ProjectDialog : public ConfirmationDialog {
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);