mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
Assistant: Add subtitle field to the Result class
This allows providers to specify an appropriate subtitle instead of making that something the UI layer has to figure out. :^)
This commit is contained in:
parent
ed2bf0a753
commit
3ecd1d603f
3 changed files with 12 additions and 10 deletions
|
@ -38,7 +38,7 @@ void AppProvider::query(String const& query, Function<void(Vector<NonnullRefPtr<
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto icon = GUI::FileIconProvider::icon_for_executable(app_file->executable());
|
auto icon = GUI::FileIconProvider::icon_for_executable(app_file->executable());
|
||||||
results.append(adopt_ref(*new AppResult(icon.bitmap_for_size(16), app_file->name(), app_file, match_result.score)));
|
results.append(adopt_ref(*new AppResult(icon.bitmap_for_size(16), app_file->name(), {}, app_file, match_result.score)));
|
||||||
});
|
});
|
||||||
|
|
||||||
on_complete(results);
|
on_complete(results);
|
||||||
|
|
|
@ -28,17 +28,21 @@ public:
|
||||||
|
|
||||||
RefPtr<Gfx::Bitmap> bitmap() { return m_bitmap; }
|
RefPtr<Gfx::Bitmap> bitmap() { return m_bitmap; }
|
||||||
String const& title() const { return m_title; }
|
String const& title() const { return m_title; }
|
||||||
|
String const& subtitle() const { return m_subtitle; }
|
||||||
Kind kind() const { return m_kind; }
|
Kind kind() const { return m_kind; }
|
||||||
int score() const { return m_score; }
|
int score() const { return m_score; }
|
||||||
bool equals(Result const& other) const
|
bool equals(Result const& other) const
|
||||||
{
|
{
|
||||||
return title() == other.title() && kind() == other.kind();
|
return kind() == other.kind()
|
||||||
|
&& title() == other.title()
|
||||||
|
&& subtitle() == other.subtitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Result(RefPtr<Gfx::Bitmap> bitmap, String title, int score = 0, Kind kind = Kind::Unknown)
|
Result(RefPtr<Gfx::Bitmap> bitmap, String title, String subtitle, int score = 0, Kind kind = Kind::Unknown)
|
||||||
: m_bitmap(move(bitmap))
|
: m_bitmap(move(bitmap))
|
||||||
, m_title(move(title))
|
, m_title(move(title))
|
||||||
|
, m_subtitle(move(subtitle))
|
||||||
, m_score(score)
|
, m_score(score)
|
||||||
, m_kind(kind)
|
, m_kind(kind)
|
||||||
{
|
{
|
||||||
|
@ -47,14 +51,15 @@ protected:
|
||||||
private:
|
private:
|
||||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||||
String m_title;
|
String m_title;
|
||||||
|
String m_subtitle;
|
||||||
int m_score { 0 };
|
int m_score { 0 };
|
||||||
Kind m_kind;
|
Kind m_kind;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AppResult : public Result {
|
class AppResult : public Result {
|
||||||
public:
|
public:
|
||||||
AppResult(RefPtr<Gfx::Bitmap> bitmap, String title, NonnullRefPtr<Desktop::AppFile> af, int score)
|
AppResult(RefPtr<Gfx::Bitmap> bitmap, String title, String subtitle, NonnullRefPtr<Desktop::AppFile> af, int score)
|
||||||
: Result(move(bitmap), move(title), score, Kind::App)
|
: Result(move(bitmap), move(title), move(subtitle), score, Kind::App)
|
||||||
, m_app_file(move(af))
|
, m_app_file(move(af))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -68,7 +73,7 @@ private:
|
||||||
class CalculatorResult : public Result {
|
class CalculatorResult : public Result {
|
||||||
public:
|
public:
|
||||||
explicit CalculatorResult(String title)
|
explicit CalculatorResult(String title)
|
||||||
: Result(GUI::Icon::default_icon("app-calculator").bitmap_for_size(16), move(title), 100, Kind::Calculator)
|
: Result(GUI::Icon::default_icon("app-calculator").bitmap_for_size(16), move(title), "'Enter' will copy to clipboard"sv, 100, Kind::Calculator)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~CalculatorResult() override = default;
|
~CalculatorResult() override = default;
|
||||||
|
|
|
@ -266,14 +266,11 @@ int main(int argc, char** argv)
|
||||||
auto& match = results_container.add<Assistant::ResultRow>();
|
auto& match = results_container.add<Assistant::ResultRow>();
|
||||||
match.set_image(result->bitmap());
|
match.set_image(result->bitmap());
|
||||||
match.set_title(result->title());
|
match.set_title(result->title());
|
||||||
|
match.set_subtitle(result->subtitle());
|
||||||
match.on_selected = [result_copy = result]() {
|
match.on_selected = [result_copy = result]() {
|
||||||
result_copy->activate();
|
result_copy->activate();
|
||||||
exit(0);
|
exit(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (result->kind() == Assistant::Result::Kind::Calculator) {
|
|
||||||
match.set_subtitle("'Enter' will copy to clipboard");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mark_selected_item();
|
mark_selected_item();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue