コード例 #1
0
    @Nullable
    public GutterIconRenderer createRenderer() {
      myCtrlPressed = myViewer.getModifierProvider().isCtrlPressed();

      boolean isEditable = DiffUtil.isEditable(myViewer.getEditor(mySide));
      boolean isOtherEditable = DiffUtil.isEditable(myViewer.getEditor(mySide.other()));
      boolean isAppendable =
          myFragment.getStartLine1() != myFragment.getEndLine1()
              && myFragment.getStartLine2() != myFragment.getEndLine2();

      if (isOtherEditable && isEditable) {
        if (myCtrlPressed && isAppendable) {
          return createAppendRenderer(mySide);
        } else {
          return createApplyRenderer(mySide);
        }
      } else if (isEditable) {
        return createRevertRenderer(mySide);
      } else if (isOtherEditable) {
        if (isAppendable) {
          return createAppendRenderer(mySide);
        }
      }
      return null;
    }
コード例 #2
0
  @Nullable
  State processBaseChange(int oldLine1, int oldLine2, int shift) {
    int line1 = getStartLine();
    int line2 = getEndLine();

    UpdatedLineRange newRange =
        DiffUtil.updateRangeOnModification(line1, line2, oldLine1, oldLine2, shift);

    boolean rangeAffected =
        newRange.damaged
            || (oldLine2 >= line1
                && oldLine1 <= line2); // RangeMarker can be updated in a different way
    State oldState = rangeAffected ? storeState() : null;

    if (newRange.startLine == newRange.endLine
        && getDiffType() == TextDiffType.DELETED
        && !isResolved()) {
      if (oldState == null) oldState = storeState();
      myViewer.markChangeResolved(this);
    }

    setStartLine(newRange.startLine);
    setEndLine(newRange.endLine);

    return oldState;
  }
コード例 #3
0
 @Nullable
 private GutterIconRenderer createIconRenderer(
     @NotNull final Side sourceSide,
     @NotNull final String tooltipText,
     @NotNull final Icon icon,
     @NotNull final Runnable perform) {
   if (!DiffUtil.isEditable(myViewer.getEditor(sourceSide.other()))) return null;
   return new DiffGutterRenderer(icon, tooltipText) {
     @Override
     protected void performAction(AnActionEvent e) {
       if (!myIsValid) return;
       final Project project = e.getProject();
       final Document document = myViewer.getEditor(sourceSide.other()).getDocument();
       DiffUtil.executeWriteCommand(
           document,
           project,
           "Replace change",
           new Runnable() {
             @Override
             public void run() {
               perform.run();
             }
           });
     }
   };
 }
コード例 #4
0
  private void createHighlighter(@NotNull Side side, boolean ignored) {
    Editor editor = myViewer.getEditor(side);

    TextDiffType type = DiffUtil.getLineDiffType(myFragment);
    int startLine = side.getStartLine(myFragment);
    int endLine = side.getEndLine(myFragment);

    myHighlighters.addAll(
        DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, ignored));
    myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, startLine, endLine, type, false));
  }
コード例 #5
0
  private void createInlineHighlighter(@NotNull DiffFragment fragment, @NotNull Side side) {
    int start = side.getStartOffset(fragment);
    int end = side.getEndOffset(fragment);
    TextDiffType type = DiffUtil.getDiffType(fragment);

    int startOffset = side.getStartOffset(myFragment);
    start += startOffset;
    end += startOffset;

    Editor editor = myViewer.getEditor(side);
    myHighlighters.addAll(DiffDrawUtil.createInlineHighlighter(editor, start, end, type));
  }
コード例 #6
0
 @Nullable
 private GutterIconRenderer createAppendRenderer(@NotNull final Side side) {
   return createIconRenderer(
       side,
       "Append",
       DiffUtil.getArrowDownIcon(side),
       new Runnable() {
         @Override
         public void run() {
           myViewer.appendChange(SimpleDiffChange.this, side);
         }
       });
 }
コード例 #7
0
 @Nullable
 private GutterIconRenderer createIconRenderer(
     @NotNull final String text,
     @NotNull final Icon icon,
     boolean ctrlClickVisible,
     @NotNull final Runnable perform) {
   final String tooltipText =
       DiffUtil.createTooltipText(text, ctrlClickVisible ? CTRL_CLICK_TO_RESOLVE : null);
   return new DiffGutterRenderer(icon, tooltipText) {
     @Override
     protected void performAction(AnActionEvent e) {
       perform.run();
     }
   };
 }
コード例 #8
0
 @Nullable
 private GutterIconRenderer createApplyRenderer(@NotNull final Side side, final boolean modifier) {
   if (isResolved(side)) return null;
   Icon icon =
       isOnesideAppliedConflict() ? DiffUtil.getArrowDownIcon(side) : DiffUtil.getArrowIcon(side);
   return createIconRenderer(
       DiffBundle.message("merge.dialog.apply.change.action.name"),
       icon,
       isConflict(),
       new Runnable() {
         @Override
         public void run() {
           myViewer.executeMergeCommand(
               "Accept change",
               Collections.singletonList(TextMergeChange.this),
               new Runnable() {
                 @Override
                 public void run() {
                   myViewer.replaceChange(TextMergeChange.this, side, modifier);
                 }
               });
         }
       });
 }
コード例 #9
0
  private void createInnerHighlighter(@NotNull ThreeSide side) {
    if (isResolved(side)) return;
    if (myInnerFragments == null) return;

    Editor editor = myViewer.getEditor(side);
    int start =
        DiffUtil.getLinesRange(editor.getDocument(), getStartLine(side), getEndLine(side))
            .getStartOffset();
    for (MergeWordFragment fragment : myInnerFragments) {
      int innerStart = start + fragment.getStartOffset(side);
      int innerEnd = start + fragment.getEndOffset(side);
      myInnerHighlighters.addAll(
          DiffDrawUtil.createInlineHighlighter(editor, innerStart, innerEnd, getDiffType()));
    }
  }
コード例 #10
0
 public void setContents(DiffContent content1, DiffContent content2) {
   LOG.assertTrue(content1 != null && content2 != null);
   LOG.assertTrue(!myDisposed);
   myData.setContents(content1, content2);
   Project project = myData.getProject();
   FileType[] types = DiffUtil.chooseContentTypes(new DiffContent[] {content1, content2});
   VirtualFile beforeFile = content1.getFile();
   VirtualFile afterFile = content2.getFile();
   String path = myDiffRequest == null ? null : myDiffRequest.getWindowTitle();
   myLeftSide.setHighlighterFactory(
       createHighlighter(types[0], beforeFile, afterFile, path, project));
   myRightSide.setHighlighterFactory(
       createHighlighter(types[1], afterFile, beforeFile, path, project));
   setSplitterProportion(content1, content2);
   rediff();
   if (myIsRequestFocus) {
     myPanel.requestScrollEditors();
   }
 }
コード例 #11
0
  public boolean processChange(int oldLine1, int oldLine2, int shift, @NotNull Side side) {
    int line1 = getStartLine(side);
    int line2 = getEndLine(side);
    int sideIndex = side.getIndex();

    DiffUtil.UpdatedLineRange newRange =
        DiffUtil.updateRangeOnModification(line1, line2, oldLine1, oldLine2, shift);
    myLineStartShifts[sideIndex] += newRange.startLine - line1;
    myLineEndShifts[sideIndex] += newRange.endLine - line2;

    if (newRange.damaged) {
      for (MyGutterOperation operation : myOperations) {
        operation.dispose();
      }
      myOperations.clear();

      myIsValid = false;
    }

    return newRange.damaged;
  }
コード例 #12
0
  @Nullable
  private MyGutterOperation createOperation(@NotNull ThreeSide side, @NotNull OperationType type) {
    if (isResolved(side)) return null;

    EditorEx editor = myViewer.getEditor(side);
    Document document = editor.getDocument();

    int line = getStartLine(side);
    int offset =
        line == DiffUtil.getLineCount(document)
            ? document.getTextLength()
            : document.getLineStartOffset(line);

    RangeHighlighter highlighter =
        editor
            .getMarkupModel()
            .addRangeHighlighter(
                offset,
                offset,
                HighlighterLayer.ADDITIONAL_SYNTAX,
                null,
                HighlighterTargetArea.LINES_IN_RANGE);
    return new MyGutterOperation(side, highlighter, type);
  }
コード例 #13
0
  public boolean isSelectedByLine(int line, @NotNull Side side) {
    int line1 = getStartLine(side);
    int line2 = getEndLine(side);

    return DiffUtil.isSelectedByLine(line, line1, line2);
  }
コード例 #14
0
 @NotNull
 public TextDiffType getDiffType() {
   return DiffUtil.getLineDiffType(myFragment);
 }