PDFViewer: Add list of recently-opened files

This commit is contained in:
Sam Atkins 2023-04-03 14:30:22 +01:00 committed by Andreas Kling
parent 15532df83d
commit 5c76b63f79
2 changed files with 9 additions and 0 deletions

View file

@ -215,6 +215,12 @@ void PDFViewerWidget::initialize_menubar(GUI::Window& window)
open_file(response.value().filename(), response.value().release_stream());
}));
file_menu.add_separator();
file_menu.add_recent_files_list([&](auto& action) {
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, action.text());
if (!response.is_error())
open_file(response.value().filename(), response.value().release_stream());
})
.release_value_but_fixme_should_propagate_errors();
file_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
}));
@ -407,5 +413,7 @@ PDF::PDFErrorOr<void> PDFViewerWidget::try_open_file(StringView path, NonnullOwn
m_sidebar_open = false;
}
GUI::Application::the()->set_most_recently_open_file(TRY(String::from_utf8(path)));
return {};
}

View file

@ -27,6 +27,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app_icon = GUI::Icon::default_icon("app-pdf-viewer"sv);
Config::pledge_domain("PDFViewer");
app->set_config_domain(TRY("PDFViewer"_string));
auto window = TRY(GUI::Window::try_create());
window->set_title("PDF Viewer");