Added the beginnings of a class to represent an undo list.
git-svn-id: http://openexile.googlecode.com/svn/trunk@82 4ebdad44-0ea0-11de-aab3-ff745001d230
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
2BF04B2E0BF51924006C0831 /* boe.town.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2BF04B090BF51924006C0831 /* boe.town.cpp */; };
|
||||
2BF04DE90BF7A6FE006C0831 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BF04DE80BF7A6FE006C0831 /* Carbon.framework */; };
|
||||
9122832E0FCF6C7200B21642 /* busywork.exs in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9122832D0FCF6C7200B21642 /* busywork.exs */; };
|
||||
912283C90FD0E16C00B21642 /* undo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 912283C80FD0E16C00B21642 /* undo.cpp */; };
|
||||
9127903E0F9B7F49007B0D52 /* boe.actions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2BF04ACF0BF51923006C0831 /* boe.actions.cpp */; };
|
||||
9127903F0F9B7F50007B0D52 /* boe.graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2BF04AD30BF51923006C0831 /* boe.graphics.cpp */; };
|
||||
912793640F9C107B007B0D52 /* viewdlog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91B3EEF80F969BA700BF5B67 /* viewdlog.cpp */; };
|
||||
@@ -331,6 +332,8 @@
|
||||
910BBAD90FB91D2A001E34EA /* dlogutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = dlogutil.h; path = dialogxml/dlogutil.h; sourceTree = "<group>"; };
|
||||
910BBADA0FB91D2A001E34EA /* dlogutil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = dlogutil.cpp; path = dialogxml/dlogutil.cpp; sourceTree = "<group>"; };
|
||||
9122832D0FCF6C7200B21642 /* busywork.exs */ = {isa = PBXFileReference; lastKnownFileType = file; path = busywork.exs; sourceTree = "<group>"; };
|
||||
912283C70FD0E16B00B21642 /* undo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = undo.h; path = tools/undo.h; sourceTree = "<group>"; };
|
||||
912283C80FD0E16C00B21642 /* undo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = undo.cpp; path = tools/undo.cpp; sourceTree = "<group>"; };
|
||||
912793480F9C0FE6007B0D52 /* ViewDlog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ViewDlog.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
912798AE0F9CA636007B0D52 /* dlgbtns.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = dlgbtns.cpp; path = tools/dlgbtns.cpp; sourceTree = "<group>"; };
|
||||
91279BAD0F9CFCBA007B0D52 /* boescenario.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = boescenario.icns; sourceTree = "<group>"; };
|
||||
@@ -804,6 +807,8 @@
|
||||
910BBA130FB8BE66001E34EA /* dialogs */,
|
||||
913D03350FA1000200184C18 /* headers */,
|
||||
913D03340FA0FFFF00184C18 /* src */,
|
||||
912283C70FD0E16B00B21642 /* undo.h */,
|
||||
912283C80FD0E16C00B21642 /* undo.cpp */,
|
||||
);
|
||||
name = tools;
|
||||
sourceTree = "<group>";
|
||||
@@ -1231,6 +1236,7 @@
|
||||
91C1FCA90FCB6F7200EBAA65 /* field.cpp in Sources */,
|
||||
91C1FCAA0FCB6F7200EBAA65 /* message.cpp in Sources */,
|
||||
91C1FCAB0FCB6F7300EBAA65 /* pict.cpp in Sources */,
|
||||
912283C90FD0E16C00B21642 /* undo.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
40
osx/tools/undo.cpp
Normal file
40
osx/tools/undo.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* undo.cpp
|
||||
* BoE
|
||||
*
|
||||
* Created by Celtic Minstrel on 29/05/09.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "undo.h"
|
||||
|
||||
cUndoList::cUndoList(){
|
||||
lastSave = cur = theList.begin();
|
||||
}
|
||||
|
||||
size_t cUndoList::maxUndoSize = 0;
|
||||
|
||||
//TODO: These functions should have error checking to ensure they do not access an out of bounds action
|
||||
void cUndoList::undo(){
|
||||
(*cur)->undo();
|
||||
cur--;
|
||||
}
|
||||
|
||||
void cUndoList::redo(){
|
||||
cur++;
|
||||
(*cur)->redo();
|
||||
}
|
||||
|
||||
void cUndoList::save(){
|
||||
lastSave = cur;
|
||||
}
|
||||
|
||||
void cUndoList::revert(){
|
||||
while(cur != lastSave) undo();
|
||||
}
|
||||
|
||||
void cUndoList::add(cAction* what){
|
||||
theList.push_back(what);
|
||||
num_actions++;
|
||||
while(num_actions > maxUndoSize) theList.pop_front(), num_actions--;
|
||||
}
|
45
osx/tools/undo.h
Normal file
45
osx/tools/undo.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* undo.h
|
||||
* BoE
|
||||
*
|
||||
* Created by Celtic Minstrel on 29/05/09.
|
||||
*
|
||||
* For use in creating an undo history in the scenario editor.
|
||||
* Could also be used in the PC editor.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <list>
|
||||
|
||||
class cAction {
|
||||
public:
|
||||
virtual void undo() = 0; // undoes this action if it has not already been undone
|
||||
virtual void redo() = 0; // redoes this action if it has been undone
|
||||
virtual bool isDone() = 0; // checks to see whether the action has been undone; returns false if it has
|
||||
virtual std::string getActionName() = 0; // returns the name of this action for display in the Edit menu
|
||||
virtual ~cAction();
|
||||
};
|
||||
|
||||
class cUndoList {
|
||||
std::list<cAction*> theList;
|
||||
std::list<cAction*>::iterator cur, lastSave;
|
||||
size_t num_actions;
|
||||
public:
|
||||
cUndoList();
|
||||
void undo(); // undoes the current action and decrements the cur pointer
|
||||
void redo(); // increments the cur pointer and redoes the current action
|
||||
void save(); // sets the last saved action to the current action
|
||||
void revert(); // undoes all actions back to (but excluding) the last saved action
|
||||
void add(cAction* what);
|
||||
static size_t maxUndoSize;
|
||||
};
|
||||
|
||||
// As a special convention, I will prefix action classes with 'a' instead of 'c'
|
||||
/*
|
||||
class aEditMonster : public cAction {
|
||||
cMonster oldMonst, newMonst;
|
||||
};
|
||||
|
||||
class aEditItem : public cAction {
|
||||
cItemRec oldItem, newItem;
|
||||
};*/
|
Reference in New Issue
Block a user