Skip to content

Commit

Permalink
Presenter: Disable "Next" and "Previous" actions when non-applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasChollet authored and awesomekling committed Jan 16, 2023
1 parent 2372b3b commit 07f0873
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Userland/Applications/Presenter/PresenterWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ ErrorOr<void> PresenterWidget::initialize_menubar()
if (m_current_presentation) {
m_current_presentation->next_frame();
update_web_view();
update_slides_actions();
}
});
auto previous_slide_action = GUI::Action::create("&Previous", { KeyCode::Key_Left }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png"sv)), [this](auto&) {
if (m_current_presentation) {
m_current_presentation->previous_frame();
update_web_view();
update_slides_actions();
}
});
TRY(presentation_menu.try_add_action(next_slide_action));
Expand All @@ -103,6 +105,14 @@ void PresenterWidget::update_web_view()
m_web_view->run_javascript(DeprecatedString::formatted("goto({}, {})", m_current_presentation->current_slide_number(), m_current_presentation->current_frame_in_slide_number()));
}

void PresenterWidget::update_slides_actions()
{
if (m_current_presentation) {
m_next_slide_action->set_enabled(m_current_presentation->has_a_next_frame());
m_previous_slide_action->set_enabled(m_current_presentation->has_a_previous_frame());
}
}

void PresenterWidget::set_file(StringView file_name)
{
auto presentation = Presentation::load_from_file(file_name);
Expand All @@ -113,6 +123,7 @@ void PresenterWidget::set_file(StringView file_name)
window()->set_title(DeprecatedString::formatted(title_template, m_current_presentation->title(), m_current_presentation->author()));
set_min_size(m_current_presentation->normative_size());
m_web_view->load_html(MUST(m_current_presentation->render()), "presenter:https://slide.html"sv);
update_slides_actions();
}
}

Expand Down
1 change: 1 addition & 0 deletions Userland/Applications/Presenter/PresenterWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PresenterWidget : public GUI::Widget {

private:
void update_web_view();
void update_slides_actions();

RefPtr<WebView::OutOfProcessWebView> m_web_view;

Expand Down

0 comments on commit 07f0873

Please sign in to comment.