Commits

Anonymous committed 1e489d1

Moved move refactoring to ropemacs.refactor

Comments (0)

Files changed (2)

ropemacs/__init__.py

 import rope.refactor.extract
 import rope.refactor.inline
 import rope.refactor.move
-import rope.refactor.rename
-import rope.refactor.restructure
 from Pymacs import lisp
 from rope.base import project, libutils
 from rope.contrib import codeassist, generate
-from ropemacs import config, refactor
+
+from ropemacs import refactor
 
 
 def interactive(func):
             for changes in self.project.history.redo():
                 self._reload_buffers(changes.get_changed_resources())
 
-    def do_rename(self, module=False):
-        renamer = refactor.Rename(self)
-        return renamer.show()
-
     @interactive
     def rename(self):
-        self.do_rename()
+        refactor.Rename(self).show()
 
     @interactive
     def rename_current_module(self):
-        self.do_rename(module=True)
+        refactor.RenameCurrentModule(self).show()
 
     @interactive
     def move(self):
-        mover = self._create_mover()
-        if isinstance(mover, rope.refactor.move.MoveGlobal):
-            self._move_global(mover)
-        if isinstance(mover, rope.refactor.move.MoveModule):
-            self._move_module(mover)
-        if isinstance(mover, rope.refactor.move.MoveMethod):
-            self._move_method(mover)
-
-    def _create_mover(self, module=False):
-        self._check_project()
-        self._save_buffers()
-        resource, offset = self._get_location()
-        if module:
-            offset = None
-        return rope.refactor.move.create_move(self.project, resource, offset)
-
-    def _move_global(self, mover):
-        dest_module = _ask('Destination Module Name: ')
-        destination = self.project.pycore.find_module(dest_module)
-        self._perform(mover.get_changes(destination))
-
-    def _move_method(self, mover):
-        dest_attr = _ask('Destination Attribute: ')
-        self._perform(mover.get_changes(dest_attr,
-                                        mover.get_method_name()))
-
-    def _move_module(self, mover):
-        dest_package = _ask('Destination Package: ')
-        destination = self.project.pycore.find_module(dest_package)
-        self._perform(mover.get_changes(destination))
+        refactor.Move(self).show()
 
     @interactive
     def move_current_module(self):
-        mover = self._create_mover(module=True)
-        dest_package = _ask('Destination Package: ')
-        destination = self.project.pycore.find_module(dest_package)
-        self._perform(mover.get_changes(destination))
+        refactor.MoveCurrentModule(self).show()
 
     @interactive
     def module_to_package(self):

ropemacs/refactor.py

+import rope.refactor.move
+import rope.refactor.rename
+
 import ropemacs
 from ropemacs import config
-import rope.refactor.rename
 
 
 class Refactoring(object):
 
     name = None
     key = None
-    confs = None
-    optionals = None
+    confs = {}
+    optionals = {}
     saveall = True
 
     def __init__(self, interface):
 
 class RenameCurrentModule(Rename):
 
+    name = 'rename_current_module'
+    key = 'C-c r 1 r'
     offset = None
 
 
         imports = [line.strip()
                    for line in values.get('imports', '').split('\n')]
         return restructuring.get_changes(checks=checks, imports=imports)
+
+
+class Move(Refactoring):
+
+    name = 'move'
+    key = 'C-c r v'
+
+    def _create_refactoring(self):
+        self.mover = rope.refactor.move.create_move(self.project,
+                                                    self.resource,
+                                                    self.offset)
+
+    def _calculate_changes(self, values):
+        destination = values['destination']
+        if isinstance(self.mover, rope.refactor.move.MoveGlobal):
+            return self._move_global(destination)
+        if isinstance(self.mover, rope.refactor.move.MoveModule):
+            return self._move_module(destination)
+        if isinstance(self.mover, rope.refactor.move.MoveMethod):
+            return self._move_method(destination)
+
+    def _move_global(self, dest):
+        destination = self.project.pycore.find_module(dest)
+        return self.mover.get_changes(destination)
+
+    def _move_method(self, dest):
+        return self.mover.get_changes(dest, self.mover.get_method_name())
+
+    def _move_module(self, dest):
+        destination = self.project.pycore.find_module(dest)
+        return self.mover.get_changes(destination)
+
+    def _get_confs(self):
+        if isinstance(self.mover, rope.refactor.move.MoveGlobal):
+            prompt = 'Destination module: '
+        if isinstance(self.mover, rope.refactor.move.MoveModule):
+            prompt = 'Destination package: '
+        if isinstance(self.mover, rope.refactor.move.MoveMethod):
+            prompt = 'Destination attribute: '
+        return {'destination': config.Data(prompt)}
+
+
+class MoveCurrentModule(Move):
+
+    name = 'move_current_module'
+    key = 'C-c r 1 v'
+
+    offset = None
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.