summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorKarol Kosek <krkk@krkk.ct8.pl>2021-08-30 18:09:22 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-03 23:15:47 +0200
commitad5bd209baf96d0a7002a50040a4092d544b865f (patch)
treea89459f0e02771830b06bc8e61f49350f79643c2 /Userland
parent77953a937d1e81ccde313b8f55a561683d508725 (diff)
downloadserenity-ad5bd209baf96d0a7002a50040a4092d544b865f.zip
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. :^)
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp19
-rw-r--r--Userland/Applications/DisplaySettings/BackgroundSettingsWidget.h4
-rw-r--r--Userland/Applications/DisplaySettings/CMakeLists.txt2
-rw-r--r--Userland/Applications/DisplaySettings/main.cpp5
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 <AK/StringBuilder.h>
#include <Applications/DisplaySettings/BackgroundSettingsGML.h>
#include <LibCore/ConfigFile.h>
+#include <LibDesktop/Launcher.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
+#include <LibGUI/Clipboard.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/Desktop.h>
#include <LibGUI/FilePicker.h>
@@ -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<GUI::Button>("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 <LibCore/Timer.h>
#include <LibGUI/ColorInput.h>
#include <LibGUI/ComboBox.h>
+#include <LibGUI/Menu.h>
#include <LibGUI/RadioButton.h>
namespace DisplaySettings {
@@ -35,6 +36,9 @@ private:
RefPtr<GUI::IconView> m_wallpaper_view;
RefPtr<GUI::ComboBox> m_mode_combo;
RefPtr<GUI::ColorInput> m_color_input;
+ RefPtr<GUI::Menu> m_context_menu;
+ RefPtr<GUI::Action> m_show_in_file_manager_action;
+ RefPtr<GUI::Action> 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();