Commits

Anonymous committed 5e3fad2

Moved extract refactorings to ropemacs.refactor

Comments (0)

Files changed (2)

ropemacs/__init__.py

     def module_to_package(self):
         refactor.ModuleToPackage(self).show()
 
-    def _do_extract(self, extractor, prompt):
-        self._check_project()
-        self._save_buffers(only_current=True)
-        resource = self._get_resource()
-        start, end = self._get_region()
-        extractor = extractor(self.project, resource, start, end)
-        newname = _ask(prompt)
-        changes = extractor.get_changes(newname)
-        self._perform(changes)
-
     @interactive
     def extract_variable(self):
-        self._do_extract(rope.refactor.extract.ExtractVariable,
-                         'New Variable Name: ')
+        refactor.ExtractVariable(self).show()
 
     @interactive
     def extract_method(self):
-        self._do_extract(rope.refactor.extract.ExtractMethod,
-                         'New Method Name: ')
+        refactor.ExtractMethod(self).show()
 
     @interactive
     def inline(self):

ropemacs/refactor.py

     def _calculate_changes(self, values):
         remove = values.get('remove', 'yes') == 'yes'
         return self.inliner.get_changes(remove=remove)
+
+
+class ExtractVariable(Refactoring):
+
+    name = 'extract_variable'
+    key = 'C-c r l'
+    saveall = False
+    confs = {'name': config.Data('Extracted variable name: ')}
+
+    def _create_refactoring(self):
+        start, end = self.region
+        self.extractor = rope.refactor.extract.ExtractVariable(
+            self.project, self.resource, start, end)
+
+    def _calculate_changes(self, values):
+        return self.extractor.get_changes(values['name'])
+
+
+class ExtractMethod(Refactoring):
+
+    name = 'extract_method'
+    key = 'C-c r m'
+    saveall = False
+    confs = {'name': config.Data('Extracted method name: ')}
+
+    def _create_refactoring(self):
+        start, end = self.region
+        self.extractor = rope.refactor.extract.ExtractMethod(
+            self.project, self.resource, start, end)
+
+    def _calculate_changes(self, values):
+        return self.extractor.get_changes(values['name'])
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.