mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +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
Notes:
sideshowbarker
2024-07-18 11:21:08 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3ecd1d603fb
3 changed files with 12 additions and 10 deletions
|
@ -38,7 +38,7 @@ void AppProvider::query(String const& query, Function<void(Vector<NonnullRefPtr<
|
|||
return;
|
||||
|
||||
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);
|
||||
|
|
|
@ -28,17 +28,21 @@ public:
|
|||
|
||||
RefPtr<Gfx::Bitmap> bitmap() { return m_bitmap; }
|
||||
String const& title() const { return m_title; }
|
||||
String const& subtitle() const { return m_subtitle; }
|
||||
Kind kind() const { return m_kind; }
|
||||
int score() const { return m_score; }
|
||||
bool equals(Result const& other) const
|
||||
{
|
||||
return title() == other.title() && kind() == other.kind();
|
||||
return kind() == other.kind()
|
||||
&& title() == other.title()
|
||||
&& subtitle() == other.subtitle();
|
||||
}
|
||||
|
||||
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_title(move(title))
|
||||
, m_subtitle(move(subtitle))
|
||||
, m_score(score)
|
||||
, m_kind(kind)
|
||||
{
|
||||
|
@ -47,14 +51,15 @@ protected:
|
|||
private:
|
||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||
String m_title;
|
||||
String m_subtitle;
|
||||
int m_score { 0 };
|
||||
Kind m_kind;
|
||||
};
|
||||
|
||||
class AppResult : public Result {
|
||||
public:
|
||||
AppResult(RefPtr<Gfx::Bitmap> bitmap, String title, NonnullRefPtr<Desktop::AppFile> af, int score)
|
||||
: Result(move(bitmap), move(title), score, Kind::App)
|
||||
AppResult(RefPtr<Gfx::Bitmap> bitmap, String title, String subtitle, NonnullRefPtr<Desktop::AppFile> af, int score)
|
||||
: Result(move(bitmap), move(title), move(subtitle), score, Kind::App)
|
||||
, m_app_file(move(af))
|
||||
{
|
||||
}
|
||||
|
@ -68,7 +73,7 @@ private:
|
|||
class CalculatorResult : public Result {
|
||||
public:
|
||||
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;
|
||||
|
|
|
@ -266,14 +266,11 @@ int main(int argc, char** argv)
|
|||
auto& match = results_container.add<Assistant::ResultRow>();
|
||||
match.set_image(result->bitmap());
|
||||
match.set_title(result->title());
|
||||
match.set_subtitle(result->subtitle());
|
||||
match.on_selected = [result_copy = result]() {
|
||||
result_copy->activate();
|
||||
exit(0);
|
||||
};
|
||||
|
||||
if (result->kind() == Assistant::Result::Kind::Calculator) {
|
||||
match.set_subtitle("'Enter' will copy to clipboard");
|
||||
}
|
||||
}
|
||||
|
||||
mark_selected_item();
|
||||
|
|
Loading…
Reference in a new issue