diff --git a/articleview.cc b/articleview.cc index ce2b9430..8acc1ae8 100644 --- a/articleview.cc +++ b/articleview.cc @@ -790,11 +790,23 @@ void ArticleView::updateMutedContents() } } +bool ArticleView::canGoBack() +{ + // First entry in a history is always an empty page, + // so we skip it. + return ui.definition->history()->currentItemIndex() > 1; +} + +bool ArticleView::canGoForward() +{ + return ui.definition->history()->canGoForward(); +} + void ArticleView::back() { // Don't allow navigating back to page 0, which is usually the initial // empty page - if ( ui.definition->history()->currentItemIndex() > 1 ) + if ( canGoBack() ) { saveHistoryUserData(); ui.definition->back(); diff --git a/articleview.hh b/articleview.hh index 23e9c5dd..76f36dd2 100644 --- a/articleview.hh +++ b/articleview.hh @@ -101,6 +101,9 @@ public: /// The function reloads content if the change affects it. void updateMutedContents(); + bool canGoBack(); + bool canGoForward(); + public slots: /// Goes back in history diff --git a/mainwindow.cc b/mainwindow.cc index cd3ab2ce..b3317eee 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -975,6 +975,8 @@ void MainWindow::iconChanged( ArticleView * view, QIcon const & icon ) void MainWindow::pageLoaded( ArticleView * view ) { + updateBackForwardButtons(); + updatePronounceAvailability(); if ( cfg.preferences.pronounceOnLoadMain ) @@ -985,6 +987,7 @@ void MainWindow::pageLoaded( ArticleView * view ) void MainWindow::tabSwitched( int ) { + updateBackForwardButtons(); updatePronounceAvailability(); updateFoundInDictsList(); } @@ -1065,6 +1068,16 @@ void MainWindow::updateFoundInDictsList() } } +void MainWindow::updateBackForwardButtons() +{ + if ( QWidget * cw = ui.tabWidget->currentWidget() ) + { + ArticleView & view = dynamic_cast< ArticleView & >( *( cw ) ); + navBack->setEnabled(view.canGoBack()); + navForward->setEnabled(view.canGoForward()); + } +} + void MainWindow::updatePronounceAvailability() { bool pronounceEnabled = ui.tabWidget->count() > 0 && @@ -1555,6 +1568,8 @@ void MainWindow::showTranslationFor( QString const & inWord, history.addItem( History::Item( group, inWord.trimmed() ) ); history.save(); + updateBackForwardButtons(); + #if 0 QUrl req; diff --git a/mainwindow.hh b/mainwindow.hh index bfcee33f..b97cdbcf 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -126,6 +126,8 @@ private: void updateFoundInDictsList(); + void updateBackForwardButtons(); + /// Updates word search request and active article view in response to /// muting or unmuting dictionaries, or showing/hiding dictionary bar. void applyMutedDictionariesState();