Search in sources :

Example 1 with FragmentSide

use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.

the class MergeList method addActions.

private void addActions(@NotNull final FragmentSide side) {
    ChangeList changeList = getChanges(side);
    final FragmentSide originalSide = BRANCH_SIDE;
    for (int i = 0; i < changeList.getCount(); i++) {
        final Change change = changeList.getChange(i);
        if (!change.canHasActions(originalSide))
            continue;
        Icon arrowIcon = side == FragmentSide.SIDE1 ? AllIcons.Diff.ArrowRight : AllIcons.Diff.Arrow;
        AnAction applyAction = new DumbAwareAction(DiffBundle.message("merge.dialog.apply.change.action.name"), null, arrowIcon) {

            @Override
            public void actionPerformed(@Nullable AnActionEvent e) {
                apply(change);
            }
        };
        AnAction ignoreAction = new DumbAwareAction(DiffBundle.message("merge.dialog.ignore.change.action.name"), null, AllIcons.Diff.Remove) {

            @Override
            public void actionPerformed(@Nullable AnActionEvent e) {
                change.removeFromList();
            }
        };
        change.getChangeSide(originalSide).getHighlighterHolder().setActions(new AnAction[] { applyAction, ignoreAction });
    }
}
Also used : FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with FragmentSide

use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.

the class MergeSearchHelper method changeAtOffset.

private Change changeAtOffset(Iterator<Change> iterator, int offset) {
    while (iterator.hasNext()) {
        Change change = iterator.next();
        FragmentSide side = chooseInterestedSide(change);
        if (side == null)
            continue;
        if (change.getChangeSide(side).contains(offset))
            return change;
    }
    return null;
}
Also used : FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide)

Example 3 with FragmentSide

use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.

the class FragmentHighlighterImpl method addModifyActions.

private static void addModifyActions(final LineFragment fragment, DiffMarkup wrapper, DiffMarkup otherWrapper) {
    if (fragment.isEqual())
        return;
    if (fragment.isHasLineChildren())
        return;
    FragmentSide side = wrapper.getSide();
    TextRange range = fragment.getRange(side);
    TextRange otherRange = fragment.getRange(side.otherSide());
    Document document = wrapper.getDocument();
    Document otherDocument = otherWrapper.getDocument();
    wrapper.addAction(MergeOperations.mostSensible(document, otherDocument, range, otherRange, side), range.getStartOffset());
    otherWrapper.addAction(MergeOperations.mostSensible(otherDocument, document, otherRange, range, side.otherSide()), otherRange.getStartOffset());
}
Also used : TextRange(com.intellij.openapi.util.TextRange) FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) Document(com.intellij.openapi.editor.Document)

Example 4 with FragmentSide

use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.

the class Change method apply.

/**
   * Apply the change, i.e. change the "Merge result" document and update range markers, highlighting, gutters, etc.
   * @param original The source side of the change, which is being applied.
   */
private void apply(@NotNull FragmentSide original) {
    FragmentSide targetSide = original.otherSide();
    RangeMarker originalRangeMarker = getRangeMarker(original);
    RangeMarker rangeMarker = getRangeMarker(targetSide);
    TextRange textRange = modifyDocument(getProject(), originalRangeMarker, rangeMarker);
    if (textRange != null && isValid()) {
        updateTargetRangeMarker(targetSide, textRange);
    }
    onApplied();
}
Also used : TextRange(com.intellij.openapi.util.TextRange) RangeMarker(com.intellij.openapi.editor.RangeMarker) FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide)

Example 5 with FragmentSide

use of com.intellij.openapi.diff.impl.highlighting.FragmentSide in project intellij-community by JetBrains.

the class Change method canHasActions.

public boolean canHasActions(FragmentSide fromSide) {
    FragmentSide targetSide = fromSide.otherSide();
    Document targetDocument = getChangeList().getDocument(targetSide);
    if (!targetDocument.isWritable())
        return false;
    Editor targetEditor = getHighlighterHolder(targetSide).getEditor();
    return !targetEditor.isViewer();
}
Also used : FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor)

Aggregations

FragmentSide (com.intellij.openapi.diff.impl.highlighting.FragmentSide)10 DiffFragment (com.intellij.openapi.diff.ex.DiffFragment)3 Editor (com.intellij.openapi.editor.Editor)3 EditingSides (com.intellij.openapi.diff.impl.EditingSides)2 DiffString (com.intellij.openapi.diff.impl.string.DiffString)2 Document (com.intellij.openapi.editor.Document)2 TextRange (com.intellij.openapi.util.TextRange)2 NotNull (org.jetbrains.annotations.NotNull)2 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 Nullable (org.jetbrains.annotations.Nullable)1