mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:07:44 +00:00
Assistant: Add a new FileProvider to assist in searching the filesystem
When searching in Assistant, we now dispatch some background jobs to query the whole filesystem. Activating a result will use the Desktop launcher's default way of opening that file or directory.
This commit is contained in:
parent
00f93b2545
commit
e6f0b2d817
3 changed files with 100 additions and 1 deletions
|
@ -6,11 +6,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Queue.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibDesktop/AppFile.h>
|
||||
#include <LibGUI/Desktop.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibThreading/BackgroundAction.h>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace Assistant {
|
||||
|
@ -72,6 +74,16 @@ public:
|
|||
void activate() const override;
|
||||
};
|
||||
|
||||
class FileResult : public Result {
|
||||
public:
|
||||
explicit FileResult(String title, int score)
|
||||
: Result(GUI::Icon::default_icon("filetype-folder").bitmap_for_size(16), move(title), "", score)
|
||||
{
|
||||
}
|
||||
~FileResult() override = default;
|
||||
void activate() const override;
|
||||
};
|
||||
|
||||
class Provider {
|
||||
public:
|
||||
virtual ~Provider() = default;
|
||||
|
@ -89,4 +101,16 @@ public:
|
|||
void query(String const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
|
||||
};
|
||||
|
||||
class FileProvider : public Provider {
|
||||
public:
|
||||
void query(String const& query, Function<void(Vector<NonnullRefPtr<Result>>)> on_complete) override;
|
||||
void build_filesystem_cache();
|
||||
|
||||
private:
|
||||
RefPtr<Threading::BackgroundAction<Vector<NonnullRefPtr<Result>>>> m_fuzzy_match_work;
|
||||
bool m_building_cache { false };
|
||||
Vector<String> m_full_path_cache;
|
||||
Queue<String> m_work_queue;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue