mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Replace UndoConfigProvider with UndoHistoryDelegate interface
This commit is contained in:
parent
b1fa72b585
commit
2ddb0ea181
@ -30,12 +30,11 @@
|
||||
|
||||
DocumentUndo::DocumentUndo()
|
||||
: m_objects(new ObjectsContainerImpl)
|
||||
, m_undoHistory(new undo::UndoHistory(m_objects, this))
|
||||
, m_undoHistory(new undo::UndoHistory(this))
|
||||
, m_enabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool DocumentUndo::canUndo() const
|
||||
{
|
||||
return m_undoHistory->canUndo();
|
||||
@ -71,11 +70,6 @@ void DocumentUndo::markSavedState()
|
||||
return m_undoHistory->markSavedState();
|
||||
}
|
||||
|
||||
undo::ObjectsContainer* DocumentUndo::getObjects() const
|
||||
{
|
||||
return m_undoHistory->getObjects();
|
||||
}
|
||||
|
||||
void DocumentUndo::pushUndoer(undo::Undoer* undoer)
|
||||
{
|
||||
return m_undoHistory->pushUndoer(undoer);
|
||||
@ -86,7 +80,7 @@ bool DocumentUndo::implantUndoerInLastGroup(undo::Undoer* undoer)
|
||||
return m_undoHistory->implantUndoerInLastGroup(undoer);
|
||||
}
|
||||
|
||||
size_t DocumentUndo::getUndoSizeLimit()
|
||||
size_t DocumentUndo::getUndoSizeLimit() const
|
||||
{
|
||||
return ((size_t)get_config_int("Options", "UndoSizeLimit", 8))*1024*1024;
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "base/disable_copying.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "raster/sprite_position.h"
|
||||
#include "undo/undo_config_provider.h"
|
||||
#include "undo/undo_history.h"
|
||||
|
||||
namespace undo {
|
||||
@ -35,7 +34,7 @@ namespace undoers {
|
||||
class CloseGroup;
|
||||
}
|
||||
|
||||
class DocumentUndo : public undo::UndoConfigProvider
|
||||
class DocumentUndo : public undo::UndoHistoryDelegate
|
||||
{
|
||||
public:
|
||||
DocumentUndo();
|
||||
@ -54,7 +53,9 @@ public:
|
||||
bool isSavedState() const;
|
||||
void markSavedState();
|
||||
|
||||
undo::ObjectsContainer* getObjects() const;
|
||||
// UndoHistoryDelegate implementation.
|
||||
undo::ObjectsContainer* getObjects() const OVERRIDE { return m_objects; }
|
||||
size_t getUndoSizeLimit() const OVERRIDE;
|
||||
|
||||
void pushUndoer(undo::Undoer* undoer);
|
||||
|
||||
@ -67,8 +68,6 @@ public:
|
||||
SpritePosition getNextRedoSpritePosition() const;
|
||||
|
||||
private:
|
||||
size_t getUndoSizeLimit() OVERRIDE;
|
||||
|
||||
undoers::CloseGroup* getNextUndoGroup() const;
|
||||
undoers::CloseGroup* getNextRedoGroup() const;
|
||||
|
||||
|
@ -1,23 +0,0 @@
|
||||
// ASEPRITE Undo Library
|
||||
// Copyright (C) 2001-2012 David Capello
|
||||
//
|
||||
// This source file is distributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef UNDO_UNDO_CONFIG_PROVIDER_H_INCLUDED
|
||||
#define UNDO_UNDO_CONFIG_PROVIDER_H_INCLUDED
|
||||
|
||||
namespace undo {
|
||||
|
||||
class UndoConfigProvider
|
||||
{
|
||||
public:
|
||||
virtual ~UndoConfigProvider() { }
|
||||
|
||||
// Returns the limit of undo history in bytes.
|
||||
virtual size_t getUndoSizeLimit() = 0;
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
||||
#endif // UNDO_UNDO_CONFIG_PROVIDER_H_INCLUDED
|
@ -9,7 +9,6 @@
|
||||
#include "undo/undo_history.h"
|
||||
|
||||
#include "undo/objects_container.h"
|
||||
#include "undo/undo_config_provider.h"
|
||||
#include "undo/undoer.h"
|
||||
#include "undo/undoers_stack.h"
|
||||
|
||||
@ -17,9 +16,8 @@
|
||||
|
||||
using namespace undo;
|
||||
|
||||
UndoHistory::UndoHistory(ObjectsContainer* objects, UndoConfigProvider* configProvider)
|
||||
: m_objects(objects)
|
||||
, m_configProvider(configProvider)
|
||||
UndoHistory::UndoHistory(UndoHistoryDelegate* delegate)
|
||||
: m_delegate(delegate)
|
||||
{
|
||||
m_groupLevel = 0;
|
||||
m_diffCount = 0;
|
||||
@ -213,16 +211,9 @@ void UndoHistory::checkSizeLimit()
|
||||
{
|
||||
// Is undo history too big?
|
||||
size_t groups = m_undoers->countUndoGroups();
|
||||
while (groups > 1 && m_undoers->getMemSize() > getUndoSizeLimit()) {
|
||||
size_t undoLimit = m_delegate->getUndoSizeLimit();
|
||||
while (groups > 1 && m_undoers->getMemSize() > undoLimit) {
|
||||
discardTail();
|
||||
groups--;
|
||||
}
|
||||
}
|
||||
|
||||
size_t UndoHistory::getUndoSizeLimit()
|
||||
{
|
||||
if (m_configProvider)
|
||||
return m_configProvider->getUndoSizeLimit();
|
||||
else
|
||||
return std::numeric_limits<size_t>::max();
|
||||
}
|
||||
|
@ -18,10 +18,22 @@ class ObjectsContainer;
|
||||
class UndoersStack;
|
||||
class UndoConfigProvider;
|
||||
|
||||
class UndoHistoryDelegate
|
||||
{
|
||||
public:
|
||||
virtual ~UndoHistoryDelegate() { }
|
||||
|
||||
// Container of objects to insert & retrieve objects by ID
|
||||
virtual ObjectsContainer* getObjects() const = 0;
|
||||
|
||||
// Returns the limit of undo history in bytes.
|
||||
virtual size_t getUndoSizeLimit() const = 0;
|
||||
};
|
||||
|
||||
class UndoHistory : public UndoersCollector
|
||||
{
|
||||
public:
|
||||
UndoHistory(ObjectsContainer* objects, UndoConfigProvider* configProvider);
|
||||
UndoHistory(UndoHistoryDelegate* delegate);
|
||||
virtual ~UndoHistory();
|
||||
|
||||
bool canUndo() const;
|
||||
@ -38,7 +50,7 @@ public:
|
||||
bool isSavedState() const;
|
||||
void markSavedState();
|
||||
|
||||
ObjectsContainer* getObjects() const { return m_objects; }
|
||||
ObjectsContainer* getObjects() const { return m_delegate->getObjects(); }
|
||||
|
||||
// UndoersCollector interface
|
||||
void pushUndoer(Undoer* undoer);
|
||||
@ -55,15 +67,13 @@ private:
|
||||
void updateUndo();
|
||||
void postUndoerAddedEvent(Undoer* undoer);
|
||||
void checkSizeLimit();
|
||||
size_t getUndoSizeLimit();
|
||||
|
||||
ObjectsContainer* m_objects; // Container of objects to insert & retrieve objects by ID
|
||||
UndoHistoryDelegate* m_delegate;
|
||||
UndoersStack* m_undoers;
|
||||
UndoersStack* m_redoers;
|
||||
int m_groupLevel;
|
||||
int m_diffCount;
|
||||
int m_diffSaved;
|
||||
UndoConfigProvider* m_configProvider;
|
||||
};
|
||||
|
||||
} // namespace undo
|
||||
|
Loading…
x
Reference in New Issue
Block a user