Exemplo n.º 1
0
 def test_optional_confs2(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['name', 'value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual({'name': 'value'}, result)
     self.assertEqual('done', action)
Exemplo n.º 2
0
 def test_asking_normal_configs(self):
     confs = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['value', 'done'])
     action, result = dialog.show_dialog(minibuffer,
                                         ['done', 'cancel'], confs)
     self.assertEqual({'name': 'value'}, result)
     self.assertEqual('done', action)
Exemplo n.º 3
0
 def test_optional_confs(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals(None, result.get('name', None))
     self.assertEquals('done', action)
Exemplo n.º 4
0
 def test_optional_confs(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual(None, result.get('name', None))
     self.assertEqual('done', action)
Exemplo n.º 5
0
 def test_optional_confs2(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['name', 'value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name': 'value'}, result)
     self.assertEquals('done', action)
Exemplo n.º 6
0
 def test_asking_normal_configs(self):
     confs = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         confs)
     self.assertEquals({'name': 'value'}, result)
     self.assertEquals('done', action)
Exemplo n.º 7
0
 def test_trivial_batchset(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['batchset', 'name value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name': 'value'}, result)
     self.assertEquals('done', action)
Exemplo n.º 8
0
 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(
         self.interface._askdata, ['perform', 'preview', 'cancel'],
         self._get_confs(), self._get_optionals(),
         initial_asking=initial_asking)
     if action == 'cancel':
         self.env.message('Cancelled!')
         return
     def calculate(handle):
         return self._calculate_changes(result, handle)
     name = 'Calculating %s changes' % self.name
     changes = runtask(self.env, calculate, name=name)
     if action == 'perform':
         self._perform(changes)
     if action == 'preview':
         if changes is not None:
             diffs = changes.get_description()
             if self.env.preview_changes(diffs):
                 self._perform(changes)
             else:
                 self.env.message('Thrown away!')
         else:
             self.env.message('No changes!')
Exemplo n.º 9
0
    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(self.interface._askdata,
                                            ['perform', 'preview', 'cancel'],
                                            self._get_confs(),
                                            self._get_optionals(),
                                            initial_asking=initial_asking)
        if action == 'cancel':
            self.env.message('Cancelled!')
            return

        def calculate(handle):
            return self._calculate_changes(result, handle)

        name = 'Calculating %s changes' % self.name
        changes = runtask(self.env, calculate, name=name)
        if action == 'perform':
            self._perform(changes)
        if action == 'preview':
            if changes is not None:
                diffs = changes.get_description()
                if self.env.preview_changes(diffs):
                    self._perform(changes)
                else:
                    self.env.message('Thrown away!')
            else:
                self.env.message('No changes!')
Exemplo n.º 10
0
 def test_ignoring_trailing_colon_in_config_names(self):
     optionals = {'name1': dialog.Data()}
     minibuffer = _MockAskConfig(['batchset', 'name1: value1\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name1': 'value1'}, result)
     self.assertEquals('done', action)
Exemplo n.º 11
0
 def test_trivial_batchset(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(['batchset', 'name value', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual({'name': 'value'}, result)
     self.assertEqual('done', action)
Exemplo n.º 12
0
 def test_skipping_blanks(self):
     optionals = {'name1': dialog.Data(), 'name2': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', '\nname1\n value1\n\nname2 value2\n\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name1': 'value1\n', 'name2': 'value2'}, result)
     self.assertEquals('done', action)
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
 def test_batchset_multiple_sets(self):
     optionals = {'name1': dialog.Data(), 'name2': dialog.Data()}
     minibuffer = _MockAskConfig(['batchset',
                                  'name1 value1\nname2 value2', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name1': 'value1', 'name2': 'value2'}, result)
     self.assertEquals('done', action)
Exemplo n.º 15
0
 def test_multiline_sets(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', 'name\n line1\n  line2\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual({'name': 'line1\n line2\n'}, result)
     self.assertEqual('done', action)
Exemplo n.º 16
0
 def test_batchset_multiple_sets(self):
     optionals = {'name1': dialog.Data(), 'name2': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', 'name1 value1\nname2 value2', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual({'name1': 'value1', 'name2': 'value2'}, result)
     self.assertEqual('done', action)
Exemplo n.º 17
0
 def test_multiline_sets(self):
     optionals = {'name': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', 'name\n line1\n  line2\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals({'name': 'line1\n line2\n'}, result)
     self.assertEquals('done', action)
Exemplo n.º 18
0
 def test_ignoring_trailing_colon_in_config_names(self):
     optionals = {'name1': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', 'name1: value1\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual({'name1': 'value1'}, result)
     self.assertEqual('done', action)
Exemplo n.º 19
0
 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.assertEqual({'name': 'value'}, result)
     self.assertEqual('done', action)
Exemplo n.º 20
0
 def test_skipping_blanks(self):
     optionals = {'name1': dialog.Data(), 'name2': dialog.Data()}
     minibuffer = _MockAskConfig(
         ['batchset', '\nname1\n value1\n\nname2 value2\n\n', 'done'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual({'name1': 'value1\n', 'name2': 'value2'}, result)
     self.assertEqual('done', action)
Exemplo n.º 21
0
 def test_complex_batchset(self):
     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'])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEqual(
         {'name1': 'line1\n line2\n', 'name2': 'value2',
          'name3': 'value3\n'}, result)
     self.assertEqual('done', action)
Exemplo n.º 22
0
 def _create(self, name, callback, parentname="source"):
     self._check_project()
     confs = {"name": dialog.Data(name.title() + " name: ")}
     parentname = parentname + "folder"
     optionals = {
         parentname: dialog.Data(parentname.title() + " Folder: ", default=self.project.address, kind="directory")
     }
     action, values = dialog.show_dialog(self._askdata, ["perform", "cancel"], confs, optionals)
     if action == "perform":
         parent = libutils.path_to_resource(self.project, values.get(parentname, self.project.address))
         resource = callback(parent, values["name"])
         if resource:
             self.env.find_file(resource.real_path)
Exemplo n.º 23
0
 def _create(self, name, callback, parentname='source'):
     self._check_project()
     confs = {'name': dialog.Data(name.title() + ' name: ')}
     parentname = parentname + 'folder'
     optionals = {parentname: dialog.Data(
             parentname.title() + ' Folder: ',
             default=self.project.address, kind='directory')}
     action, values = dialog.show_dialog(
         self._askdata, ['perform', 'cancel'], confs, optionals)
     if action == 'perform':
         parent = libutils.path_to_resource(
             self.project, values.get(parentname, self.project.address))
         resource = callback(parent, values['name'])
         if resource:
             self.env.find_file(resource.real_path)
Exemplo n.º 24
0
 def _create(self, name, callback, parentname='source'):
     self._check_project()
     confs = {'name': dialog.Data(name.title() + ' name: ')}
     parentname = parentname + 'folder'
     optionals = {parentname: dialog.Data(
             parentname.title() + ' Folder: ',
             default=self.project.address, kind='directory')}
     action, values = dialog.show_dialog(
         self._askdata, ['perform', 'cancel'], confs, optionals)
     if action == 'perform':
         parent = libutils.path_to_resource(
             self.project, values.get(parentname, self.project.address))
         resource = callback(parent, values['name'])
         if resource:
             self.env.find_file(resource.real_path)
Exemplo n.º 25
0
    def _base_findit(self, do_find, optionals, get_kwds):
        self._check_project()
        self._save_buffers()
        resource, offset = self._get_location()

        action, values = dialog.show_dialog(self._askdata, ["search", "cancel"], optionals=optionals)
        if action == "search":
            kwds = get_kwds(values)

            def calculate(handle):
                resources = refactor._resources(self.project, values.get("resources"))
                return do_find(self.project, resource, offset, resources=resources, task_handle=handle, **kwds)

            result = refactor.runtask(self.env, calculate, "Find Occurrences")
            locations = [Location(location) for location in result]
            self.env.show_occurrences(locations)
Exemplo n.º 26
0
    def _base_findit(self, do_find, optionals, get_kwds):
        self._check_project()
        self._save_buffers()
        resource, offset = self._get_location()

        action, values = dialog.show_dialog(
            self._askdata, ['search', 'cancel'], optionals=optionals)
        if action == 'search':
            kwds = get_kwds(values)
            def calculate(handle):
                resources = refactor._resources(self.project,
                                                values.get('resources'))
                return do_find(self.project, resource, offset,
                               resources=resources, task_handle=handle, **kwds)
            result = refactor.runtask(self.env, calculate, 'Find Occurrences')
            locations = [Location(location) for location in result]
            self.env.show_occurrences(locations)
Exemplo n.º 27
0
 def test_complex_batchset(self):
     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'
     ])
     action, result = dialog.show_dialog(minibuffer, ['done', 'cancel'],
                                         optionals=optionals)
     self.assertEquals(
         {
             'name1': 'line1\n line2\n',
             'name2': 'value2',
             'name3': 'value3\n'
         }, result)
     self.assertEquals('done', action)
Exemplo n.º 28
0
 def test_trivial_case(self):
     action, confs = dialog.show_dialog(_MockAskConfig(['done']), ['done'])
     self.assertEqual('done', action)
     self.assertEqual({}, confs)
Exemplo n.º 29
0
 def test_trivial_case(self):
     action, confs = dialog.show_dialog(_MockAskConfig(['done']), ['done'])
     self.assertEquals('done', action)
     self.assertEquals({}, confs)