logic: rewrote UndoRedoController to differentiate 3 types of priority
ORDER_ACTIVATE for messages that change active symbols ORDER_ADAPT for graph and code view expanding and collapsing ORDER_VIEW for scrolling and local symbol activation
This commit is contained in:
@@ -224,7 +224,7 @@ void CodeController::handleMessage(MessageFocusOut* message)
|
||||
|
||||
void CodeController::handleMessage(MessageScrollCode* message)
|
||||
{
|
||||
if (!message->isFresh())
|
||||
if (message->isReplayed())
|
||||
{
|
||||
getView()->scrollToValue(message->value);
|
||||
}
|
||||
@@ -287,7 +287,7 @@ CodeView* CodeController::getView()
|
||||
|
||||
void CodeController::showContents(MessageBase* message)
|
||||
{
|
||||
if (message->undoRedoType == MessageBase::UNDOTYPE_NORMAL)
|
||||
if (!message->isReplayed())
|
||||
{
|
||||
getView()->showContents();
|
||||
}
|
||||
|
||||
@@ -151,13 +151,13 @@ void GraphController::handleMessage(MessageGraphNodeMove* message)
|
||||
{
|
||||
node->position += message->delta;
|
||||
|
||||
if (message->isFresh())
|
||||
if (message->isReplayed())
|
||||
{
|
||||
getView()->resizeView();
|
||||
buildGraph(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
buildGraph(message);
|
||||
getView()->resizeView();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1176,7 +1176,7 @@ DummyNode* GraphController::findDummyNodeAccessRecursive(
|
||||
|
||||
void GraphController::buildGraph(MessageBase* message)
|
||||
{
|
||||
if (message->undoRedoType == MessageBase::UNDOTYPE_NORMAL)
|
||||
if (!message->isReplayed())
|
||||
{
|
||||
getView()->rebuildGraph(m_graph, m_dummyNodes, m_dummyEdges);
|
||||
m_graph.reset();
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
UndoRedoController::UndoRedoController(StorageAccess* storageAccess)
|
||||
: m_activationTranslator(storageAccess)
|
||||
, m_lastCommand(nullptr, 0)
|
||||
{
|
||||
m_iterator = m_list.end();
|
||||
}
|
||||
|
||||
UndoRedoController::~UndoRedoController()
|
||||
@@ -23,7 +23,7 @@ UndoRedoView* UndoRedoController::getView()
|
||||
return Controller::getView<UndoRedoView>();
|
||||
}
|
||||
|
||||
UndoRedoController::Command::Command(std::shared_ptr<MessageBase> message, size_t order)
|
||||
UndoRedoController::Command::Command(std::shared_ptr<MessageBase> message, Order order)
|
||||
: message(message)
|
||||
, order(order)
|
||||
{
|
||||
@@ -31,105 +31,115 @@ UndoRedoController::Command::Command(std::shared_ptr<MessageBase> message, size_
|
||||
|
||||
void UndoRedoController::handleMessage(MessageActivateEdge* message)
|
||||
{
|
||||
if (m_lastCommand.message && m_lastCommand.message->getType() == message->getType() &&
|
||||
static_cast<MessageActivateEdge*>(m_lastCommand.message.get())->getFullName() == message->getFullName())
|
||||
if (sameMessageTypeAsLast(message) &&
|
||||
static_cast<MessageActivateEdge*>(lastMessage())->getFullName() == message->getFullName())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Command command(std::make_shared<MessageActivateEdge>(*message), (message->isAggregation() ? 0 : 1));
|
||||
Command command(
|
||||
std::make_shared<MessageActivateEdge>(*message),
|
||||
(message->isAggregation() ? Command::ORDER_ACTIVATE : Command::ORDER_ADAPT)
|
||||
);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageActivateFile* message)
|
||||
{
|
||||
if (m_lastCommand.message && m_lastCommand.message->getType() == message->getType() &&
|
||||
static_cast<MessageActivateFile*>(m_lastCommand.message.get())->filePath == message->filePath)
|
||||
if (sameMessageTypeAsLast(message) &&
|
||||
static_cast<MessageActivateFile*>(lastMessage())->filePath == message->filePath)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Command command(std::make_shared<MessageActivateFile>(*message), 0);
|
||||
Command command(std::make_shared<MessageActivateFile>(*message), Command::ORDER_ACTIVATE);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageActivateLocalSymbols* message)
|
||||
{
|
||||
if (sameMessageTypeAsLast(message))
|
||||
{
|
||||
static_cast<MessageActivateLocalSymbols*>(lastMessage())->symbolIds = message->symbolIds;
|
||||
return;
|
||||
}
|
||||
|
||||
Command command(std::make_shared<MessageActivateLocalSymbols>(*message), Command::ORDER_VIEW);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageActivateNodes* message)
|
||||
{
|
||||
if (m_lastCommand.message &&
|
||||
m_lastCommand.message->getType() == message->getType() &&
|
||||
if (sameMessageTypeAsLast(message) &&
|
||||
message->nodes.size() &&
|
||||
static_cast<MessageActivateNodes*>(m_lastCommand.message.get())->nodes.size() == message->nodes.size() &&
|
||||
static_cast<MessageActivateNodes*>(m_lastCommand.message.get())->nodes[0].nameHierarchy.getQualifiedNameWithSignature() ==
|
||||
static_cast<MessageActivateNodes*>(lastMessage())->nodes.size() == message->nodes.size() &&
|
||||
static_cast<MessageActivateNodes*>(lastMessage())->nodes[0].nameHierarchy.getQualifiedNameWithSignature() ==
|
||||
message->nodes[0].nameHierarchy.getQualifiedNameWithSignature())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Command command(std::make_shared<MessageActivateNodes>(*message), 0);
|
||||
Command command(std::make_shared<MessageActivateNodes>(*message), Command::ORDER_ACTIVATE);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageActivateTokenIds* message)
|
||||
{
|
||||
if (m_lastCommand.message && m_lastCommand.message->getType() == message->getType() && message->tokenIds.size() &&
|
||||
static_cast<MessageActivateTokenIds*>(m_lastCommand.message.get())->tokenIds == message->tokenIds)
|
||||
if (sameMessageTypeAsLast(message) && message->tokenIds.size() &&
|
||||
static_cast<MessageActivateTokenIds*>(lastMessage())->tokenIds == message->tokenIds)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Command command(std::make_shared<MessageActivateTokenIds>(*message), 0);
|
||||
Command command(std::make_shared<MessageActivateTokenIds>(*message), Command::ORDER_ACTIVATE);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageChangeFileView* message)
|
||||
{
|
||||
Command command(std::make_shared<MessageChangeFileView>(*message), 1);
|
||||
Command command(std::make_shared<MessageChangeFileView>(*message), Command::ORDER_ADAPT);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageDeactivateEdge* message)
|
||||
{
|
||||
MessageBase* m = nullptr;
|
||||
|
||||
if (m_lastCommand.message && m_lastCommand.order == 0)
|
||||
if (m_iterator == m_list.begin())
|
||||
{
|
||||
m = m_lastCommand.message.get();
|
||||
}
|
||||
else if (m_undo.size())
|
||||
{
|
||||
int i = m_undo.size() - 1;
|
||||
while (i >= 0 && m_undo[i].order > 0)
|
||||
{
|
||||
i--;
|
||||
}
|
||||
m = m_undo[i].message.get();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m)
|
||||
std::list<Command>::iterator it = m_iterator;
|
||||
do
|
||||
{
|
||||
bool keepContent = m->keepContent();
|
||||
m->undoRedoType = MessageBase::UNDOTYPE_NORMAL;
|
||||
m->setKeepContent(true);
|
||||
m->dispatch();
|
||||
m->setKeepContent(keepContent);
|
||||
std::advance(it, -1);
|
||||
}
|
||||
while (it != m_list.begin() && it->order != Command::ORDER_ACTIVATE);
|
||||
|
||||
MessageBase* m = it->message.get();
|
||||
bool keepContent = m->keepContent();
|
||||
|
||||
m->setIsReplayed(false);
|
||||
m->setKeepContent(true);
|
||||
m->dispatch();
|
||||
|
||||
m->setKeepContent(keepContent);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageGraphNodeBundleSplit* message)
|
||||
{
|
||||
Command command(std::make_shared<MessageGraphNodeBundleSplit>(*message), 1);
|
||||
Command command(std::make_shared<MessageGraphNodeBundleSplit>(*message), Command::ORDER_ADAPT);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageGraphNodeExpand* message)
|
||||
{
|
||||
Command command(std::make_shared<MessageGraphNodeExpand>(*message), 1);
|
||||
Command command(std::make_shared<MessageGraphNodeExpand>(*message), Command::ORDER_ADAPT);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageGraphNodeMove* message)
|
||||
{
|
||||
Command command(std::make_shared<MessageGraphNodeMove>(*message), 1);
|
||||
Command command(std::make_shared<MessageGraphNodeMove>(*message), Command::ORDER_ADAPT);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
@@ -140,15 +150,28 @@ void UndoRedoController::handleMessage(MessageLoadProject* message)
|
||||
|
||||
void UndoRedoController::handleMessage(MessageRedo* message)
|
||||
{
|
||||
if (!m_redo.empty())
|
||||
if (m_iterator == m_list.end())
|
||||
{
|
||||
std::shared_ptr<MessageBase> m = m_redo.back().message;
|
||||
m_redo.pop_back();
|
||||
m->undoRedoType = MessageBase::UNDOTYPE_REDO;
|
||||
m->dispatch();
|
||||
|
||||
MessageFlushUpdates().dispatch();
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<Command>::iterator oldIterator = m_iterator;
|
||||
|
||||
std::advance(m_iterator, 1);
|
||||
while (m_iterator->order == Command::ORDER_VIEW)
|
||||
{
|
||||
std::advance(m_iterator, 1);
|
||||
}
|
||||
|
||||
getView()->setUndoButtonEnabled(true);
|
||||
if (m_iterator == m_list.end())
|
||||
{
|
||||
getView()->setRedoButtonEnabled(false);
|
||||
}
|
||||
|
||||
replayCommands(oldIterator);
|
||||
|
||||
MessageFlushUpdates().dispatch();
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageRefresh* message)
|
||||
@@ -166,25 +189,7 @@ void UndoRedoController::handleMessage(MessageRefresh* message)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_lastCommand.order > 0)
|
||||
{
|
||||
replayCommands(false);
|
||||
}
|
||||
|
||||
std::shared_ptr<MessageBase> msg = m_lastCommand.message;
|
||||
|
||||
if (m_undo.size() > 0)
|
||||
{
|
||||
m_lastCommand = m_undo.back();
|
||||
m_undo.pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lastCommand.message.reset();
|
||||
}
|
||||
|
||||
msg->undoRedoType = MessageBase::UNDOTYPE_REDO;
|
||||
msg->dispatch();
|
||||
replayCommands();
|
||||
|
||||
MessageFlushUpdates().dispatch();
|
||||
}
|
||||
@@ -192,197 +197,198 @@ void UndoRedoController::handleMessage(MessageRefresh* message)
|
||||
|
||||
void UndoRedoController::handleMessage(MessageScrollCode* message)
|
||||
{
|
||||
if (!m_lastCommand.message)
|
||||
if (sameMessageTypeAsLast(message))
|
||||
{
|
||||
static_cast<MessageScrollCode*>(lastMessage())->value = message->value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_lastCommand.subMessage && m_lastCommand.subMessage->getType() == message->getType())
|
||||
{
|
||||
static_cast<MessageScrollCode*>(m_lastCommand.subMessage.get())->value = message->value;
|
||||
return;
|
||||
}
|
||||
|
||||
m_lastCommand.subMessage = std::make_shared<MessageScrollCode>(*message);
|
||||
Command command(std::make_shared<MessageScrollCode>(*message), Command::ORDER_VIEW);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageSearch* message)
|
||||
{
|
||||
if (m_lastCommand.message && m_lastCommand.message->getType() == message->getType() &&
|
||||
static_cast<MessageSearch*>(m_lastCommand.message.get())->getMatchesAsString() == message->getMatchesAsString())
|
||||
if (sameMessageTypeAsLast(message) &&
|
||||
static_cast<MessageSearch*>(lastMessage())->getMatchesAsString() == message->getMatchesAsString())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Command command(std::make_shared<MessageSearch>(*message), 0);
|
||||
Command command(std::make_shared<MessageSearch>(*message), Command::ORDER_ACTIVATE);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageShowScope* message)
|
||||
{
|
||||
Command command(std::make_shared<MessageShowScope>(*message), 1);
|
||||
Command command(std::make_shared<MessageShowScope>(*message), Command::ORDER_ADAPT);
|
||||
processCommand(command);
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageUndo* message)
|
||||
{
|
||||
replayCommands(true);
|
||||
if (!m_list.size() || std::prev(m_iterator) == m_list.begin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (std::prev(m_iterator)->order == Command::ORDER_VIEW)
|
||||
{
|
||||
std::advance(m_iterator, -1);
|
||||
}
|
||||
std::advance(m_iterator, -1);
|
||||
|
||||
if (std::distance(m_list.begin(), m_iterator) <= 1)
|
||||
{
|
||||
getView()->setUndoButtonEnabled(false);
|
||||
}
|
||||
getView()->setRedoButtonEnabled(true);
|
||||
|
||||
replayCommands();
|
||||
|
||||
MessageFlushUpdates().dispatch();
|
||||
}
|
||||
|
||||
void UndoRedoController::replayCommands(bool removeLast)
|
||||
void UndoRedoController::replayCommands()
|
||||
{
|
||||
if (!m_undo.empty())
|
||||
std::list<Command>::iterator startIterator = m_iterator;
|
||||
|
||||
do
|
||||
{
|
||||
int i = m_undo.size() - 1;
|
||||
while (i >= 1 && m_undo[i].order > 0)
|
||||
{
|
||||
i--;
|
||||
}
|
||||
std::advance(startIterator, -1);
|
||||
}
|
||||
while (startIterator != m_list.begin() && startIterator->order != Command::ORDER_ACTIVATE);
|
||||
|
||||
std::shared_ptr<MessageBase> m;
|
||||
while (i < int(m_undo.size() - 1))
|
||||
replayCommands(startIterator);
|
||||
}
|
||||
|
||||
void UndoRedoController::replayCommands(std::list<Command>::iterator it)
|
||||
{
|
||||
std::vector<std::list<Command>::iterator> viewCommands;
|
||||
|
||||
std::shared_ptr<MessageBase> m;
|
||||
while (it != m_iterator)
|
||||
{
|
||||
m = it->message;
|
||||
if (it->order != Command::ORDER_VIEW)
|
||||
{
|
||||
m = m_undo[i].message;
|
||||
m->undoRedoType = MessageBase::UNDOTYPE_IGNORE;
|
||||
m->setIsLast(false);
|
||||
m->setIsReplayed(true);
|
||||
m->setIsLast(it == std::prev(m_iterator));
|
||||
m->dispatch();
|
||||
i++;
|
||||
}
|
||||
|
||||
m = m_undo.back().message;
|
||||
|
||||
std::shared_ptr<MessageBase> sm;
|
||||
if (m_lastCommand.order == 0)
|
||||
{
|
||||
sm = m_undo.back().subMessage;
|
||||
}
|
||||
|
||||
if (removeLast)
|
||||
{
|
||||
m_undo.pop_back();
|
||||
m->undoRedoType = MessageBase::UNDOTYPE_UNDO;
|
||||
viewCommands.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
m->undoRedoType = MessageBase::UNDOTYPE_IGNORE;
|
||||
viewCommands.push_back(it);
|
||||
}
|
||||
|
||||
m->setIsLast(!sm);
|
||||
m->dispatch();
|
||||
std::advance(it, 1);
|
||||
}
|
||||
|
||||
if (sm)
|
||||
std::set<std::string> messageTypes;
|
||||
std::vector<std::list<Command>::iterator> lastViewCommands;
|
||||
|
||||
for (size_t i = viewCommands.size(); i > 0; i--)
|
||||
{
|
||||
it = viewCommands[i - 1];
|
||||
if (messageTypes.find(it->message->getType()) == messageTypes.end())
|
||||
{
|
||||
sm->undoRedoType = MessageBase::UNDOTYPE_IGNORE;
|
||||
sm->setIsLast(true);
|
||||
sm->dispatch();
|
||||
messageTypes.insert(it->message->getType());
|
||||
lastViewCommands.push_back(it);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = lastViewCommands.size(); i > 0; i--)
|
||||
{
|
||||
it = lastViewCommands[i - 1];
|
||||
m = it->message;
|
||||
m->setIsReplayed(true);
|
||||
m->setIsLast(it == std::prev(m_iterator));
|
||||
m->dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void UndoRedoController::processCommand(Command command)
|
||||
{
|
||||
if (command.order == 0 && command.message->keepContent())
|
||||
if (command.order == Command::ORDER_ACTIVATE && command.message->keepContent())
|
||||
{
|
||||
command.order = 1;
|
||||
command.order = Command::ORDER_ADAPT;
|
||||
}
|
||||
|
||||
switch (command.message->undoRedoType)
|
||||
if (!command.message->isReplayed())
|
||||
{
|
||||
case MessageBase::UNDOTYPE_NORMAL:
|
||||
processNormalCommand(command);
|
||||
break;
|
||||
case MessageBase::UNDOTYPE_REDO:
|
||||
processRedoCommand(command);
|
||||
break;
|
||||
case MessageBase::UNDOTYPE_UNDO:
|
||||
processUndoCommand(command);
|
||||
break;
|
||||
case MessageBase::UNDOTYPE_IGNORE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (command.order == Command::ORDER_ACTIVATE)
|
||||
{
|
||||
m_iterator = m_list.erase(m_iterator, m_list.end());
|
||||
}
|
||||
else if (command.order == Command::ORDER_ADAPT)
|
||||
{
|
||||
std::list<Command>::iterator end = m_iterator;
|
||||
while (end != m_list.end())
|
||||
{
|
||||
if (end->order == Command::ORDER_ACTIVATE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
std::advance(end, 1);
|
||||
}
|
||||
|
||||
void UndoRedoController::processNormalCommand(const Command& command)
|
||||
{
|
||||
if (m_lastCommand.message)
|
||||
{
|
||||
m_undo.push_back(m_lastCommand);
|
||||
getView()->setUndoButtonEnabled(true);
|
||||
}
|
||||
m_iterator = m_list.erase(m_iterator, end);
|
||||
}
|
||||
|
||||
m_lastCommand = command;
|
||||
m_list.insert(m_iterator, command);
|
||||
|
||||
m_redo.clear();
|
||||
getView()->setRedoButtonEnabled(false);
|
||||
}
|
||||
if (command.order != Command::ORDER_VIEW)
|
||||
{
|
||||
if (m_list.begin() != std::prev(m_iterator))
|
||||
{
|
||||
getView()->setUndoButtonEnabled(true);
|
||||
}
|
||||
|
||||
void UndoRedoController::processRedoCommand(const Command& command)
|
||||
{
|
||||
if (m_lastCommand.message)
|
||||
{
|
||||
m_undo.push_back(m_lastCommand);
|
||||
getView()->setUndoButtonEnabled(true);
|
||||
}
|
||||
|
||||
m_lastCommand = command;
|
||||
|
||||
if (m_redo.empty())
|
||||
{
|
||||
getView()->setRedoButtonEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void UndoRedoController::processUndoCommand(const Command& command)
|
||||
{
|
||||
if (m_lastCommand.message)
|
||||
{
|
||||
m_redo.push_back(m_lastCommand);
|
||||
getView()->setRedoButtonEnabled(true);
|
||||
}
|
||||
|
||||
m_lastCommand = command;
|
||||
|
||||
if (m_undo.empty())
|
||||
{
|
||||
getView()->setUndoButtonEnabled(false);
|
||||
if (m_list.end() == m_iterator)
|
||||
{
|
||||
getView()->setRedoButtonEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UndoRedoController::clear()
|
||||
{
|
||||
m_lastCommand = Command(nullptr, 0);
|
||||
|
||||
m_undo.clear();
|
||||
m_redo.clear();
|
||||
m_list.clear();
|
||||
m_iterator = m_list.end();
|
||||
|
||||
getView()->setUndoButtonEnabled(false);
|
||||
getView()->setRedoButtonEnabled(false);
|
||||
}
|
||||
|
||||
bool UndoRedoController::sameMessageTypeAsLast(MessageBase* message) const
|
||||
{
|
||||
if (!m_list.size() || m_list.begin() == m_iterator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::prev(m_iterator)->message->getType() == message->getType();
|
||||
}
|
||||
|
||||
MessageBase* UndoRedoController::lastMessage() const
|
||||
{
|
||||
return std::prev(m_iterator)->message.get();
|
||||
}
|
||||
|
||||
bool UndoRedoController::requiresActivateFallbackToken() const
|
||||
{
|
||||
bool activateFallbackToken = true;
|
||||
if (m_lastCommand.message)
|
||||
std::list<Command>::iterator it = m_iterator;
|
||||
|
||||
do
|
||||
{
|
||||
if (m_lastCommand.order == 0)
|
||||
{
|
||||
activateFallbackToken = !checkCommandCausesTokenActivation(m_lastCommand);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = m_undo.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if (m_undo[i].order == 0)
|
||||
{
|
||||
activateFallbackToken = !checkCommandCausesTokenActivation(m_undo[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::advance(it, -1);
|
||||
}
|
||||
return activateFallbackToken;
|
||||
while (it != m_list.begin() && it->order != Command::ORDER_ACTIVATE);
|
||||
|
||||
return !checkCommandCausesTokenActivation(*it);
|
||||
}
|
||||
|
||||
bool UndoRedoController::checkCommandCausesTokenActivation(const Command& command) const
|
||||
@@ -403,7 +409,7 @@ bool UndoRedoController::checkCommandCausesTokenActivation(const Command& comman
|
||||
else if (commandMessageTypeString == MessageActivateNodes::getStaticType())
|
||||
{
|
||||
MessageActivateNodes inputMessage(*dynamic_cast<MessageActivateNodes*>(commandMessage));
|
||||
inputMessage.undoRedoType = MessageBase::UNDOTYPE_REDO;
|
||||
inputMessage.setIsReplayed(true);
|
||||
m = m_activationTranslator.translateMessage(&inputMessage);
|
||||
}
|
||||
else if (commandMessageTypeString == MessageSearch::getStaticType())
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#ifndef UNDO_REDO_CONTROLLER_H
|
||||
#define UNDO_REDO_CONTROLLER_H
|
||||
|
||||
#include <deque>
|
||||
#include <list>
|
||||
|
||||
#include "utility/messaging/MessageBase.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateEdge.h"
|
||||
#include "utility/messaging/type/MessageActivateFile.h"
|
||||
#include "utility/messaging/type/MessageActivateLocalSymbols.h"
|
||||
#include "utility/messaging/type/MessageActivateNodes.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenIds.h"
|
||||
#include "utility/messaging/type/MessageChangeFileView.h"
|
||||
@@ -32,6 +33,7 @@ class UndoRedoController
|
||||
: public Controller
|
||||
, public MessageListener<MessageActivateEdge>
|
||||
, public MessageListener<MessageActivateFile>
|
||||
, public MessageListener<MessageActivateLocalSymbols>
|
||||
, public MessageListener<MessageActivateNodes>
|
||||
, public MessageListener<MessageActivateTokenIds>
|
||||
, public MessageListener<MessageChangeFileView>
|
||||
@@ -56,15 +58,22 @@ public:
|
||||
private:
|
||||
struct Command
|
||||
{
|
||||
Command(std::shared_ptr<MessageBase> message, size_t order);
|
||||
enum Order
|
||||
{
|
||||
ORDER_ACTIVATE,
|
||||
ORDER_ADAPT,
|
||||
ORDER_VIEW
|
||||
};
|
||||
|
||||
Command(std::shared_ptr<MessageBase> message, Order order);
|
||||
|
||||
std::shared_ptr<MessageBase> message;
|
||||
std::shared_ptr<MessageBase> subMessage;
|
||||
size_t order;
|
||||
Order order;
|
||||
};
|
||||
|
||||
virtual void handleMessage(MessageActivateEdge* message);
|
||||
virtual void handleMessage(MessageActivateFile* message);
|
||||
virtual void handleMessage(MessageActivateLocalSymbols* message);
|
||||
virtual void handleMessage(MessageActivateNodes* message);
|
||||
virtual void handleMessage(MessageActivateTokenIds* message);
|
||||
virtual void handleMessage(MessageChangeFileView* message);
|
||||
@@ -80,24 +89,23 @@ private:
|
||||
virtual void handleMessage(MessageShowScope* message);
|
||||
virtual void handleMessage(MessageUndo* message);
|
||||
|
||||
void replayCommands(bool removeLast);
|
||||
void replayCommands();
|
||||
void replayCommands(std::list<Command>::iterator iterator);
|
||||
|
||||
void processCommand(Command command);
|
||||
void processNormalCommand(const Command& command);
|
||||
void processRedoCommand(const Command& command);
|
||||
void processUndoCommand(const Command& command);
|
||||
|
||||
void clear();
|
||||
|
||||
bool sameMessageTypeAsLast(MessageBase* message) const;
|
||||
MessageBase* lastMessage() const;
|
||||
|
||||
bool requiresActivateFallbackToken() const;
|
||||
bool checkCommandCausesTokenActivation(const Command& command) const;
|
||||
|
||||
ActivationTranslator m_activationTranslator;
|
||||
|
||||
Command m_lastCommand;
|
||||
|
||||
std::deque<Command> m_undo;
|
||||
std::deque<Command> m_redo;
|
||||
std::list<Command> m_list;
|
||||
std::list<Command>::iterator m_iterator;
|
||||
};
|
||||
|
||||
#endif // UNDO_REDO_CONTROLLER_H
|
||||
|
||||
@@ -36,7 +36,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
|
||||
{
|
||||
Id edgeId = message->tokenId;
|
||||
|
||||
if (!message->isFresh())
|
||||
if (message->isReplayed())
|
||||
{
|
||||
edgeId = m_storageAccess->getIdForEdge(message->type, message->fromNameHierarchy, message->toNameHierarchy);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
|
||||
false,
|
||||
nullptr
|
||||
);
|
||||
msg.undoRedoType = message->undoRedoType;
|
||||
msg.setIsReplayed(message->isReplayed());
|
||||
msg.setKeepContent(message->keepContent());
|
||||
msg.dispatch();
|
||||
return nullptr;
|
||||
@@ -75,7 +75,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
|
||||
std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(const MessageActivateNodes* message) const
|
||||
{
|
||||
std::vector<Id> nodeIds;
|
||||
if (message->isFresh())
|
||||
if (!message->isReplayed())
|
||||
{
|
||||
for (const MessageActivateNodes::ActiveNode& node : message->nodes)
|
||||
{
|
||||
@@ -115,7 +115,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
|
||||
match.getFullName() == SearchMatch::getCommandName(SearchMatch::COMMAND_ALL))
|
||||
{
|
||||
MessageActivateAll msg;
|
||||
msg.undoRedoType = message->undoRedoType;
|
||||
msg.setIsReplayed(message->isReplayed());
|
||||
msg.dispatchImmediately();
|
||||
return nullptr;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
|
||||
match.getFullName() == SearchMatch::getCommandName(SearchMatch::COMMAND_ERROR))
|
||||
{
|
||||
MessageShowErrors msg(ErrorCountInfo(-1, 0));
|
||||
msg.undoRedoType = message->undoRedoType;
|
||||
msg.setIsReplayed(message->isReplayed());
|
||||
msg.dispatchImmediately();
|
||||
return nullptr;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
|
||||
std::vector<Id> tokenIds = m_storageAccess->getTokenIdsForMatches(matches);
|
||||
|
||||
std::shared_ptr<MessageActivateTokens> m = std::make_shared<MessageActivateTokens>(message, tokenIds);
|
||||
if (message->isFresh())
|
||||
if (!message->isReplayed())
|
||||
{
|
||||
m->isFromSearch = true;
|
||||
}
|
||||
|
||||
@@ -538,7 +538,10 @@ std::vector<Id> Storage::getTokenIdsForMatches(const std::vector<SearchMatch>& m
|
||||
std::vector<Id> ids;
|
||||
for (std::set<Id>::const_iterator it = idSet.begin(); it != idSet.end(); it++)
|
||||
{
|
||||
ids.push_back(*it);
|
||||
if (*it != 0)
|
||||
{
|
||||
ids.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
|
||||
@@ -7,16 +7,8 @@
|
||||
class MessageBase
|
||||
{
|
||||
public:
|
||||
enum UndoType
|
||||
{
|
||||
UNDOTYPE_NORMAL,
|
||||
UNDOTYPE_REDO,
|
||||
UNDOTYPE_UNDO,
|
||||
UNDOTYPE_IGNORE
|
||||
};
|
||||
|
||||
MessageBase()
|
||||
: undoRedoType(UNDOTYPE_NORMAL)
|
||||
: m_isReplayed(false)
|
||||
, m_sendAsTask(true)
|
||||
, m_keepContent(false)
|
||||
, m_cancelled(false)
|
||||
@@ -42,9 +34,14 @@ public:
|
||||
m_sendAsTask = sendAsTask;
|
||||
}
|
||||
|
||||
bool isFresh() const
|
||||
bool isReplayed() const
|
||||
{
|
||||
return (undoRedoType == UNDOTYPE_NORMAL);
|
||||
return m_isReplayed;
|
||||
}
|
||||
|
||||
void setIsReplayed(bool isReplayed)
|
||||
{
|
||||
m_isReplayed = isReplayed;
|
||||
}
|
||||
|
||||
bool isLast() const
|
||||
@@ -97,9 +94,8 @@ public:
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
UndoType undoRedoType;
|
||||
|
||||
private:
|
||||
bool m_isReplayed;
|
||||
bool m_sendAsTask;
|
||||
bool m_keepContent;
|
||||
bool m_cancelled;
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
, isFromSystem(false)
|
||||
, isFromSearch(false)
|
||||
{
|
||||
undoRedoType = other->undoRedoType;
|
||||
setIsReplayed(other->isReplayed());
|
||||
setKeepContent(other->keepContent());
|
||||
setIsLast(other->isLast());
|
||||
}
|
||||
|
||||
@@ -429,7 +429,8 @@ void QtCodeFile::requestSnippets() const
|
||||
hasErrors(),
|
||||
m_locationFile
|
||||
);
|
||||
msg.undoRedoType = MessageBase::UNDOTYPE_IGNORE;
|
||||
|
||||
msg.setIsReplayed(true);
|
||||
msg.dispatch();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user