Mercurial > fife-parpg
comparison tools/editor/scripts/tests/undotest.py @ 378:64738befdf3b
bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author | vtchill@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 11 Jan 2010 23:34:52 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2009 by the FIFE team | |
5 # http://www.fifengine.de | |
6 # This file is part of FIFE. | |
7 # | |
8 # FIFE is free software; you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public | |
10 # License as published by the Free Software Foundation; either | |
11 # version 2.1 of the License, or (at your option) any later version. | |
12 # | |
13 # This library is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this library; if not, write to the | |
20 # Free Software Foundation, Inc., | |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 # #################################################################### | |
23 | |
24 import scripts.undomanager as undomanager | |
25 | |
26 print "Testing undomanager:" | |
27 umanager = undomanager.UndoManager(branchedMode=False) | |
28 | |
29 print "--- Testing basic undo/redo ---" | |
30 | |
31 print "Adding 3 actions:" | |
32 def undoPrint(msg): | |
33 print msg | |
34 def newAction(nr): | |
35 undo = lambda: undoPrint("Undo: "+str(nr)) | |
36 redo = lambda: undoPrint("Redo: "+str(nr)) | |
37 return undomanager.UndoObject(undo, redo, "Name: "+str(nr), "Description: "+str(nr)) | |
38 | |
39 | |
40 umanager.addAction(newAction("1")) | |
41 umanager.addAction(newAction("2")) | |
42 umanager.addAction(newAction("3")) | |
43 | |
44 print "Undoing 3 actions:" | |
45 umanager.undo(3); | |
46 | |
47 print "Redoing 3 actions, individually:" | |
48 umanager.redo() | |
49 umanager.redo() | |
50 umanager.redo() | |
51 | |
52 print "--- Testing undogroups ---" | |
53 print "10 actions, 2 undogroups nested within 1 undogroup" | |
54 umanager.startGroup("ActionGroup 1", "Desc: AG1") | |
55 umanager.addAction(newAction("1")) | |
56 umanager.addAction(newAction("2")) | |
57 umanager.addAction(newAction("3")) | |
58 umanager.startGroup("ActionGroup 2", "AG2") | |
59 umanager.addAction(newAction("4")) | |
60 umanager.addAction(newAction("5")) | |
61 umanager.addAction(newAction("6")) | |
62 umanager.endGroup() | |
63 umanager.startGroup("ActionGroup 2", "AG2") | |
64 umanager.addAction(newAction("7")) | |
65 umanager.addAction(newAction("8")) | |
66 umanager.addAction(newAction("9")) | |
67 umanager.addAction(newAction("10")) | |
68 umanager.endGroup() | |
69 umanager.endGroup() | |
70 | |
71 print "Undoing group:" | |
72 umanager.undo() | |
73 | |
74 print "Redo" | |
75 umanager.redo() | |
76 | |
77 print "--- Testing branches (without branch mode) ---" | |
78 print "Branch mode:", umanager.getBranchMode() | |
79 | |
80 print "Setting up actions" | |
81 umanager.addAction(newAction("1-1")) | |
82 umanager.addAction(newAction("1-2")) | |
83 umanager.addAction(newAction("1-3")) | |
84 umanager.undo(3) | |
85 umanager.addAction(newAction("2-1")) | |
86 umanager.addAction(newAction("2-2")) | |
87 umanager.addAction(newAction("2-3")) | |
88 umanager.undo(3) | |
89 umanager.addAction(newAction("3-1")) | |
90 umanager.addAction(newAction("3-2")) | |
91 umanager.addAction(newAction("3-3")) | |
92 umanager.undo(3) | |
93 print "Branches", umanager.getBranches() | |
94 print "Next branch" | |
95 umanager.nextBranch() | |
96 umanager.redo(3) | |
97 umanager.undo(3) | |
98 print "Prev branch" | |
99 umanager.previousBranch() | |
100 umanager.redo(3) | |
101 | |
102 print "--- Testing branches (with branch mode) ---" | |
103 print "Activating branch mode:" | |
104 umanager.setBranchMode(True) | |
105 print "Branch mode:", umanager.getBranchMode() | |
106 | |
107 print "Setting up actions" | |
108 umanager.addAction(newAction("1-1")) | |
109 umanager.addAction(newAction("1-2")) | |
110 umanager.addAction(newAction("1-3")) | |
111 umanager.undo(3) | |
112 umanager.addAction(newAction("2-1")) | |
113 umanager.addAction(newAction("2-2")) | |
114 umanager.addAction(newAction("2-3")) | |
115 umanager.undo(3) | |
116 umanager.addAction(newAction("3-1")) | |
117 umanager.addAction(newAction("3-2")) | |
118 umanager.addAction(newAction("3-3")) | |
119 umanager.undo(3) | |
120 print "Branches", umanager.getBranches() | |
121 print "Next branch" | |
122 umanager.nextBranch() | |
123 umanager.redo(3) | |
124 umanager.undo(3) | |
125 print "Prev branch" | |
126 umanager.previousBranch() | |
127 umanager.redo(3) | |
128 | |
129 import gc | |
130 print "--- Testing clear() function ---" | |
131 print "Checking garbage:", gc.collect(), "Uncollectable:", len(gc.garbage) | |
132 print "Clearing history" | |
133 umanager.clear() | |
134 print "Checking garbage:", gc.collect(), "Uncollectable:", len(gc.garbage) | |
135 | |
136 print "--- Done ---" |