Anonymous avatar Anonymous committed 9d91052

Renamed ropemacs.config to dialog

Comments (0)

Files changed (4)

ropemacs/config.py

-class Data(object):
-
-    def __init__(self, prompt=None, default=None,
-                 values=None, starting=None):
-        self.prompt = prompt
-        self.default = default
-        self.values = values
-        self.starting = starting
-
-
-def show_dialog(askdata, actions, confs={}, optionals={}):
-    result = {}
-    for name, conf in confs.items():
-        result[name] = askdata(conf)
-    names = list(confs.keys())
-    names.extend(optionals.keys())
-    names.extend(actions)
-    base_question = Data('Choose what to do: ',
-                         default=actions[0], values=names)
-    while True:
-        response = askdata(base_question)
-        if response == '':
-            response = base_question.default
-        if response in actions:
-            break
-        else:
-            if response in confs:
-                conf = confs[response]
-            else:
-                conf = optionals[response]
-            result[response] = askdata(conf)
-    return response, result

ropemacs/dialog.py

+class Data(object):
+
+    def __init__(self, prompt=None, default=None,
+                 values=None, starting=None):
+        self.prompt = prompt
+        self.default = default
+        self.values = values
+        self.starting = starting
+
+
+def show_dialog(askdata, actions, confs={}, optionals={}):
+    result = {}
+    for name, conf in confs.items():
+        result[name] = askdata(conf)
+    names = list(confs.keys())
+    names.extend(optionals.keys())
+    names.extend(actions)
+    base_question = Data('Choose what to do: ',
+                         default=actions[0], values=names)
+    while True:
+        response = askdata(base_question)
+        if response == '':
+            response = base_question.default
+        if response in actions:
+            break
+        else:
+            if response in confs:
+                conf = confs[response]
+            else:
+                conf = optionals[response]
+            result[response] = askdata(conf)
+    return response, result

ropemacs/refactor.py

 import rope.refactor.restructure
 
 import ropemacs
-from ropemacs import config
+from ropemacs import dialog
 
 
 class Refactoring(object):
         self.interface._check_project()
         self.interface._save_buffers(only_current=not self.saveall)
         self._create_refactoring()
-        action, result = config.show_dialog(
+        action, result = dialog.show_dialog(
             ropemacs._lisp_askdata, ['perform', 'preview', 'cancel'],
             self._get_confs(), self._get_optionals())
         if action == 'cancel':
     name = 'rename'
     key = 'C-c r r'
     optionals = {
-        'docs': config.Data('Rename occurrences in comments and docs: ', values=['yes', 'no']),
-        'in_hierarchy': config.Data('Method in class hierarchy: ', values=['yes', 'no']),
-        'unsure': config.Data('Unsure occurrences: ', values=['ignore', 'match'])}
+        'docs': dialog.Data('Rename occurrences in comments and docs: ', values=['yes', 'no']),
+        'in_hierarchy': dialog.Data('Method in class hierarchy: ', values=['yes', 'no']),
+        'unsure': dialog.Data('Unsure occurrences: ', values=['ignore', 'match'])}
     saveall = True
 
     def __init__(self, interface):
 
     def _get_confs(self):
         oldname = str(self.renamer.get_old_name())
-        return {'newname': config.Data('New name: ', starting=oldname)}
+        return {'newname': dialog.Data('New name: ', starting=oldname)}
 
 
 class RenameCurrentModule(Rename):
 
     name = 'restructure'
     key = 'C-c r x'
-    confs = {'pattern': config.Data('Restructuring pattern: '),
-             'goal': config.Data('Restructuring goal: ')}
-    optionals = {'checks': config.Data('Checks: '),
-                     'imports': config.Data('Imports: ')}
+    confs = {'pattern': dialog.Data('Restructuring pattern: '),
+             'goal': dialog.Data('Restructuring goal: ')}
+    optionals = {'checks': dialog.Data('Checks: '),
+                     'imports': dialog.Data('Imports: ')}
 
     def _calculate_changes(self, values, task_handle):
         restructuring = rope.refactor.restructure.Restructure(
             prompt = 'Destination package: '
         if isinstance(self.mover, rope.refactor.move.MoveMethod):
             prompt = 'Destination attribute: '
-        return {'destination': config.Data(prompt)}
+        return {'destination': dialog.Data(prompt)}
 
 
 class MoveCurrentModule(Move):
 
     name = 'inline'
     key = 'C-c r i'
-    optionals = {'remove': config.Data('Remove the definition: ',
+    optionals = {'remove': dialog.Data('Remove the definition: ',
                                        values=['yes', 'no'])}
 
     def _create_refactoring(self):
     name = 'extract_variable'
     key = 'C-c r l'
     saveall = False
-    confs = {'name': config.Data('Extracted variable name: ')}
+    confs = {'name': dialog.Data('Extracted variable name: ')}
 
     def _create_refactoring(self):
         start, end = self.region
     name = 'extract_method'
     key = 'C-c r m'
     saveall = False
-    confs = {'name': config.Data('Extracted method name: ')}
+    confs = {'name': dialog.Data('Extracted method name: ')}
 
     def _create_refactoring(self):
         start, end = self.region
 import unittest
 
-from ropemacs import config
+from ropemacs import dialog
 
 
 class ConfigTest(unittest.TestCase):
         super(ConfigTest, self).tearDown()
 
     def test_trivial_case(self):
-        action, confs = config.show_dialog(_MockAskConfig(['done']), ['done'])
+        action, confs = dialog.show_dialog(_MockAskConfig(['done']), ['done'])
         self.assertEquals('done', action)
         self.assertEquals({}, confs)
 
     def test_asking_normal_configs(self):
-        confs = {'name': config.Data()}
+        confs = {'name': dialog.Data()}
         minibuffer = _MockAskConfig(['value', 'done'])
-        action, result = config.show_dialog(minibuffer,
+        action, result = dialog.show_dialog(minibuffer,
                                             ['done', 'cancel'], confs)
         self.assertEquals({'name': 'value'}, result)
         self.assertEquals('done', action)
 
     def test_optional_confs(self):
-        optionals = {'name': config.Data()}
+        optionals = {'name': dialog.Data()}
         minibuffer = _MockAskConfig(['done'])
-        action, result = config.show_dialog(minibuffer, ['done', 'cancel'],
+        action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                             optionals=optionals)
         self.assertEquals(None, result.get('name', None))
         self.assertEquals('done', action)
 
     def test_optional_confs2(self):
-        optionals = {'name': config.Data()}
+        optionals = {'name': dialog.Data()}
         minibuffer = _MockAskConfig(['name', 'value', 'done'])
-        action, result = config.show_dialog(minibuffer, ['done', 'cancel'],
+        action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                             optionals=optionals)
         self.assertEquals({'name': 'value'}, result)
         self.assertEquals('done', action)
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.