Merge pull request #41242 from geekrelief/folder_reimport

Modified FileSystemDock so folders can be selected for reimport.
This commit is contained in:
Rémi Verschelde 2020-08-14 14:07:40 +02:00 committed by GitHub
commit f165761075
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 16 deletions

View file

@ -2430,11 +2430,31 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
}
}
void FileSystemDock::_update_import_dock() {
if (!import_dock_needs_update) {
void FileSystemDock::_get_imported_files(const String &p_path, Vector<String> &files) const {
if (!p_path.ends_with("/")) {
if (FileAccess::exists(p_path + ".import")) {
files.push_back(p_path);
}
return;
}
DirAccess *da = DirAccess::open(p_path);
da->list_dir_begin();
String n = da->get_next();
while (n != String()) {
if (n != "." && n != ".." && !n.ends_with(".import")) {
String npath = p_path + n + (da->current_is_dir() ? "/" : "");
_get_imported_files(npath, files);
}
n = da->get_next();
}
da->list_dir_end();
}
void FileSystemDock::_update_import_dock() {
if (!import_dock_needs_update)
return;
// List selected.
Vector<String> selected;
if (display_mode == DISPLAY_MODE_TREE_ONLY) {
@ -2444,29 +2464,24 @@ void FileSystemDock::_update_import_dock() {
} else {
// Use the file list.
for (int i = 0; i < files->get_item_count(); i++) {
if (!files->is_selected(i)) {
if (!files->is_selected(i))
continue;
}
selected.push_back(files->get_item_metadata(i));
}
}
// Expand directory selection
Vector<String> efiles;
for (int i = 0; i < selected.size(); i++) {
_get_imported_files(selected[i], efiles);
}
// Check import.
Vector<String> imports;
String import_type;
for (int i = 0; i < selected.size(); i++) {
String fpath = selected[i];
if (fpath.ends_with("/")) {
imports.clear();
break;
}
if (!FileAccess::exists(fpath + ".import")) {
imports.clear();
break;
}
for (int i = 0; i < efiles.size(); i++) {
String fpath = efiles[i];
Ref<ConfigFile> cf;
cf.instance();
Error err = cf->load(fpath + ".import");

View file

@ -195,6 +195,7 @@ private:
void _file_multi_selected(int p_index, bool p_selected);
void _tree_multi_selected(Object *p_item, int p_column, bool p_selected);
void _get_imported_files(const String &p_path, Vector<String> &files) const;
void _update_import_dock();
void _get_all_items_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files, Vector<String> &folders) const;