Anonymous avatar Anonymous committed 97af5a8

refactor: using new dialogs for Inline and UseFunction

Comments (0)

Files changed (1)

ropemacs/refactor.py

 
 class UseFunction(Refactoring):
     key = 'u'
-    optionals = {
-        'resources': dialog.Data('Files to apply this refactoring on: ')}
 
     def _create_refactoring(self):
         self.user = rope.refactor.usefunction.UseFunction(
             self.project, self.resource, self.offset)
 
     def _calculate_changes(self, values, task_handle):
-        resources = _resources(self.project, values.get('resources', None))
-        return self.user.get_changes(resources=resources,
-                                     task_handle=task_handle)
+        return self.user.get_changes(task_handle=task_handle, **values)
+
+    def _get_optionals(self):
+        return {'resources': self.resources_option}
 
 
 class Move(Refactoring):
     key = 'v'
-    optionals = {
-        'resources': dialog.Data('Files to apply this refactoring on: ')}
 
     def _create_refactoring(self):
         self.mover = rope.refactor.move.create_move(self.project,
 
     def _calculate_changes(self, values, task_handle):
         destination = values['destination']
-        resources = _resources(self.project, values.get('resources', None))
+        resources = values.get('resources', None)
         if isinstance(self.mover, rope.refactor.move.MoveGlobal):
             return self._move_global(destination, resources, task_handle)
         if isinstance(self.mover, rope.refactor.move.MoveModule):
             prompt = 'Destination attribute: '
         return {'destination': dialog.Data(prompt)}
 
+    def _get_optionals(self):
+        return {'resources': self.resources_option}
+
 
 class MoveCurrentModule(Move):
     key = '1 v'
 
 class Inline(Refactoring):
     key = 'i'
-    optionals = {
-        'remove': dialog.Data('Remove the definition: ',
-                              values=['yes', 'no'], default='yes'),
-        'only_current': dialog.Data('Inline this occurrence only: ',
-                                    values=['yes', 'no'], default='no'),
-        'resources': dialog.Data('Files to apply this refactoring on: ')}
 
     def _create_refactoring(self):
         self.inliner = rope.refactor.inline.create_inline(
             self.project, self.resource, self.offset)
 
     def _calculate_changes(self, values, task_handle):
-        remove = values.get('remove', 'yes') == 'yes'
-        only_current = values.get('only_current', 'no') == 'yes'
-        resources = _resources(self.project, values.get('resources'))
-        return self.inliner.get_changes(
-            remove=remove, only_current=only_current,
-            resources=resources, task_handle=task_handle)
+        return self.inliner.get_changes(task_handle=task_handle, **values)
+
+    def _get_optionals(self):
+        opts = {'resources': self.resources_option}
+        if self.inliner.get_kind() != 'parameter':
+            opts['remove'] = dialog.Boolean('Remove the definition: ', True)
+            opts['only_current'] = dialog.Boolean('Inline this '
+                                                  'occurrence only: ')
+        return opts
 
 
 class _Extract(Refactoring):
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.