logic: UndoRedo
UndoRedo working for ActiveTokensMessages
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ endif ()
|
||||
# Settings ---------------------------------------------------------------------
|
||||
|
||||
if (UNIX)
|
||||
add_definitions(-std=c++11 -Wno-unknown-warning-option)
|
||||
add_definitions(-std=c++11 -Wno-unknown-warning-option -fcolor-diagnostics)
|
||||
endif ()
|
||||
|
||||
# Project ----------------------------------------------------------------------
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
@@ -0,0 +1,42 @@
|
||||
#undo_redo_bar {
|
||||
background: white;
|
||||
}
|
||||
|
||||
QPushButton {
|
||||
background: #E0E0E0;
|
||||
border: none;
|
||||
background-position: 15px 5px;
|
||||
height: 30px;
|
||||
width: 30px;
|
||||
}
|
||||
|
||||
#undo_button {
|
||||
border-bottom-left-radius: 12px;
|
||||
border-top-left-radius: 12px;
|
||||
}
|
||||
|
||||
#redo_button {
|
||||
border-bottom-right-radius: 12px;
|
||||
border-top-right-radius: 12px;
|
||||
}
|
||||
|
||||
#undo_button:disabled,
|
||||
#redo_button:disabled {
|
||||
background: #F4F4F4;
|
||||
}
|
||||
|
||||
#undo_button:hover,
|
||||
#redo_button:hover {
|
||||
background: #B2B2B2;
|
||||
}
|
||||
|
||||
#undo_button:pressed,
|
||||
#redo_button:pressed {
|
||||
background: #626262;
|
||||
}
|
||||
|
||||
QToolTip {
|
||||
background-color: rgb(204, 204, 204);
|
||||
border: 1px solid rgb(0, 0, 0);
|
||||
color: rgb(0, 0, 0);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ set(CLANG_INCLUDE_DIRS
|
||||
|
||||
set(CLANG_LIBRARY_DIRS "$ENV{CLANG_DIR}/build/lib")
|
||||
if (UNIX)
|
||||
if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
||||
set(CLANG_LIBRARY_DIRS "$ENV{CLANG_DIR}/build/Release+Asserts/lib")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
@@ -21,6 +21,8 @@ add_files(
|
||||
qt/element/QtSmartSearchBox.h
|
||||
qt/element/QtStatusBar.cpp
|
||||
qt/element/QtStatusBar.h
|
||||
qt/element/QtUndoRedo.cpp
|
||||
qt/element/QtUndoRedo.h
|
||||
|
||||
qt/graphics/QtGraphicsRoundedRectItem.cpp
|
||||
qt/graphics/QtGraphicsRoundedRectItem.h
|
||||
@@ -58,6 +60,8 @@ add_files(
|
||||
qt/view/QtSearchView.h
|
||||
qt/view/QtStatusBarView.cpp
|
||||
qt/view/QtStatusBarView.h
|
||||
qt/view/QtUndoRedoView.cpp
|
||||
qt/view/QtUndoRedoView.h
|
||||
qt/view/QtViewFactory.cpp
|
||||
qt/view/QtViewFactory.h
|
||||
qt/view/QtViewWidgetWrapper.cpp
|
||||
|
||||
@@ -13,8 +13,10 @@
|
||||
#include "utility/messaging/type/MessageFind.h"
|
||||
#include "utility/messaging/type/MessageLoadProject.h"
|
||||
#include "utility/messaging/type/MessageLoadSource.h"
|
||||
#include "utility/messaging/type/MessageRedo.h"
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
#include "utility/messaging/type/MessageSaveProject.h"
|
||||
#include "utility/messaging/type/MessageUndo.h"
|
||||
|
||||
QtMainWindow::QtMainWindow()
|
||||
{
|
||||
@@ -23,6 +25,7 @@ QtMainWindow::QtMainWindow()
|
||||
setDockNestingEnabled(true);
|
||||
|
||||
setupProjectMenu();
|
||||
setupEditMenu();
|
||||
setupViewMenu();
|
||||
setupFindMenu();
|
||||
setupHelpMenu();
|
||||
@@ -73,6 +76,16 @@ void QtMainWindow::openProject(const QString &path)
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::undo()
|
||||
{
|
||||
MessageUndo().dispatch();
|
||||
}
|
||||
|
||||
void QtMainWindow::redo()
|
||||
{
|
||||
MessageRedo().dispatch();
|
||||
}
|
||||
|
||||
void QtMainWindow::saveProject()
|
||||
{
|
||||
MessageSaveProject("").dispatch();
|
||||
@@ -216,6 +229,15 @@ void QtMainWindow::setupViewMenu()
|
||||
menu->addAction(tr("&Refresh"), this, SLOT(refresh()), QKeySequence::Refresh);
|
||||
}
|
||||
|
||||
void QtMainWindow::setupEditMenu()
|
||||
{
|
||||
QMenu *menu = new QMenu(tr("&Edit"), this);
|
||||
menuBar()->addMenu(menu);
|
||||
|
||||
menu->addAction(tr("Undo"), this, SLOT(undo()), QKeySequence::Undo );
|
||||
menu->addAction(tr("Redo"), this, SLOT(redo()), QKeySequence::Redo );
|
||||
}
|
||||
|
||||
void QtMainWindow::setupFindMenu()
|
||||
{
|
||||
QMenu *menu = new QMenu(tr("&Find"), this);
|
||||
|
||||
@@ -35,8 +35,11 @@ public slots:
|
||||
void refresh();
|
||||
void saveProject();
|
||||
void saveAsProject();
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
private:
|
||||
void setupEditMenu();
|
||||
void setupProjectMenu();
|
||||
void setupViewMenu();
|
||||
void setupFindMenu();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "qt/element/QtUndoRedo.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include <utility/messaging/type/MessageUndo.h>
|
||||
#include <utility/messaging/type/MessageRedo.h>
|
||||
|
||||
|
||||
QtUndoRedo::QtUndoRedo()
|
||||
{
|
||||
setObjectName("undo_redo_bar");
|
||||
|
||||
m_undoButton = new QPushButton(this);
|
||||
m_undoButton->setObjectName("undo_button");
|
||||
m_undoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_undoButton->setIcon(QIcon("data/gui/undoredo_view/images/arrow_left.png"));
|
||||
m_undoButton->setEnabled(false);
|
||||
|
||||
m_redoButton = new QPushButton(this);
|
||||
m_redoButton->setObjectName("redo_button");
|
||||
m_redoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
|
||||
m_redoButton->setIcon(QIcon("data/gui/undoredo_view/images/arrow_right.png"));
|
||||
m_redoButton->setEnabled(false);
|
||||
|
||||
QBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setSpacing(0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
layout->addWidget(m_undoButton);
|
||||
layout->addSpacing(2);
|
||||
layout->addWidget(m_redoButton);
|
||||
layout->addStretch();
|
||||
|
||||
connect(m_undoButton, SIGNAL(clicked()), this, SLOT(undo()));
|
||||
connect(m_redoButton, SIGNAL(clicked()), this, SLOT(redo()));
|
||||
}
|
||||
|
||||
QtUndoRedo::~QtUndoRedo()
|
||||
{
|
||||
}
|
||||
|
||||
void QtUndoRedo::undo()
|
||||
{
|
||||
MessageUndo().dispatch();
|
||||
}
|
||||
|
||||
void QtUndoRedo::redo()
|
||||
{
|
||||
MessageRedo().dispatch();
|
||||
}
|
||||
|
||||
void QtUndoRedo::setUndoButtonEnabled(bool enabled)
|
||||
{
|
||||
m_undoButton->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void QtUndoRedo::setRedoButtonEnabled(bool enabled)
|
||||
{
|
||||
m_redoButton->setEnabled(enabled);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef QT_UNDO_REDO_H
|
||||
#define QT_UNDO_REDO_H
|
||||
|
||||
#include <string>
|
||||
#include <QFrame>
|
||||
|
||||
|
||||
class QPushButton;
|
||||
|
||||
class QtUndoRedo
|
||||
: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtUndoRedo();
|
||||
~QtUndoRedo();
|
||||
void setRedoButtonEnabled(bool enabled);
|
||||
void setUndoButtonEnabled(bool enabled);
|
||||
|
||||
private slots:
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
private:
|
||||
QPushButton* m_undoButton;
|
||||
QPushButton* m_redoButton;
|
||||
|
||||
};
|
||||
|
||||
#endif // QT_UNDO_REDO_H
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "qt/view/QtUndoRedoView.h"
|
||||
|
||||
#include "qt/view/QtMainView.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
QtUndoRedoView::QtUndoRedoView(ViewLayout* viewLayout)
|
||||
: UndoRedoView(viewLayout)
|
||||
, m_setRedoButtonEnabledFunctor(std::bind(&QtUndoRedoView::doSetRedoButtonEnabled, this, std::placeholders::_1))
|
||||
, m_setUndoButtonEnabledFunctor(std::bind(&QtUndoRedoView::doSetUndoButtonEnabled, this, std::placeholders::_1))
|
||||
{
|
||||
m_widget = std::make_shared<QtUndoRedo>();
|
||||
setStyleSheet();
|
||||
}
|
||||
|
||||
QtUndoRedoView::~QtUndoRedoView()
|
||||
{
|
||||
}
|
||||
|
||||
void QtUndoRedoView::createWidgetWrapper()
|
||||
{
|
||||
setWidgetWrapper(std::make_shared<QtViewWidgetWrapper>(m_widget));
|
||||
}
|
||||
|
||||
void QtUndoRedoView::initView()
|
||||
{
|
||||
}
|
||||
|
||||
void QtUndoRedoView::refreshView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QtUndoRedoView::setStyleSheet()
|
||||
{
|
||||
std::string css = TextAccess::createFromFile("data/gui/undoredo_view/undoredo_view.css")->getText();
|
||||
|
||||
m_widget->setStyleSheet(css.c_str());
|
||||
|
||||
}
|
||||
|
||||
void QtUndoRedoView::doSetRedoButtonEnabled(bool enabled)
|
||||
{
|
||||
m_widget->setRedoButtonEnabled(enabled);
|
||||
}
|
||||
|
||||
void QtUndoRedoView::doSetUndoButtonEnabled(bool enabled)
|
||||
{
|
||||
m_widget->setUndoButtonEnabled(enabled);
|
||||
}
|
||||
|
||||
void QtUndoRedoView::setRedoButtonEnabled(bool enabled)
|
||||
{
|
||||
m_setRedoButtonEnabledFunctor(enabled);
|
||||
}
|
||||
|
||||
void QtUndoRedoView::setUndoButtonEnabled(bool enabled)
|
||||
{
|
||||
m_setUndoButtonEnabledFunctor(enabled);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef QT_UNDO_REDO_VIEW_H
|
||||
#define QT_UNDO_REDO_VIEW_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "component/view/UndoRedoView.h"
|
||||
#include "qt/element/QtUndoRedo.h"
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
|
||||
class QtUndoRedoView : public UndoRedoView
|
||||
{
|
||||
public:
|
||||
QtUndoRedoView(ViewLayout* viewLayout);
|
||||
~QtUndoRedoView();
|
||||
|
||||
// View implementation
|
||||
virtual void createWidgetWrapper();
|
||||
virtual void initView();
|
||||
virtual void refreshView();
|
||||
|
||||
// UndoRedo view implementation
|
||||
virtual void setRedoButtonEnabled(bool enabled);
|
||||
virtual void setUndoButtonEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
void doSetRedoButtonEnabled(bool enabled);
|
||||
void doSetUndoButtonEnabled(bool enabled);
|
||||
|
||||
QtThreadedFunctor<bool> m_setRedoButtonEnabledFunctor;
|
||||
QtThreadedFunctor<bool> m_setUndoButtonEnabledFunctor;
|
||||
|
||||
void setStyleSheet();
|
||||
std::shared_ptr<QtUndoRedo> m_widget;
|
||||
};
|
||||
|
||||
#endif // !QT_UNDO_REDO_VIEW_H
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "qt/view/QtMainView.h"
|
||||
#include "qt/view/QtSearchView.h"
|
||||
#include "qt/view/QtStatusBarView.h"
|
||||
#include "qt/view/QtUndoRedoView.h"
|
||||
|
||||
QtViewFactory::QtViewFactory()
|
||||
{
|
||||
@@ -38,3 +39,8 @@ std::shared_ptr<StatusBarView> QtViewFactory::createStatusBarView(ViewLayout* vi
|
||||
{
|
||||
return View::createAndDontAddToLayout<QtStatusBarView>(viewLayout);
|
||||
}
|
||||
|
||||
std::shared_ptr<UndoRedoView> QtViewFactory::createUndoRedoView(ViewLayout* viewLayout) const
|
||||
{
|
||||
return View::create<QtUndoRedoView>(viewLayout);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<SearchView> createSearchView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<StatusBarView> createStatusBarView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<UndoRedoView> createUndoRedoView(ViewLayout* viewLayout) const;
|
||||
};
|
||||
|
||||
#endif // QT_VIEW_FACTORY_H
|
||||
|
||||
@@ -36,6 +36,8 @@ add_files(
|
||||
component/controller/SearchController.h
|
||||
component/controller/StatusBarController.cpp
|
||||
component/controller/StatusBarController.h
|
||||
component/controller/UndoRedoController.cpp
|
||||
component/controller/UndoRedoController.h
|
||||
|
||||
component/view/graphElements/GraphEdge.cpp
|
||||
component/view/graphElements/GraphEdge.h
|
||||
@@ -52,6 +54,8 @@ add_files(
|
||||
component/view/SearchView.h
|
||||
component/view/StatusBarView.cpp
|
||||
component/view/StatusBarView.h
|
||||
component/view/UndoRedoView.cpp
|
||||
component/view/UndoRedoView.h
|
||||
component/view/View.cpp
|
||||
component/view/View.h
|
||||
component/view/ViewFactory.cpp
|
||||
@@ -213,6 +217,8 @@ add_files(
|
||||
utility/messaging/type/MessageSearchAutocomplete.h
|
||||
utility/messaging/type/MessageShowFile.h
|
||||
utility/messaging/type/MessageStatus.h
|
||||
utility/messaging/type/MessageRedo.h
|
||||
utility/messaging/type/MessageUndo.h
|
||||
|
||||
utility/messaging/Message.h
|
||||
utility/messaging/MessageBase.h
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
#include "component/controller/GraphController.h"
|
||||
#include "component/controller/SearchController.h"
|
||||
#include "component/controller/StatusBarController.h"
|
||||
#include "component/controller/UndoRedoController.h"
|
||||
#include "component/view/CodeView.h"
|
||||
#include "component/view/GraphView.h"
|
||||
#include "component/view/SearchView.h"
|
||||
#include "component/view/StatusBarView.h"
|
||||
#include "component/view/UndoRedoView.h"
|
||||
#include "component/view/ViewFactory.h"
|
||||
#include "component/view/ViewLayout.h"
|
||||
|
||||
@@ -54,6 +56,15 @@ std::shared_ptr<Component> ComponentFactory::createSearchComponent()
|
||||
return component;
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> ComponentFactory::createUndoRedoComponent()
|
||||
{
|
||||
std::shared_ptr<UndoRedoView> view = m_viewFactory->createUndoRedoView(m_viewLayout);
|
||||
std::shared_ptr<UndoRedoController> controller = std::make_shared<UndoRedoController>();
|
||||
|
||||
std::shared_ptr<Component> component = std::make_shared<Component>(view, controller);
|
||||
return component;
|
||||
}
|
||||
|
||||
std::shared_ptr<Component> ComponentFactory::createStatusBarComponent()
|
||||
{
|
||||
std::shared_ptr<StatusBarView> view = m_viewFactory->createStatusBarView(m_viewLayout);
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
std::shared_ptr<Component> createGraphComponent();
|
||||
std::shared_ptr<Component> createSearchComponent();
|
||||
std::shared_ptr<Component> createStatusBarComponent();
|
||||
std::shared_ptr<Component> createUndoRedoComponent();
|
||||
|
||||
private:
|
||||
ComponentFactory();
|
||||
|
||||
@@ -29,6 +29,9 @@ void ComponentManager::setup()
|
||||
|
||||
std::shared_ptr<Component> statusBarComponent = m_componentFactory->createStatusBarComponent();
|
||||
m_components.push_back(statusBarComponent);
|
||||
|
||||
std::shared_ptr<Component> undoRedoComponent = m_componentFactory->createUndoRedoComponent();
|
||||
m_components.push_back(undoRedoComponent);
|
||||
}
|
||||
|
||||
ComponentManager::ComponentManager()
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
#include "component/controller/UndoRedoController.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "component/view/UndoRedoView.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
UndoRedoController::UndoRedoController()
|
||||
: MessageListener<MessageActivateTokens>(true)
|
||||
, MessageListener<MessageGraphNodeExpand>(true)
|
||||
, MessageListener<MessageGraphNodeMove>(true)
|
||||
, m_lastCommand(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
UndoRedoController::~UndoRedoController()
|
||||
{
|
||||
for(MessageBase* m : m_redo)
|
||||
{
|
||||
delete m;
|
||||
}
|
||||
for(MessageBase* m : m_undo)
|
||||
{
|
||||
delete m;
|
||||
}
|
||||
}
|
||||
|
||||
UndoRedoView* UndoRedoController::getView()
|
||||
{
|
||||
return Controller::getView<UndoRedoView>();
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageActivateTokens* message)
|
||||
{
|
||||
MessageActivateTokens* m = new MessageActivateTokens(message->tokenIds);
|
||||
m->isAggregation = message->isAggregation;
|
||||
m->isEdge = message->isEdge;
|
||||
m->UndoRedoType = message->UndoRedoType;
|
||||
|
||||
processMessage(m);
|
||||
}
|
||||
|
||||
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(MessageRedo* message)
|
||||
{
|
||||
if(!m_redo.empty())
|
||||
{
|
||||
MessageBase* m = m_redo.back();
|
||||
m_redo.pop_back();
|
||||
m->UndoRedoType = MessageBase::UndoType_Redo;
|
||||
m->dispatch();
|
||||
delete m;
|
||||
}
|
||||
}
|
||||
|
||||
void UndoRedoController::handleMessage(MessageUndo* message)
|
||||
{
|
||||
if(!m_undo.empty())
|
||||
{
|
||||
MessageBase* m = m_undo.back();
|
||||
m_undo.pop_back();
|
||||
m->UndoRedoType = MessageBase::UndoType_Undo;
|
||||
m->dispatch();
|
||||
delete m;
|
||||
}
|
||||
}
|
||||
|
||||
void UndoRedoController::processMessage(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UndoRedoController::processNormalMessage(MessageBase* message)
|
||||
{
|
||||
if(m_lastCommand != nullptr)
|
||||
{
|
||||
m_undo.push_back(m_lastCommand);
|
||||
getView()->setUndoButtonEnabled(true);
|
||||
}
|
||||
m_lastCommand = message;
|
||||
while(!m_redo.empty())
|
||||
{
|
||||
MessageBase* m = m_redo.back();
|
||||
m_redo.pop_back();
|
||||
delete m;
|
||||
}
|
||||
getView()->setRedoButtonEnabled(false);
|
||||
}
|
||||
|
||||
void UndoRedoController::processRedoMessage(MessageBase* message)
|
||||
{
|
||||
m_undo.push_back(m_lastCommand);
|
||||
getView()->setUndoButtonEnabled(true);
|
||||
m_lastCommand = message;
|
||||
if(m_redo.empty())
|
||||
{
|
||||
getView()->setRedoButtonEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void UndoRedoController::processUndoMessage(MessageBase* message)
|
||||
{
|
||||
m_redo.push_back(m_lastCommand);
|
||||
getView()->setRedoButtonEnabled(true);
|
||||
m_lastCommand = message;
|
||||
if(m_undo.empty())
|
||||
{
|
||||
getView()->setUndoButtonEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#ifndef UNDO_REDO_CONTROLLER_H
|
||||
#define UNDO_REDO_CONTROLLER_H
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
|
||||
#include "component/controller/Controller.h"
|
||||
|
||||
#include "utility/messaging/MessageBase.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateTokens.h"
|
||||
#include "utility/messaging/type/MessageGraphNodeExpand.h"
|
||||
#include "utility/messaging/type/MessageGraphNodeMove.h"
|
||||
#include "utility/messaging/type/MessageRedo.h"
|
||||
#include "utility/messaging/type/MessageUndo.h"
|
||||
|
||||
class UndoRedoView;
|
||||
|
||||
struct UndoContainer
|
||||
{
|
||||
MessageBase* message;
|
||||
std::vector<MessageBase*> subMessages;
|
||||
};
|
||||
|
||||
class UndoRedoController
|
||||
: public Controller
|
||||
, public MessageListener<MessageActivateTokens>
|
||||
, public MessageListener<MessageGraphNodeExpand>
|
||||
, public MessageListener<MessageGraphNodeMove>
|
||||
, public MessageListener<MessageRedo>
|
||||
, public MessageListener<MessageUndo>
|
||||
{
|
||||
public:
|
||||
UndoRedoController(void);
|
||||
virtual ~UndoRedoController(void);
|
||||
UndoRedoView* getView();
|
||||
private:
|
||||
enum UndoRedoType
|
||||
{
|
||||
UndoRedoType_Normal,
|
||||
UndoRedoType_Undo,
|
||||
UndoRedoType_Redo
|
||||
};
|
||||
|
||||
virtual void handleMessage(MessageActivateTokens* message);
|
||||
virtual void handleMessage(MessageGraphNodeExpand* message);
|
||||
virtual void handleMessage(MessageGraphNodeMove* message);
|
||||
virtual void handleMessage(MessageRedo* message);
|
||||
virtual void handleMessage(MessageUndo* message);
|
||||
|
||||
void processMessage(MessageBase* message);
|
||||
void processNormalMessage(MessageBase* message);
|
||||
void processRedoMessage(MessageBase* message);
|
||||
void processUndoMessage(MessageBase* message);
|
||||
|
||||
MessageBase* m_lastCommand;
|
||||
|
||||
std::deque<MessageBase*> m_undo;
|
||||
std::deque<MessageBase*> m_redo;
|
||||
};
|
||||
|
||||
#endif // UNDO_REDO_CONTROLLER_H
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "component/view/UndoRedoView.h"
|
||||
|
||||
#include "component/controller/UndoRedoController.h"
|
||||
|
||||
UndoRedoView::UndoRedoView(ViewLayout* viewLayout)
|
||||
: View(viewLayout, Vec2i(100,100))
|
||||
{
|
||||
}
|
||||
|
||||
UndoRedoView::~UndoRedoView()
|
||||
{
|
||||
}
|
||||
|
||||
std::string UndoRedoView::getName() const
|
||||
{
|
||||
return "UndoRedoView";
|
||||
}
|
||||
|
||||
UndoRedoController* UndoRedoView::getController()
|
||||
{
|
||||
return View::getController<UndoRedoController>();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef UNDO_REDO_VIEW_H
|
||||
#define UNDO_REDO_VIEW_H
|
||||
|
||||
#include "component/view/View.h"
|
||||
|
||||
class UndoRedoController;
|
||||
|
||||
class UndoRedoView : public View
|
||||
{
|
||||
public:
|
||||
UndoRedoView(ViewLayout* viewLayout);
|
||||
~UndoRedoView(void);
|
||||
|
||||
virtual std::string getName() const;
|
||||
|
||||
virtual void setRedoButtonEnabled(bool enabled) = 0;
|
||||
virtual void setUndoButtonEnabled(bool enabled) = 0;
|
||||
protected:
|
||||
UndoRedoController* getController();
|
||||
};
|
||||
|
||||
#endif //UNDO_REDO_VIEW_H
|
||||
@@ -8,6 +8,7 @@ class GraphView;
|
||||
class MainView;
|
||||
class SearchView;
|
||||
class StatusBarView;
|
||||
class UndoRedoView;
|
||||
class ViewLayout;
|
||||
|
||||
class ViewFactory
|
||||
@@ -21,6 +22,7 @@ public:
|
||||
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const = 0;
|
||||
virtual std::shared_ptr<SearchView> createSearchView(ViewLayout* viewLayout) const = 0;
|
||||
virtual std::shared_ptr<StatusBarView> createStatusBarView(ViewLayout* viewLayout) const = 0;
|
||||
virtual std::shared_ptr<UndoRedoView> createUndoRedoView(ViewLayout* viewLayout) const = 0;
|
||||
};
|
||||
|
||||
#endif // VIEW_FACTORY_H
|
||||
|
||||
@@ -11,6 +11,7 @@ template<typename MessageType>
|
||||
class Message: public MessageBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Message()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -6,11 +6,22 @@
|
||||
class MessageBase
|
||||
{
|
||||
public:
|
||||
enum UndoType
|
||||
{
|
||||
UndoType_Normal,
|
||||
UndoType_Redo,
|
||||
UndoType_Undo,
|
||||
};
|
||||
MessageBase() : UndoRedoType(UndoType_Normal){};
|
||||
virtual ~MessageBase()
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string getType() const = 0;
|
||||
virtual void dispatch() = 0;
|
||||
|
||||
UndoType UndoRedoType;
|
||||
|
||||
};
|
||||
|
||||
#endif // MESSAGE_BASE_H
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef MESSAGE_REDO_H
|
||||
#define MESSAGE_REDO_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageRedo: public Message<MessageRedo>
|
||||
{
|
||||
public:
|
||||
MessageRedo()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageRedo";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MESSAGE_REDO_H
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef MESSAGE_UNDO_H
|
||||
#define MESSAGE_UNDO_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageUndo: public Message<MessageUndo>
|
||||
{
|
||||
public:
|
||||
MessageUndo()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageUndo";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MESSAGE_UNDO_H
|
||||
Reference in New Issue
Block a user