summaryrefslogtreecommitdiff
path: root/Userland/Applications/Assistant
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-03-06 14:17:01 +0100
committerAndreas Kling <kling@serenityos.org>2023-03-06 23:46:35 +0100
commit8a48246ed1a93983668a25f5b9b0af0e745e3f04 (patch)
treedd98425d119f79e0160bf19951f96a4a30276cbb /Userland/Applications/Assistant
parent104be6c8ace8d56f66a89b570cdd615e74d22aa8 (diff)
downloadserenity-8a48246ed1a93983668a25f5b9b0af0e745e3f04.zip
Everywhere: Stop using NonnullRefPtrVector
This class had slightly confusing semantics and the added weirdness doesn't seem worth it just so we can say "." instead of "->" when iterating over a vector of NNRPs. This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
Diffstat (limited to 'Userland/Applications/Assistant')
-rw-r--r--Userland/Applications/Assistant/Providers.cpp24
-rw-r--r--Userland/Applications/Assistant/Providers.h14
-rw-r--r--Userland/Applications/Assistant/main.cpp18
3 files changed, 28 insertions, 28 deletions
diff --git a/Userland/Applications/Assistant/Providers.cpp b/Userland/Applications/Assistant/Providers.cpp
index 89b740857e..1a0c034bca 100644
--- a/Userland/Applications/Assistant/Providers.cpp
+++ b/Userland/Applications/Assistant/Providers.cpp
@@ -61,12 +61,12 @@ void URLResult::activate() const
Desktop::Launcher::open(URL::create_with_url_or_path(title()));
}
-void AppProvider::query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
+void AppProvider::query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
{
if (query.starts_with('=') || query.starts_with('$'))
return;
- NonnullRefPtrVector<Result> results;
+ Vector<NonnullRefPtr<Result>> results;
Desktop::AppFile::for_each([&](NonnullRefPtr<Desktop::AppFile> app_file) {
auto query_and_arguments = query.split_limit(' ', 2);
@@ -83,7 +83,7 @@ void AppProvider::query(DeprecatedString const& query, Function<void(NonnullRefP
on_complete(move(results));
}
-void CalculatorProvider::query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
+void CalculatorProvider::query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
{
if (!query.starts_with('='))
return;
@@ -108,7 +108,7 @@ void CalculatorProvider::query(DeprecatedString const& query, Function<void(Nonn
calculation = result.to_string_without_side_effects().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
}
- NonnullRefPtrVector<Result> results;
+ Vector<NonnullRefPtr<Result>> results;
results.append(adopt_ref(*new CalculatorResult(calculation)));
on_complete(move(results));
}
@@ -123,16 +123,16 @@ FileProvider::FileProvider()
build_filesystem_cache();
}
-void FileProvider::query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
+void FileProvider::query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
{
build_filesystem_cache();
if (m_fuzzy_match_work)
m_fuzzy_match_work->cancel();
- m_fuzzy_match_work = Threading::BackgroundAction<Optional<NonnullRefPtrVector<Result>>>::construct(
- [this, query](auto& task) -> Optional<NonnullRefPtrVector<Result>> {
- NonnullRefPtrVector<Result> results;
+ m_fuzzy_match_work = Threading::BackgroundAction<Optional<Vector<NonnullRefPtr<Result>>>>::construct(
+ [this, query](auto& task) -> Optional<Vector<NonnullRefPtr<Result>>> {
+ Vector<NonnullRefPtr<Result>> results;
for (auto& path : m_full_path_cache) {
if (task.is_cancelled())
@@ -203,19 +203,19 @@ void FileProvider::build_filesystem_cache()
});
}
-void TerminalProvider::query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
+void TerminalProvider::query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
{
if (!query.starts_with('$'))
return;
auto command = query.substring(1).trim_whitespace();
- NonnullRefPtrVector<Result> results;
+ Vector<NonnullRefPtr<Result>> results;
results.append(adopt_ref(*new TerminalResult(move(command))));
on_complete(move(results));
}
-void URLProvider::query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
+void URLProvider::query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete)
{
if (query.is_empty() || query.starts_with('=') || query.starts_with('$'))
return;
@@ -232,7 +232,7 @@ void URLProvider::query(DeprecatedString const& query, Function<void(NonnullRefP
if (!url.is_valid())
return;
- NonnullRefPtrVector<Result> results;
+ Vector<NonnullRefPtr<Result>> results;
results.append(adopt_ref(*new URLResult(url)));
on_complete(results);
}
diff --git a/Userland/Applications/Assistant/Providers.h b/Userland/Applications/Assistant/Providers.h
index cef555dceb..3d1daba6c2 100644
--- a/Userland/Applications/Assistant/Providers.h
+++ b/Userland/Applications/Assistant/Providers.h
@@ -134,28 +134,28 @@ class Provider : public RefCounted<Provider> {
public:
virtual ~Provider() = default;
- virtual void query(DeprecatedString const&, Function<void(NonnullRefPtrVector<Result>)> on_complete) = 0;
+ virtual void query(DeprecatedString const&, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) = 0;
};
class AppProvider final : public Provider {
public:
- void query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete) override;
+ void query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
};
class CalculatorProvider final : public Provider {
public:
- void query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete) override;
+ void query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
};
class FileProvider final : public Provider {
public:
FileProvider();
- void query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete) override;
+ void query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
void build_filesystem_cache();
private:
- RefPtr<Threading::BackgroundAction<Optional<NonnullRefPtrVector<Result>>>> m_fuzzy_match_work;
+ RefPtr<Threading::BackgroundAction<Optional<Vector<NonnullRefPtr<Result>>>>> m_fuzzy_match_work;
bool m_building_cache { false };
Vector<DeprecatedString> m_full_path_cache;
Queue<DeprecatedString> m_work_queue;
@@ -163,12 +163,12 @@ private:
class TerminalProvider final : public Provider {
public:
- void query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete) override;
+ void query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
};
class URLProvider final : public Provider {
public:
- void query(DeprecatedString const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete) override;
+ void query(DeprecatedString const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
};
}
diff --git a/Userland/Applications/Assistant/main.cpp b/Userland/Applications/Assistant/main.cpp
index 83a928c9c5..04129cfbcb 100644
--- a/Userland/Applications/Assistant/main.cpp
+++ b/Userland/Applications/Assistant/main.cpp
@@ -36,7 +36,7 @@ namespace Assistant {
struct AppState {
Optional<size_t> selected_index;
- NonnullRefPtrVector<Result const> results;
+ Vector<NonnullRefPtr<Result const>> results;
size_t visible_result_count { 0 };
Threading::Mutex lock;
@@ -84,7 +84,7 @@ public:
{
}
- Function<void(NonnullRefPtrVector<Result const>)> on_new_results;
+ Function<void(Vector<NonnullRefPtr<Result const>>)> on_new_results;
void search(DeprecatedString const& query)
{
@@ -98,7 +98,7 @@ public:
auto& result_array = m_result_cache.ensure(query);
if (result_array.at(i) != nullptr)
return;
- result_array[i] = make<NonnullRefPtrVector<Result>>(results);
+ result_array[i] = make<Vector<NonnullRefPtr<Result>>>(results);
}
on_result_cache_updated();
});
@@ -142,7 +142,7 @@ private:
Array<NonnullRefPtr<Provider>, ProviderCount> m_providers;
Threading::Mutex m_mutex;
- HashMap<DeprecatedString, Array<OwnPtr<NonnullRefPtrVector<Result>>, ProviderCount>> m_result_cache;
+ HashMap<DeprecatedString, Array<OwnPtr<Vector<NonnullRefPtr<Result>>>, ProviderCount>> m_result_cache;
};
}
@@ -211,7 +211,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!app_state.selected_index.has_value())
return;
lockfile.release();
- app_state.results[app_state.selected_index.value()].activate();
+ app_state.results[app_state.selected_index.value()]->activate();
GUI::Application::the()->quit();
};
text_box.on_up_pressed = [&]() {
@@ -254,11 +254,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
for (size_t i = 0; i < app_state.visible_result_count; ++i) {
auto& result = app_state.results[i];
auto& match = results_container.add<Assistant::ResultRow>();
- match.set_icon(result.bitmap());
- match.set_text(String::from_deprecated_string(result.title()).release_value_but_fixme_should_propagate_errors());
- match.set_tooltip(move(result.tooltip()));
+ match.set_icon(result->bitmap());
+ match.set_text(String::from_deprecated_string(result->title()).release_value_but_fixme_should_propagate_errors());
+ match.set_tooltip(move(result->tooltip()));
match.on_click = [&result](auto) {
- result.activate();
+ result->activate();
GUI::Application::the()->quit();
};
}