Exemplo n.º 1
0
    def diff_documents(self,
                       paths,
                       texts,
                       metadatas=None,
                       workdir='',
                       show=False):

        self._paths = list(paths)
        self._texts = list(texts)
        self._metadatas = metadatas
        self._workdir = workdir

        file1, file2 = self._paths
        if self._is_directory(file1) or self._is_directory(file2):
            self._highlighted_documents = [
                TextDocumentModel(metadata) for metadata in self._metadatas
            ]
        else:
            self.diff_text_documents(show)

        self._set_document_models()

        if self._repository:
            self._staged = self._repository.is_staged(file2)
            self._status_label.clear()
            if self._repository.is_modified(file2):
                self._status_label.setText(
                    '<font color="red">Modified !</font>')
            if self._staged:
                self._logger.info("File {} is staged".format(file2))
            self._stage_action.blockSignals(True)
            self._stage_action.setChecked(self._staged)
            self._stage_action.blockSignals(False)
def highlight_text(raw_text_document, lexer):

    """ Highlight a text.

    The parameter *raw_text_document* is a :class:`DiffViewer.RawTextDocument` instance and the
    parameter *lexer* is a Pygments lexer instance.

    Return an :class:`DiffViewer.TextDocumentModel` instance.  The document has one text block that
    contains all the fragments.  Text fragments use light views.
    """

    highlighted_text = HighlightedText(raw_text_document, lexer)

    document = TextDocumentModel()
    text_block = TextBlock(raw_text_document.line_slice)
    document.append(text_block)
    for highlighted_fragment in highlighted_text:
        text_fragment = TextFragment(raw_text_document.light_view(highlighted_fragment.slice),
                                     token_type=highlighted_fragment.token)
        text_block.append(text_fragment)

    return document
    def diff_documents(self, paths, texts, metadatas=None, workdir='', show=False):

        self._paths = list(paths)
        self._texts = list(texts)
        self._metadatas = metadatas
        self._workdir = workdir

        file1, file2 = self._paths
        if self._is_directory(file1) or self._is_directory(file2):
            self._highlighted_documents = [TextDocumentModel(metadata) for metadata in self._metadatas]
        else:
            self.diff_text_documents(show)

        self._set_document_models()