diff options
author | Linus Groh <mail@linusgroh.de> | 2021-05-27 18:47:44 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-27 18:47:44 +0100 |
commit | a8d47d648c0a57ade2c81f8cd60340e3a38b6524 (patch) | |
tree | 6df12f169c944e646d598cbb6007000738fa2504 /Userland/Applications | |
parent | dbb0ee07047c44afaf4700eaf3160fa817c51e20 (diff) | |
download | serenity-a8d47d648c0a57ade2c81f8cd60340e3a38b6524.zip |
PDFViewer: Enable previous/next buttons conditionally
Instead of having both always enabled once a document is loaded, update
them on each page change and disable if appropriate.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/PDFViewer/PDFViewerWidget.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index 25235555e0..96addf693c 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -67,14 +67,14 @@ void PDFViewerWidget::create_toolbar() toolbar.add_separator(); m_go_to_prev_page_action = GUI::Action::create("Go to &Previous Page", Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"), [&](auto&) { - if (m_viewer->current_page() > 0) - m_page_text_box->set_current_number(m_viewer->current_page()); + VERIFY(m_viewer->current_page() > 0); + m_page_text_box->set_current_number(m_viewer->current_page()); }); m_go_to_prev_page_action->set_enabled(false); m_go_to_next_page_action = GUI::Action::create("Go to &Next Page", Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [&](auto&) { - if (m_viewer->current_page() < m_viewer->document()->get_page_count() - 1) - m_page_text_box->set_current_number(m_viewer->current_page() + 2); + VERIFY(m_viewer->current_page() < m_viewer->document()->get_page_count() - 1); + m_page_text_box->set_current_number(m_viewer->current_page() + 2); }); m_go_to_next_page_action->set_enabled(false); @@ -87,9 +87,13 @@ void PDFViewerWidget::create_toolbar() m_page_text_box->set_min_number(1); m_page_text_box->on_number_changed = [&](i32 number) { - VERIFY(number >= 1 && static_cast<u32>(number) <= m_viewer->document()->get_page_count()); - m_viewer->set_current_page(static_cast<u32>(number) - 1); + auto page_count = m_viewer->document()->get_page_count(); + auto new_page_number = static_cast<u32>(number); + VERIFY(new_page_number >= 1 && new_page_number <= page_count); + m_viewer->set_current_page(new_page_number - 1); m_viewer->update(); + m_go_to_prev_page_action->set_enabled(new_page_number > 1); + m_go_to_next_page_action->set_enabled(new_page_number < page_count); }; m_total_page_label = toolbar.add<GUI::Label>(); @@ -109,8 +113,8 @@ void PDFViewerWidget::open_file(const String& path) m_page_text_box->set_text(String::number(m_viewer->current_page() + 1)); m_page_text_box->set_enabled(true); m_page_text_box->set_max_number(document->get_page_count()); - m_go_to_prev_page_action->set_enabled(true); - m_go_to_next_page_action->set_enabled(true); + m_go_to_prev_page_action->set_enabled(false); + m_go_to_next_page_action->set_enabled(document->get_page_count() > 1); m_toggle_sidebar_action->set_enabled(true); if (document->outline()) { |