Merge pull request #90845 from KoBeWi/best_of_both_worlds
Fix folder scan replacing project list
This commit is contained in:
commit
8d557e517b
4 changed files with 33 additions and 23 deletions
|
@ -1571,6 +1571,8 @@ ProjectManager::ProjectManager() {
|
||||||
|
|
||||||
// Initialize project list.
|
// Initialize project list.
|
||||||
{
|
{
|
||||||
|
project_list->load_project_list();
|
||||||
|
|
||||||
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::AccessType::ACCESS_FILESYSTEM);
|
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::AccessType::ACCESS_FILESYSTEM);
|
||||||
|
|
||||||
String default_project_path = EDITOR_GET("filesystem/directories/default_project_path");
|
String default_project_path = EDITOR_GET("filesystem/directories/default_project_path");
|
||||||
|
@ -1581,13 +1583,10 @@ ProjectManager::ProjectManager() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool scanned_for_projects = false; // Scanning will update the list automatically.
|
|
||||||
|
|
||||||
String autoscan_path = EDITOR_GET("filesystem/directories/autoscan_project_path");
|
String autoscan_path = EDITOR_GET("filesystem/directories/autoscan_project_path");
|
||||||
if (!autoscan_path.is_empty()) {
|
if (!autoscan_path.is_empty()) {
|
||||||
if (dir_access->dir_exists(autoscan_path)) {
|
if (dir_access->dir_exists(autoscan_path)) {
|
||||||
project_list->find_projects(autoscan_path);
|
project_list->find_projects(autoscan_path);
|
||||||
scanned_for_projects = true;
|
|
||||||
} else {
|
} else {
|
||||||
Error error = dir_access->make_dir_recursive(autoscan_path);
|
Error error = dir_access->make_dir_recursive(autoscan_path);
|
||||||
if (error != OK) {
|
if (error != OK) {
|
||||||
|
@ -1595,10 +1594,8 @@ ProjectManager::ProjectManager() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
project_list->update_project_list();
|
||||||
if (!scanned_for_projects) {
|
initialized = true;
|
||||||
project_list->update_project_list();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extend menu bar to window title.
|
// Extend menu bar to window title.
|
||||||
|
|
|
@ -141,6 +141,7 @@ class ProjectManager : public Control {
|
||||||
void _update_list_placeholder();
|
void _update_list_placeholder();
|
||||||
|
|
||||||
ProjectList *project_list = nullptr;
|
ProjectList *project_list = nullptr;
|
||||||
|
bool initialized = false;
|
||||||
|
|
||||||
LineEdit *search_box = nullptr;
|
LineEdit *search_box = nullptr;
|
||||||
Label *loading_label = nullptr;
|
Label *loading_label = nullptr;
|
||||||
|
@ -239,6 +240,7 @@ public:
|
||||||
|
|
||||||
// Project list.
|
// Project list.
|
||||||
|
|
||||||
|
bool is_initialized() const { return initialized; }
|
||||||
LineEdit *get_search_box();
|
LineEdit *get_search_box();
|
||||||
|
|
||||||
// Project tag management.
|
// Project tag management.
|
||||||
|
|
|
@ -469,23 +469,19 @@ void ProjectList::update_project_list() {
|
||||||
// If you have 150 projects, it may read through 150 files on your disk at once + load 150 icons.
|
// If you have 150 projects, it may read through 150 files on your disk at once + load 150 icons.
|
||||||
// FIXME: Does it really have to be a full, hard reload? Runtime updates should be made much cheaper.
|
// FIXME: Does it really have to be a full, hard reload? Runtime updates should be made much cheaper.
|
||||||
|
|
||||||
// Clear whole list
|
if (ProjectManager::get_singleton()->is_initialized()) {
|
||||||
for (int i = 0; i < _projects.size(); ++i) {
|
// Clear whole list
|
||||||
Item &project = _projects.write[i];
|
for (int i = 0; i < _projects.size(); ++i) {
|
||||||
CRASH_COND(project.control == nullptr);
|
Item &project = _projects.write[i];
|
||||||
memdelete(project.control); // Why not queue_free()?
|
CRASH_COND(project.control == nullptr);
|
||||||
}
|
memdelete(project.control); // Why not queue_free()?
|
||||||
_projects.clear();
|
}
|
||||||
_last_clicked = "";
|
|
||||||
_selected_project_paths.clear();
|
|
||||||
|
|
||||||
List<String> sections;
|
_projects.clear();
|
||||||
_config.load(_config_path);
|
_last_clicked = "";
|
||||||
_config.get_sections(§ions);
|
_selected_project_paths.clear();
|
||||||
|
|
||||||
for (const String &path : sections) {
|
load_project_list();
|
||||||
bool favorite = _config.get_value(path, "favorite", false);
|
|
||||||
_projects.push_back(load_project_data(path, favorite));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create controls
|
// Create controls
|
||||||
|
@ -590,7 +586,21 @@ void ProjectList::find_projects_multiple(const PackedStringArray &p_paths) {
|
||||||
}
|
}
|
||||||
|
|
||||||
save_config();
|
save_config();
|
||||||
update_project_list();
|
|
||||||
|
if (ProjectManager::get_singleton()->is_initialized()) {
|
||||||
|
update_project_list();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProjectList::load_project_list() {
|
||||||
|
List<String> sections;
|
||||||
|
_config.load(_config_path);
|
||||||
|
_config.get_sections(§ions);
|
||||||
|
|
||||||
|
for (const String &path : sections) {
|
||||||
|
bool favorite = _config.get_value(path, "favorite", false);
|
||||||
|
_projects.push_back(load_project_data(path, favorite));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectList::_scan_folder_recursive(const String &p_path, List<String> *r_projects) {
|
void ProjectList::_scan_folder_recursive(const String &p_path, List<String> *r_projects) {
|
||||||
|
|
|
@ -220,6 +220,7 @@ public:
|
||||||
|
|
||||||
// Project list updates.
|
// Project list updates.
|
||||||
|
|
||||||
|
void load_project_list();
|
||||||
void update_project_list();
|
void update_project_list();
|
||||||
void sort_projects();
|
void sort_projects();
|
||||||
int get_project_count() const;
|
int get_project_count() const;
|
||||||
|
|
Loading…
Reference in a new issue