Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve path handling in EditorQuickOpenDialog #102678

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,16 @@ EditorFileSystemDirectory *EditorFileSystem::find_file(const String &p_file, int
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) {
if (!filesystem || scanning) {
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ class EditorFileSystem : public Node {
EditorFileSystemDirectory *get_filesystem_path(const String &p_path);
String get_file_type(const String &p_file) 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);
Error reimport_append(const String &p_file, const HashMap<StringName, Variant> &p_custom_options, const String &p_custom_importer, Variant p_generator_parameters);
Expand Down
24 changes: 18 additions & 6 deletions editor/gui/editor_quick_open_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,17 @@ void QuickOpenResultContainer::init(const Vector<StringName> &p_base_types) {
QuickOpenResultCandidate *candidates_write = loaded_candidates.ptrw();
int i = 0;
for (const String &path : paths) {
if (!ResourceLoader::exists(path)) {
continue;
}

filetypes.insert(path, type_name);
QuickOpenResultCandidate candidate;
_setup_candidate(candidate, path);
candidates_write[i] = candidate;
i++;
}
loaded_candidates.resize(i);
selected_history.insert(type, loaded_candidates);
}
}
Expand Down Expand Up @@ -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) {
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;

StringName actual_type;
Expand Down Expand Up @@ -717,7 +727,7 @@ bool QuickOpenResultContainer::has_nothing_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.");
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) {
Expand Down Expand Up @@ -971,8 +981,9 @@ QuickOpenResultListItem::QuickOpenResultListItem() {

void QuickOpenResultListItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
thumbnail->set_texture(p_candidate.thumbnail);
name->set_text(p_candidate.file_path.get_file());
path->set_text(p_candidate.file_path.get_base_dir());
const String file_path = ResourceUID::ensure_path(p_candidate.file_path);
name->set_text(file_path.get_file());
path->set_text(file_path.get_base_dir());
name->reset_highlights();
path->reset_highlights();

Expand Down Expand Up @@ -1042,8 +1053,9 @@ QuickOpenResultGridItem::QuickOpenResultGridItem() {

void QuickOpenResultGridItem::set_content(const QuickOpenResultCandidate &p_candidate, bool p_highlight) {
thumbnail->set_texture(p_candidate.thumbnail);
name->set_text(p_candidate.file_path.get_file());
name->set_tooltip_text(p_candidate.file_path);
const String file_path = ResourceUID::ensure_path(p_candidate.file_path);
name->set_text(file_path.get_file());
name->set_tooltip_text(file_path);
name->reset_highlights();

if (p_highlight && p_candidate.result != nullptr) {
Expand Down