mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-148560 diff: allow to change separator color
This commit is contained in:
committed by
Aleksey Pivovarov
parent
bd773436aa
commit
f8de2a58d6
@@ -253,9 +253,9 @@ public class DiffLineSeparatorRenderer implements LineMarkerRendererEx, LineSepa
|
||||
// Parameters
|
||||
//
|
||||
|
||||
private static final ColorKey BACKGROUND = ColorKey.createColorKey("DIFF_SEPARATORS_BACKGROUND");
|
||||
private static final ColorKey TOP_BORDER = ColorKey.createColorKey("DIFF_SEPARATORS_TOP_BORDER");
|
||||
private static final ColorKey BOTTOM_BORDER = ColorKey.createColorKey("DIFF_SEPARATORS_BOTTOM_BORDER");
|
||||
public static final ColorKey BACKGROUND = ColorKey.createColorKey("DIFF_SEPARATORS_BACKGROUND");
|
||||
public static final ColorKey TOP_BORDER = ColorKey.createColorKey("DIFF_SEPARATORS_TOP_BORDER");
|
||||
public static final ColorKey BOTTOM_BORDER = ColorKey.createColorKey("DIFF_SEPARATORS_BOTTOM_BORDER");
|
||||
|
||||
private static int getStepSize(int lineHeight) {
|
||||
return Math.max(lineHeight / 3, 1);
|
||||
|
||||
+8
@@ -48,6 +48,8 @@ class DiffColorSettingsTest : HeavyDiffTestCase() {
|
||||
assertContainsMarkerColor(viewer, TextDiffType.INSERTED)
|
||||
assertContainsMarkerColor(viewer, TextDiffType.DELETED)
|
||||
assertContainsMarkerColor(viewer, TextDiffType.CONFLICT)
|
||||
|
||||
assertContainsFoldedFragment(viewer)
|
||||
}
|
||||
finally {
|
||||
panel?.disposeUIResources()
|
||||
@@ -82,4 +84,10 @@ class DiffColorSettingsTest : HeavyDiffTestCase() {
|
||||
}
|
||||
assertTrue(ranges.isNotEmpty())
|
||||
}
|
||||
|
||||
private fun assertContainsFoldedFragment(viewer: SimpleThreesideDiffViewer) {
|
||||
assertTrue(viewer.editors.all {
|
||||
it.foldingModel.allFoldRegions.any { !it.isExpanded }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+18
-3
@@ -16,8 +16,10 @@
|
||||
package com.intellij.openapi.diff.impl.settings;
|
||||
|
||||
import com.intellij.application.options.colors.*;
|
||||
import com.intellij.diff.util.DiffLineSeparatorRenderer;
|
||||
import com.intellij.diff.util.TextDiffTypeFactory;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.options.OptionsBundle;
|
||||
import com.intellij.openapi.options.colors.AttributesDescriptor;
|
||||
import com.intellij.openapi.options.colors.ColorAndFontDescriptorsProvider;
|
||||
import com.intellij.openapi.options.colors.ColorDescriptor;
|
||||
@@ -27,6 +29,7 @@ import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DiffColorsPageFactory implements ColorAndFontPanelFactory, ColorAndFontDescriptorsProvider, DisplayPrioritySortable {
|
||||
@@ -36,7 +39,11 @@ public class DiffColorsPageFactory implements ColorAndFontPanelFactory, ColorAnd
|
||||
@NotNull
|
||||
public NewColorAndFontPanel createPanel(@NotNull ColorAndFontOptions options) {
|
||||
final SchemesPanel schemesPanel = new SchemesPanel(options);
|
||||
final DiffColorDescriptionPanel descriptionPanel = new DiffColorDescriptionPanel(options);
|
||||
|
||||
CompositeColorDescriptionPanel descriptionPanel = new CompositeColorDescriptionPanel();
|
||||
descriptionPanel.addDescriptionPanel(new ColorAndFontDescriptionPanel(), it -> it instanceof ColorAndFontDescription);
|
||||
descriptionPanel.addDescriptionPanel(new DiffColorDescriptionPanel(options), it -> it instanceof TextAttributesDescription);
|
||||
|
||||
final OptionsPanelImpl optionsPanel = new OptionsPanelImpl(options, schemesPanel, DIFF_GROUP, descriptionPanel);
|
||||
final DiffPreviewPanel previewPanel = new DiffPreviewPanel();
|
||||
|
||||
@@ -55,14 +62,22 @@ public class DiffColorsPageFactory implements ColorAndFontPanelFactory, ColorAnd
|
||||
@Override
|
||||
public AttributesDescriptor[] getAttributeDescriptors() {
|
||||
TextDiffTypeFactory.TextDiffTypeImpl[] diffTypes = TextDiffTypeFactory.getInstance().getAllDiffTypes();
|
||||
List<AttributesDescriptor> attributes = ContainerUtil.map(diffTypes, (type) -> new AttributesDescriptor(type.getName(), type.getKey()));
|
||||
List<AttributesDescriptor> attributes = ContainerUtil.map(diffTypes, type -> {
|
||||
return new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.vcs.diff.type.tag.prefix") + type.getName(), type.getKey());
|
||||
});
|
||||
return ArrayUtil.toObjectArray(attributes, AttributesDescriptor.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ColorDescriptor[] getColorDescriptors() {
|
||||
return ColorDescriptor.EMPTY_ARRAY;
|
||||
List<ColorDescriptor> descriptors = new ArrayList<>();
|
||||
|
||||
descriptors.add(new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.vcs.diff.separator.background"), DiffLineSeparatorRenderer.BACKGROUND, ColorDescriptor.Kind.BACKGROUND));
|
||||
descriptors.add(new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.vcs.diff.separator.top_border"), DiffLineSeparatorRenderer.TOP_BORDER, ColorDescriptor.Kind.BACKGROUND));
|
||||
descriptors.add(new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.vcs.diff.separator.bottom_border"), DiffLineSeparatorRenderer.BOTTOM_BORDER, ColorDescriptor.Kind.BACKGROUND));
|
||||
|
||||
return ArrayUtil.toObjectArray(descriptors, ColorDescriptor.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+61
-21
@@ -25,14 +25,18 @@ import com.intellij.diff.tools.simple.SimpleThreesideDiffChange;
|
||||
import com.intellij.diff.tools.simple.SimpleThreesideDiffViewer;
|
||||
import com.intellij.diff.tools.util.base.HighlightPolicy;
|
||||
import com.intellij.diff.tools.util.base.IgnorePolicy;
|
||||
import com.intellij.diff.util.DiffLineSeparatorRenderer;
|
||||
import com.intellij.diff.util.DiffUtil;
|
||||
import com.intellij.diff.util.TextDiffTypeFactory.TextDiffTypeImpl;
|
||||
import com.intellij.diff.util.ThreeSide;
|
||||
import com.intellij.openapi.diff.DiffBundle;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.FoldRegion;
|
||||
import com.intellij.openapi.editor.LogicalPosition;
|
||||
import com.intellij.openapi.editor.colors.EditorColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.editor.event.*;
|
||||
import com.intellij.openapi.editor.ex.DocumentEx;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -58,17 +62,12 @@ import static com.intellij.diff.tools.util.base.TextDiffSettingsHolder.TextDiffS
|
||||
*/
|
||||
class DiffPreviewPanel implements PreviewPanel {
|
||||
private final JPanel myPanel;
|
||||
private final SimpleThreesideDiffViewer myViewer;
|
||||
private final MyViewer myViewer;
|
||||
|
||||
private final EventDispatcher<ColorAndFontSettingsListener> myDispatcher = EventDispatcher.create(ColorAndFontSettingsListener.class);
|
||||
|
||||
public DiffPreviewPanel() {
|
||||
myViewer = new SimpleThreesideDiffViewer(new SampleContext(), new SampleRequest()) {
|
||||
@Override
|
||||
protected boolean forceRediffSynchronously() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
myViewer = new MyViewer();
|
||||
myViewer.init();
|
||||
|
||||
for (ThreeSide side : ThreeSide.values()) {
|
||||
@@ -94,11 +93,14 @@ class DiffPreviewPanel implements PreviewPanel {
|
||||
for (SimpleThreesideDiffChange change : changes) {
|
||||
change.reinstallHighlighters();
|
||||
}
|
||||
myViewer.repaint();
|
||||
}
|
||||
|
||||
public void setColorScheme(final EditorColorsScheme highlighterSettings) {
|
||||
for (EditorEx editorEx : myViewer.getEditors()) {
|
||||
editorEx.setColorsScheme(highlighterSettings);
|
||||
editorEx.setColorsScheme(editorEx.createBoundColorSchemeDelegate(highlighterSettings));
|
||||
editorEx.getColorsScheme().setAttributes(EditorColors.FOLDED_TEXT_ATTRIBUTES, null);
|
||||
editorEx.reinitSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +135,8 @@ class DiffPreviewPanel implements PreviewPanel {
|
||||
TextDiffSettings settings = new TextDiffSettings();
|
||||
settings.setHighlightPolicy(HighlightPolicy.BY_WORD);
|
||||
settings.setIgnorePolicy(IgnorePolicy.IGNORE_WHITESPACES);
|
||||
settings.setContextRange(2);
|
||||
settings.setExpandByDefault(false);
|
||||
putUserData(TextDiffSettings.KEY, settings);
|
||||
}
|
||||
|
||||
@@ -171,7 +175,10 @@ class DiffPreviewPanel implements PreviewPanel {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(EditorMouseEvent e) {
|
||||
if (getChange(mySide, e) != null) EditorUtil.setHandCursor(e.getEditor());
|
||||
int line = getLineNumber(mySide, e);
|
||||
if (getChange(mySide, line) != null || getFoldRegion(mySide, line) != null) {
|
||||
EditorUtil.setHandCursor(e.getEditor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,34 +191,41 @@ class DiffPreviewPanel implements PreviewPanel {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(EditorMouseEvent e) {
|
||||
selectChange(getChange(mySide, e));
|
||||
selectColorForLine(mySide, getLineNumber(mySide, e));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caretPositionChanged(CaretEvent e) {
|
||||
selectChange(getChange(mySide, e.getNewPosition().line));
|
||||
selectColorForLine(mySide, e.getNewPosition().line);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectChange(@Nullable SimpleThreesideDiffChange change) {
|
||||
if (change == null) return;
|
||||
TextDiffTypeImpl diffType = ObjectUtils.tryCast(change.getDiffType(), TextDiffTypeImpl.class);
|
||||
if (diffType != null) {
|
||||
myDispatcher.getMulticaster().selectionInPreviewChanged(diffType.getKey().getExternalName());
|
||||
private void selectColorForLine(@NotNull ThreeSide side, int line) {
|
||||
SimpleThreesideDiffChange change = getChange(side, line);
|
||||
if (change != null) {
|
||||
TextDiffTypeImpl diffType = ObjectUtils.tryCast(change.getDiffType(), TextDiffTypeImpl.class);
|
||||
if (diffType != null) {
|
||||
myDispatcher.getMulticaster().selectionInPreviewChanged(diffType.getKey().getExternalName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FoldRegion region = getFoldRegion(side, line);
|
||||
if (region != null) {
|
||||
myDispatcher.getMulticaster().selectionInPreviewChanged(DiffLineSeparatorRenderer.BACKGROUND.getExternalName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private SimpleThreesideDiffChange getChange(ThreeSide side, EditorMouseEvent e) {
|
||||
private int getLineNumber(@NotNull ThreeSide side, EditorMouseEvent e) {
|
||||
EditorEx editor = myViewer.getEditor(side);
|
||||
LogicalPosition logicalPosition = editor.xyToLogicalPosition(e.getMouseEvent().getPoint());
|
||||
int offset = editor.logicalPositionToOffset(logicalPosition);
|
||||
int line = editor.getDocument().getLineNumber(offset);
|
||||
return getChange(side, line);
|
||||
return editor.getDocument().getLineNumber(offset);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private SimpleThreesideDiffChange getChange(ThreeSide side, int line) {
|
||||
private SimpleThreesideDiffChange getChange(@NotNull ThreeSide side, int line) {
|
||||
for (SimpleThreesideDiffChange change : myViewer.getChanges()) {
|
||||
int startLine = change.getStartLine(side);
|
||||
int endLine = change.getEndLine(side);
|
||||
@@ -220,6 +234,19 @@ class DiffPreviewPanel implements PreviewPanel {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FoldRegion getFoldRegion(@NotNull ThreeSide side, int line) {
|
||||
EditorEx editor = myViewer.getEditor(side);
|
||||
DocumentEx document = editor.getDocument();
|
||||
for (FoldRegion region : editor.getFoldingModel().getAllFoldRegions()) {
|
||||
if (region.isExpanded()) continue;
|
||||
int line1 = document.getLineNumber(region.getStartOffset());
|
||||
int line2 = document.getLineNumber(region.getEndOffset());
|
||||
if (line1 <= line && line <= line2) return region;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blinkSelectedHighlightType(final Object selected) {
|
||||
}
|
||||
@@ -234,4 +261,17 @@ class DiffPreviewPanel implements PreviewPanel {
|
||||
public SimpleThreesideDiffViewer testGetViewer() {
|
||||
return myViewer;
|
||||
}
|
||||
|
||||
private static class MyViewer extends SimpleThreesideDiffViewer {
|
||||
public MyViewer() {super(new SampleContext(), new SampleRequest());}
|
||||
|
||||
@Override
|
||||
protected boolean forceRediffSynchronously() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void repaint() {
|
||||
myPanel.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-3
@@ -73,7 +73,9 @@ public abstract class DiffPreviewProvider {
|
||||
" void bar() {\n" +
|
||||
"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"\n";
|
||||
@NonNls private static final String CENTER_TEXT = "class MyClass {\n" +
|
||||
" int value;\n" +
|
||||
"\n" +
|
||||
@@ -85,7 +87,9 @@ public abstract class DiffPreviewProvider {
|
||||
" void bar() {\n" +
|
||||
"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"\n";
|
||||
@NonNls private static final String RIGHT_TEXT = "class MyClass {\n" +
|
||||
" long value;\n" +
|
||||
"\n" +
|
||||
@@ -98,5 +102,7 @@ public abstract class DiffPreviewProvider {
|
||||
" void bar() {\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
"}";
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"\n";
|
||||
}
|
||||
|
||||
@@ -141,6 +141,10 @@ options.general.color.descriptor.vcs.log.refs.leaf=VCS Log//Common//Leaf
|
||||
options.general.color.descriptor.vcs.log.refs.branch=VCS Log//Common//Branch
|
||||
options.general.color.descriptor.vcs.log.refs.branch.tag=VCS Log//Common//Branch tag
|
||||
options.general.color.descriptor.vcs.log.refs.tag=VCS Log//Common//Tag
|
||||
options.general.color.descriptor.vcs.diff.type.tag.prefix=Changed lines//
|
||||
options.general.color.descriptor.vcs.diff.separator.background=Folded unchanged fragments//Background
|
||||
options.general.color.descriptor.vcs.diff.separator.top_border=Folded unchanged fragments//Top border
|
||||
options.general.color.descriptor.vcs.diff.separator.bottom_border=Folded unchanged fragments//Bottom border
|
||||
options.general.color.descriptor.tearline=Editor//Tear line
|
||||
options.general.color.descriptor.tearline.selected=Editor//Tear line selection
|
||||
options.general.color.descriptor.separator.above=Editor//Separator line above
|
||||
|
||||
+12
-3
@@ -44,7 +44,10 @@ public class PyDiffPreviewProvider extends DiffPreviewProvider {
|
||||
" def bar(self, a, b)\n" +
|
||||
"\n" +
|
||||
" print a\n" +
|
||||
" print b";
|
||||
" print b\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n";
|
||||
@NonNls private static final String CENTER_TEXT = "class MyClass\n" +
|
||||
" value = 123\n" +
|
||||
"\n" +
|
||||
@@ -57,7 +60,10 @@ public class PyDiffPreviewProvider extends DiffPreviewProvider {
|
||||
" def bar(self, a, b)\n" +
|
||||
"\n" +
|
||||
" print a\n" +
|
||||
" print b";
|
||||
" print b\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n";
|
||||
@NonNls private static final String RIGHT_TEXT = "class MyClass\n" +
|
||||
" value = -123\n" +
|
||||
"\n" +
|
||||
@@ -71,5 +77,8 @@ public class PyDiffPreviewProvider extends DiffPreviewProvider {
|
||||
" def bar(self, a, b)\n" +
|
||||
" print a\n" +
|
||||
"\n" +
|
||||
" print b";
|
||||
" print b\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user