@Override public void run() { if (myWasInvoked) return; if (!getWholePanel().isDisplayable()) return; myWasInvoked = true; ChangeCounter.getOrCreate(myMergePanel.getMergeList()).removeListener(this); int doApply = Messages.showOkCancelDialog( getWholePanel(), DiffBundle.message( "merge.all.changes.have.processed.save.and.finish.confirmation.text"), DiffBundle.message("all.changes.processed.dialog.title"), DiffBundle.message("merge.save.and.finish.button"), DiffBundle.message("merge.continue.button"), Messages.getQuestionIcon()); if (doApply != Messages.OK) return; myDialogWrapper.close(DialogWrapper.OK_EXIT_CODE); }
@Nullable private static String addReadOnly(@Nullable String title, @Nullable Editor editor) { if (editor == null || title == null) { return title; } boolean readonly = editor.isViewer() || !editor.getDocument().isWritable(); if (readonly) { title += " " + DiffBundle.message("diff.content.read.only.content.title.suffix"); } return title; }
private static boolean askForceOpenDiff(DiffRequest data) { byte[] bytes1; byte[] bytes2; try { bytes1 = data.getContents()[0].getBytes(); bytes2 = data.getContents()[1].getBytes(); } catch (IOException e) { MessagesEx.error(data.getProject(), e.getMessage()).showNow(); return false; } String message = Arrays.equals(bytes1, bytes2) ? DiffBundle.message("diff.contents.are.identical.message.text") : DiffBundle.message( "diff.contents.have.differences.only.in.line.separators.message.text"); return Messages.showYesNoDialog( data.getProject(), message + "\n" + DiffBundle.message("show.diff.anyway.dialog.message"), DiffBundle.message("no.differences.dialog.title"), Messages.getQuestionIcon()) == Messages.YES; }
@Nullable private GutterIconRenderer createIgnoreRenderer( @NotNull final Side side, final boolean modifier) { if (isResolved(side)) return null; return createIconRenderer( DiffBundle.message("merge.dialog.ignore.change.action.name"), AllIcons.Diff.Remove, isConflict(), new Runnable() { @Override public void run() { myViewer.executeMergeCommand( "Ignore change", Collections.singletonList(TextMergeChange.this), new Runnable() { @Override public void run() { myViewer.ignoreChange(TextMergeChange.this, side, modifier); } }); } }); }
@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); } }); } }); }
public String getNumDifferencesText() { return DiffBundle.message("diff.count.differences.status.text", getLineBlocks().getCount()); }
public LineSeparatorsOnlyDiffPanel() { myLabel.setText( DiffBundle.message( "diff.contents.have.differences.only.in.line.separators.message.text")); }
public FileContentsAreIdenticalDiffPanel() { myLabel.setText(DiffBundle.message("diff.contents.are.identical.message.text")); }
public class TextDiffType implements DiffStatusBar.LegendTypeDescriptor { public static final TextDiffType INSERT = new TextDiffType( TextDiffTypeEnum.INSERT, DiffBundle.message("diff.type.inserted.name"), DiffColors.DIFF_INSERTED); public static final TextDiffType CHANGED = new TextDiffType( TextDiffTypeEnum.CHANGED, DiffBundle.message("diff.type.changed.name"), DiffColors.DIFF_MODIFIED); public static final TextDiffType DELETED = new TextDiffType( TextDiffTypeEnum.DELETED, DiffBundle.message("diff.type.deleted.name"), DiffColors.DIFF_DELETED); public static final TextDiffType CONFLICT = new TextDiffType( TextDiffTypeEnum.CONFLICT, DiffBundle.message("diff.type.conflict.name"), DiffColors.DIFF_CONFLICT); public static final TextDiffType NONE = new TextDiffType(TextDiffTypeEnum.NONE, DiffBundle.message("diff.type.none.name"), null); public static final List<TextDiffType> DIFF_TYPES = Arrays.asList(DELETED, CHANGED, INSERT); public static final List<TextDiffType> MERGE_TYPES = Arrays.asList(DELETED, CHANGED, INSERT, CONFLICT); public static final Convertor<TextDiffType, TextAttributesKey> ATTRIBUTES_KEY = new Convertor<TextDiffType, TextAttributesKey>() { public TextAttributesKey convert(TextDiffType textDiffType) { return textDiffType.getAttributesKey(); } }; private static final double MIDDLE_COLOR_FACTOR = 0.6; private final TextDiffTypeEnum myType; private final TextAttributesKey myAttributesKey; private final String myDisplayName; private final boolean myApplied; private final boolean myInlineWrapper; public boolean isApplied() { return myApplied; } public boolean isInlineWrapper() { return myInlineWrapper; } @NotNull public static TextDiffType create(@Nullable final TextDiffTypeEnum type) { if (TextDiffTypeEnum.INSERT.equals(type)) { return INSERT; } else if (TextDiffTypeEnum.CHANGED.equals(type)) { return CHANGED; } else if (TextDiffTypeEnum.DELETED.equals(type)) { return DELETED; } else if (TextDiffTypeEnum.CONFLICT.equals(type)) { return CONFLICT; } else { return NONE; } } /** * Creates a new TextDiffType based on the given one. * * @param source * @return */ @NotNull public static TextDiffType deriveApplied(@NotNull TextDiffType source) { return new TextDiffType( source.myType, source.myDisplayName, source.myAttributesKey, true, false); } public static TextDiffType deriveInstanceForInlineWrapperFragment(@NotNull TextDiffType source) { return new TextDiffType( source.myType, source.myDisplayName, source.myAttributesKey, source.myApplied, true); } private TextDiffType(TextDiffTypeEnum type, String displayName, TextAttributesKey attributesKey) { this(type, displayName, attributesKey, false, false); } private TextDiffType( TextDiffTypeEnum type, String displayName, TextAttributesKey attributesKey, boolean applied, boolean inlineWrapper) { myType = type; myAttributesKey = attributesKey; myDisplayName = displayName; myApplied = applied; myInlineWrapper = inlineWrapper; } public String getDisplayName() { return myDisplayName; } @Nullable public Color getLegendColor(EditorColorsScheme colorScheme) { TextAttributes attributes = colorScheme.getAttributes(myAttributesKey); return attributes != null ? attributes.getBackgroundColor() : null; } public TextAttributesKey getAttributesKey() { return myAttributesKey; } @Nullable public TextAttributes getTextAttributes(EditorColorsScheme scheme) { return scheme.getAttributes(myAttributesKey); } @Nullable public Color getPolygonColor(Editor editor) { if (isApplied()) { return getLegendColor(editor.getColorsScheme()); } else if (isInlineWrapper()) { return getBgColorForFragmentContainingInlines((EditorEx) editor); } else { TextAttributes attributes = getTextAttributes(editor); return attributes == null ? null : attributes.getBackgroundColor(); } } @Nullable public TextAttributes getTextAttributes(@NotNull Editor editor) { TextAttributes originalAttrs = getTextAttributes(editor.getColorsScheme()); if (originalAttrs == null) { return null; } TextAttributes overridingAttributes = new TextAttributes(); if (myApplied) { overridingAttributes.setBackgroundColor(((EditorEx) editor).getBackgroundColor()); } else if (myInlineWrapper) { overridingAttributes.setBackgroundColor( getBgColorForFragmentContainingInlines((EditorEx) editor)); } return TextAttributes.merge(originalAttrs, overridingAttributes); } @Nullable public Color getTextBackground(Editor editor) { TextAttributes attributes = getTextAttributes(editor); return attributes != null ? attributes.getBackgroundColor() : null; } public String toString() { return myApplied ? myDisplayName + "_applied" : myDisplayName; } public TextDiffTypeEnum getType() { return myType; } @Nullable private Color getBgColorForFragmentContainingInlines(@NotNull EditorEx editor) { TextAttributes originalAttrs = getTextAttributes(editor.getColorsScheme()); if (originalAttrs == null) { return null; } Color fg = originalAttrs.getBackgroundColor(); if (fg == null) { return null; } Color bg = editor.getBackgroundColor(); return getMiddleColor(fg, bg, MIDDLE_COLOR_FACTOR); } @NotNull private static Color getMiddleColor(Color fg, Color bg, double factor) { int red = avg(fg.getRed(), bg.getRed(), factor); int green = avg(fg.getGreen(), bg.getGreen(), factor); int blue = avg(fg.getBlue(), bg.getBlue(), factor); return new Color(red, green, blue); } private static int avg(int fg, int bg, double factor) { return (int) (fg + Math.round(factor * (bg - fg))); } }