Exemple #1
0
    def run(self):
        settings = NamedSettingsDict('Syntax Selector')

        view = self.window.active_view()
        current_syntax_path = view.settings().get('syntax')

        syntaxes = [
            s for s in list_syntaxes()
            if settings['show_hidden_syntaxes'] or not s.hidden
        ]

        selected = next((s for s in syntaxes if s.path == current_syntax_path),
                        NO_SELECTION)

        def change_syntax(s):
            view.assign_syntax(s.path)

        if settings['preview_on_highlight']:
            on_cancel = partial(view.assign_syntax, current_syntax_path)
            on_highlight = change_syntax
        else:
            on_cancel = None
            on_highlight = None

        show_selection_panel(
            self.window,
            syntaxes,
            selected=selected,
            labels=lambda s: (s.name or '', s.path),
            on_select=change_syntax,
            on_cancel=on_cancel,
            on_highlight=on_highlight,
        )
Exemple #2
0
    def test_flags(self):
        window = WindowMock()

        flags = sublime.MONOSPACE_FONT | sublime.KEEP_OPEN_ON_FOCUS_LOST

        show_selection_panel(window=window, items=['a', 'b', 'c'], flags=flags)

        assert_called_once_with_partial(window.show_quick_panel, flags=flags)
Exemple #3
0
    def test_highlight(self):
        on_highlight = MagicMock()

        show_selection_panel(
            window=WindowMock(lambda on_highlight, **rest: on_highlight(1)),
            items=['a', 'b', 'c'],
            on_highlight=on_highlight,
        )
        on_highlight.assert_called_once_with('b')
Exemple #4
0
    def test_selected_simple(self):
        window = WindowMock()

        show_selection_panel(window=window,
                             items=['a', 'b', 'c'],
                             selected='b')

        assert_called_once_with_partial(window.show_quick_panel,
                                        selected_index=1)
Exemple #5
0
    def test_mixed_label_lengths(self):
        window = WindowMock()
        show_selection_panel(window=window,
                             items=['a', 'b'],
                             labels=[['a'], ['b', 'c']])

        assert_called_once_with_partial(
            window.show_quick_panel,
            items=[['a', ''], ['b', 'c']],
        )
Exemple #6
0
    def test_type_coercion(self):
        window = WindowMock()
        show_selection_panel(
            window=window,
            items=[10, 20, 30],
        )

        assert_called_once_with_partial(
            window.show_quick_panel,
            items=['10', '20', '30'],
        )
Exemple #7
0
    def test_cancel(self):
        on_select = MagicMock()
        on_cancel = MagicMock()

        show_selection_panel(
            window=WindowMock(lambda on_select, **rest: on_select(-1)),
            items=['a', 'b', 'c'],
            on_select=on_select,
            on_cancel=on_cancel)
        assert_not_called(on_select)
        on_cancel.assert_called_once_with()
Exemple #8
0
    def test_no_flags(self):
        window = WindowMock()

        show_selection_panel(
            window=window,
            items=['a', 'b', 'c']
        )

        assert_called_once_with_partial(
            window.show_quick_panel,
            flags=0
        )
    def run(self, edit):
        first_selection = self.view.substr(self.view.sel()[0])
        items = [
            [name.capitalize(), function(list(split_words(first_selection)))]
            for name, function in TRANSFORMS.items()
        ]
        print(items)

        def replace(item):
            name, function = item
            self.view.run_command('recase_selection', {'case': name})

        show_selection_panel(self.view.window(), items, on_select=replace)
    def run(self, context={}):
        self.context = context
        show_selection_panel(
            self.window,
            get_templates(),

            labels=lambda template: (
                template.metadata.get('name', template.path.stem),
                template.metadata.get('description', template.path),
            ),

            on_select=self.on_select,
            on_cancel=self.on_cancel,
            on_highlight=self.on_highlight if SETTINGS['preview_on_highlight'] else None,
        )
Exemple #11
0
    def test_labels_list(self):
        window = WindowMock()

        show_selection_panel(
            window=window,
            items=[
                {'name': 'a'},
                {'name': 'b'},
                {'name': 'c'},
            ],
            labels=['a', 'b', 'c'],
        )

        assert_called_once_with_partial(
            window.show_quick_panel,
            items=['a', 'b', 'c'],
        )
Exemple #12
0
    def test_selected_complex(self):
        window = WindowMock()

        show_selection_panel(
            window=window,
            items=[
                {'name': 'a'},
                {'name': 'b'},
                {'name': 'c'},
            ],
            labels=lambda item: item['name'],
            selected={'name': 'b'}
        )

        assert_called_once_with_partial(
            window.show_quick_panel,
            selected_index=1
        )
Exemple #13
0
    def test_multiline_type_coercion(self):
        window = WindowMock()
        show_selection_panel(
            window=window,
            items=[
                ['a', 10],
                ['b', 20],
                ('c', 30),
            ],
        )

        assert_called_once_with_partial(
            window.show_quick_panel,
            items=[
                ['a', '10'],
                ['b', '20'],
                ['c', '30'],
            ],
        )
Exemple #14
0
    def test_labels_function(self):
        window = WindowMock()

        show_selection_panel(window=window,
                             items=[
                                 {
                                     'name': 'a'
                                 },
                                 {
                                     'name': 'b'
                                 },
                                 {
                                     'name': 'c'
                                 },
                             ],
                             labels=lambda item: item['name'])

        assert_called_once_with_partial(
            window.show_quick_panel,
            items=[['a'], ['b'], ['c']],
        )
Exemple #15
0
 def test_empty_items_error(self):
     with self.assertRaises(ValueError):
         show_selection_panel(WindowMock(), items=[])
Exemple #16
0
 def test_item_labels_lengths_error(self):
     with self.assertRaises(ValueError):
         show_selection_panel(WindowMock(),
                              items=['a', 'b', 'c'],
                              labels=['x', 'y'])