mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 06:32:42 +00:00
Remove dependency of "undo" library with "base"
This commit is contained in:
parent
c88f9b172b
commit
9eebfc5812
@ -7,38 +7,38 @@
|
||||
#ifndef UNDO_OBJECTS_CONTAINER_H_INCLUDED
|
||||
#define UNDO_OBJECTS_CONTAINER_H_INCLUDED
|
||||
|
||||
#include "base/exception.h"
|
||||
#include "undo/object_id.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace undo {
|
||||
|
||||
// Thrown when you use ObjectsContainer::insertObject() with an
|
||||
// existent ID or pointer.
|
||||
class ExistentObjectException : base::Exception
|
||||
{
|
||||
public:
|
||||
ExistentObjectException() { }
|
||||
};
|
||||
// Thrown when you use ObjectsContainer::insertObject() with an
|
||||
// existent ID or pointer.
|
||||
class ExistentObjectException : public std::runtime_error {
|
||||
public:
|
||||
ExistentObjectException()
|
||||
: std::runtime_error("Duplicated object in container") { }
|
||||
};
|
||||
|
||||
// Thrown when an object is not found when
|
||||
// ObjectsContainer::getObject() or removeObject() methods are used.
|
||||
class ObjectNotFoundException : base::Exception
|
||||
{
|
||||
public:
|
||||
ObjectNotFoundException() { }
|
||||
};
|
||||
// Thrown when an object is not found when
|
||||
// ObjectsContainer::getObject() or removeObject() methods are used.
|
||||
class ObjectNotFoundException : public std::runtime_error {
|
||||
public:
|
||||
ObjectNotFoundException()
|
||||
: std::runtime_error("Object not found in container") { }
|
||||
};
|
||||
|
||||
// A container of any kind of object used to generate serializable
|
||||
// references (ID) to instances in memory. It converts a pointer to a
|
||||
// 32-bits ID, and then you can get back the original object pointer
|
||||
// from the ID.
|
||||
//
|
||||
// If the original pointer is deleted, you must use removeObject(),
|
||||
// and if the object is re-created (e.g. by an undo operation),
|
||||
// the object can be added back to the container using insertObject().
|
||||
class ObjectsContainer
|
||||
{
|
||||
public:
|
||||
// A container of any kind of object used to generate serializable
|
||||
// references (ID) to instances in memory. It converts a pointer to a
|
||||
// 32-bits ID, and then you can get back the original object pointer
|
||||
// from the ID.
|
||||
//
|
||||
// If the original pointer is deleted, you must use removeObject(),
|
||||
// and if the object is re-created (e.g. by an undo operation),
|
||||
// the object can be added back to the container using insertObject().
|
||||
class ObjectsContainer {
|
||||
public:
|
||||
virtual ~ObjectsContainer() { };
|
||||
|
||||
// Adds an object in the container and returns an ID, so then you
|
||||
@ -77,7 +77,7 @@ public:
|
||||
return reinterpret_cast<T*>(getObject(id));
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
|
@ -7,15 +7,14 @@
|
||||
#ifndef UNDO_UNDO_EXCEPTION_H_INCLUDED
|
||||
#define UNDO_UNDO_EXCEPTION_H_INCLUDED
|
||||
|
||||
#include "base/exception.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace undo {
|
||||
|
||||
class UndoException : public base::Exception
|
||||
{
|
||||
public:
|
||||
UndoException(const char* msg) throw() : base::Exception(msg) { }
|
||||
};
|
||||
class UndoException : public std::runtime_error {
|
||||
public:
|
||||
UndoException(const char* msg) throw() : std::runtime_error(msg) { }
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
|
@ -14,13 +14,12 @@
|
||||
|
||||
namespace undo {
|
||||
|
||||
class ObjectsContainer;
|
||||
class UndoersStack;
|
||||
class UndoConfigProvider;
|
||||
class ObjectsContainer;
|
||||
class UndoersStack;
|
||||
class UndoConfigProvider;
|
||||
|
||||
class UndoHistoryDelegate
|
||||
{
|
||||
public:
|
||||
class UndoHistoryDelegate {
|
||||
public:
|
||||
virtual ~UndoHistoryDelegate() { }
|
||||
|
||||
// Container of objects to insert & retrieve objects by ID
|
||||
@ -28,11 +27,10 @@ public:
|
||||
|
||||
// Returns the limit of undo history in bytes.
|
||||
virtual size_t getUndoSizeLimit() const = 0;
|
||||
};
|
||||
};
|
||||
|
||||
class UndoHistory : public UndoersCollector
|
||||
{
|
||||
public:
|
||||
class UndoHistory : public UndoersCollector {
|
||||
public:
|
||||
UndoHistory(UndoHistoryDelegate* delegate);
|
||||
virtual ~UndoHistory();
|
||||
|
||||
@ -59,7 +57,7 @@ public:
|
||||
// Returns true if the undoer was added in a group.
|
||||
bool implantUndoerInLastGroup(Undoer* undoer);
|
||||
|
||||
private:
|
||||
private:
|
||||
enum Direction { UndoDirection, RedoDirection };
|
||||
|
||||
void runUndo(Direction direction);
|
||||
@ -74,7 +72,7 @@ private:
|
||||
int m_groupLevel;
|
||||
int m_diffCount;
|
||||
int m_diffSaved;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
|
@ -11,13 +11,12 @@
|
||||
|
||||
namespace undo {
|
||||
|
||||
class ObjectsContainer;
|
||||
class UndoersCollector;
|
||||
class ObjectsContainer;
|
||||
class UndoersCollector;
|
||||
|
||||
// Generic interface to undo/revert an action.
|
||||
class Undoer
|
||||
{
|
||||
public:
|
||||
// Generic interface to undo/revert an action.
|
||||
class Undoer {
|
||||
public:
|
||||
virtual ~Undoer() { }
|
||||
|
||||
// Used to destroy the undoer when it is not needed anymore. A
|
||||
@ -46,7 +45,7 @@ public:
|
||||
// actions to redo the reverted action. It is the main method used
|
||||
// to undo any action.
|
||||
virtual void revert(ObjectsContainer* objects, UndoersCollector* redoers) = 0;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
|
@ -13,16 +13,15 @@
|
||||
|
||||
namespace undo {
|
||||
|
||||
class UndoHistory;
|
||||
class Undoer;
|
||||
class UndoHistory;
|
||||
class Undoer;
|
||||
|
||||
// A stack of undoable actions (Undoers). There exist two stacks (see
|
||||
// the UndoHistory class): One stack to hold actions to be undone (the
|
||||
// "undoers stack"), and another stack were actions are held to redo
|
||||
// reverted actions (the "redoers stack").
|
||||
class UndoersStack : public UndoersCollector
|
||||
{
|
||||
public:
|
||||
// A stack of undoable actions (Undoers). There exist two stacks (see
|
||||
// the UndoHistory class): One stack to hold actions to be undone (the
|
||||
// "undoers stack"), and another stack were actions are held to redo
|
||||
// reverted actions (the "redoers stack").
|
||||
class UndoersStack : public UndoersCollector {
|
||||
public:
|
||||
enum PopFrom {
|
||||
PopFromHead,
|
||||
PopFromTail
|
||||
@ -60,13 +59,13 @@ public:
|
||||
|
||||
size_t countUndoGroups() const;
|
||||
|
||||
private:
|
||||
private:
|
||||
UndoHistory* m_undoHistory;
|
||||
Items m_items;
|
||||
|
||||
// Bytes occupied by all undoers in the stack.
|
||||
size_t m_size;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user