mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
HackStudio: Rename & move DeclarationsModel::Suggestion -> Declaration
This commit is contained in:
parent
28e4e351cb
commit
44033415bc
|
@ -11,22 +11,22 @@
|
|||
|
||||
namespace HackStudio {
|
||||
|
||||
DeclarationsModel::Suggestion DeclarationsModel::Suggestion::create_filename(ByteString const& filename)
|
||||
Declaration Declaration::create_filename(ByteString const& filename)
|
||||
{
|
||||
DeclarationsModel::Suggestion s;
|
||||
Declaration s;
|
||||
s.as_filename = filename;
|
||||
return s;
|
||||
}
|
||||
DeclarationsModel::Suggestion DeclarationsModel::Suggestion::create_symbol_declaration(CodeComprehension::Declaration const& decl)
|
||||
Declaration Declaration::create_symbol_declaration(CodeComprehension::Declaration const& decl)
|
||||
{
|
||||
DeclarationsModel::Suggestion s;
|
||||
Declaration s;
|
||||
s.as_symbol_declaration = decl;
|
||||
return s;
|
||||
}
|
||||
|
||||
GUI::Variant DeclarationsModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const
|
||||
{
|
||||
auto& suggestion = m_suggestions.at(index.row());
|
||||
auto& suggestion = m_declarations.at(index.row());
|
||||
if (role != GUI::ModelRole::Display)
|
||||
return {};
|
||||
|
||||
|
|
|
@ -14,21 +14,21 @@
|
|||
|
||||
namespace HackStudio {
|
||||
|
||||
struct Declaration {
|
||||
static Declaration create_filename(ByteString const& filename);
|
||||
static Declaration create_symbol_declaration(CodeComprehension::Declaration const&);
|
||||
|
||||
bool is_filename() const { return as_filename.has_value(); }
|
||||
bool is_symbol_declaration() const { return as_symbol_declaration.has_value(); }
|
||||
|
||||
Optional<ByteString> as_filename;
|
||||
Optional<CodeComprehension::Declaration> as_symbol_declaration;
|
||||
};
|
||||
|
||||
class DeclarationsModel final : public GUI::Model {
|
||||
public:
|
||||
struct Suggestion {
|
||||
static Suggestion create_filename(ByteString const& filename);
|
||||
static Suggestion create_symbol_declaration(CodeComprehension::Declaration const&);
|
||||
|
||||
bool is_filename() const { return as_filename.has_value(); }
|
||||
bool is_symbol_declaration() const { return as_symbol_declaration.has_value(); }
|
||||
|
||||
Optional<ByteString> as_filename;
|
||||
Optional<CodeComprehension::Declaration> as_symbol_declaration;
|
||||
};
|
||||
|
||||
explicit DeclarationsModel(Vector<Suggestion>&& suggestions)
|
||||
: m_suggestions(move(suggestions))
|
||||
explicit DeclarationsModel(Vector<Declaration>&& declarations)
|
||||
: m_declarations(move(declarations))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -38,14 +38,14 @@ public:
|
|||
Filename,
|
||||
__Column_Count,
|
||||
};
|
||||
virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return m_suggestions.size(); }
|
||||
virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return m_declarations.size(); }
|
||||
virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Column_Count; }
|
||||
virtual GUI::Variant data(GUI::ModelIndex const& index, GUI::ModelRole role) const override;
|
||||
|
||||
Vector<Suggestion> const& suggestions() const { return m_suggestions; }
|
||||
Vector<Declaration> const& declarations() const { return m_declarations; }
|
||||
|
||||
private:
|
||||
Vector<Suggestion> m_suggestions;
|
||||
Vector<Declaration> m_declarations;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ Locator::Locator(Core::EventReceiver* parent)
|
|||
void Locator::open_suggestion(const GUI::ModelIndex& index)
|
||||
{
|
||||
auto& model = reinterpret_cast<DeclarationsModel&>(*m_suggestion_view->model());
|
||||
auto suggestion = model.suggestions()[index.row()];
|
||||
auto suggestion = model.declarations()[index.row()];
|
||||
if (suggestion.is_filename()) {
|
||||
auto filename = suggestion.as_filename.value();
|
||||
open_file(filename);
|
||||
|
@ -112,15 +112,15 @@ void Locator::close()
|
|||
void Locator::update_suggestions()
|
||||
{
|
||||
auto typed_text = m_textbox->text();
|
||||
Vector<DeclarationsModel::Suggestion> suggestions;
|
||||
Vector<Declaration> suggestions;
|
||||
project().for_each_text_file([&](auto& file) {
|
||||
if (file.name().contains(typed_text, CaseSensitivity::CaseInsensitive))
|
||||
suggestions.append(DeclarationsModel::Suggestion::create_filename(file.name()));
|
||||
suggestions.append(Declaration::create_filename(file.name()));
|
||||
});
|
||||
|
||||
ProjectDeclarations::the().for_each_declared_symbol([&suggestions, &typed_text](auto& decl) {
|
||||
if (decl.name.contains(typed_text, CaseSensitivity::CaseInsensitive) || decl.scope.contains(typed_text, CaseSensitivity::CaseInsensitive))
|
||||
suggestions.append((DeclarationsModel::Suggestion::create_symbol_declaration(decl)));
|
||||
suggestions.append((Declaration::create_symbol_declaration(decl)));
|
||||
});
|
||||
|
||||
bool has_suggestions = !suggestions.is_empty();
|
||||
|
|
Loading…
Reference in a new issue