Enable/disable Back and Forward buttons depending on the history.

This is a standard behavior for any history-enabled app
(like web browser). When there is no previous or next item
in the history, the appropriate button on the toolbar
is disabled.
This commit is contained in:
Tvangeste 2011-06-07 13:27:19 +02:00
parent 0712d8fd96
commit 6f192dca6e
4 changed files with 33 additions and 1 deletions

View file

@ -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();

View file

@ -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

View file

@ -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;

View file

@ -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();