From ad5bd209baf96d0a7002a50040a4092d544b865f Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Mon, 30 Aug 2021 18:09:22 +0200 Subject: [PATCH] DisplaySettings: Add context menu for wallpapers This adds a 'Show in File Manager' action and copy path action to file context menu for quicker navigation. :^) --- .../BackgroundSettingsWidget.cpp | 19 +++++++++++++++++++ .../BackgroundSettingsWidget.h | 4 ++++ .../DisplaySettings/CMakeLists.txt | 2 +- .../Applications/DisplaySettings/main.cpp | 5 ----- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp index bda2bdbf3e..d60d925690 100644 --- a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp @@ -9,9 +9,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -62,6 +64,23 @@ void BackgroundSettingsWidget::create_frame() m_monitor_widget->set_wallpaper(path); }; + m_context_menu = GUI::Menu::construct(); + m_show_in_file_manager_action = GUI::Action::create("Show in File Manager", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-file-manager.png"), [this](GUI::Action const&) { + LexicalPath path { m_monitor_widget->wallpaper() }; + Desktop::Launcher::open(URL::create_with_file_protocol(path.dirname(), path.basename())); + }); + m_context_menu->add_action(*m_show_in_file_manager_action); + + m_context_menu->add_separator(); + m_copy_action = GUI::CommonActions::make_copy_action([this](auto&) { GUI::Clipboard::the().set_plain_text(m_monitor_widget->wallpaper()); }, this); + m_context_menu->add_action(*m_copy_action); + + m_wallpaper_view->on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) { + if (index.is_valid()) { + m_context_menu->popup(event.screen_position(), m_show_in_file_manager_action); + } + }; + auto& button = *find_descendant_of_type_named("wallpaper_open_button"); button.on_click = [this](auto) { auto path = GUI::FilePicker::get_open_filepath(window(), "Select wallpaper from file system", "/res/wallpapers"); diff --git a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h index b90d6cf21f..fd18bc8424 100644 --- a/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h +++ b/Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace DisplaySettings { @@ -35,6 +36,9 @@ private: RefPtr m_wallpaper_view; RefPtr m_mode_combo; RefPtr m_color_input; + RefPtr m_context_menu; + RefPtr m_show_in_file_manager_action; + RefPtr m_copy_action; }; } diff --git a/Userland/Applications/DisplaySettings/CMakeLists.txt b/Userland/Applications/DisplaySettings/CMakeLists.txt index 2ee90b2fb8..457e70d4be 100644 --- a/Userland/Applications/DisplaySettings/CMakeLists.txt +++ b/Userland/Applications/DisplaySettings/CMakeLists.txt @@ -23,4 +23,4 @@ set(SOURCES ) serenity_app(DisplaySettings ICON app-display-settings) -target_link_libraries(DisplaySettings LibGUI LibConfig) +target_link_libraries(DisplaySettings LibDesktop LibGUI LibConfig) diff --git a/Userland/Applications/DisplaySettings/main.cpp b/Userland/Applications/DisplaySettings/main.cpp index 7b3917d9a4..ea14405669 100644 --- a/Userland/Applications/DisplaySettings/main.cpp +++ b/Userland/Applications/DisplaySettings/main.cpp @@ -31,11 +31,6 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); Config::pledge_domains("WindowManager"); - if (pledge("stdio thread recvfd sendfd rpath cpath wpath", nullptr) < 0) { - perror("pledge"); - return 1; - } - auto app_icon = GUI::Icon::default_icon("app-display-settings"); auto window = GUI::Window::construct();