예제 #1
0
    def create_editor_switcher(self):
        """Populate switcher with open files."""
        self._switcher.set_placeholder_text(
            _('Start typing the name of an open file'))

        editorstack = self._editorstack()
        paths = [data.filename.lower() for data in editorstack.data]
        save_statuses = [data.newly_created for data in editorstack.data]
        short_paths = shorten_paths(paths, save_statuses)

        for idx, data in enumerate(editorstack.data):
            path = data.filename
            title = osp.basename(path)
            icon = get_file_icon(path)
            # TODO: Handle of shorten paths based on font size
            # and available space per item
            if len(paths[idx]) > 75:
                path = short_paths[idx]
            else:
                path = osp.dirname(data.filename.lower())
            last_item = idx + 1 == len(editorstack.data)
            self._switcher.add_item(title=title,
                                    description=path,
                                    icon=icon,
                                    section=self._section,
                                    data=data,
                                    last_item=last_item)
예제 #2
0
 def create_line_switcher(self):
     """Populate switcher with line info."""
     editor = self._editor()
     editorstack = self._editorstack()
     self._current_line = editor.get_cursor_line_number()
     self._switcher.clear()
     self._switcher.set_placeholder_text(_('Select line'))
     data = editorstack.get_current_finfo()
     path = data.filename
     title = osp.basename(path)
     lines = data.editor.get_line_count()
     icon = get_file_icon(path)
     line_template_title = u"{title} [{lines} {text}]"
     title = line_template_title.format(title=title,
                                        lines=lines,
                                        text=_("lines"))
     description = _('Go to line')
     self._switcher.add_item(title=title,
                             description=description,
                             icon=icon,
                             section=self._section,
                             data=data,
                             action_item=True)