You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
Improve path handling in EditorQuickOpenDialog
This commit is contained in:
@@ -1948,6 +1948,16 @@ EditorFileSystemDirectory *EditorFileSystem::find_file(const String &p_file, int
|
|||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResourceUID::ID EditorFileSystem::get_file_uid(const String &p_path) const {
|
||||||
|
int file_idx;
|
||||||
|
EditorFileSystemDirectory *directory = find_file(p_path, &file_idx);
|
||||||
|
|
||||||
|
if (!directory) {
|
||||||
|
return ResourceUID::INVALID_ID;
|
||||||
|
}
|
||||||
|
return directory->files[file_idx]->uid;
|
||||||
|
}
|
||||||
|
|
||||||
EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p_path) {
|
EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p_path) {
|
||||||
if (!filesystem || scanning) {
|
if (!filesystem || scanning) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -401,6 +401,7 @@ public:
|
|||||||
EditorFileSystemDirectory *get_filesystem_path(const String &p_path);
|
EditorFileSystemDirectory *get_filesystem_path(const String &p_path);
|
||||||
String get_file_type(const String &p_file) const;
|
String get_file_type(const String &p_file) const;
|
||||||
EditorFileSystemDirectory *find_file(const String &p_file, int *r_index) const;
|
EditorFileSystemDirectory *find_file(const String &p_file, int *r_index) const;
|
||||||
|
ResourceUID::ID get_file_uid(const String &p_path) const;
|
||||||
|
|
||||||
void reimport_files(const Vector<String> &p_files);
|
void reimport_files(const Vector<String> &p_files);
|
||||||
Error reimport_append(const String &p_file, const HashMap<StringName, Variant> &p_custom_options, const String &p_custom_importer, Variant p_generator_parameters);
|
Error reimport_append(const String &p_file, const HashMap<StringName, Variant> &p_custom_options, const String &p_custom_importer, Variant p_generator_parameters);
|
||||||
|
|||||||
@@ -355,12 +355,17 @@ void QuickOpenResultContainer::init(const Vector<StringName> &p_base_types) {
|
|||||||
QuickOpenResultCandidate *candidates_write = loaded_candidates.ptrw();
|
QuickOpenResultCandidate *candidates_write = loaded_candidates.ptrw();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const String &path : paths) {
|
for (const String &path : paths) {
|
||||||
|
if (!ResourceLoader::exists(path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
filetypes.insert(path, type_name);
|
filetypes.insert(path, type_name);
|
||||||
QuickOpenResultCandidate candidate;
|
QuickOpenResultCandidate candidate;
|
||||||
_setup_candidate(candidate, path);
|
_setup_candidate(candidate, path);
|
||||||
candidates_write[i] = candidate;
|
candidates_write[i] = candidate;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
loaded_candidates.resize(i);
|
||||||
selected_history.insert(type, loaded_candidates);
|
selected_history.insert(type, loaded_candidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,7 +417,12 @@ void QuickOpenResultContainer::set_query_and_update(const String &p_query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QuickOpenResultContainer::_setup_candidate(QuickOpenResultCandidate &p_candidate, const String &p_filepath) {
|
void QuickOpenResultContainer::_setup_candidate(QuickOpenResultCandidate &p_candidate, const String &p_filepath) {
|
||||||
p_candidate.file_path = p_filepath;
|
ResourceUID::ID id = EditorFileSystem::get_singleton()->get_file_uid(p_filepath);
|
||||||
|
if (id == ResourceUID::INVALID_ID) {
|
||||||
|
p_candidate.file_path = p_filepath;
|
||||||
|
} else {
|
||||||
|
p_candidate.file_path = ResourceUID::get_singleton()->id_to_text(id);
|
||||||
|
}
|
||||||
p_candidate.result = nullptr;
|
p_candidate.result = nullptr;
|
||||||
|
|
||||||
StringName actual_type;
|
StringName actual_type;
|
||||||
@@ -717,7 +727,7 @@ bool QuickOpenResultContainer::has_nothing_selected() const {
|
|||||||
|
|
||||||
String QuickOpenResultContainer::get_selected() const {
|
String QuickOpenResultContainer::get_selected() const {
|
||||||
ERR_FAIL_COND_V_MSG(has_nothing_selected(), String(), "Tried to get selected file, but nothing was selected.");
|
ERR_FAIL_COND_V_MSG(has_nothing_selected(), String(), "Tried to get selected file, but nothing was selected.");
|
||||||
return candidates[selection_index].file_path;
|
return ResourceUID::ensure_path(candidates[selection_index].file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
QuickOpenDisplayMode QuickOpenResultContainer::get_adaptive_display_mode(const Vector<StringName> &p_base_types) {
|
QuickOpenDisplayMode QuickOpenResultContainer::get_adaptive_display_mode(const Vector<StringName> &p_base_types) {
|
||||||
@@ -971,8 +981,9 @@ QuickOpenResultListItem::QuickOpenResultListItem() {
|
|||||||
|
|
||||||
void QuickOpenResultListItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
|
void QuickOpenResultListItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
|
||||||
thumbnail->set_texture(p_candidate.thumbnail);
|
thumbnail->set_texture(p_candidate.thumbnail);
|
||||||
name->set_text(p_candidate.file_path.get_file());
|
const String file_path = ResourceUID::ensure_path(p_candidate.file_path);
|
||||||
path->set_text(p_candidate.file_path.get_base_dir());
|
name->set_text(file_path.get_file());
|
||||||
|
path->set_text(file_path.get_base_dir());
|
||||||
name->reset_highlights();
|
name->reset_highlights();
|
||||||
path->reset_highlights();
|
path->reset_highlights();
|
||||||
|
|
||||||
@@ -1042,8 +1053,9 @@ QuickOpenResultGridItem::QuickOpenResultGridItem() {
|
|||||||
|
|
||||||
void QuickOpenResultGridItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
|
void QuickOpenResultGridItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
|
||||||
thumbnail->set_texture(p_candidate.thumbnail);
|
thumbnail->set_texture(p_candidate.thumbnail);
|
||||||
name->set_text(p_candidate.file_path.get_file());
|
const String file_path = ResourceUID::ensure_path(p_candidate.file_path);
|
||||||
name->set_tooltip_text(p_candidate.file_path);
|
name->set_text(file_path.get_file());
|
||||||
|
name->set_tooltip_text(file_path);
|
||||||
name->reset_highlights();
|
name->reset_highlights();
|
||||||
|
|
||||||
if (p_highlight && p_candidate.result != nullptr) {
|
if (p_highlight && p_candidate.result != nullptr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user