Commit f4725115 authored by Ludovic Fauvet's avatar Ludovic Fauvet

Disable undo/redo menu items if no action available in the stack

parent 48e382b2
......@@ -111,6 +111,15 @@ MainWindow::MainWindow( QWidget *parent ) :
connect( ProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
this, SLOT( projectUpdated( const QString&, bool ) ) );
// Undo/Redo
connect( UndoStack::getInstance( this ), SIGNAL( canRedoChanged( bool ) ),
this, SLOT( canRedoChanged( bool ) ) );
connect( UndoStack::getInstance( this ), SIGNAL( canUndoChanged( bool ) ),
this, SLOT( canUndoChanged( bool ) ) );
canRedoChanged( UndoStack::getInstance( this )->canRedo() );
canUndoChanged( UndoStack::getInstance( this )->canUndo() );
// Wizard
m_pWizard = new ProjectWizard( this );
m_pWizard->setModal( true );
......@@ -575,6 +584,16 @@ void MainWindow::on_actionImport_triggered()
m_importController->exec();
}
void MainWindow::canUndoChanged( bool canUndo )
{
m_ui.actionUndo->setEnabled( canUndo );
}
void MainWindow::canRedoChanged( bool canRedo )
{
m_ui.actionRedo->setEnabled( canRedo );
}
#ifdef DEBUG_CRASHHANDLER
void MainWindow::setupCrashTester()
{
......
......@@ -109,6 +109,8 @@ private slots:
void toolButtonClicked( int id );
void projectUpdated( const QString& projectName, bool savedStatus );
void keyboardShortcutChanged( const QString&, const QString& );
void canUndoChanged( bool canUndo );
void canRedoChanged( bool canRedo );
signals:
void translateDockWidgetTitle();
......
......@@ -40,6 +40,9 @@ UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent )
connect( ProjectManager::getInstance(), SIGNAL( projectSaved() ),
m_undoStack, SLOT( setClean() ) );
connect( m_undoStack, SIGNAL( canRedoChanged(bool) ), this, SIGNAL( canRedoChanged(bool) ) );
connect( m_undoStack, SIGNAL( canUndoChanged(bool) ), this, SIGNAL( canUndoChanged(bool) ) );
connect( ProjectManager::getInstance(), SIGNAL( projectClosed() ), this, SLOT( clear() ) );
}
......@@ -58,6 +61,16 @@ void UndoStack::endMacro()
m_undoStack->endMacro();
}
bool UndoStack::canUndo()
{
m_undoStack->canUndo();
}
bool UndoStack::canRedo()
{
m_undoStack->canRedo();
}
void UndoStack::clear()
{
m_undoStack->clear();
......
......@@ -40,6 +40,8 @@ class UndoStack : public QUndoView, public QSingleton<UndoStack>
void push( QUndoCommand* command );
void beginMacro( const QString& text );
void endMacro();
bool canUndo();
bool canRedo();
private:
UndoStack( QWidget* parent );
......@@ -53,6 +55,8 @@ class UndoStack : public QUndoView, public QSingleton<UndoStack>
signals:
void cleanChanged( bool val );
void canRedoChanged( bool canRedo );
void canUndoChanged( bool canUndo );
friend class QSingleton<UndoStack>;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment