Added history functionality for swapping

Sun, 07 Jul 2013 23:43:43 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sun, 07 Jul 2013 23:43:43 +0300
changeset 362
344fe1da32c8
parent 361
f4c029f2a75b
child 363
75583c9f289d

Added history functionality for swapping

src/history.cpp file | annotate | diff | comparison | revisions
src/history.h file | annotate | diff | comparison | revisions
src/ldtypes.cpp file | annotate | diff | comparison | revisions
--- a/src/history.cpp	Sun Jul 07 23:22:28 2013 +0300
+++ b/src/history.cpp	Sun Jul 07 23:43:43 2013 +0300
@@ -191,4 +191,18 @@
 	g_win->R()->compileObject( newobj );
 }
 
-EditHistory::~EditHistory() {}
\ No newline at end of file
+EditHistory::~EditHistory() {}
+
+// =============================================================================
+
+void SwapHistory::undo() const
+{
+	LDObject::fromID( a )->swap( LDObject::fromID( b ));
+}
+
+void SwapHistory::redo() const
+{
+	undo(); // :v
+}
+
+SwapHistory::~SwapHistory() {}
\ No newline at end of file
--- a/src/history.h	Sun Jul 07 23:22:28 2013 +0300
+++ b/src/history.h	Sun Jul 07 23:43:43 2013 +0300
@@ -23,10 +23,10 @@
 #include "ldtypes.h"
 
 #define IMPLEMENT_HISTORY_TYPE(N) \
-	virtual ~N##History (); \
-	virtual void undo () const; \
-	virtual void redo () const; \
-	virtual History::Type type () { return History::N; }
+	virtual ~N##History(); \
+	virtual void undo() const; \
+	virtual void redo() const; \
+	virtual History::Type type() { return History::N; }
 
 class AbstractHistoryEntry;
 
@@ -42,9 +42,9 @@
 	enum Type {
 		Del,
 		Edit,
-		ListMove,
 		Add,
 		Move,
+		Swap,
 	};
 	
 	History ();
@@ -124,20 +124,6 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-class ListMoveHistory : public AbstractHistoryEntry {
-public:
-	IMPLEMENT_HISTORY_TYPE (ListMove)
-	
-	vector<ulong> idxs;
-	long dest;
-	
-	ListMoveHistory (vector<ulong> idxs, long dest) :
-		idxs (idxs), dest (dest) {}
-};
-
-// =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
 class AddHistory : public AbstractHistoryEntry {
 public:
 	enum Type {
@@ -170,4 +156,13 @@
 		indices (indices), dest (dest) {}
 };
 
+class SwapHistory : public AbstractHistoryEntry
+{
+public:
+	IMPLEMENT_HISTORY_TYPE( Swap )
+	ulong a, b;
+	
+	SwapHistory( ulong a, ulong b ) : a( a ), b( b ) {}
+};
+
 #endif // HISTORY_H
\ No newline at end of file
--- a/src/ldtypes.cpp	Sun Jul 07 23:22:28 2013 +0300
+++ b/src/ldtypes.cpp	Sun Jul 07 23:43:43 2013 +0300
@@ -194,6 +194,8 @@
 		elif( obj == other )
 			obj = this;
 	}
+	
+	g_curfile->addToHistory( new SwapHistory( id(), other->id() ));
 }
 
 LDLine::LDLine( vertex v1, vertex v2 )

mercurial