You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-10 13:00:37 +00:00
Merge pull request #11031 from nabor/rename-dialog
Added support to rename projects on manager
This commit is contained in:
@@ -59,11 +59,13 @@ public:
|
|||||||
enum Mode {
|
enum Mode {
|
||||||
MODE_NEW,
|
MODE_NEW,
|
||||||
MODE_IMPORT,
|
MODE_IMPORT,
|
||||||
MODE_INSTALL
|
MODE_INSTALL,
|
||||||
|
MODE_RENAME
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mode mode;
|
Mode mode;
|
||||||
|
Button *browse;
|
||||||
Label *pp, *pn;
|
Label *pp, *pn;
|
||||||
Label *error;
|
Label *error;
|
||||||
LineEdit *project_path;
|
LineEdit *project_path;
|
||||||
@@ -91,20 +93,20 @@ private:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode != MODE_IMPORT) {
|
if (mode == MODE_IMPORT || mode == MODE_RENAME) {
|
||||||
|
|
||||||
if (d->file_exists("project.godot")) {
|
if (valid_path != "" && !d->file_exists("project.godot")) {
|
||||||
|
|
||||||
error->set_text(TTR("Invalid project path, project.godot must not exist."));
|
error->set_text(TTR("Invalid project path, project.godot must exist."));
|
||||||
memdelete(d);
|
memdelete(d);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (valid_path != "" && !d->file_exists("project.godot")) {
|
if (d->file_exists("project.godot")) {
|
||||||
|
|
||||||
error->set_text(TTR("Invalid project path, project.godot must exist."));
|
error->set_text(TTR("Invalid project path, project.godot must not exist."));
|
||||||
memdelete(d);
|
memdelete(d);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -172,6 +174,17 @@ private:
|
|||||||
|
|
||||||
void _text_changed(const String &p_text) {
|
void _text_changed(const String &p_text) {
|
||||||
_test_path();
|
_test_path();
|
||||||
|
error->set_text("");
|
||||||
|
if (p_text == "") {
|
||||||
|
|
||||||
|
error->set_text(TTR("Name cannot be empty"));
|
||||||
|
get_ok()->set_disabled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
get_ok()->set_disabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _name_changed(const String &p_text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ok_pressed() {
|
void ok_pressed() {
|
||||||
@@ -182,6 +195,32 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode == MODE_RENAME) {
|
||||||
|
|
||||||
|
String dir = _test_path();
|
||||||
|
if (dir == "") {
|
||||||
|
error->set_text(TTR("Invalid project path (changed anything?)."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectSettings *current = memnew(ProjectSettings);
|
||||||
|
current->add_singleton(ProjectSettings::Singleton("Current"));
|
||||||
|
|
||||||
|
if (current->setup(dir, "")) {
|
||||||
|
error->set_text(TTR("Couldn't get project.godot in project path."));
|
||||||
|
} else {
|
||||||
|
ProjectSettings::CustomMap edited_settings;
|
||||||
|
edited_settings["application/config/name"] = project_name->get_text();
|
||||||
|
|
||||||
|
if (current->save_custom(dir.plus_file("/project.godot"), edited_settings, Vector<String>(), true)) {
|
||||||
|
error->set_text(TTR("Couldn't edit project.godot in project path."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hide();
|
||||||
|
emit_signal("project_renamed");
|
||||||
|
} else {
|
||||||
|
|
||||||
if (mode == MODE_IMPORT) {
|
if (mode == MODE_IMPORT) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
} else {
|
} else {
|
||||||
@@ -315,6 +354,7 @@ private:
|
|||||||
hide();
|
hide();
|
||||||
emit_signal("project_created", dir);
|
emit_signal("project_created", dir);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods() {
|
static void _bind_methods() {
|
||||||
@@ -325,6 +365,7 @@ protected:
|
|||||||
ClassDB::bind_method("_path_selected", &NewProjectDialog::_path_selected);
|
ClassDB::bind_method("_path_selected", &NewProjectDialog::_path_selected);
|
||||||
ClassDB::bind_method("_file_selected", &NewProjectDialog::_file_selected);
|
ClassDB::bind_method("_file_selected", &NewProjectDialog::_file_selected);
|
||||||
ADD_SIGNAL(MethodInfo("project_created"));
|
ADD_SIGNAL(MethodInfo("project_created"));
|
||||||
|
ADD_SIGNAL(MethodInfo("project_renamed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -340,10 +381,50 @@ public:
|
|||||||
mode = p_mode;
|
mode = p_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_project_path(const String &p_path) {
|
||||||
|
project_path->set_text(p_path);
|
||||||
|
}
|
||||||
|
|
||||||
void show_dialog() {
|
void show_dialog() {
|
||||||
|
|
||||||
|
if (mode == MODE_RENAME) {
|
||||||
|
|
||||||
|
project_path->set_editable(false);
|
||||||
|
browse->set_disabled(true);
|
||||||
|
|
||||||
|
set_title(TTR("Rename Project"));
|
||||||
|
get_ok()->set_text(TTR("Rename"));
|
||||||
|
pp->set_text(TTR("Project Path:"));
|
||||||
|
pn->set_text(TTR("Project Name:"));
|
||||||
|
pn->show();
|
||||||
|
project_name->show();
|
||||||
|
|
||||||
|
String dir = _test_path();
|
||||||
|
if (dir == "") {
|
||||||
|
error->set_text(TTR("Invalid project path (changed anything?)."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProjectSettings *current = memnew(ProjectSettings);
|
||||||
|
current->add_singleton(ProjectSettings::Singleton("Current"));
|
||||||
|
|
||||||
|
if (current->setup(dir, "")) {
|
||||||
|
error->set_text(TTR("Couldn't get project.godot in project path."));
|
||||||
|
} else {
|
||||||
|
if (current->has("application/config/name")) {
|
||||||
|
String appname = current->get("application/config/name");
|
||||||
|
project_name->set_text(appname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
popup_centered(Size2(500, 125) * EDSCALE);
|
||||||
|
project_name->grab_focus();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
project_path->clear();
|
project_path->clear();
|
||||||
project_name->clear();
|
project_name->clear();
|
||||||
|
project_path->set_editable(true);
|
||||||
|
browse->set_disabled(false);
|
||||||
|
|
||||||
if (mode == MODE_IMPORT) {
|
if (mode == MODE_IMPORT) {
|
||||||
set_title(TTR("Import Existing Project"));
|
set_title(TTR("Import Existing Project"));
|
||||||
@@ -379,6 +460,7 @@ public:
|
|||||||
|
|
||||||
_test_path();
|
_test_path();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NewProjectDialog() {
|
NewProjectDialog() {
|
||||||
|
|
||||||
@@ -399,7 +481,7 @@ public:
|
|||||||
pphb->add_child(project_path);
|
pphb->add_child(project_path);
|
||||||
project_path->set_h_size_flags(SIZE_EXPAND_FILL);
|
project_path->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||||
|
|
||||||
Button *browse = memnew(Button);
|
browse = memnew(Button);
|
||||||
pphb->add_child(browse);
|
pphb->add_child(browse);
|
||||||
browse->set_text(TTR("Browse"));
|
browse->set_text(TTR("Browse"));
|
||||||
browse->connect("pressed", this, "_browse_path");
|
browse->connect("pressed", this, "_browse_path");
|
||||||
@@ -495,6 +577,7 @@ void ProjectManager::_update_project_buttons() {
|
|||||||
|
|
||||||
erase_btn->set_disabled(selected_list.size() < 1);
|
erase_btn->set_disabled(selected_list.size() < 1);
|
||||||
open_btn->set_disabled(selected_list.size() < 1);
|
open_btn->set_disabled(selected_list.size() < 1);
|
||||||
|
rename_btn->set_disabled(selected_list.size() < 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectManager::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
|
void ProjectManager::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
|
||||||
@@ -889,6 +972,10 @@ void ProjectManager::_load_recent_projects() {
|
|||||||
tabs->set_current_tab(0);
|
tabs->set_current_tab(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectManager::_on_project_renamed() {
|
||||||
|
_load_recent_projects();
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectManager::_on_project_created(const String &dir) {
|
void ProjectManager::_on_project_created(const String &dir) {
|
||||||
bool has_already = false;
|
bool has_already = false;
|
||||||
for (int i = 0; i < scroll_childs->get_child_count(); i++) {
|
for (int i = 0; i < scroll_childs->get_child_count(); i++) {
|
||||||
@@ -1091,6 +1178,21 @@ void ProjectManager::_import_project() {
|
|||||||
npdialog->show_dialog();
|
npdialog->show_dialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectManager::_rename_project() {
|
||||||
|
|
||||||
|
if (selected_list.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map<String, String>::Element *E = selected_list.front(); E; E = E->next()) {
|
||||||
|
const String &selected = E->key();
|
||||||
|
String path = EditorSettings::get_singleton()->get("projects/" + selected);
|
||||||
|
npdialog->set_project_path(path);
|
||||||
|
npdialog->set_mode(NewProjectDialog::MODE_RENAME);
|
||||||
|
npdialog->show_dialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectManager::_erase_project_confirm() {
|
void ProjectManager::_erase_project_confirm() {
|
||||||
|
|
||||||
if (selected_list.size() == 0) {
|
if (selected_list.size() == 0) {
|
||||||
@@ -1185,10 +1287,12 @@ void ProjectManager::_bind_methods() {
|
|||||||
ClassDB::bind_method("_scan_begin", &ProjectManager::_scan_begin);
|
ClassDB::bind_method("_scan_begin", &ProjectManager::_scan_begin);
|
||||||
ClassDB::bind_method("_import_project", &ProjectManager::_import_project);
|
ClassDB::bind_method("_import_project", &ProjectManager::_import_project);
|
||||||
ClassDB::bind_method("_new_project", &ProjectManager::_new_project);
|
ClassDB::bind_method("_new_project", &ProjectManager::_new_project);
|
||||||
|
ClassDB::bind_method("_rename_project", &ProjectManager::_rename_project);
|
||||||
ClassDB::bind_method("_erase_project", &ProjectManager::_erase_project);
|
ClassDB::bind_method("_erase_project", &ProjectManager::_erase_project);
|
||||||
ClassDB::bind_method("_erase_project_confirm", &ProjectManager::_erase_project_confirm);
|
ClassDB::bind_method("_erase_project_confirm", &ProjectManager::_erase_project_confirm);
|
||||||
ClassDB::bind_method("_exit_dialog", &ProjectManager::_exit_dialog);
|
ClassDB::bind_method("_exit_dialog", &ProjectManager::_exit_dialog);
|
||||||
ClassDB::bind_method("_load_recent_projects", &ProjectManager::_load_recent_projects);
|
ClassDB::bind_method("_load_recent_projects", &ProjectManager::_load_recent_projects);
|
||||||
|
ClassDB::bind_method("_on_project_renamed", &ProjectManager::_on_project_renamed);
|
||||||
ClassDB::bind_method("_on_project_created", &ProjectManager::_on_project_created);
|
ClassDB::bind_method("_on_project_created", &ProjectManager::_on_project_created);
|
||||||
ClassDB::bind_method("_update_scroll_pos", &ProjectManager::_update_scroll_pos);
|
ClassDB::bind_method("_update_scroll_pos", &ProjectManager::_update_scroll_pos);
|
||||||
ClassDB::bind_method("_panel_draw", &ProjectManager::_panel_draw);
|
ClassDB::bind_method("_panel_draw", &ProjectManager::_panel_draw);
|
||||||
@@ -1349,6 +1453,12 @@ ProjectManager::ProjectManager() {
|
|||||||
tree_vb->add_child(import);
|
tree_vb->add_child(import);
|
||||||
import->connect("pressed", this, "_import_project");
|
import->connect("pressed", this, "_import_project");
|
||||||
|
|
||||||
|
Button *rename = memnew(Button);
|
||||||
|
rename->set_text(TTR("Rename"));
|
||||||
|
tree_vb->add_child(rename);
|
||||||
|
rename->connect("pressed", this, "_rename_project");
|
||||||
|
rename_btn = rename;
|
||||||
|
|
||||||
Button *erase = memnew(Button);
|
Button *erase = memnew(Button);
|
||||||
erase->set_text(TTR("Remove"));
|
erase->set_text(TTR("Remove"));
|
||||||
tree_vb->add_child(erase);
|
tree_vb->add_child(erase);
|
||||||
@@ -1404,6 +1514,7 @@ ProjectManager::ProjectManager() {
|
|||||||
npdialog = memnew(NewProjectDialog);
|
npdialog = memnew(NewProjectDialog);
|
||||||
gui_base->add_child(npdialog);
|
gui_base->add_child(npdialog);
|
||||||
|
|
||||||
|
npdialog->connect("project_renamed", this, "_on_project_renamed");
|
||||||
npdialog->connect("project_created", this, "_on_project_created");
|
npdialog->connect("project_created", this, "_on_project_created");
|
||||||
_load_recent_projects();
|
_load_recent_projects();
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class ProjectManager : public Control {
|
|||||||
|
|
||||||
Button *erase_btn;
|
Button *erase_btn;
|
||||||
Button *open_btn;
|
Button *open_btn;
|
||||||
|
Button *rename_btn;
|
||||||
Button *run_btn;
|
Button *run_btn;
|
||||||
|
|
||||||
FileDialog *scan_dir;
|
FileDialog *scan_dir;
|
||||||
@@ -79,6 +80,7 @@ class ProjectManager : public Control {
|
|||||||
void _open_project_confirm();
|
void _open_project_confirm();
|
||||||
void _import_project();
|
void _import_project();
|
||||||
void _new_project();
|
void _new_project();
|
||||||
|
void _rename_project();
|
||||||
void _erase_project();
|
void _erase_project();
|
||||||
void _erase_project_confirm();
|
void _erase_project_confirm();
|
||||||
void _update_project_buttons();
|
void _update_project_buttons();
|
||||||
@@ -87,6 +89,7 @@ class ProjectManager : public Control {
|
|||||||
|
|
||||||
void _load_recent_projects();
|
void _load_recent_projects();
|
||||||
void _on_project_created(const String &dir);
|
void _on_project_created(const String &dir);
|
||||||
|
void _on_project_renamed();
|
||||||
void _update_scroll_pos(const String &dir);
|
void _update_scroll_pos(const String &dir);
|
||||||
void _scan_dir(DirAccess *da, float pos, float total, List<String> *r_projects);
|
void _scan_dir(DirAccess *da, float pos, float total, List<String> *r_projects);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user