Skip to content

Commit bee2091

Browse files
committed
Auto import project folder, confirm scan multiple folders or non-project folder
1 parent 0b595f9 commit bee2091

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

tools/editor/project_manager.cpp

+48-8
Original file line numberDiff line numberDiff line change
@@ -1103,16 +1103,50 @@ void ProjectManager::_install_project(const String& p_zip_path,const String& p_t
11031103
}
11041104

11051105
void ProjectManager::_files_dropped(StringArray p_files, int p_screen) {
1106-
bool import_project_file = false;
1106+
Set<String> folders_set;
1107+
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
11071108
for (int i = 0; i < p_files.size(); i++) {
1108-
if (p_files[i].ends_with("engine.cfg")) {
1109-
npdialog->import_from_file(p_files[i]);
1110-
import_project_file = true;
1109+
String file = p_files[i];
1110+
folders_set.insert(da->dir_exists(file) ? file : file.get_base_dir());
1111+
}
1112+
memdelete(da);
1113+
if (folders_set.size()>0) {
1114+
StringArray folders;
1115+
for (Set<String>::Element *E=folders_set.front();E;E=E->next()) {
1116+
folders.append(E->get());
1117+
}
1118+
1119+
bool confirm = true;
1120+
if (folders.size()==1) {
1121+
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
1122+
if (dir->change_dir(folders[0])==OK) {
1123+
dir->list_dir_begin();
1124+
String file = dir->get_next();
1125+
while(confirm && file!=String()) {
1126+
if (!da->current_is_dir() && file.ends_with("engine.cfg")) {
1127+
confirm = false;
1128+
}
1129+
file = dir->get_next();
1130+
}
1131+
dir->list_dir_end();
1132+
}
1133+
memdelete(dir);
1134+
}
1135+
if (confirm) {
1136+
multi_scan_ask->get_ok()->disconnect("pressed", this, "_scan_multiple_folders");
1137+
multi_scan_ask->get_ok()->connect("pressed", this, "_scan_multiple_folders", varray(folders));
1138+
multi_scan_ask->set_text(vformat(TTR("You are about the scan %s folders for existing Godot projects. Do you confirm?"), folders.size()));
1139+
multi_scan_ask->popup_centered_minsize();
1140+
} else {
1141+
_scan_multiple_folders(folders);
11111142
}
11121143
}
1113-
if (!import_project_file && p_files.size() > 0) {
1114-
scan_dir->set_current_dir(p_files[0]);
1115-
scan_dir->popup_centered_ratio();
1144+
}
1145+
1146+
void ProjectManager::_scan_multiple_folders(StringArray p_files)
1147+
{
1148+
for (int i = 0; i < p_files.size(); i++) {
1149+
_scan_begin(p_files.get(i));
11161150
}
11171151
}
11181152

@@ -1136,6 +1170,7 @@ void ProjectManager::_bind_methods() {
11361170
ObjectTypeDB::bind_method("_favorite_pressed",&ProjectManager::_favorite_pressed);
11371171
ObjectTypeDB::bind_method("_install_project",&ProjectManager::_install_project);
11381172
ObjectTypeDB::bind_method("_files_dropped",&ProjectManager::_files_dropped);
1173+
ObjectTypeDB::bind_method(_MD("_scan_multiple_folders", "files"),&ProjectManager::_scan_multiple_folders);
11391174

11401175

11411176
}
@@ -1332,8 +1367,13 @@ ProjectManager::ProjectManager() {
13321367
multi_run_ask = memnew( ConfirmationDialog );
13331368
multi_run_ask->get_ok()->set_text(TTR("Run"));
13341369
multi_run_ask->get_ok()->connect("pressed", this, "_run_project_confirm");
1335-
1370+
13361371
gui_base->add_child(multi_run_ask);
1372+
1373+
multi_scan_ask = memnew( ConfirmationDialog );
1374+
multi_scan_ask->get_ok()->set_text(TTR("Scan"));
1375+
1376+
gui_base->add_child(multi_scan_ask);
13371377

13381378
OS::get_singleton()->set_low_processor_usage_mode(true);
13391379

tools/editor/project_manager.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class ProjectManager : public Control {
5555
ConfirmationDialog *erase_ask;
5656
ConfirmationDialog *multi_open_ask;
5757
ConfirmationDialog *multi_run_ask;
58+
ConfirmationDialog *multi_scan_ask;
5859
NewProjectDialog *npdialog;
5960
ScrollContainer *scroll;
6061
VBoxContainer *scroll_childs;
@@ -93,6 +94,7 @@ class ProjectManager : public Control {
9394
void _unhandled_input(const InputEvent& p_ev);
9495
void _favorite_pressed(Node *p_hb);
9596
void _files_dropped(StringArray p_files, int p_screen);
97+
void _scan_multiple_folders(StringArray p_files);
9698

9799
protected:
98100

0 commit comments

Comments
 (0)