ui: Added singleton QtContextMenu with global back and forward actions

* QtContextMenu holds default actions for back and forward
* additional actions can be passed to extend the default menu
* currently used in QtMainWindow and QtCodeArea
* fixed crash on undo when only view actions happened since project load

bug id = 108
This commit is contained in:
Eberhard Graether
2016-06-30 16:49:16 +02:00
parent 32f894422d
commit 4e18389d38
9 changed files with 181 additions and 20 deletions
@@ -243,23 +243,40 @@ void UndoRedoController::handleMessage(MessageShowScope* message)
void UndoRedoController::handleMessage(MessageUndo* message)
{
if (!m_list.size() || std::prev(m_iterator) == m_list.begin())
if (!m_list.size())
{
return;
}
while (std::prev(m_iterator)->order == Command::ORDER_VIEW)
// return to last non view command
std::list<Command>::iterator it = m_iterator;
while (std::prev(it)->order == Command::ORDER_VIEW)
{
std::advance(m_iterator, -1);
std::advance(it, -1);
}
std::advance(m_iterator, -1);
std::advance(it, -1);
if (std::distance(m_list.begin(), m_iterator) <= 1)
// disable undo button if there is no non view command till the first command
std::list<Command>::iterator it2 = std::prev(it);
while (it2->order == Command::ORDER_VIEW)
{
std::advance(it2, -1);
}
if (it2 == m_list.begin())
{
getView()->setUndoButtonEnabled(false);
}
// abort if first command is reached
if (it == m_list.begin())
{
return;
}
getView()->setRedoButtonEnabled(true);
m_iterator = it;
replayCommands();
MessageFlushUpdates().dispatch();
@@ -392,3 +409,39 @@ MessageBase* UndoRedoController::lastMessage() const
{
return std::prev(m_iterator)->message.get();
}
void UndoRedoController::dump() const
{
std::cout << "Undo Redo Stack:\n\n";
std::list<Command>::const_iterator it = m_list.begin();
while (it != m_list.end())
{
switch (it->order)
{
case Command::ORDER_VIEW:
std::cout << "\t";
case Command::ORDER_ADAPT:
std::cout << "\t";
case Command::ORDER_ACTIVATE:
break;
}
std::cout << it->message->getType() << " " << it->replayLastOnly;
if (it == m_iterator)
{
std::cout << " <-";
}
std::cout << std::endl;
std::advance(it, 1);
}
if (m_list.end() == m_iterator)
{
std::cout << " <-";
}
std::cout << std::endl;
}