Commits

Anonymous committed b3926a4

changestack: moved ChangeStack from history

  • Participants
  • Parent commits 7b66da0

Comments (0)

Files changed (4)

File rope/base/history.py

         del self.redo_list[:]
 
 
-class ChangeStack(object):
-
-    def __init__(self, project, description='merged changes'):
-        self.project = project
-        self.description = description
-        self.stack = []
-
-    def push_change(self, changes):
-        self.stack.append(changes)
-        self.project.do(changes)
-
-    def pop_all(self):
-        for i in range(len(self.stack)):
-            self.project.history.undo()
-
-    def merged_changes(self):
-        result = change.ChangeSet(self.description)
-        for changes in self.stack:
-            for c in self._basic_changes(changes):
-                result.add_change(c)
-        return result
-
-    def _basic_changes(self, changes):
-        if isinstance(changes, change.ChangeSet):
-            for child in changes.changes:
-                for atom in self._basic_changes(child):
-                    yield atom
-        else:
-            yield changes
-
-
 class _FindChangeDependencies(object):
 
     def __init__(self, change_list):

File rope/contrib/changestack.py

+from rope.base import change
+
+
+class ChangeStack(object):
+
+    def __init__(self, project, description='merged changes'):
+        self.project = project
+        self.description = description
+        self.stack = []
+
+    def push_change(self, changes):
+        self.stack.append(changes)
+        self.project.do(changes)
+
+    def pop_all(self):
+        for i in range(len(self.stack)):
+            self.project.history.undo()
+
+    def merged_changes(self):
+        result = change.ChangeSet(self.description)
+        for changes in self.stack:
+            for c in self._basic_changes(changes):
+                result.add_change(c)
+        return result
+
+    def _basic_changes(self, changes):
+        if isinstance(changes, change.ChangeSet):
+            for child in changes.changes:
+                for atom in self._basic_changes(child):
+                    yield atom
+        else:
+            yield changes

File ropetest/contrib/changestacktest.py

+import unittest
+
+import rope.base.history
+import rope.contrib.changestack
+from rope.base.change import *
+from ropetest import testutils
+
+
+class ChangeStackTest(unittest.TestCase):
+
+    def setUp(self):
+        super(ChangeStackTest, self).setUp()
+        self.project = testutils.sample_project()
+
+    def tearDown(self):
+        testutils.remove_project(self.project)
+        super(ChangeStackTest, self).tearDown()
+
+    def test_change_stack(self):
+        myfile = self.project.root.create_file('myfile.txt')
+        myfile.write('1')
+        stack = rope.contrib.changestack.ChangeStack(self.project)
+        stack.push_change(ChangeContents(myfile, '2'))
+        self.assertEquals('2', myfile.read())
+        stack.push_change(ChangeContents(myfile, '3'))
+        self.assertEquals('3', myfile.read())
+        stack.pop_all()
+        self.assertEquals('1', myfile.read())
+        changes = stack.merged_changes()
+        self.project.do(changes)
+        self.assertEquals('3', myfile.read())
+
+
+if __name__ == '__main__':
+    unittest.main()

File ropetest/historytest.py

         history.redo()
         self.assertTrue(myfile.exists())
 
-class ChangeStackTest(unittest.TestCase):
-
-    def setUp(self):
-        super(ChangeStackTest, self).setUp()
-        self.project = testutils.sample_project()
-
-    def tearDown(self):
-        testutils.remove_project(self.project)
-        super(ChangeStackTest, self).tearDown()
-
-    def test_change_stack(self):
-        myfile = self.project.root.create_file('myfile.txt')
-        myfile.write('1')
-        stack = rope.base.history.ChangeStack(self.project)
-        stack.push_change(ChangeContents(myfile, '2'))
-        self.assertEquals('2', myfile.read())
-        stack.push_change(ChangeContents(myfile, '3'))
-        self.assertEquals('3', myfile.read())
-        stack.pop_all()
-        self.assertEquals('1', myfile.read())
-        changes = stack.merged_changes()
-        self.project.do(changes)
-        self.assertEquals('3', myfile.read())
-
-
 def suite():
     result = unittest.TestSuite()
     result.addTests(unittest.makeSuite(HistoryTest))
     result.addTests(unittest.makeSuite(IsolatedHistoryTest))
     result.addTests(unittest.makeSuite(SavingHistoryTest))
-    result.addTests(unittest.makeSuite(ChangeStackTest))
     return result
 
 if __name__ == '__main__':