public void setHighlightMode(@NotNull HighlightMode mode, boolean notifyManager) {
    myData.setHighlightMode(mode);
    rediff();

    if (notifyManager) {
      DiffManagerImpl.getInstanceEx().setHighlightMode(mode);
    }
  }
  private void setComparisonPolicy(@NotNull ComparisonPolicy policy, boolean notifyManager) {
    myData.setComparisonPolicy(policy);
    rediff();

    if (notifyManager) {
      DiffManagerImpl.getInstanceEx().setComparisonPolicy(policy);
    }
  }
  public DiffPanelImpl(
      final Window owner,
      @NotNull Project project,
      boolean enableToolbar,
      boolean horizontal,
      int diffDividerPolygonsOffset,
      DiffTool parentTool) {
    myProject = project;
    myIsHorizontal = horizontal;
    myParentTool = parentTool;
    myOptions = new DiffPanelOptions(this);
    myPanel = new DiffPanelOuterComponent(TextDiffType.DIFF_TYPES, null);
    myPanel.disableToolbar(!enableToolbar);
    if (enableToolbar) myPanel.resetToolbar();
    myOwnerWindow = owner;
    myIsSyncScroll = true;
    final boolean v = !horizontal;
    myLeftSide = new DiffSideView(this, new CustomLineBorder(1, 0, v ? 0 : 1, v ? 0 : 1));
    myRightSide = new DiffSideView(this, new CustomLineBorder(v ? 0 : 1, v ? 0 : 1, 1, 0));
    myLeftSide.becomeMaster();
    myDiffUpdater = new Rediffers(this);

    myDiffDividerPolygonsOffset = diffDividerPolygonsOffset;

    myData = createDiffPanelState(this);

    if (horizontal) {
      mySplitter =
          new DiffSplitter(
              myLeftSide.getComponent(),
              myRightSide.getComponent(),
              new DiffDividerPaint(this, FragmentSide.SIDE1, diffDividerPolygonsOffset),
              myData);
    } else {
      mySplitter =
          new HorizontalDiffSplitter(myLeftSide.getComponent(), myRightSide.getComponent());
    }

    myPanel.insertDiffComponent(mySplitter.getComponent(), new MyScrollingPanel());
    myDataProvider = new MyGenericDataProvider(this);
    myPanel.setDataProvider(myDataProvider);

    ComparisonPolicy comparisonPolicy = getComparisonPolicy();
    ComparisonPolicy defaultComparisonPolicy =
        DiffManagerImpl.getInstanceEx().getComparisonPolicy();
    if (comparisonPolicy != defaultComparisonPolicy) {
      setComparisonPolicy(defaultComparisonPolicy, false);
    }

    HighlightMode highlightMode = getHighlightMode();
    HighlightMode defaultHighlightMode = DiffManagerImpl.getInstanceEx().getHighlightMode();
    if (highlightMode != defaultHighlightMode) {
      setHighlightMode(defaultHighlightMode, false);
    }

    myVisibleAreaListener =
        new VisibleAreaListener() {
          @Override
          public void visibleAreaChanged(VisibleAreaEvent e) {
            Editor editor1 = getEditor1();
            if (editor1 != null) {
              editor1.getComponent().repaint();
            }
            Editor editor2 = getEditor2();
            if (editor2 != null) {
              editor2.getComponent().repaint();
            }
          }
        };
    registerActions();
  }
Exemple #4
0
    public void execute(
        final Change change,
        final FilePath filePath,
        final SLRUMap<Pair<Long, String>, List<BeforeAfter<TextRange>>> cache,
        final LineStatusTrackerManagerI lstManager) {
      try {
        myDocument = null;
        myOldDocument = documentFromRevision(change.getBeforeRevision());
        final String convertedPath = FilePathsHelper.convertPath(filePath);
        if (filePath.getVirtualFile() != null) {
          myDocument =
              FileStatus.DELETED.equals(change.getFileStatus())
                  ? new DocumentImpl("")
                  : FileDocumentManager.getInstance().getDocument(filePath.getVirtualFile());
          if (myDocument != null) {
            final List<BeforeAfter<TextRange>> cached =
                cache.get(new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath));
            if (cached != null) {
              myRanges = cached;
              return;
            }
          }
        }

        if (myDocument == null) {
          myDocument = documentFromRevision(change.getAfterRevision());
          final List<BeforeAfter<TextRange>> cached =
              cache.get(new Pair<Long, String>(-1L, convertedPath));
          if (cached != null) {
            myRanges = cached;
            return;
          }
        }

        ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy();
        if (comparisonPolicy == null) {
          comparisonPolicy = ComparisonPolicy.DEFAULT;
        }
        final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy);
        final List<LineFragment> lineFragments =
            processor.process(myOldDocument.getText(), myDocument.getText());
        myRanges = new ArrayList<BeforeAfter<TextRange>>(lineFragments.size());
        for (LineFragment lineFragment : lineFragments) {
          if (!lineFragment.isEqual()) {
            final TextRange oldRange = lineFragment.getRange(FragmentSide.SIDE1);
            final TextRange newRange = lineFragment.getRange(FragmentSide.SIDE2);
            int beforeBegin = myOldDocument.getLineNumber(oldRange.getStartOffset());
            int beforeEnd =
                myOldDocument.getLineNumber(
                    correctRangeEnd(oldRange.getEndOffset(), myOldDocument));
            int afterBegin = myDocument.getLineNumber(newRange.getStartOffset());
            int afterEnd =
                myDocument.getLineNumber(correctRangeEnd(newRange.getEndOffset(), myDocument));
            if (oldRange.isEmpty()) {
              beforeEnd = beforeBegin - 1;
            }
            if (newRange.isEmpty()) {
              afterEnd = afterBegin - 1;
            }
            myRanges.add(
                new BeforeAfter<TextRange>(
                    new UnfairTextRange(beforeBegin, beforeEnd),
                    new UnfairTextRange(afterBegin, afterEnd)));
          }
        }
        cache.put(
            new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath),
            new ArrayList<BeforeAfter<TextRange>>(myRanges));
      } catch (VcsException e) {
        myException = e;
      } catch (FilesTooBigForDiffException e) {
        myException = new VcsException(e);
      }
    }