diff options
author | Tim Ledbetter <timledbetter@gmail.com> | 2023-01-20 21:58:37 +0000 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-02-11 19:32:24 +0000 |
commit | d910dd345e090012db3dcc1f02ab140432c334b8 (patch) | |
tree | 86afd13673b192d06b6df5536ddb74011fed9c90 | |
parent | 3b446fba34189b2b989a59e8caea6701930609db (diff) | |
download | serenity-d910dd345e090012db3dcc1f02ab140432c334b8.zip |
Assistant: Allow arguments in AppProvider queries
-rw-r--r-- | Userland/Applications/Assistant/Providers.cpp | 10 | ||||
-rw-r--r-- | Userland/Applications/Assistant/Providers.h | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/Userland/Applications/Assistant/Providers.cpp b/Userland/Applications/Assistant/Providers.cpp index e2382697b6..bfdcb66d8a 100644 --- a/Userland/Applications/Assistant/Providers.cpp +++ b/Userland/Applications/Assistant/Providers.cpp @@ -34,7 +34,8 @@ void AppResult::activate() const exit(1); } - m_app_file->spawn(); + auto arguments_list = m_arguments.split_view(' '); + m_app_file->spawn(arguments_list.span()); } void CalculatorResult::activate() const @@ -68,12 +69,15 @@ void AppProvider::query(DeprecatedString const& query, Function<void(NonnullRefP NonnullRefPtrVector<Result> results; Desktop::AppFile::for_each([&](NonnullRefPtr<Desktop::AppFile> app_file) { - auto match_result = fuzzy_match(query, app_file->name()); + auto query_and_arguments = query.split_limit(' ', 2); + auto app_name = query_and_arguments.is_empty() ? query : query_and_arguments[0]; + auto arguments = query_and_arguments.size() < 2 ? DeprecatedString::empty() : query_and_arguments[1]; + auto match_result = fuzzy_match(app_name, app_file->name()); if (!match_result.matched) 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, arguments, match_result.score))); }); on_complete(move(results)); diff --git a/Userland/Applications/Assistant/Providers.h b/Userland/Applications/Assistant/Providers.h index 4e44d4169b..3444a5e801 100644 --- a/Userland/Applications/Assistant/Providers.h +++ b/Userland/Applications/Assistant/Providers.h @@ -52,9 +52,10 @@ private: class AppResult final : public Result { public: - AppResult(RefPtr<Gfx::Bitmap> bitmap, DeprecatedString title, DeprecatedString tooltip, NonnullRefPtr<Desktop::AppFile> af, int score) + AppResult(RefPtr<Gfx::Bitmap> bitmap, DeprecatedString title, DeprecatedString tooltip, NonnullRefPtr<Desktop::AppFile> af, DeprecatedString arguments, int score) : Result(move(title), move(tooltip), score) , m_app_file(move(af)) + , m_arguments(move(arguments)) , m_bitmap(move(bitmap)) { } @@ -65,6 +66,7 @@ public: private: NonnullRefPtr<Desktop::AppFile> m_app_file; + DeprecatedString m_arguments; RefPtr<Gfx::Bitmap> m_bitmap; }; |