Skip to content

Commit

Permalink
Added create folder button to project imports
Browse files Browse the repository at this point in the history
Closes #2754

This adds a "create folder" button to the import project window in the project manager as described in the linked proposal.
  • Loading branch information
likeich committed Jun 14, 2021
1 parent 12e0f10 commit d4d4a1f
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,20 +376,33 @@ class ProjectDialog : public ConfirmationDialog {
fdialog_install->popup_file_dialog();
}

void _create_folder() {
const String project_name_no_edges = project_name->get_text().strip_edges();
void _create_new_project_folder() {
_create_folder(project_name->get_text(), project_path);
}

void _create_install_folder() {
Vector<String> strings = project_path->get_text().split("/");
String filename = strings[strings.size() - 1];
String filename_no_extension = filename.trim_suffix("." + filename.get_extension());
project_name->set_text(filename_no_extension);

_create_folder(project_name->get_text(), install_path);
}

void _create_folder(const String p_project_name, LineEdit *p_path) {
const String project_name_no_edges = p_project_name.strip_edges();
if (project_name_no_edges == "" || created_folder_path != "" || project_name_no_edges.ends_with(".")) {
set_message(TTR("Invalid project name."), MESSAGE_WARNING);
return;
}

DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (d->change_dir(project_path->get_text()) == OK) {
if (d->change_dir(p_path->get_text()) == OK) {
if (!d->dir_exists(project_name_no_edges)) {
if (d->make_dir(project_name_no_edges) == OK) {
d->change_dir(project_name_no_edges);
String dir_str = d->get_current_dir();
project_path->set_text(dir_str);
p_path->set_text(dir_str);
_path_text_changed(dir_str);
created_folder_path = d->get_current_dir();
create_dir->set_disabled(true);
Expand Down Expand Up @@ -658,7 +671,6 @@ class ProjectDialog : public ConfirmationDialog {
protected:
static void _bind_methods() {
ClassDB::bind_method("_browse_path", &ProjectDialog::_browse_path);
ClassDB::bind_method("_create_folder", &ProjectDialog::_create_folder);
ClassDB::bind_method("_text_changed", &ProjectDialog::_text_changed);
ClassDB::bind_method("_path_text_changed", &ProjectDialog::_path_text_changed);
ClassDB::bind_method("_path_selected", &ProjectDialog::_path_selected);
Expand Down Expand Up @@ -798,7 +810,7 @@ class ProjectDialog : public ConfirmationDialog {
create_dir = memnew(Button);
pnhb->add_child(create_dir);
create_dir->set_text(TTR("Create Folder"));
create_dir->connect("pressed", callable_mp(this, &ProjectDialog::_create_folder));
create_dir->connect("pressed", callable_mp(this, &ProjectDialog::_create_new_project_folder));

path_container = memnew(VBoxContainer);
vb->add_child(path_container);
Expand Down Expand Up @@ -850,6 +862,11 @@ class ProjectDialog : public ConfirmationDialog {
install_browse->connect("pressed", callable_mp(this, &ProjectDialog::_browse_install_path));
iphb->add_child(install_browse);

create_dir = memnew(Button);
create_dir->set_text(TTR("Create Folder"));
create_dir->connect("pressed", callable_mp(this, &ProjectDialog::_create_install_folder));
iphb->add_child(create_dir);

msg = memnew(Label);
msg->set_align(Label::ALIGN_CENTER);
vb->add_child(msg);
Expand Down

0 comments on commit d4d4a1f

Please sign in to comment.