Exemplo n.º 1
0
 def update_info(self, name, kind, position, status, selected):
     self.setIcon(0, ima.icon(SYMBOL_KIND_ICON.get(kind, 'no_match')))
     identifier = SYMBOL_NAME_MAP.get(kind, '')
     identifier = identifier.replace('_', ' ').capitalize()
     self.setToolTip(0, '{3} {2}: {0} {1}'.format(
         identifier, name, position, _('Line')))
     set_item_user_text(self, name)
     self.setText(0, name)
     self.setExpanded(status)
     self.setSelected(selected)
Exemplo n.º 2
0
    def create_symbol_switcher(self):
        """Populate switcher with symbol info."""
        editor = self._editor()
        language = editor.language
        editor.update_whitespace_count(0, 0)
        self._current_line = editor.get_cursor_line_number()
        self._switcher.clear()
        self._switcher.set_placeholder_text(_('Select symbol'))
        oe_symbols = editor.oe_proxy.info or []
        display_variables = CONF.get('outline_explorer', 'display_variables')

        idx = 0
        total_symbols = len(oe_symbols)
        oe_symbols = sorted(
            oe_symbols, key=lambda x: x['location']['range']['start']['line'])
        for symbol in oe_symbols:
            symbol_name = symbol['name']
            symbol_kind = symbol['kind']
            if language.lower() == 'python':
                if symbol_kind == SymbolKind.MODULE:
                    total_symbols -= 1
                    continue
                if (symbol_kind == SymbolKind.VARIABLE
                        and not display_variables):
                    total_symbols -= 1
                    continue
                if symbol_kind == SymbolKind.FIELD and not display_variables:
                    total_symbols -= 1
                    continue

            symbol_range = symbol['location']['range']
            symbol_start = symbol_range['start']['line']

            fold_level = editor.leading_whitespaces[symbol_start]

            space = ' ' * fold_level
            formated_title = '{space}{title}'.format(title=symbol_name,
                                                     space=space)
            icon = ima.icon(SYMBOL_KIND_ICON.get(symbol_kind, 'no_match'))
            data = {'title': symbol_name, 'line_number': symbol_start + 1}
            last_item = idx + 1 == total_symbols
            self._switcher.add_item(title=formated_title,
                                    icon=icon,
                                    section=self._section,
                                    data=data,
                                    last_item=last_item)
            idx += 1
        # Needed to update fold spaces for items titles
        self._switcher.setup()