Commits

Anonymous committed 8d3e095

updating moved buffers after undos

Comments (0)

Files changed (2)

ropemacs/interface.py

+import rope.base.change
 from Pymacs import lisp
-from rope.base import project, libutils
+from rope.base import libutils
 from rope.contrib import codeassist, generate
 
 import ropemacs
         if self.project is not None:
             self.close_project()
         progress = lisputils.create_progress('Opening "%s" project' % root)
-        self.project = project.Project(root)
+        self.project = rope.base.project.Project(root)
         progress.done()
 
     @interactive
         if lisp.y_or_n_p('Undo <%s>? ' % str(change)):
             def undo(handle):
                 for changes in self.project.history.undo(task_handle=handle):
-                    self._reload_buffers(changes.get_changed_resources())
+                    self._reload_buffers(changes, undo=True)
             lisputils.RunTask(undo, 'Undo refactoring', interrupts=False)()
 
     @interactive
         if lisp.y_or_n_p('Redo <%s>? ' % str(change)):
             def redo(handle):
                 for changes in self.project.history.redo(task_handle=handle):
-                    self._reload_buffers(changes.get_changed_resources())
+                    self._reload_buffers(changes)
             lisputils.RunTask(redo, 'Redo refactoring', interrupts=False)()
 
     def _get_region(self):
             coding = lisp['buffer-file-coding-system'].value()
         if isinstance(coding, str):
             return coding
-        elif coding is not None and hasattr(coding, 'text'):
+        if coding is not None and hasattr(coding, 'text'):
             return coding.text
 
     @interactive
         else:
             self.project.validate(self.project.root)
 
-    def _reload_buffers(self, changed_resources, moved={}):
+    def _reload_buffers(self, changes, undo=False):
+        self._reload_buffers_for_changes(changes.get_changed_resources(),
+                             self._get_moved_resources(changes, undo))
+
+    def _reload_buffers_for_changes(self, changed_resources,
+                                    moved_resources={}):
         for resource in changed_resources:
             buffer = lisp.find_buffer_visiting(str(resource.real_path))
             if buffer:
                 if resource.exists():
                     lisp.set_buffer(buffer)
                     lisp.revert_buffer(None, 1)
-                elif resource in moved:
-                    new_resource = moved[resource]
+                elif resource in moved_resources:
+                    new_resource = moved_resources[resource]
                     lisp.kill_buffer(buffer)
                     lisp.find_file(new_resource.real_path)
 
+    def _get_moved_resources(self, changes, undo=False):
+        result = {}
+        if isinstance(changes, rope.base.change.ChangeSet):
+            for change in changes.changes:
+                result.update(self._get_moved_resources(change))
+        if isinstance(changes, rope.base.change.MoveResource):
+            result[changes.resource] = changes.new_resource
+        if undo:
+            return dict([(value, key) for key, value in result.items()])
+        return result
+
     def _save_buffers(self, only_current=False):
         ask = lisp['ropemacs-confirm-saving'].value()
         initial = lisp.current_buffer()

ropemacs/refactor.py

             return
         def perform(handle, self=self, changes=changes):
             self.project.do(changes, task_handle=handle)
-            self.interface._reload_buffers(changes.get_changed_resources(),
-                                           self._get_moved_resources(changes))
+            self.interface._reload_buffers(changes)
             self._done()
         lisputils.RunTask(perform, 'Making %s changes' % self.name,
-                           interrupts=False)()
+                          interrupts=False)()
         lisputils.message(str(changes.description) + ' finished')
 
     def _get_confs(self):
     def _get_optionals(self):
         return self.optionals
 
-    def _get_moved_resources(self, changes):
-        result = {}
-        if isinstance(changes, rope.base.change.ChangeSet):
-            for change in changes.changes:
-                result.update(self._get_moved_resources(change))
-        if isinstance(changes, rope.base.change.MoveResource):
-            result[changes.resource] = changes.new_resource
-        return result
-
 
 class Rename(Refactoring):
     key = 'r'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.