Commit ab2b95dd authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add undo/redo

parent 493bc626
Pipeline #87016 passed with stage
in 24 minutes and 11 seconds
......@@ -20,7 +20,7 @@ HistorySwitchFolderManager::~HistorySwitchFolderManager()
void HistorySwitchFolderManager::addHistory(const Akonadi::Collection &currentCol, const Akonadi::Collection &col)
{
mUndoStack->push(new HistorySwitchFolderCommand(currentCol, col));
mUndoStack->push(new HistorySwitchFolderCommand(this, currentCol, col));
}
void HistorySwitchFolderManager::clear()
......@@ -28,16 +28,36 @@ void HistorySwitchFolderManager::clear()
mUndoStack->clear();
}
HistorySwitchFolderCommand::HistorySwitchFolderCommand(const Akonadi::Collection &currentCol, const Akonadi::Collection &col)
void HistorySwitchFolderManager::changeCollection(const Akonadi::Collection &currentCol)
{
Q_EMIT switchToFolder(currentCol);
}
void HistorySwitchFolderManager::undo()
{
mUndoStack->undo();
}
void HistorySwitchFolderManager::redo()
{
mUndoStack->redo();
}
HistorySwitchFolderCommand::HistorySwitchFolderCommand(HistorySwitchFolderManager *manager,
const Akonadi::Collection &currentCol,
const Akonadi::Collection &col)
: mCurrentCollection(currentCol)
, mNewCollection(col)
, mManager(manager)
{
}
void HistorySwitchFolderCommand::undo()
{
mManager->changeCollection(mCurrentCollection);
}
void HistorySwitchFolderCommand::redo()
{
mManager->changeCollection(mNewCollection);
}
......@@ -10,18 +10,6 @@
#include <QUndoStack>
class QUndoStack;
class HistorySwitchFolderCommand : public QUndoCommand
{
public:
explicit HistorySwitchFolderCommand(const Akonadi::Collection &currentCol, const Akonadi::Collection &col);
void undo() override;
void redo() override;
private:
const Akonadi::Collection mCurrentCollection;
const Akonadi::Collection mNewCollection;
};
class HistorySwitchFolderManager : public QObject
{
......@@ -33,9 +21,28 @@ public:
void clear();
void addHistory(const Akonadi::Collection &currentCol, const Akonadi::Collection &col);
void changeCollection(const Akonadi::Collection &currentCol);
void undo();
void redo();
Q_SIGNALS:
void switchToFolder(const Akonadi::Collection &col);
private:
QUndoStack *const mUndoStack;
};
class HistorySwitchFolderCommand : public QUndoCommand
{
public:
explicit HistorySwitchFolderCommand(HistorySwitchFolderManager *manager, const Akonadi::Collection &currentCol, const Akonadi::Collection &col);
void undo() override;
void redo() override;
private:
const Akonadi::Collection mCurrentCollection;
const Akonadi::Collection mNewCollection;
HistorySwitchFolderManager *const mManager;
};
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