diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-11-26 10:22:44 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-11-26 18:11:51 +0100 |
commit | bc0d56fa747e95218c4258ead8a52cd0cd3df16d (patch) | |
tree | ed8e08d859b343e5abec731de7d6949ea4f2c671 /Userland/Applications | |
parent | 65c5901e7cfd4114989ff7248fd12e00b53b7bce (diff) | |
download | serenity-bc0d56fa747e95218c4258ead8a52cd0cd3df16d.zip |
Assistant: Add a context menu for search results
Right-clicking now reveals menu options for copying text and
showing results in the File Manager
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/Assistant/main.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Userland/Applications/Assistant/main.cpp b/Userland/Applications/Assistant/main.cpp index 2d3b0c5c90..f51de15a8c 100644 --- a/Userland/Applications/Assistant/main.cpp +++ b/Userland/Applications/Assistant/main.cpp @@ -7,17 +7,21 @@ #include "Providers.h" #include <AK/Error.h> +#include <AK/LexicalPath.h> #include <AK/QuickSort.h> #include <AK/String.h> #include <AK/Try.h> #include <LibCore/LockFile.h> #include <LibCore/System.h> +#include <LibDesktop/Launcher.h> +#include <LibGUI/Action.h> #include <LibGUI/Application.h> #include <LibGUI/BoxLayout.h> #include <LibGUI/Event.h> #include <LibGUI/Icon.h> #include <LibGUI/ImageWidget.h> #include <LibGUI/Label.h> +#include <LibGUI/Menu.h> #include <LibGUI/Painter.h> #include <LibGUI/TextBox.h> #include <LibGfx/Palette.h> @@ -46,7 +50,27 @@ class ResultRow final : public GUI::Button { set_text_alignment(Gfx::TextAlignment::CenterLeft); set_button_style(Gfx::ButtonStyle::Coolbar); set_focus_policy(GUI::FocusPolicy::NoFocus); + + on_context_menu_request = [this](auto& event) { + if (!m_context_menu) { + m_context_menu = GUI::Menu::construct(); + + if (LexicalPath path { text() }; path.is_absolute()) { + m_context_menu->add_action(GUI::Action::create("&Show in File Manager", MUST(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-file-manager.png"sv)), [=](auto&) { + Desktop::Launcher::open(URL::create_with_file_scheme(path.dirname(), path.basename())); + })); + m_context_menu->add_separator(); + } + + m_context_menu->add_action(GUI::Action::create("&Copy as Text", MUST(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"sv)), [&](auto&) { + GUI::Clipboard::the().set_plain_text(text()); + })); + } + m_context_menu->popup(event.screen_position()); + }; } + + RefPtr<GUI::Menu> m_context_menu; }; class Database { |