Commits

Anonymous committed d1f2eeb

Moved generate element and organize imports to ropemacs.refactor

Comments (0)

Files changed (2)

ropemacs/__init__.py

 
     @interactive
     def organize_imports(self):
-        self._check_project()
-        self._save_buffers(only_current=True)
-        organizer = rope.refactor.ImportOrganizer(self.project)
-        self._perform(organizer.organize_imports(self._get_resource()))
+        refactor.OrganizeImports(self).show()
 
     def _perform(self, changes):
         if changes is None:
         file = self.project.get_file(path)
         lisp.find_file(file.real_path)
 
-    def _generate_element(self, kind):
-        self._check_project()
-        self._save_buffers()
-        resource, offset = self._get_location()
-        generator = generate.create_generate(kind, self.project,
-                                             resource, offset)
-        self._perform(generator.get_changes())
-        self._goto_location(generator.get_location())
-
     def _goto_location(self, location, readonly=False):
         if location[0]:
             resource = location[0]
 
     @interactive
     def generate_variable(self):
-        self._generate_element('variable')
+        refactor.GenerateVariable(self).show()
 
     @interactive
     def generate_function(self):
-        self._generate_element('function')
+        refactor.GenerateFunction(self).show()
 
     @interactive
     def generate_class(self):
-        self._generate_element('class')
+        refactor.GenerateClass(self).show()
 
     @interactive
     def generate_module(self):
-        self._generate_element('module')
+        refactor.GenerateModule(self).show()
 
     @interactive
     def generate_package(self):
-        self._generate_element('package')
+        refactor.GeneratePackage(self).show()
 
     def _get_location(self):
         resource = self._get_resource()

ropemacs/refactor.py

 import rope.refactor.move
 import rope.refactor.move
 import rope.refactor.rename
+import rope.contrib.generate
 
 import ropemacs
 from ropemacs import config
             return
         changes = self._calculate_changes(result)
         self._perform(changes)
+        self._done()
 
     @property
     def project(self):
     def _create_refactoring(self):
         pass
 
+    def _done(self):
+        pass
+
     def _perform(self, changes):
         self.interface._perform(changes)
 
 
     def _calculate_changes(self, values):
         return self.extractor.get_changes(values['name'])
+
+
+class OrganizeImports(Refactoring):
+
+    name = 'organize_imports'
+    key = 'C-c i o'
+    saveall = False
+
+    def _create_refactoring(self):
+        self.organizer = rope.refactor.ImportOrganizer(self.project)
+
+    def _calculate_changes(self, values):
+        return self.organizer.organize_imports(self.resource)
+
+
+class _GenerateElement(Refactoring):
+
+    def _create_refactoring(self):
+        kind = self.name.split('_')[-1]
+        self.generator = rope.contrib.generate.create_generate(
+            kind, self.project, self.resource, self.offset)
+
+    def _calculate_changes(self, values):
+        return self.generator.get_changes()
+
+    def _done(self):
+        self.interface._goto_location(self.generator.get_location())
+
+
+class GenerateVariable(_GenerateElement):
+
+    name = 'generate_variable'
+    key = 'C-c n v'
+
+
+class GenerateFunction(_GenerateElement):
+
+    name = 'generate_function'
+    key = 'C-c n f'
+
+
+class GenerateClass(_GenerateElement):
+
+    name = 'generate_class'
+    key = 'C-c n c'
+
+
+class GenerateModule(_GenerateElement):
+
+    name = 'generate_module'
+    key = 'C-c n m'
+
+
+class GeneratePackage(_GenerateElement):
+
+    name = 'generate_package'
+    key = 'C-c n p'
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.