1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

HackStudio: Keep the DeclarationsModel around, and use a filtering proxy

Rather than construct a new DeclarationsModel each time the user types
something in the Locator, keep a single one around permanently in the
ProjectDeclarations, and then use a FilteringProxyModel over it for the
suggestions.
This commit is contained in:
Sam Atkins 2024-01-25 14:19:15 +00:00 committed by Sam Atkins
parent e72b14ef1d
commit 85101c6626
6 changed files with 78 additions and 22 deletions

View file

@ -57,4 +57,35 @@ GUI::Variant DeclarationsModel::data(GUI::ModelIndex const& index, GUI::ModelRol
return {};
}
GUI::Model::MatchResult DeclarationsModel::data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const
{
if (index.row() < 0 || (size_t)index.row() >= m_declarations.size())
return { TriState::False };
auto needle = term.as_string();
if (needle.is_empty())
return { TriState::True };
auto& declaration = m_declarations[index.row()];
if (declaration.is_filename()) {
if (declaration.as_filename->contains(needle, CaseSensitivity::CaseInsensitive))
return { TriState::True };
return { TriState::False };
}
if (declaration.is_symbol_declaration()) {
if (declaration.as_symbol_declaration->name.contains(needle, CaseSensitivity::CaseInsensitive)
|| declaration.as_symbol_declaration->scope.contains(needle, CaseSensitivity::CaseInsensitive))
return { TriState::True };
return { TriState::False };
}
return { TriState::False };
}
void DeclarationsModel::set_declarations(Vector<HackStudio::Declaration>&& declarations)
{
m_declarations = move(declarations);
did_update();
}
}