mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 06:39:38 +07:00
diff: simplify DataContext of a DiffRequestProcessor
Avoid computing data context for a DiffViewer component twice. GitOrigin-RevId: 3b61fc4840d7cdb42cce76b22601ebd1f021d682
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f36778006d
commit
b4ca6c7ea3
@@ -30,6 +30,10 @@ public interface FrameDiffTool extends DiffTool {
|
||||
}
|
||||
|
||||
interface DiffViewer extends Disposable {
|
||||
/**
|
||||
* The component will be used for {@link com.intellij.openapi.actionSystem.ActionToolbar#setTargetComponent(JComponent)}
|
||||
* and might want to implement {@link com.intellij.openapi.actionSystem.UiDataProvider} for {@link ToolbarComponents#toolbarActions}.
|
||||
*/
|
||||
@NotNull
|
||||
JComponent getComponent();
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ public interface MergeTool {
|
||||
* {@link MergeRequest#applyResult(MergeResult)} will be performed by the caller, so it shouldn't be called by MergeViewer directly.
|
||||
*/
|
||||
interface MergeViewer extends Disposable {
|
||||
/**
|
||||
* The component will be used for {@link com.intellij.openapi.actionSystem.ActionToolbar#setTargetComponent(JComponent)}
|
||||
* and might want to implement {@link com.intellij.openapi.actionSystem.UiDataProvider} for {@link ToolbarComponents#toolbarActions}.
|
||||
*/
|
||||
@NotNull
|
||||
JComponent getComponent();
|
||||
|
||||
|
||||
@@ -2770,7 +2770,6 @@ f:com.intellij.diff.util.DiffUtil
|
||||
- s:getArrowIcon(com.intellij.diff.util.Side):javax.swing.Icon
|
||||
- s:getCaretPosition(com.intellij.openapi.editor.Editor):com.intellij.openapi.editor.LogicalPosition
|
||||
- s:getContentLineConvertor(com.intellij.diff.contents.DocumentContent):java.util.function.IntUnaryOperator
|
||||
- s:getData(com.intellij.openapi.actionSystem.DataProvider,com.intellij.openapi.actionSystem.DataProvider,java.lang.String):java.lang.Object
|
||||
- s:getDefaultDiffPanelSize():java.awt.Dimension
|
||||
- s:getDefaultDiffWindowSize():java.awt.Dimension
|
||||
- s:getDiffSettings(com.intellij.diff.DiffContext):com.intellij.diff.impl.DiffSettingsHolder$DiffSettings
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.intellij.diff.util.DiffUserDataKeysEx;
|
||||
import com.intellij.diff.util.DiffUserDataKeysEx.ScrollToPolicy;
|
||||
import com.intellij.diff.util.DiffUtil;
|
||||
import com.intellij.diff.util.LineRange;
|
||||
import com.intellij.ide.impl.DataManagerImpl;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
@@ -184,12 +183,12 @@ public abstract class DiffRequestProcessor
|
||||
if (myIsNewToolbar) {
|
||||
myToolbar.setLayoutStrategy(ToolbarLayoutStrategy.NOWRAP_STRATEGY);
|
||||
}
|
||||
myToolbar.setTargetComponent(myMainPanel);
|
||||
myToolbarWrapper = new Wrapper(myToolbar.getComponent());
|
||||
myToolbar.setTargetComponent(myContentPanel);
|
||||
myToolbarWrapper = new Wrapper(myContentPanel.getTargetComponent());
|
||||
|
||||
myRightToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.DIFF_RIGHT_TOOLBAR, myRightToolbarGroup, true);
|
||||
myRightToolbar.setLayoutStrategy(ToolbarLayoutStrategy.NOWRAP_STRATEGY);
|
||||
myRightToolbar.setTargetComponent(myMainPanel);
|
||||
myRightToolbar.setTargetComponent(myContentPanel.getTargetComponent());
|
||||
|
||||
myRightToolbarWrapper = new Wrapper(JBUI.Panels.simplePanel(myRightToolbar.getComponent()));
|
||||
|
||||
@@ -631,10 +630,12 @@ public abstract class DiffRequestProcessor
|
||||
collectToolbarActions(viewerActions);
|
||||
|
||||
((ActionToolbarImpl)myToolbar).reset(); // do not leak previous DiffViewer via caches
|
||||
myToolbar.setTargetComponent(myContentPanel.getTargetComponent());
|
||||
myToolbar.updateActionsImmediately();
|
||||
recursiveRegisterShortcutSet(myToolbarGroup, myMainPanel, null);
|
||||
|
||||
if (myIsNewToolbar) {
|
||||
myRightToolbar.setTargetComponent(myContentPanel.getTargetComponent());
|
||||
((ActionToolbarImpl)myRightToolbar).reset();
|
||||
myRightToolbar.updateActionsImmediately();
|
||||
recursiveRegisterShortcutSet(myRightToolbarGroup, myMainPanel, null);
|
||||
@@ -1347,7 +1348,6 @@ public abstract class DiffRequestProcessor
|
||||
DataSink.uiDataSnapshot(sink, myContext.getUserData(DiffUserDataKeys.DATA_PROVIDER));
|
||||
DataSink.uiDataSnapshot(sink, myActiveRequest.getUserData(DiffUserDataKeys.DATA_PROVIDER));
|
||||
DataSink.uiDataSnapshot(sink, myState);
|
||||
DataSink.uiDataSnapshot(sink, DataManagerImpl.getDataProviderEx(myContentPanel.getTargetComponent()));
|
||||
|
||||
sink.set(CommonDataKeys.PROJECT, myProject);
|
||||
sink.set(DiffDataKeys.DIFF_CONTEXT, myContext);
|
||||
|
||||
@@ -11,8 +11,6 @@ import com.intellij.diff.tools.util.PrevNextDifferenceIterable;
|
||||
import com.intellij.diff.util.DiffPlaces;
|
||||
import com.intellij.diff.util.DiffUserDataKeys;
|
||||
import com.intellij.diff.util.DiffUtil;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.impl.DataManagerImpl;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.openapi.Disposable;
|
||||
@@ -238,7 +236,7 @@ public abstract class MergeRequestProcessor implements Disposable {
|
||||
private @NotNull BorderLayoutPanel createFeedbackToolbarPanel() {
|
||||
AnAction action = ActionManager.getInstance().getAction("Diff.Conflicts.Feedback");
|
||||
ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("FeedbackToolbar", (ActionGroup)action, true);
|
||||
actionToolbar.setTargetComponent(myMainPanel);
|
||||
actionToolbar.setTargetComponent(myContentPanel.getTargetComponent());
|
||||
return new BorderLayoutPanel().addToRight(actionToolbar.getComponent());
|
||||
}
|
||||
|
||||
@@ -271,8 +269,7 @@ public abstract class MergeRequestProcessor implements Disposable {
|
||||
ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.DIFF_TOOLBAR, group, true);
|
||||
toolbar.setShowSeparatorTitles(true);
|
||||
|
||||
DataManager.registerDataProvider(toolbar.getComponent(), myMainPanel);
|
||||
toolbar.setTargetComponent(toolbar.getComponent());
|
||||
toolbar.setTargetComponent(myContentPanel.getTargetComponent());
|
||||
|
||||
myToolbarPanel.setContent(toolbar.getComponent());
|
||||
recursiveRegisterShortcutSet(group, myMainPanel, null);
|
||||
@@ -553,12 +550,6 @@ public abstract class MergeRequestProcessor implements Disposable {
|
||||
public Object getData(@NotNull @NonNls String dataId) {
|
||||
Object data;
|
||||
|
||||
DataProvider contentProvider = DataManagerImpl.getDataProviderEx(myContentPanel.getTargetComponent());
|
||||
if (contentProvider != null) {
|
||||
data = contentProvider.getData(dataId);
|
||||
if (data != null) return data;
|
||||
}
|
||||
|
||||
if (CommonDataKeys.PROJECT.is(dataId)) {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@@ -1744,19 +1744,6 @@ public final class DiffUtil {
|
||||
// DataProvider
|
||||
//
|
||||
|
||||
@Nullable
|
||||
public static Object getData(@Nullable DataProvider provider, @Nullable DataProvider fallbackProvider, @NotNull @NonNls String dataId) {
|
||||
if (provider != null) {
|
||||
Object data = provider.getData(dataId);
|
||||
if (data != null) return data;
|
||||
}
|
||||
if (fallbackProvider != null) {
|
||||
Object data = fallbackProvider.getData(dataId);
|
||||
if (data != null) return data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> void putDataKey(@NotNull UserDataHolder holder, @NotNull DataKey<T> key, @Nullable T value) {
|
||||
DataProvider dataProvider = holder.getUserData(DiffUserDataKeys.DATA_PROVIDER);
|
||||
if (!(dataProvider instanceof GenericDataProvider)) {
|
||||
|
||||
@@ -10,8 +10,6 @@ import com.intellij.diff.requests.DiffRequest;
|
||||
import com.intellij.diff.requests.ErrorDiffRequest;
|
||||
import com.intellij.diff.tools.ErrorDiffTool;
|
||||
import com.intellij.diff.util.DiffUtil;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.impl.DataManagerImpl;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -93,16 +91,9 @@ public class SvnDiffViewer implements DiffViewer {
|
||||
MyPropertyContext propertyContext = initPropertyContext(context);
|
||||
myPropertiesViewer = createPropertiesViewer(propertyRequest, propertyContext);
|
||||
|
||||
myPanel = new JPanel(new BorderLayout());
|
||||
myPanel = new SvnContentPanel();
|
||||
myPanel.add(mySplitter, BorderLayout.CENTER);
|
||||
myPanel.add(myNotificationPanel, BorderLayout.SOUTH);
|
||||
DataManager.registerDataProvider(myPanel, dataId -> {
|
||||
DataProvider propertiesDataProvider = DataManagerImpl.getDataProviderEx(myPropertiesViewer.getComponent());
|
||||
DataProvider contentDataProvider = DataManagerImpl.getDataProviderEx(myContentViewer.getComponent());
|
||||
DataProvider defaultDP = myPropertiesViewerFocused ? propertiesDataProvider : contentDataProvider;
|
||||
DataProvider fallbackDP = myPropertiesViewerFocused ? contentDataProvider : propertiesDataProvider;
|
||||
return DiffUtil.getData(defaultDP, fallbackDP, dataId);
|
||||
});
|
||||
|
||||
updatePropertiesPanel();
|
||||
}
|
||||
@@ -321,6 +312,24 @@ public class SvnDiffViewer implements DiffViewer {
|
||||
// Helpers
|
||||
//
|
||||
|
||||
private class SvnContentPanel extends JPanel implements UiDataProvider {
|
||||
private SvnContentPanel() {
|
||||
super(new BorderLayout());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uiDataSnapshot(@NotNull DataSink sink) {
|
||||
if (myPropertiesViewerFocused) {
|
||||
DataSink.uiDataSnapshot(sink, myContentViewer);
|
||||
DataSink.uiDataSnapshot(sink, myPropertiesViewer);
|
||||
}
|
||||
else {
|
||||
DataSink.uiDataSnapshot(sink, myPropertiesViewer);
|
||||
DataSink.uiDataSnapshot(sink, myContentViewer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MyPropertyContext extends DiffContext {
|
||||
@Nullable
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user