diff --git a/include/MainWindow.h b/include/MainWindow.h index 5e1f294ae..2c32ad117 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -121,6 +121,7 @@ public slots: void updatePlayPauseIcons(); + void updateUndoRedoButtons(); void undo(); void redo(); @@ -167,6 +168,8 @@ private: } m_keyMods; QMenu * m_toolsMenu; + QAction * m_undoAction; + QAction * m_redoAction; QList m_tools; QBasicTimer m_updateTimer; diff --git a/include/ProjectJournal.h b/include/ProjectJournal.h index 5cb7920f6..28beaa82f 100644 --- a/include/ProjectJournal.h +++ b/include/ProjectJournal.h @@ -45,6 +45,9 @@ public: void undo(); void redo(); + bool canUndo() const; + bool canRedo() const; + void addJournalCheckPoint( JournallingObject *jo ); bool isJournalling() const diff --git a/src/core/ProjectJournal.cpp b/src/core/ProjectJournal.cpp index 77c5c461f..4e5c9229b 100644 --- a/src/core/ProjectJournal.cpp +++ b/src/core/ProjectJournal.cpp @@ -97,6 +97,15 @@ void ProjectJournal::redo() } } +bool ProjectJournal::canUndo() const +{ + return !m_undoCheckPoints.isEmpty(); +} + +bool ProjectJournal::canRedo() const +{ + return !m_redoCheckPoints.isEmpty(); +} diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 961e51d94..d4858e0c3 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -288,11 +288,11 @@ void MainWindow::finalize() QMenu * edit_menu = new QMenu( this ); menuBar()->addMenu( edit_menu )->setText( tr( "&Edit" ) ); - edit_menu->addAction( embed::getIconPixmap( "edit_undo" ), + m_undoAction = edit_menu->addAction( embed::getIconPixmap( "edit_undo" ), tr( "Undo" ), this, SLOT( undo() ), Qt::CTRL + Qt::Key_Z ); - edit_menu->addAction( embed::getIconPixmap( "edit_redo" ), + m_redoAction = edit_menu->addAction( embed::getIconPixmap( "edit_redo" ), tr( "Redo" ), this, SLOT( redo() ), Qt::CTRL + Qt::Key_Y ); @@ -300,6 +300,7 @@ void MainWindow::finalize() edit_menu->addAction( embed::getIconPixmap( "setup_general" ), tr( "Settings" ), this, SLOT( showSettingsDialog() ) ); + connect( edit_menu, SIGNAL(aboutToShow()), this, SLOT(updateUndoRedoButtons()) ); m_viewMenu = new QMenu( this ); menuBar()->addMenu( m_viewMenu )->setText( tr( "&View" ) ); @@ -1182,6 +1183,14 @@ void MainWindow::updatePlayPauseIcons() } +void MainWindow::updateUndoRedoButtons() +{ + // when the edit menu is shown, grey out the undo/redo buttons if there's nothing to undo/redo + // else, un-grey them + m_undoAction->setEnabled(Engine::projectJournal()->canUndo()); + m_redoAction->setEnabled(Engine::projectJournal()->canRedo()); +} + void MainWindow::undo()