From 000c74e6a8171e7d477b9226a1e3e5da2fd8a1c5 Mon Sep 17 00:00:00 2001 From: Dawid Wolosowicz Date: Fri, 3 Sep 2021 21:30:45 +0200 Subject: [PATCH] SystemMonitor: Make the process list searchable --- .../SystemMonitor/ProcessModel.cpp | 18 ++++++++++++++++++ .../Applications/SystemMonitor/ProcessModel.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/Userland/Applications/SystemMonitor/ProcessModel.cpp b/Userland/Applications/SystemMonitor/ProcessModel.cpp index b421e94c02..cdefa57338 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.cpp +++ b/Userland/Applications/SystemMonitor/ProcessModel.cpp @@ -313,6 +313,24 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol return {}; } +Vector ProcessModel::matches(const StringView& searching, unsigned flags, const GUI::ModelIndex&) +{ + Vector found_indices; + + for (auto& thread : m_threads) { + if (string_matches(thread.value->current_state.name, searching, flags)) { + auto maybe_tid_index = m_tids.find_first_index(thread.key); + if (!maybe_tid_index.has_value()) + continue; + found_indices.append(create_index(maybe_tid_index.value(), Column::Name)); + if (flags & FirstMatchOnly) + break; + } + } + + return found_indices; +} + void ProcessModel::update() { auto previous_tid_count = m_tids.size(); diff --git a/Userland/Applications/SystemMonitor/ProcessModel.h b/Userland/Applications/SystemMonitor/ProcessModel.h index f6a77c4106..548b8942aa 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.h +++ b/Userland/Applications/SystemMonitor/ProcessModel.h @@ -60,6 +60,8 @@ public: virtual int column_count(const GUI::ModelIndex&) const override; virtual String column_name(int column) const override; virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override; + virtual bool is_searchable() const override { return true; } + virtual Vector matches(const StringView&, unsigned = MatchesFlag::AllMatching, const GUI::ModelIndex& = GUI::ModelIndex()) override; virtual bool is_column_sortable(int column_index) const override { return column_index != Column::Icon; } void update();