mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
HackStudio: Rename & move DeclarationsModel::Suggestion -> Declaration
This commit is contained in:
parent
28e4e351cb
commit
44033415bc
3 changed files with 25 additions and 25 deletions
|
@ -11,22 +11,22 @@
|
||||||
|
|
||||||
namespace HackStudio {
|
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;
|
s.as_filename = filename;
|
||||||
return s;
|
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;
|
s.as_symbol_declaration = decl;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI::Variant DeclarationsModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const
|
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)
|
if (role != GUI::ModelRole::Display)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
|
@ -14,21 +14,21 @@
|
||||||
|
|
||||||
namespace HackStudio {
|
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 {
|
class DeclarationsModel final : public GUI::Model {
|
||||||
public:
|
public:
|
||||||
struct Suggestion {
|
explicit DeclarationsModel(Vector<Declaration>&& declarations)
|
||||||
static Suggestion create_filename(ByteString const& filename);
|
: m_declarations(move(declarations))
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,14 +38,14 @@ public:
|
||||||
Filename,
|
Filename,
|
||||||
__Column_Count,
|
__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 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;
|
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:
|
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)
|
void Locator::open_suggestion(const GUI::ModelIndex& index)
|
||||||
{
|
{
|
||||||
auto& model = reinterpret_cast<DeclarationsModel&>(*m_suggestion_view->model());
|
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()) {
|
if (suggestion.is_filename()) {
|
||||||
auto filename = suggestion.as_filename.value();
|
auto filename = suggestion.as_filename.value();
|
||||||
open_file(filename);
|
open_file(filename);
|
||||||
|
@ -112,15 +112,15 @@ void Locator::close()
|
||||||
void Locator::update_suggestions()
|
void Locator::update_suggestions()
|
||||||
{
|
{
|
||||||
auto typed_text = m_textbox->text();
|
auto typed_text = m_textbox->text();
|
||||||
Vector<DeclarationsModel::Suggestion> suggestions;
|
Vector<Declaration> suggestions;
|
||||||
project().for_each_text_file([&](auto& file) {
|
project().for_each_text_file([&](auto& file) {
|
||||||
if (file.name().contains(typed_text, CaseSensitivity::CaseInsensitive))
|
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) {
|
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))
|
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();
|
bool has_suggestions = !suggestions.is_empty();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue