Anonymous avatar Anonymous committed dfa0ac2

Prefixing refactorings skips the initial asking

Comments (0)

Files changed (4)

ropemacs/__init__.py

         for name in dir(refactor):
             if not name.startswith('_') and name != 'Refactoring':
                 attr = getattr(refactor, name)
-                if isinstance(attr, type) and issubclass(attr, refactor.Refactoring):
-                    @interactive
-                    def do_refactor(self=self, refactoring=attr):
-                        refactoring(self).show()
+                if isinstance(attr, type) and \
+                   issubclass(attr, refactor.Refactoring):
+                    @rawprefixed
+                    def do_refactor(prefix, self=self, refactoring=attr):
+                        initial_asking = prefix is None
+                        refactoring(self).show(initial_asking=initial_asking)
                     setattr(self, attr.name, do_refactor)
                     name = 'rope-' + attr.name.replace('_', '-')
                     if attr.key.startswith('C-x'):

ropemacs/dialog.py

         self.kind = kind
 
 
-def show_dialog(askdata, actions, confs={}, optionals={}):
+def show_dialog(askdata, actions, confs={}, optionals={}, initial_asking=True):
     result = {}
-    for name, conf in confs.items():
-        result[name] = askdata(conf)
+    if initial_asking:
+        for name, conf in confs.items():
+            result[name] = askdata(conf)
     actions.append('batchset')
     names = list(confs.keys())
     names.extend(optionals.keys())

ropemacs/refactor.py

+import rope.base.change
 import rope.base.taskhandle
-import rope.base.change
 import rope.contrib.generate
 import rope.refactor.extract
 import rope.refactor.inline
     def __init__(self, interface):
         self.interface = interface
 
-    def show(self):
+    def show(self, initial_asking=True):
         self.interface._check_project()
         self.interface._save_buffers(only_current=not self.saveall)
         self._create_refactoring()
         action, result = dialog.show_dialog(
             lisputils.askdata, ['perform', 'preview', 'cancel'],
-            self._get_confs(), self._get_optionals())
+            self._get_confs(), self._get_optionals(),
+            initial_asking=initial_asking)
         if action == 'cancel':
             lisputils.message('Cancelled!')
             return
         optionals = {'name1': dialog.Data(), 'name2': dialog.Data(),
                      'name3': dialog.Data()}
         minibuffer = _MockAskConfig(
-            ['batchset', 'name3\n value3\nname1\n line1\n  line2\n\nname2 value2\n', 'done'])
+            ['batchset', 'name3\n value3\nname1\n line1\n  '
+             'line2\n\nname2 value2\n', 'done'])
         action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                             optionals=optionals)
         self.assertEquals(
              'name3': 'value3\n'}, result)
         self.assertEquals('done', action)
 
+    def test_skip_initial_asking(self):
+        confs = {'name': dialog.Data()}
+        minibuffer = _MockAskConfig(
+            ['name', 'value', 'done'])
+        action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
+                                            confs=confs, initial_asking=False)
+        self.assertEquals({'name': 'value'}, result)
+        self.assertEquals('done', action)
+
 
 class _MockAskConfig(object):
 
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.