Search in sources :

Example 1 with VisibleAreaListener

use of com.intellij.openapi.editor.event.VisibleAreaListener in project intellij-community by JetBrains.

the class DiffPanelImpl method onContentChangedIn.

public void onContentChangedIn(EditorSource source) {
    myDiffUpdater.contentRemoved(source);
    final EditorEx editor = source.getEditor();
    if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) {
        editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT);
    }
    DiffSideView viewSide = getSideView(source.getSide());
    viewSide.setEditorSource(getProject(), source);
    Disposer.dispose(myScrollSupport);
    if (editor == null) {
        if (!myDisposed) {
            rediff();
        }
        return;
    }
    final MouseListener mouseListener = PopupHandler.installUnknownPopupHandler(editor.getContentComponent(), new MergeActionGroup(this, source.getSide()), ActionManager.getInstance());
    myDiffUpdater.contentAdded(source);
    editor.getSettings().setLineNumbersShown(true);
    editor.getSettings().setFoldingOutlineShown(false);
    editor.getFoldingModel().setFoldingEnabled(false);
    ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
    Editor editor1 = getEditor(FragmentSide.SIDE1);
    Editor editor2 = getEditor(FragmentSide.SIDE2);
    if (editor1 != null && editor2 != null && myIsSyncScroll) {
        myScrollSupport.install(new EditingSides[] { this });
    }
    final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener();
    final ScrollingModel scrollingModel = editor.getScrollingModel();
    if (visibleAreaListener != null) {
        scrollingModel.addVisibleAreaListener(visibleAreaListener);
        scrollingModel.addVisibleAreaListener(myVisibleAreaListener);
    }
    myFontSizeSynchronizer.synchronize(editor);
    source.addDisposable(new Disposable() {

        public void dispose() {
            myFontSizeSynchronizer.stopSynchronize(editor);
        }
    });
    source.addDisposable(new Disposable() {

        public void dispose() {
            if (visibleAreaListener != null) {
                scrollingModel.removeVisibleAreaListener(visibleAreaListener);
                scrollingModel.removeVisibleAreaListener(myVisibleAreaListener);
            }
            editor.getContentComponent().removeMouseListener(mouseListener);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorEx(com.intellij.openapi.editor.ex.EditorEx) MouseListener(java.awt.event.MouseListener) ScrollingModel(com.intellij.openapi.editor.ScrollingModel) VisibleAreaListener(com.intellij.openapi.editor.event.VisibleAreaListener) Editor(com.intellij.openapi.editor.Editor) EditorMarkupModel(com.intellij.openapi.editor.ex.EditorMarkupModel) MergeActionGroup(com.intellij.openapi.diff.actions.MergeActionGroup)

Example 2 with VisibleAreaListener

use of com.intellij.openapi.editor.event.VisibleAreaListener 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

Disposable (com.intellij.openapi.Disposable)2 VisibleAreaListener (com.intellij.openapi.editor.event.VisibleAreaListener)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 EditorMarkupModel (com.intellij.openapi.editor.ex.EditorMarkupModel)2 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