Commits

Anonymous committed 728be93

Added basic refactoring dialog

Comments (0)

Files changed (3)

 
 > Public Release 1.0
 
-* previewing changes
-* showing refactoring progress
 * adding a menu
 * including pymacs in ropemacs?
 * change pymacs to accept unicode strings
+* previewing changes
+* showing refactoring progress
 
 > Public Release 0.2
 

ropemacs/config.py

-class Config(object):
+class Data(object):
 
-    def __init__(self, name, prompt=None, values=None):
-        self.name = name
+    def __init__(self, prompt=None, default=None, values=None):
         self.prompt = prompt
+        self.default = default
         self.values = values
 
 
-def ask(confs, askconfig):
+def show_dialog(askdata, actions, confs={}, optionals={}):
     result = {}
-    for conf in confs:
-        result[conf.name] = askconfig(conf)
-    return 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 in actions:
+            break
+        else:
+            if response in confs:
+                conf = confs[response]
+            else:
+                conf = optionals[response]
+            result[response] = askdata(conf)
+    return response, result
         super(ConfigTest, self).tearDown()
 
     def test_trivial_case(self):
-        config.ask([], _MockAskConfig())
+        action, confs = config.show_dialog(_MockAskConfig(['done']), ['done'])
+        self.assertEquals('done', action)
+        self.assertEquals({}, confs)
 
     def test_asking_normal_configs(self):
-        confs = [config.Config('name')]
-        minibuffer = _MockAskConfig(['value'])
-        result = config.ask(confs, minibuffer)
-        self.assertEquals(['name'], minibuffer.asked)
+        confs = {'name': config.Data()}
+        minibuffer = _MockAskConfig(['value', 'done'])
+        action, result = config.show_dialog(minibuffer,
+                                            ['done', 'cancel'], confs)
         self.assertEquals({'name': 'value'}, result)
+        self.assertEquals('done', action)
+
+    def test_optional_confs(self):
+        optionals = {'name': config.Data()}
+        minibuffer = _MockAskConfig(['done'])
+        action, result = config.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()}
+        minibuffer = _MockAskConfig(['name', 'value', 'done'])
+        action, result = config.show_dialog(minibuffer, ['done', 'cancel'],
+                                            optionals=optionals)
+        self.assertEquals({'name': 'value'}, result)
+        self.assertEquals('done', action)
 
 
 class _MockAskConfig(object):
         self.asked = []
 
     def __call__(self, config):
-        self.asked.append(config.name)
+        self.asked.append(config)
         return self.responses[len(self.asked) - 1]