Search in sources :

Example 1 with LineNumberConvertor

use of com.intellij.diff.tools.fragmented.LineNumberConvertor in project intellij-community by JetBrains.

the class ApplyPatchViewer method initPatchViewer.

//
// Impl
//
protected void initPatchViewer() {
    final Document outputDocument = myResultEditor.getDocument();
    boolean success = DiffUtil.executeWriteCommand(outputDocument, myProject, "Init merge content", () -> {
        outputDocument.setText(myPatchRequest.getLocalContent());
        if (!isReadOnly())
            DiffUtil.putNonundoableOperation(myProject, outputDocument);
    });
    if (!success && !StringUtil.equals(outputDocument.getText(), myPatchRequest.getLocalContent())) {
        myPanel.setErrorContent("Failed to display patch applier - local content was modified");
        return;
    }
    PatchChangeBuilder builder = new PatchChangeBuilder();
    builder.exec(myPatchRequest.getPatch().getHunks());
    Document patchDocument = myPatchEditor.getDocument();
    patchDocument.setText(builder.getPatchContent());
    LineNumberConvertor convertor1 = builder.getLineConvertor1();
    LineNumberConvertor convertor2 = builder.getLineConvertor2();
    myPatchEditor.getGutterComponentEx().setLineNumberConvertor(convertor1.createConvertor(), convertor2.createConvertor());
    TIntArrayList lines = builder.getSeparatorLines();
    for (int i = 0; i < lines.size(); i++) {
        int offset = patchDocument.getLineStartOffset(lines.get(i));
        DiffDrawUtil.createLineSeparatorHighlighter(myPatchEditor, offset, offset, BooleanGetter.TRUE);
    }
    List<PatchChangeBuilder.Hunk> hunks = builder.getHunks();
    int[] modelToPatchIndexes = DiffUtil.getSortedIndexes(hunks, (h1, h2) -> {
        LineRange lines1 = h1.getAppliedToLines();
        LineRange lines2 = h2.getAppliedToLines();
        if (lines1 == null && lines2 == null)
            return 0;
        if (lines1 == null)
            return -1;
        if (lines2 == null)
            return 1;
        return lines1.start - lines2.start;
    });
    int[] patchToModelIndexes = DiffUtil.invertIndexes(modelToPatchIndexes);
    List<LineRange> modelRanges = new ArrayList<>();
    for (int modelIndex = 0; modelIndex < hunks.size(); modelIndex++) {
        int patchIndex = modelToPatchIndexes[modelIndex];
        PatchChangeBuilder.Hunk hunk = hunks.get(patchIndex);
        LineRange resultRange = hunk.getAppliedToLines();
        ApplyPatchChange change = new ApplyPatchChange(hunk, modelIndex, this);
        myModelChanges.add(change);
        if (resultRange != null)
            myResultChanges.add(change);
        modelRanges.add(resultRange != null ? resultRange : new LineRange(-1, -1));
    }
    myModel.setChanges(modelRanges);
    for (int index : patchToModelIndexes) {
        myPatchChanges.add(myModelChanges.get(index));
    }
    myFoldingModel.install(myResultChanges, getFoldingModelSettings());
    for (ApplyPatchChange change : myModelChanges) {
        change.reinstallHighlighters();
    }
    myStatusPanel.update();
    myContentPanel.setPainter(new MyDividerPainter());
    VisibleAreaListener areaListener = (e) -> myContentPanel.repaint();
    myResultEditor.getScrollingModel().addVisibleAreaListener(areaListener);
    myPatchEditor.getScrollingModel().addVisibleAreaListener(areaListener);
    myPatchEditor.getGutterComponentEx().revalidateMarkup();
    if (myResultChanges.size() > 0) {
        scrollToChange(myResultChanges.get(0), Side.LEFT, true);
    }
}
Also used : TwosideContentPanel(com.intellij.diff.tools.util.side.TwosideContentPanel) com.intellij.diff.tools.util(com.intellij.diff.tools.util) AllIcons(com.intellij.icons.AllIcons) DiffContentFactory(com.intellij.diff.DiffContentFactory) FocusOppositePaneAction(com.intellij.diff.actions.impl.FocusOppositePaneAction) ActionUtil(com.intellij.openapi.actionSystem.ex.ActionUtil) DiffBundle(com.intellij.openapi.diff.DiffBundle) com.intellij.openapi.editor(com.intellij.openapi.editor) org.jetbrains.annotations(org.jetbrains.annotations) DiffManager(com.intellij.diff.DiffManager) ContainerUtil(com.intellij.util.containers.ContainerUtil) SetEditorSettingsAction(com.intellij.diff.actions.impl.SetEditorSettingsAction) ArrayList(java.util.ArrayList) Disposer(com.intellij.openapi.util.Disposer) MergeModelBase(com.intellij.diff.merge.MergeModelBase) Project(com.intellij.openapi.project.Project) EditorEx(com.intellij.openapi.editor.ex.EditorEx) UndoConfirmationPolicy(com.intellij.openapi.command.UndoConfirmationPolicy) Logger(com.intellij.openapi.diagnostic.Logger) TIntArrayList(gnu.trove.TIntArrayList) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) BooleanGetter(com.intellij.openapi.util.BooleanGetter) DiffContext(com.intellij.diff.DiffContext) TextDiffViewerUtil(com.intellij.diff.tools.util.base.TextDiffViewerUtil) Iterator(java.util.Iterator) com.intellij.diff.util(com.intellij.diff.util) StringUtil(com.intellij.openapi.util.text.StringUtil) TextDiffSettings(com.intellij.diff.tools.util.base.TextDiffSettingsHolder.TextDiffSettings) DocumentContent(com.intellij.diff.contents.DocumentContent) ProxyUndoRedoAction(com.intellij.diff.actions.ProxyUndoRedoAction) EditorMarkupModel(com.intellij.openapi.editor.ex.EditorMarkupModel) DiffDialogHints(com.intellij.diff.DiffDialogHints) LineNumberConvertor(com.intellij.diff.tools.fragmented.LineNumberConvertor) Disposable(com.intellij.openapi.Disposable) AppliedTextPatch(com.intellij.openapi.vcs.changes.patch.AppliedTextPatch) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) Pair(com.intellij.openapi.util.Pair) VisibleAreaListener(com.intellij.openapi.editor.event.VisibleAreaListener) TextEditorHolder(com.intellij.diff.tools.holders.TextEditorHolder) BitSet(java.util.BitSet) javax.swing(javax.swing) LineNumberConvertor(com.intellij.diff.tools.fragmented.LineNumberConvertor) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) TIntArrayList(gnu.trove.TIntArrayList) VisibleAreaListener(com.intellij.openapi.editor.event.VisibleAreaListener)

Aggregations

DiffContentFactory (com.intellij.diff.DiffContentFactory)1 DiffContext (com.intellij.diff.DiffContext)1 DiffDialogHints (com.intellij.diff.DiffDialogHints)1 DiffManager (com.intellij.diff.DiffManager)1 ProxyUndoRedoAction (com.intellij.diff.actions.ProxyUndoRedoAction)1 FocusOppositePaneAction (com.intellij.diff.actions.impl.FocusOppositePaneAction)1 SetEditorSettingsAction (com.intellij.diff.actions.impl.SetEditorSettingsAction)1 DocumentContent (com.intellij.diff.contents.DocumentContent)1 MergeModelBase (com.intellij.diff.merge.MergeModelBase)1 SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)1 LineNumberConvertor (com.intellij.diff.tools.fragmented.LineNumberConvertor)1 TextEditorHolder (com.intellij.diff.tools.holders.TextEditorHolder)1 com.intellij.diff.tools.util (com.intellij.diff.tools.util)1 TextDiffSettings (com.intellij.diff.tools.util.base.TextDiffSettingsHolder.TextDiffSettings)1 TextDiffViewerUtil (com.intellij.diff.tools.util.base.TextDiffViewerUtil)1 TwosideContentPanel (com.intellij.diff.tools.util.side.TwosideContentPanel)1 com.intellij.diff.util (com.intellij.diff.util)1 AllIcons (com.intellij.icons.AllIcons)1 Disposable (com.intellij.openapi.Disposable)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1