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. :^)
This commit is contained in:
Karol Kosek 2021-08-30 18:09:22 +02:00 committed by Andreas Kling
parent 77953a937d
commit ad5bd209ba
Notes: sideshowbarker 2024-07-19 17:15:55 +09:00
4 changed files with 24 additions and 6 deletions

View file

@ -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");

View file

@ -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;
};
}

View file

@ -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)

View file

@ -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();