Skip to content

Commit f85d694

Browse files
[VCS]: Diff Toolbar: New diff type selector IJPL-240828
GitOrigin-RevId: e9924c53695dabfb93096dff5116a3afedce420d
1 parent 9a69be4 commit f85d694

13 files changed

Lines changed: 78 additions & 9 deletions

File tree

platform/diff-api/api-dump.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ com.intellij.diff.FocusableContext
139139
com.intellij.diff.FrameDiffTool
140140
- com.intellij.diff.DiffTool
141141
- a:createComponent(com.intellij.diff.DiffContext,com.intellij.diff.requests.DiffRequest):com.intellij.diff.FrameDiffTool$DiffViewer
142+
- getIcon():javax.swing.Icon
142143
- getToolType():com.intellij.diff.DiffToolType
143144
com.intellij.diff.FrameDiffTool$DiffViewer
144145
- com.intellij.openapi.Disposable

platform/diff-api/src/com/intellij/diff/FrameDiffTool.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.intellij.diff;
33

44
import com.intellij.diff.requests.DiffRequest;
5+
import com.intellij.icons.AllIcons;
56
import com.intellij.openapi.Disposable;
67
import com.intellij.openapi.actionSystem.AnAction;
78
import com.intellij.util.concurrency.annotations.RequiresEdt;
89
import org.jetbrains.annotations.ApiStatus;
910
import org.jetbrains.annotations.NotNull;
1011
import org.jetbrains.annotations.Nullable;
1112

13+
import javax.swing.Icon;
1214
import javax.swing.JComponent;
1315
import java.util.List;
1416

@@ -25,6 +27,12 @@ public interface FrameDiffTool extends DiffTool {
2527
@NotNull
2628
DiffViewer createComponent(@NotNull DiffContext context, @NotNull DiffRequest request);
2729

30+
default @NotNull Icon getIcon() {
31+
return getToolType() == DiffToolType.Unified.INSTANCE
32+
? AllIcons.Diff.Unified
33+
: AllIcons.Diff.SideBySide;
34+
}
35+
2836
default @NotNull DiffToolType getToolType() {
2937
return DiffToolType.Default.INSTANCE;
3038
}

platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.intellij.diff.impl;
33

44
import com.intellij.codeInsight.hint.HintManager;
@@ -934,7 +934,13 @@ public void onSelected(@NotNull Project project, @NotNull DiffTool diffTool) {
934934

935935
@Override
936936
public @NotNull DiffTool getActiveTool() {
937-
return myState.getActiveTool();
937+
DiffTool activeTool = myState.getActiveTool();
938+
for (DiffTool tool : getTools()) {
939+
if (isSameToolOrSubstitutor(tool, activeTool, myContext, myActiveRequest)) {
940+
return tool;
941+
}
942+
}
943+
return activeTool;
938944
}
939945

940946
@Override
@@ -944,7 +950,6 @@ public void onSelected(@NotNull Project project, @NotNull DiffTool diffTool) {
944950
}
945951

946952
private class MyChangeDiffToolComboBoxAction extends ComboBoxAction implements DumbAware {
947-
// TODO: add icons for diff tools, show only icon in toolbar - to reduce jumping on change ?
948953
@Override
949954
public @NotNull ActionUpdateThread getActionUpdateThread() {
950955
return ActionUpdateThread.BGT;

platform/diff-impl/src/com/intellij/diff/impl/ui/DiffToolChooser.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.intellij.diff.impl.ui
33

44
import com.intellij.diff.DiffTool
5+
import com.intellij.diff.FrameDiffTool
6+
import com.intellij.diff.tools.combined.CombinedDiffTool
57
import com.intellij.openapi.actionSystem.ActionUpdateThread
68
import com.intellij.openapi.actionSystem.AnActionEvent
79
import com.intellij.openapi.actionSystem.Presentation
@@ -18,7 +20,17 @@ import javax.swing.JComponent
1820
@ApiStatus.Experimental
1921
@Suppress("DialogTitleCapitalization")
2022
abstract class DiffToolChooser(private val project: Project?) : DumbAwareAction(), CustomComponentAction {
21-
private val segmentedButton = SegmentedButtonComponent { diffTool: DiffTool -> SegmentedButton.createPresentation(text = diffTool.name) }
23+
private val segmentedButton = SegmentedButtonComponent { diffTool: DiffTool ->
24+
val icon = when (diffTool) {
25+
is FrameDiffTool -> diffTool.icon
26+
is CombinedDiffTool -> diffTool.getIcon()
27+
else -> null
28+
}
29+
if (icon != null)
30+
SegmentedButton.createPresentation(icon = icon, toolTipText = diffTool.name)
31+
else
32+
SegmentedButton.createPresentation(text = diffTool.name)
33+
}
2234

2335
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
2436

@@ -61,4 +73,3 @@ abstract class DiffToolChooser(private val project: Project?) : DumbAwareAction(
6173
return segmentedButton
6274
}
6375
}
64-

platform/diff-impl/src/com/intellij/diff/tools/combined/CombinedDiffTool.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
1+
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
22
package com.intellij.diff.tools.combined
33

44
import com.intellij.diff.DiffContext
55
import com.intellij.diff.DiffTool
66
import com.intellij.diff.requests.DiffRequest
7+
import com.intellij.icons.AllIcons
78
import com.intellij.openapi.diff.DiffBundle
89
import org.jetbrains.annotations.ApiStatus
10+
import javax.swing.Icon
911

1012
@ApiStatus.Experimental
11-
internal interface CombinedDiffTool : DiffTool
13+
internal interface CombinedDiffTool : DiffTool {
14+
fun getIcon(): Icon
15+
}
1216

1317
/**
1418
* This tool intended only for persistence purpose.
@@ -18,6 +22,8 @@ internal class CombinedSideBySideDiffTool : CombinedDiffTool {
1822
override fun canShow(context: DiffContext, request: DiffRequest): Boolean = false
1923

2024
override fun getName(): String = DiffBundle.message("combined.side.by.side.viewer")
25+
26+
override fun getIcon(): Icon = AllIcons.Diff.SideBySide
2127
}
2228

2329
/**
@@ -28,4 +34,6 @@ internal class CombinedUnifiedDiffTool : CombinedDiffTool {
2834
override fun canShow(context: DiffContext, request: DiffRequest): Boolean = false
2935

3036
override fun getName(): String = DiffBundle.message("combined.unified.viewer")
37+
38+
override fun getIcon(): Icon = AllIcons.Diff.Unified
3139
}
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading

platform/jewel/ui/api-dump.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,6 +2885,8 @@ f:org.jetbrains.jewel.ui.icons.AllIconsKeys$Diff
28852885
- sf:MagicResolveToolbar:org.jetbrains.jewel.ui.icon.IntelliJIconKey
28862886
- sf:Remove:org.jetbrains.jewel.ui.icon.IntelliJIconKey
28872887
- sf:Revert:org.jetbrains.jewel.ui.icon.IntelliJIconKey
2888+
- sf:SideBySide:org.jetbrains.jewel.ui.icon.IntelliJIconKey
2889+
- sf:Unified:org.jetbrains.jewel.ui.icon.IntelliJIconKey
28882890
- <init>():V
28892891
f:org.jetbrains.jewel.ui.icons.AllIconsKeys$Duplicates
28902892
- sf:SendToTheLeft:org.jetbrains.jewel.ui.icon.IntelliJIconKey

0 commit comments

Comments
 (0)