Exemple #1
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(
            lisputils.askdata,
            ["perform", "preview", "cancel"],
            self._get_confs(),
            self._get_optionals(),
            initial_asking=initial_asking,
        )
        if action == "cancel":
            lisputils.message("Cancelled!")
            return

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

        name = "Calculating %s changes" % self.name
        changes = lisputils.runtask(calculate, name=name)
        if action == "perform":
            self._perform(changes)
        if action == "preview":
            if changes is not None:
                diffs = str(changes.get_description())
                lisputils.make_buffer("*rope-preview*", diffs, switch=True, modes=["diff"], window="current")
                if lisputils.yes_or_no("Do the changes? "):
                    self._perform(changes)
                else:
                    lisputils.message("Thrown away!")
                lisputils.hide_buffer("*rope-preview*", delete=False)
            else:
                lisputils.message("No changes!")
Exemple #2
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(
            lisputils.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 = lisputils.runtask(calculate, 'Find Occurrences')
            text = []
            for occurrence in result:
                line = '%s : %s' % (occurrence.resource.path, occurrence.offset)
                if occurrence.unsure:
                    line += ' ?'
                text.append(line)
            text = '\n'.join(text) + '\n'
            buffer = lisputils.make_buffer('*rope-occurrences*',
                                           text, switch=True)
            lisp.set_buffer(buffer)
            lisp.local_set_key('\r', lisp.rope_occurrences_goto_occurrence)
            lisp.local_set_key('q', lisp.rope_occurrences_quit)
Exemple #3
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(
         lisputils.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:
             lisp.find_file(resource.real_path)
Exemple #4
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)
Exemple #5
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)
Exemple #6
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)
Exemple #7
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)
Exemple #8
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)
Exemple #9
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)
Exemple #10
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)
Exemple #11
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)
Exemple #12
0
 def test_trivial_case(self):
     action, confs = dialog.show_dialog(_MockAskConfig(["done"]), ["done"])
     self.assertEquals("done", action)
     self.assertEquals({}, confs)