diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 97294179e66..9475b0108c9 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -61,6 +61,7 @@ static void do_copy(Vector const& selected_file_paths, FileOperation fil static void do_paste(String const& target_directory, GUI::Window* window); static void do_create_link(Vector const& selected_file_paths, GUI::Window* window); static void do_create_archive(Vector const& selected_file_paths, GUI::Window* window); +static void do_set_wallpaper(String const& file_path, GUI::Window* window); static void do_unzip_archive(Vector const& selected_file_paths, GUI::Window* window); static void show_properties(String const& container_dir_path, String const& path, Vector const& selected, GUI::Window* window); static bool add_launch_handler_actions_to_menu(RefPtr& menu, DirectoryView const& directory_view, String const& full_path, RefPtr& default_action, NonnullRefPtrVector& current_file_launch_handlers); @@ -243,6 +244,22 @@ void do_create_archive(Vector const& selected_file_paths, GUI::Window* w } } +void do_set_wallpaper(String const& file_path, GUI::Window* window) +{ + auto show_error = [&] { + GUI::MessageBox::show(window, String::formatted("Failed to set {} as wallpaper.", file_path), "Failed to set wallpaper"sv, GUI::MessageBox::Type::Error); + }; + + auto bitmap_or_error = Gfx::Bitmap::try_load_from_file(file_path); + if (bitmap_or_error.is_error()) { + show_error(); + return; + } + + if (!GUI::Desktop::the().set_wallpaper(bitmap_or_error.release_value(), file_path)) + show_error(); +} + void do_unzip_archive(Vector const& selected_file_paths, GUI::Window* window) { String archive_file_path = selected_file_paths.first(); @@ -384,6 +401,19 @@ ErrorOr run_in_desktop_mode() }, window); + auto set_wallpaper_action + = GUI::Action::create( + "Set as Desktop &Wallpaper", + Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-display-settings.png"sv).release_value_but_fixme_should_propagate_errors(), + [&](GUI::Action const&) { + auto paths = directory_view->selected_file_paths(); + if (paths.is_empty()) + return; + + do_set_wallpaper(paths.first(), directory_view->window()); + }, + window); + directory_view->on_selection_change = [&](GUI::AbstractView const& view) { cut_action->set_enabled(!view.selection().is_empty()); copy_action->set_enabled(!view.selection().is_empty()); @@ -488,6 +518,11 @@ ErrorOr run_in_desktop_mode() file_context_menu->add_action(create_archive_action); file_context_menu->add_separator(); + if (Gfx::Bitmap::is_path_a_supported_image_format(node.name)) { + file_context_menu->add_action(set_wallpaper_action); + file_context_menu->add_separator(); + } + if (node.full_path().ends_with(".zip"sv, AK::CaseSensitivity::CaseInsensitive)) { file_context_menu->add_action(unzip_archive_action); file_context_menu->add_separator(); @@ -825,6 +860,19 @@ ErrorOr run_in_windowed_mode(String const& initial_location, String const& }, window); + auto set_wallpaper_action + = GUI::Action::create( + "Set as Desktop &Wallpaper", + Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-display-settings.png"sv).release_value_but_fixme_should_propagate_errors(), + [&](GUI::Action const&) { + auto paths = directory_view->selected_file_paths(); + if (paths.is_empty()) + return; + + do_set_wallpaper(paths.first(), directory_view->window()); + }, + window); + auto properties_action = GUI::CommonActions::make_properties_action( [&](auto& action) { String container_dir_path; @@ -1180,6 +1228,11 @@ ErrorOr run_in_windowed_mode(String const& initial_location, String const& file_context_menu->add_action(create_archive_action); file_context_menu->add_separator(); + if (Gfx::Bitmap::is_path_a_supported_image_format(node.name)) { + file_context_menu->add_action(set_wallpaper_action); + file_context_menu->add_separator(); + } + if (node.full_path().ends_with(".zip"sv, AK::CaseSensitivity::CaseInsensitive)) { file_context_menu->add_action(unzip_archive_action); file_context_menu->add_separator();