mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-02 13:20:12 +00:00
Replace UndoConfigProvider with UndoHistoryDelegate interface
This commit is contained in:
parent
b1fa72b585
commit
2ddb0ea181
@ -30,12 +30,11 @@
|
|||||||
|
|
||||||
DocumentUndo::DocumentUndo()
|
DocumentUndo::DocumentUndo()
|
||||||
: m_objects(new ObjectsContainerImpl)
|
: m_objects(new ObjectsContainerImpl)
|
||||||
, m_undoHistory(new undo::UndoHistory(m_objects, this))
|
, m_undoHistory(new undo::UndoHistory(this))
|
||||||
, m_enabled(true)
|
, m_enabled(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool DocumentUndo::canUndo() const
|
bool DocumentUndo::canUndo() const
|
||||||
{
|
{
|
||||||
return m_undoHistory->canUndo();
|
return m_undoHistory->canUndo();
|
||||||
@ -71,11 +70,6 @@ void DocumentUndo::markSavedState()
|
|||||||
return m_undoHistory->markSavedState();
|
return m_undoHistory->markSavedState();
|
||||||
}
|
}
|
||||||
|
|
||||||
undo::ObjectsContainer* DocumentUndo::getObjects() const
|
|
||||||
{
|
|
||||||
return m_undoHistory->getObjects();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentUndo::pushUndoer(undo::Undoer* undoer)
|
void DocumentUndo::pushUndoer(undo::Undoer* undoer)
|
||||||
{
|
{
|
||||||
return m_undoHistory->pushUndoer(undoer);
|
return m_undoHistory->pushUndoer(undoer);
|
||||||
@ -86,7 +80,7 @@ bool DocumentUndo::implantUndoerInLastGroup(undo::Undoer* undoer)
|
|||||||
return m_undoHistory->implantUndoerInLastGroup(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;
|
return ((size_t)get_config_int("Options", "UndoSizeLimit", 8))*1024*1024;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include "base/disable_copying.h"
|
#include "base/disable_copying.h"
|
||||||
#include "base/unique_ptr.h"
|
#include "base/unique_ptr.h"
|
||||||
#include "raster/sprite_position.h"
|
#include "raster/sprite_position.h"
|
||||||
#include "undo/undo_config_provider.h"
|
|
||||||
#include "undo/undo_history.h"
|
#include "undo/undo_history.h"
|
||||||
|
|
||||||
namespace undo {
|
namespace undo {
|
||||||
@ -35,7 +34,7 @@ namespace undoers {
|
|||||||
class CloseGroup;
|
class CloseGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DocumentUndo : public undo::UndoConfigProvider
|
class DocumentUndo : public undo::UndoHistoryDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DocumentUndo();
|
DocumentUndo();
|
||||||
@ -54,7 +53,9 @@ public:
|
|||||||
bool isSavedState() const;
|
bool isSavedState() const;
|
||||||
void markSavedState();
|
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);
|
void pushUndoer(undo::Undoer* undoer);
|
||||||
|
|
||||||
@ -67,8 +68,6 @@ public:
|
|||||||
SpritePosition getNextRedoSpritePosition() const;
|
SpritePosition getNextRedoSpritePosition() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t getUndoSizeLimit() OVERRIDE;
|
|
||||||
|
|
||||||
undoers::CloseGroup* getNextUndoGroup() const;
|
undoers::CloseGroup* getNextUndoGroup() const;
|
||||||
undoers::CloseGroup* getNextRedoGroup() 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/undo_history.h"
|
||||||
|
|
||||||
#include "undo/objects_container.h"
|
#include "undo/objects_container.h"
|
||||||
#include "undo/undo_config_provider.h"
|
|
||||||
#include "undo/undoer.h"
|
#include "undo/undoer.h"
|
||||||
#include "undo/undoers_stack.h"
|
#include "undo/undoers_stack.h"
|
||||||
|
|
||||||
@ -17,9 +16,8 @@
|
|||||||
|
|
||||||
using namespace undo;
|
using namespace undo;
|
||||||
|
|
||||||
UndoHistory::UndoHistory(ObjectsContainer* objects, UndoConfigProvider* configProvider)
|
UndoHistory::UndoHistory(UndoHistoryDelegate* delegate)
|
||||||
: m_objects(objects)
|
: m_delegate(delegate)
|
||||||
, m_configProvider(configProvider)
|
|
||||||
{
|
{
|
||||||
m_groupLevel = 0;
|
m_groupLevel = 0;
|
||||||
m_diffCount = 0;
|
m_diffCount = 0;
|
||||||
@ -213,16 +211,9 @@ void UndoHistory::checkSizeLimit()
|
|||||||
{
|
{
|
||||||
// Is undo history too big?
|
// Is undo history too big?
|
||||||
size_t groups = m_undoers->countUndoGroups();
|
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();
|
discardTail();
|
||||||
groups--;
|
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 UndoersStack;
|
||||||
class UndoConfigProvider;
|
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
|
class UndoHistory : public UndoersCollector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UndoHistory(ObjectsContainer* objects, UndoConfigProvider* configProvider);
|
UndoHistory(UndoHistoryDelegate* delegate);
|
||||||
virtual ~UndoHistory();
|
virtual ~UndoHistory();
|
||||||
|
|
||||||
bool canUndo() const;
|
bool canUndo() const;
|
||||||
@ -38,7 +50,7 @@ public:
|
|||||||
bool isSavedState() const;
|
bool isSavedState() const;
|
||||||
void markSavedState();
|
void markSavedState();
|
||||||
|
|
||||||
ObjectsContainer* getObjects() const { return m_objects; }
|
ObjectsContainer* getObjects() const { return m_delegate->getObjects(); }
|
||||||
|
|
||||||
// UndoersCollector interface
|
// UndoersCollector interface
|
||||||
void pushUndoer(Undoer* undoer);
|
void pushUndoer(Undoer* undoer);
|
||||||
@ -55,15 +67,13 @@ private:
|
|||||||
void updateUndo();
|
void updateUndo();
|
||||||
void postUndoerAddedEvent(Undoer* undoer);
|
void postUndoerAddedEvent(Undoer* undoer);
|
||||||
void checkSizeLimit();
|
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_undoers;
|
||||||
UndoersStack* m_redoers;
|
UndoersStack* m_redoers;
|
||||||
int m_groupLevel;
|
int m_groupLevel;
|
||||||
int m_diffCount;
|
int m_diffCount;
|
||||||
int m_diffSaved;
|
int m_diffSaved;
|
||||||
UndoConfigProvider* m_configProvider;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace undo
|
} // namespace undo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user