new undo_modification context manager on select nodes stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 01 Jul 2011 15:30:06 +0200
branchstable
changeset 638 9d0f53bac016
parent 637 23ae480e4e43
child 639 1a9f3c52176b
new undo_modification context manager on select nodes
stmts.py
--- a/stmts.py	Fri Jul 01 12:08:52 2011 +0200
+++ b/stmts.py	Fri Jul 01 15:30:06 2011 +0200
@@ -48,6 +48,13 @@
             raise AssertionError('vref %r is not referenced (%r)' % (vref, vref.stmt))
     return True
 
+class undo_modification(object):
+    def __init__(self, select):
+        self.select = select
+    def __enter__(self):
+        self.select.save_state()
+    def __exit__(self):
+        self.select.recover()
 
 class ScopeNode(BaseNode):
     solutions = ()   # list of possibles solutions for used variables
@@ -355,6 +362,9 @@
     def should_register_op(self):
         return self.memorizing and not self.undoing
 
+    def undo_modification(self):
+        return undo_modification(self)
+
     def save_state(self):
         """save the current tree"""
         self.undo_manager.push_state()