Anonymous avatar Anonymous committed 0637cd5

rename: added resources option instead of in_file

Comments (0)

Files changed (1)

ropemacs/refactor.py

 import rope.base.change
+import rope.base.exceptions
 import rope.contrib.generate
 import rope.refactor.extract
 import rope.refactor.inline
                             values=['yes', 'no'], default='yes'),
         'in_hierarchy': dialog.Data('Method in class hierarchy: ',
                                     values=['yes', 'no'], default='no'),
-        'in_file': dialog.Data('Only rename occurrences in the same file: ',
-                               values=['yes', 'no'], default='no'),
+        'resources': dialog.Data('Files to apply this refactoring on: '),
         'unsure': dialog.Data('Unsure occurrences: ',
                               values=['ignore', 'match'], default='ignore')}
     saveall = True
     def _calculate_changes(self, values, task_handle):
         newname = values['newname']
         unsure = values.get('unsure', 'ignore') == 'match'
+        resources = _resources(self.project, values.get('resources', None))
         kwds = {
             'docs': values.get('docs', 'yes') == 'yes',
             'in_file': values.get('in_file', 'no') == 'yes',
-            'unsure': (lambda occurrence: unsure)}
+            'unsure': (lambda occurrence: unsure),
+            'resources': resources}
         if self.renamer.is_method():
             kwds['in_hierarchy'] = values.get('in_hierarchy', 'no') == 'yes'
         return self.renamer.get_changes(newname,
         result.append(c.lower())
     name = ''.join(result)
     return name
+
+def _resources(project, text):
+    if text is None:
+        return None
+    result = []
+    for line in text.splitlines():
+        try:
+            result.append(project.get_resource(line.strip()))
+        except rope.base.exceptions.ResourceNotFoundError:
+            pass
+    return result
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.