Serenity Operating System

ImageViewer: Add list of recently open files to the File menu :^)

+15 -1
+1 -1
Userland/Applications/ImageViewer/CMakeLists.txt
··· 12 12 ) 13 13 14 14 serenity_app(ImageViewer ICON filetype-image) 15 - target_link_libraries(ImageViewer PRIVATE LibCore LibDesktop LibGUI LibGfx LibImageDecoderClient LibMain) 15 + target_link_libraries(ImageViewer PRIVATE LibCore LibDesktop LibGUI LibGfx LibConfig LibImageDecoderClient LibMain)
+2
Userland/Applications/ImageViewer/ViewWidget.cpp
··· 16 16 #include <LibCore/MappedFile.h> 17 17 #include <LibCore/MimeData.h> 18 18 #include <LibCore/Timer.h> 19 + #include <LibGUI/Application.h> 19 20 #include <LibGUI/MessageBox.h> 20 21 #include <LibGfx/Bitmap.h> 21 22 #include <LibGfx/Orientation.h> ··· 196 197 } 197 198 198 199 m_path = Core::DeprecatedFile::real_path_for(path); 200 + GUI::Application::the()->set_most_recently_open_file(String::from_utf8(path).release_value_but_fixme_should_propagate_errors()); 199 201 reset_view(); 200 202 } 201 203
+12
Userland/Applications/ImageViewer/main.cpp
··· 8 8 #include "MainWidget.h" 9 9 #include "ViewWidget.h" 10 10 #include <AK/URL.h> 11 + #include <LibConfig/Client.h> 11 12 #include <LibCore/ArgsParser.h> 12 13 #include <LibCore/System.h> 13 14 #include <LibDesktop/Launcher.h> ··· 39 40 TRY(Core::System::pledge("stdio recvfd sendfd rpath wpath cpath unix thread")); 40 41 41 42 auto app = TRY(GUI::Application::try_create(arguments)); 43 + 44 + Config::pledge_domain("ImageViewer"); 45 + 46 + app->set_config_domain(TRY(String::from_utf8("ImageViewer"sv))); 42 47 43 48 TRY(Desktop::Launcher::add_allowed_handler_with_any_url("/bin/ImageViewer")); 44 49 TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man1/ImageViewer.md") })); ··· 286 291 TRY(file_menu->try_add_action(open_action)); 287 292 TRY(file_menu->try_add_action(delete_action)); 288 293 TRY(file_menu->try_add_separator()); 294 + 295 + TRY(file_menu->add_recent_files_list([&](auto& action) { 296 + auto path = action.text(); 297 + widget->set_path(path); 298 + widget->load_from_file(path); 299 + })); 300 + 289 301 TRY(file_menu->try_add_action(quit_action)); 290 302 291 303 auto image_menu = TRY(window->try_add_menu("&Image"));