logic: rewrote messages handling token activation for correct restoring on undo

* saving search query to undo stack with MessageSearch
* saving node and edge with name to undo stack with MessageActivateNode and MessageActivateEdge
* added FeatureController that handels distribution of MessageActivateTokens
* clearing views when refreshing or changing project
* clearing undo stack when changing project
* added StorageCache derived from StorageAccessProxy
This commit is contained in:
Eberhard Graether
2015-06-19 00:20:50 +02:00
parent d6269f9608
commit a527a3c34d
47 changed files with 726 additions and 268 deletions
@@ -1,8 +1,9 @@
#include "component/controller/UndoRedoController.h"
#include "component/view/UndoRedoView.h"
#include "utility/logging/logging.h"
#include "component/view/UndoRedoView.h"
UndoRedoController::UndoRedoController()
: m_lastCommand(nullptr)
{
@@ -17,108 +18,153 @@ UndoRedoView* UndoRedoController::getView()
return Controller::getView<UndoRedoView>();
}
void UndoRedoController::handleMessage(MessageActivateTokens* message)
void UndoRedoController::handleMessage(MessageActivateEdge* message)
{
if(m_lastCommand && m_lastCommand->getType() == "MessageActivateTokens")
{
if(static_cast<MessageActivateTokens*>(m_lastCommand.get())->tokenIds == message->tokenIds)
{
return;
}
}
std::shared_ptr<MessageActivateTokens> m = std::shared_ptr<MessageActivateTokens>(new MessageActivateTokens(*message));
std::shared_ptr<MessageBase> msg = m;
processMessage(msg);
if (m_lastCommand && m_lastCommand->getType() == message->getType() &&
static_cast<MessageActivateEdge*>(m_lastCommand.get())->name == message->name)
{
return;
}
processMessage(std::make_shared<MessageActivateEdge>(*message));
}
void UndoRedoController::handleMessage(MessageActivateFile* message)
{
if (m_lastCommand && m_lastCommand->getType() == message->getType() &&
static_cast<MessageActivateFile*>(m_lastCommand.get())->filePath == message->filePath)
{
return;
}
processMessage(std::make_shared<MessageActivateFile>(*message));
}
void UndoRedoController::handleMessage(MessageActivateNode* message)
{
if (m_lastCommand && m_lastCommand->getType() == message->getType() &&
static_cast<MessageActivateNode*>(m_lastCommand.get())->name == message->name)
{
return;
}
processMessage(std::make_shared<MessageActivateNode>(*message));
}
void UndoRedoController::handleMessage(MessageGraphNodeExpand* message)
{
/*MessageGraphNodeExpand* m = new MessageGraphNodeExpand(message->tokenId,message->access);
m->UndoRedoType = message->UndoRedoType;
processMessage(m);*/
}
void UndoRedoController::handleMessage(MessageGraphNodeMove* message)
{
/*MessageGraphNodeMove* m = new MessageGraphNodeMove(message->tokenId,message->position);
m->UndoRedoType = message->UndoRedoType;
processMessage(m, true);*/
}
void UndoRedoController::handleMessage(MessageLoadProject* message)
{
clear();
}
void UndoRedoController::handleMessage(MessageLoadSource* message)
{
clear();
}
void UndoRedoController::handleMessage(MessageRedo* message)
{
if(!m_redo.empty())
{
std::shared_ptr<MessageBase> m = m_redo.back();
m_redo.pop_back();
m->UndoRedoType = MessageBase::UndoType_Redo;
m->dispatch();
}
if (!m_redo.empty())
{
std::shared_ptr<MessageBase> m = m_redo.back();
m_redo.pop_back();
m->undoRedoType = MessageBase::UndoType_Redo;
m->dispatch();
}
}
void UndoRedoController::handleMessage(MessageSearch* message)
{
if (m_lastCommand && m_lastCommand->getType() == message->getType() &&
static_cast<MessageSearch*>(m_lastCommand.get())->getQuery() == message->getQuery())
{
return;
}
processMessage(std::make_shared<MessageSearch>(*message));
}
void UndoRedoController::handleMessage(MessageUndo* message)
{
if(!m_undo.empty())
{
std::shared_ptr<MessageBase> m = m_undo.back();
m_undo.pop_back();
m->UndoRedoType = MessageBase::UndoType_Undo;
m->dispatch();
}
if (!m_undo.empty())
{
std::shared_ptr<MessageBase> m = m_undo.back();
m_undo.pop_back();
m->undoRedoType = MessageBase::UndoType_Undo;
m->dispatch();
}
}
void UndoRedoController::processMessage(std::shared_ptr<MessageBase> message)
{
switch(message->UndoRedoType)
{
case MessageBase::UndoType_Normal:
processNormalMessage(message);;
break;
case MessageBase::UndoType_Redo:
processRedoMessage(message);
break;
case MessageBase::UndoType_Undo:
processUndoMessage(message);
break;
}
switch (message->undoRedoType)
{
case MessageBase::UndoType_Normal:
processNormalMessage(message);;
break;
case MessageBase::UndoType_Redo:
processRedoMessage(message);
break;
case MessageBase::UndoType_Undo:
processUndoMessage(message);
break;
}
}
void UndoRedoController::processNormalMessage(std::shared_ptr<MessageBase> message)
{
if(m_lastCommand != nullptr)
{
m_undo.push_back(m_lastCommand);
getView()->setUndoButtonEnabled(true);
}
m_lastCommand = message;
while(!m_redo.empty())
{
std::shared_ptr<MessageBase> m = m_redo.back();
m_redo.pop_back();
}
getView()->setRedoButtonEnabled(false);
if (m_lastCommand)
{
m_undo.push_back(m_lastCommand);
getView()->setUndoButtonEnabled(true);
}
m_lastCommand = message;
m_redo.clear();
getView()->setRedoButtonEnabled(false);
}
void UndoRedoController::processRedoMessage(std::shared_ptr<MessageBase> message)
{
m_undo.push_back(m_lastCommand);
getView()->setUndoButtonEnabled(true);
m_lastCommand = message;
if(m_redo.empty())
{
getView()->setRedoButtonEnabled(false);
}
m_undo.push_back(m_lastCommand);
m_lastCommand = message;
getView()->setUndoButtonEnabled(true);
if (m_redo.empty())
{
getView()->setRedoButtonEnabled(false);
}
}
void UndoRedoController::processUndoMessage(std::shared_ptr<MessageBase> message)
{
m_redo.push_back(m_lastCommand);
getView()->setRedoButtonEnabled(true);
m_lastCommand = message;
if(m_undo.empty())
{
getView()->setUndoButtonEnabled(false);
}
m_redo.push_back(m_lastCommand);
m_lastCommand = message;
getView()->setRedoButtonEnabled(true);
if (m_undo.empty())
{
getView()->setUndoButtonEnabled(false);
}
}
void UndoRedoController::clear()
{
m_lastCommand = nullptr;
m_undo.clear();
m_redo.clear();
getView()->setUndoButtonEnabled(false);
getView()->setRedoButtonEnabled(false);
}