diff --git a/Userland/Applications/Assistant/Providers.h b/Userland/Applications/Assistant/Providers.h index f9aed96648..8acaa756ed 100644 --- a/Userland/Applications/Assistant/Providers.h +++ b/Userland/Applications/Assistant/Providers.h @@ -27,33 +27,33 @@ public: virtual Gfx::Bitmap const* bitmap() const = 0; String const& title() const { return m_title; } - String const& subtitle() const { return m_subtitle; } + String const& tooltip() const { return m_tooltip; } int score() const { return m_score; } bool equals(Result const& other) const { return typeid(this) == typeid(&other) && title() == other.title() - && subtitle() == other.subtitle(); + && tooltip() == other.tooltip(); } protected: - Result(String title, String subtitle, int score = 0) + Result(String title, String tooltip, int score = 0) : m_title(move(title)) - , m_subtitle(move(subtitle)) + , m_tooltip(move(tooltip)) , m_score(score) { } private: String m_title; - String m_subtitle; + String m_tooltip; int m_score { 0 }; }; class AppResult final : public Result { public: - AppResult(RefPtr bitmap, String title, String subtitle, NonnullRefPtr af, int score) - : Result(move(title), move(subtitle), score) + AppResult(RefPtr bitmap, String title, String tooltip, NonnullRefPtr af, int score) + : Result(move(title), move(tooltip), score) , m_app_file(move(af)) , m_bitmap(move(bitmap)) { @@ -71,7 +71,7 @@ private: class CalculatorResult final : public Result { public: explicit CalculatorResult(String title) - : Result(move(title), "'Enter' will copy to clipboard"sv, 100) + : Result(move(title), "Copy to Clipboard"sv, 100) , m_bitmap(GUI::Icon::default_icon("app-calculator"sv).bitmap_for_size(16)) { } @@ -115,7 +115,7 @@ private: class URLResult final : public Result { public: explicit URLResult(const URL& url) - : Result(url.to_string(), "'Enter' will open this URL in the browser"sv, 50) + : Result(url.to_string(), "Open URL in Browser"sv, 50) , m_bitmap(GUI::Icon::default_icon("app-browser"sv).bitmap_for_size(16)) { } diff --git a/Userland/Applications/Assistant/main.cpp b/Userland/Applications/Assistant/main.cpp index 69a4dcfdef..9c6fa48047 100644 --- a/Userland/Applications/Assistant/main.cpp +++ b/Userland/Applications/Assistant/main.cpp @@ -37,89 +37,16 @@ struct AppState { String last_query; }; -class ResultRow final : public GUI::Widget { +class ResultRow final : public GUI::Button { C_OBJECT(ResultRow) -public: - void set_image(RefPtr bitmap) - { - m_image->set_bitmap(bitmap); - } - void set_title(String text) - { - m_title->set_text(move(text)); - } - void set_subtitle(String text) - { - if (text.is_empty()) { - if (m_subtitle) - m_subtitle->remove_from_parent(); - m_subtitle = nullptr; - return; - } - if (!m_subtitle) { - m_subtitle = m_label_container->add(); - m_subtitle->set_text_alignment(Gfx::TextAlignment::CenterLeft); - } - m_subtitle->set_text(move(text)); - } - void set_is_highlighted(bool value) - { - if (m_is_highlighted == value) - return; - - m_is_highlighted = value; - m_title->set_font_weight(value ? 700 : 400); - } - - Function on_selected; - -private: ResultRow() { - auto& layout = set_layout(); - layout.set_spacing(12); - layout.set_margins(4); - - m_image = add(); - - m_label_container = add(); - m_label_container->set_layout(); - m_label_container->set_fixed_height(30); - - m_title = m_label_container->add(); - m_title->set_text_alignment(Gfx::TextAlignment::CenterLeft); - - set_shrink_to_fit(true); - set_fill_with_background_color(true); set_greedy_for_hits(true); + set_fixed_height(36); + set_text_alignment(Gfx::TextAlignment::CenterLeft); + set_button_style(Gfx::ButtonStyle::Coolbar); + set_focus_policy(GUI::FocusPolicy::NoFocus); } - - void mousedown_event(GUI::MouseEvent&) override - { - set_background_role(ColorRole::MenuBase); - } - - void mouseup_event(GUI::MouseEvent&) override - { - set_background_role(ColorRole::NoRole); - on_selected(); - } - - void enter_event(Core::Event&) override - { - set_background_role(ColorRole::HoverHighlight); - } - - void leave_event(Core::Event&) override - { - set_background_role(ColorRole::NoRole); - } - - RefPtr m_image; - RefPtr m_label_container; - RefPtr m_title; - RefPtr m_subtitle; - bool m_is_highlighted { false }; }; class Database { @@ -218,17 +145,16 @@ ErrorOr serenity_main(Main::Arguments arguments) container.set_fill_with_background_color(true); container.set_frame_shape(Gfx::FrameShape::Window); auto& layout = container.set_layout(); - layout.set_margins({ 8, 8, 0 }); + layout.set_margins({ 8 }); auto& text_box = container.add(); auto& results_container = container.add(); auto& results_layout = results_container.set_layout(); - results_layout.set_margins({ 10, 0 }); auto mark_selected_item = [&]() { for (size_t i = 0; i < app_state.visible_result_count; ++i) { auto& row = static_cast(results_container.child_widgets()[i]); - row.set_is_highlighted(i == app_state.selected_index); + row.set_font_weight(i == app_state.selected_index ? 700 : 400); } }; @@ -285,14 +211,15 @@ ErrorOr serenity_main(Main::Arguments arguments) auto update_ui_timer = Core::Timer::create_single_shot(10, [&] { results_container.remove_all_children(); + results_layout.set_margins(app_state.visible_result_count ? GUI::Margins { 4, 0, 0, 0 } : GUI::Margins { 0 }); for (size_t i = 0; i < app_state.visible_result_count; ++i) { auto& result = app_state.results[i]; auto& match = results_container.add(); - match.set_image(result.bitmap()); - match.set_title(result.title()); - match.set_subtitle(result.subtitle()); - match.on_selected = [&result]() { + match.set_icon(result.bitmap()); + match.set_text(move(result.title())); + match.set_tooltip(move(result.tooltip())); + match.on_click = [&result](auto) { result.activate(); GUI::Application::the()->quit(); };