From 1dee3a5d6d5a32f345a828fa6c74898df937ab25 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 9 Aug 2024 02:15:28 +0400 Subject: [PATCH] migrate `DataManager.registerDataProvider`: platform GitOrigin-RevId: c7805a21defb3a6c7192c65e4f38ba46e894f4e5 --- .../comment/CodeReviewCommentUIUtil.kt | 45 +++++++------- .../diff/tools/dir/DirDiffViewer.java | 18 +++--- .../openapi/diff/impl/dir/DirDiffFrame.java | 19 +++--- .../openapi/diff/impl/dir/DirDiffPanel.java | 37 +++-------- .../ConfigurationSettingsEditorWrapper.java | 10 +-- .../execution/impl/RunConfigurable.kt | 14 ++--- .../impl/SingleConfigurationConfigurable.java | 45 +++++++------- .../src/ServiceViewManagerImpl.java | 23 +++---- .../src/ServiceViewTreeUi.java | 16 ++--- .../services/ServiceViewDescriptor.java | 10 +-- .../documentation/DocumentationComponent.java | 8 +-- .../codeInsight/lookup/impl/LookupUi.java | 14 ++--- .../ide/projectView/impl/ProjectViewImpl.java | 59 ++++++++---------- .../intellij/ide/util/FileStructurePopup.java | 62 ++++++------------- .../internal/ImageDuplicateResultsDialog.java | 40 ++++-------- .../ide/ui/DocumentationPopupUI.kt | 36 ++++------- .../configuration/ContentEntryTreeEditor.java | 34 ++++------ .../integration/ui/views/RevisionsList.java | 14 ++--- .../LightEditModeNotificationWidget.java | 27 +++----- .../impl/frame/XSplitterWatchesViewImpl.kt | 5 +- .../xdebugger/impl/frame/XVariablesView.java | 31 ++++------ .../impl/frame/XWatchesViewImpl.java | 10 +-- .../XToggleEvaluateExpressionFieldAction.java | 2 +- 23 files changed, 210 insertions(+), 369 deletions(-) diff --git a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/CodeReviewCommentUIUtil.kt b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/CodeReviewCommentUIUtil.kt index 908d963ebd6c..7ccbc27d9296 100644 --- a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/CodeReviewCommentUIUtil.kt +++ b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/comment/CodeReviewCommentUIUtil.kt @@ -17,10 +17,10 @@ import com.intellij.collaboration.ui.util.bindIconIn import com.intellij.collaboration.ui.util.bindTextIn import com.intellij.collaboration.ui.util.bindVisibilityIn import com.intellij.icons.AllIcons -import com.intellij.ide.DataManager import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.openapi.actionSystem.CustomizedDataContext +import com.intellij.openapi.actionSystem.DataSink import com.intellij.openapi.actionSystem.PlatformCoreDataKeys +import com.intellij.openapi.actionSystem.UiDataProvider import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColorsManager import com.intellij.openapi.ui.MessageDialogBuilder @@ -69,33 +69,32 @@ object CodeReviewCommentUIUtil { val scheme = EditorColorsManager.getInstance().globalScheme scheme.getColor(EditorColors.TEARLINE_COLOR) ?: JBColor.border() } - return ClippingRoundedPanel(EDITOR_INLAY_PANEL_ARC, borderColor, BorderLayout()).apply { + val roundedPanel = ClippingRoundedPanel(EDITOR_INLAY_PANEL_ARC, borderColor, BorderLayout()).apply { background = JBColor.lazy { val scheme = EditorColorsManager.getInstance().globalScheme scheme.defaultBackground } - add(component) - }.also { - component.addComponentListener(object : ComponentAdapter() { - override fun componentResized(e: ComponentEvent?) = - it.dispatchEvent(ComponentEvent(component, ComponentEvent.COMPONENT_RESIZED)) + add(UiDataProvider.wrapComponent(component) { sink -> + suppressOuterEditorData(sink) }) - DataManager.registerDataProvider(it) { dataId -> - when { - CommonDataKeys.EDITOR.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - CommonDataKeys.HOST_EDITOR.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - CommonDataKeys.EDITOR_EVEN_IF_INACTIVE.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - CommonDataKeys.CARET.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - CommonDataKeys.VIRTUAL_FILE.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - CommonDataKeys.VIRTUAL_FILE_ARRAY.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - CommonDataKeys.LANGUAGE.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - CommonDataKeys.PSI_FILE.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - CommonDataKeys.PSI_ELEMENT.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - PlatformCoreDataKeys.FILE_EDITOR.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.`is`(dataId) -> CustomizedDataContext.EXPLICIT_NULL - else -> null - } + } + component.addComponentListener(object : ComponentAdapter() { + override fun componentResized(e: ComponentEvent?) { + roundedPanel.dispatchEvent(ComponentEvent(component, ComponentEvent.COMPONENT_RESIZED)) } + }) + return roundedPanel + } + + private fun suppressOuterEditorData(sink: DataSink) { + arrayOf(CommonDataKeys.EDITOR, CommonDataKeys.HOST_EDITOR, CommonDataKeys.EDITOR_EVEN_IF_INACTIVE, + CommonDataKeys.CARET, + CommonDataKeys.VIRTUAL_FILE, CommonDataKeys.VIRTUAL_FILE_ARRAY, + CommonDataKeys.LANGUAGE, + CommonDataKeys.PSI_FILE, CommonDataKeys.PSI_ELEMENT, + PlatformCoreDataKeys.FILE_EDITOR, + PlatformCoreDataKeys.PSI_ELEMENT_ARRAY).forEach { + sink.setNull(it) } } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/dir/DirDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/dir/DirDiffViewer.java index 953639f7afa4..b65ec02db73b 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/dir/DirDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/dir/DirDiffViewer.java @@ -24,13 +24,14 @@ import com.intellij.diff.contents.EmptyContent; import com.intellij.diff.contents.FileContent; import com.intellij.diff.requests.ContentDiffRequest; import com.intellij.diff.requests.DiffRequest; -import com.intellij.ide.DataManager; import com.intellij.ide.diff.DiffElement; import com.intellij.ide.diff.DirDiffSettings; import com.intellij.ide.diff.VirtualFileDiffElement; import com.intellij.ide.highlighter.ArchiveFileType; import com.intellij.openapi.Disposable; +import com.intellij.openapi.actionSystem.DataSink; import com.intellij.openapi.actionSystem.PlatformCoreDataKeys; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.diff.impl.dir.DirDiffPanel; import com.intellij.openapi.diff.impl.dir.DirDiffTableModel; import com.intellij.openapi.diff.impl.dir.DirDiffWindow; @@ -42,14 +43,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.*; import java.util.Arrays; import java.util.List; class DirDiffViewer implements FrameDiffTool.DiffViewer { private final DirDiffPanel myDirDiffPanel; - private final JPanel myPanel; + private final JComponent myComponent; private final String myHelpID; DirDiffViewer(@NotNull DiffContext context, @NotNull ContentDiffRequest request) { @@ -82,13 +82,9 @@ class DirDiffViewer implements FrameDiffTool.DiffViewer { } }); - myPanel = new JPanel(new BorderLayout()); - myPanel.add(myDirDiffPanel.getPanel(), BorderLayout.CENTER); - DataManager.registerDataProvider(myPanel, dataId -> { - if (PlatformCoreDataKeys.HELP_ID.is(dataId)) { - return myHelpID; - } - return myDirDiffPanel.getData(dataId); + myComponent = UiDataProvider.wrapComponent(myDirDiffPanel.getPanel(), sink -> { + sink.set(PlatformCoreDataKeys.HELP_ID, myHelpID); + DataSink.uiDataSnapshot(sink, myDirDiffPanel); }); } @@ -109,7 +105,7 @@ class DirDiffViewer implements FrameDiffTool.DiffViewer { @NotNull @Override public JComponent getComponent() { - return myPanel; + return myComponent; } @Nullable diff --git a/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java b/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java index 9b2a27b1b344..0f81c215c507 100644 --- a/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java +++ b/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffFrame.java @@ -1,8 +1,8 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.diff.impl.dir; -import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.PlatformCoreDataKeys; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.FrameWrapper; import com.intellij.openapi.util.Disposer; @@ -14,22 +14,17 @@ import org.jetbrains.annotations.ApiStatus; */ @ApiStatus.Internal public final class DirDiffFrame extends FrameWrapper { - private final DirDiffPanel myPanel; public DirDiffFrame(Project project, DirDiffTableModel model) { super(project, "DirDiffDialog"); setSize(JBUI.size(800, 600)); setTitle(model.getTitle()); - myPanel = new DirDiffPanel(model, new DirDiffWindow.Frame(this)); - Disposer.register(this, myPanel); - setComponent(myPanel.getPanel()); - setPreferredFocusedComponent(myPanel.getTable()); + DirDiffPanel panel = new DirDiffPanel(model, new DirDiffWindow.Frame(this)); + Disposer.register(this, panel); + setComponent(UiDataProvider.wrapComponent(panel.getPanel(), sink -> { + sink.set(PlatformCoreDataKeys.HELP_ID, "reference.dialogs.diff.folder"); + })); + setPreferredFocusedComponent(panel.getTable()); closeOnEsc(); - DataManager.registerDataProvider(myPanel.getPanel(), dataId -> { - if (PlatformCoreDataKeys.HELP_ID.is(dataId)) { - return "reference.dialogs.diff.folder"; - } - return null; - }); } } diff --git a/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java b/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java index 4ef75fbaa2fa..e641a25d9c95 100644 --- a/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java +++ b/platform/diff-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffPanel.java @@ -10,7 +10,6 @@ import com.intellij.diff.requests.SimpleDiffRequest; import com.intellij.diff.tools.util.DiffDataKeys; import com.intellij.diff.tools.util.PrevNextDifferenceIterable; import com.intellij.diff.util.DiffPlaces; -import com.intellij.ide.DataManager; import com.intellij.ide.HelpTooltip; import com.intellij.ide.diff.DiffElement; import com.intellij.ide.util.PropertiesComponent; @@ -45,7 +44,6 @@ import com.intellij.util.ui.NamedColorUtil; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.components.BorderLayoutPanel; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,7 +65,7 @@ import java.util.concurrent.Callable; */ @ApiStatus.Internal @SuppressWarnings("unchecked") -public class DirDiffPanel implements Disposable, DataProvider { +public class DirDiffPanel implements Disposable { private static final Logger LOG = Logger.getInstance(DirDiffPanel.class); public static final DataKey DIR_DIFF_MODEL = DataKey.create("DIR_DIFF_MODEL"); @@ -205,7 +203,6 @@ public class DirDiffPanel implements Disposable, DataProvider { UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, label); filesPanel.addToBottom(label); } - DataManager.registerDataProvider(filesPanel, this); PopupHandler.installPopupMenu(myTable, "DirDiffMenu", "DirDiffPanel"); myFilterPanel = new JPanel(new BorderLayout()); @@ -222,8 +219,8 @@ public class DirDiffPanel implements Disposable, DataProvider { headerPanel.add(targetPanel, gb.next()); Splitter tableSplitter = new OnePixelSplitter(true, SPLITTER_PROPORTION_KEY, 0.4f); - tableSplitter.setFirstComponent(JBUI.Panels.simplePanel(filesPanel) - .addToTop(headerPanel)); + JComponent wrapped = UiDataProvider.wrapComponent(filesPanel, sink -> uiDataSnapshot(sink)); + tableSplitter.setFirstComponent(JBUI.Panels.simplePanel(wrapped).addToTop(headerPanel)); final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), wnd.getDisposable()); loadingPanel.addListener(new JBLoadingPanelListener.Adapter() { @@ -453,27 +450,13 @@ public class DirDiffPanel implements Disposable, DataProvider { myModel.stopUpdating(); } - @Override - public Object getData(@NotNull @NonNls String dataId) { - if (CommonDataKeys.PROJECT.is(dataId)) { - return myProject; - } - else if (DIR_DIFF_MODEL.is(dataId)) { - return myModel; - } - else if (DIR_DIFF_TABLE.is(dataId)) { - return myTable; - } - else if (DIR_DIFF_FILTER.is(dataId)) { - return myFilter; - } - else if (DiffDataKeys.NAVIGATABLE_ARRAY.is(dataId)) { - return getNavigatableArray(); - } - else if (DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE.is(dataId)) { - return new MyPrevNextDifferenceIterable(); - } - return null; + private void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(CommonDataKeys.PROJECT, myProject); + sink.set(DIR_DIFF_MODEL, myModel); + sink.set(DIR_DIFF_TABLE, myTable); + sink.set(DIR_DIFF_FILTER, myFilter); + sink.set(DiffDataKeys.NAVIGATABLE_ARRAY, getNavigatableArray()); + sink.set(DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE, new MyPrevNextDifferenceIterable()); } private Navigatable @NotNull [] getNavigatableArray() { diff --git a/platform/execution-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java b/platform/execution-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java index e550748e2634..c0cf1f40201c 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java +++ b/platform/execution-impl/src/com/intellij/execution/impl/ConfigurationSettingsEditorWrapper.java @@ -10,8 +10,8 @@ import com.intellij.execution.runners.ProgramRunner; import com.intellij.execution.ui.RunConfigurationFragmentedEditor; import com.intellij.execution.ui.RunnerAndConfigurationSettingsEditor; import com.intellij.execution.ui.TargetAwareRunConfigurationEditor; -import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.project.Project; @@ -84,13 +84,9 @@ public final class ConfigurationSettingsEditorWrapper extends SettingsEditor { - if (CONFIGURATION_EDITOR_KEY.is(dataId)) { - return this; - } - return null; + return UiDataProvider.wrapComponent(content.panel, sink -> { + sink.set(CONFIGURATION_EDITOR_KEY, this); }); - return content.panel; } @Override diff --git a/platform/execution-impl/src/com/intellij/execution/impl/RunConfigurable.kt b/platform/execution-impl/src/com/intellij/execution/impl/RunConfigurable.kt index bb8c72ae34e8..975adf7623fc 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/RunConfigurable.kt +++ b/platform/execution-impl/src/com/intellij/execution/impl/RunConfigurable.kt @@ -11,7 +11,6 @@ import com.intellij.execution.impl.RunConfigurable.Companion.collectNodesRecursi import com.intellij.execution.impl.RunConfigurableNodeKind.* import com.intellij.execution.impl.statistics.RunConfigurationOptionUsagesCollector import com.intellij.icons.AllIcons -import com.intellij.ide.DataManager import com.intellij.ide.IdeBundle import com.intellij.ide.dnd.TransferableList import com.intellij.openapi.Disposable @@ -486,16 +485,13 @@ open class RunConfigurable constructor(protected val project: Project) : Configu } override fun createComponent(): JComponent? { - wholePanel = JPanel(BorderLayout()) - DataManager.registerDataProvider(wholePanel!!) { dataId -> - when (dataId) { - RunConfigurationSelector.KEY.name -> RunConfigurationSelector { configuration -> selectConfiguration(configuration) } - CommonDataKeys.PROJECT.name -> project - RunConfigurationCreator.KEY.name -> this - else -> null + wholePanel = object : JPanel(BorderLayout()), UiDataProvider { + override fun uiDataSnapshot(sink: DataSink) { + sink[RunConfigurationSelector.KEY] = RunConfigurationSelector { selectConfiguration(it) } + sink[CommonDataKeys.PROJECT] = project + sink[RunConfigurationCreator.KEY] = this@RunConfigurable } } - if (SystemInfo.isMac) { val touchbarActions = DefaultActionGroup(toolbarAddAction) TouchbarActionCustomizations.setShowText(touchbarActions, true) diff --git a/platform/execution-impl/src/com/intellij/execution/impl/SingleConfigurationConfigurable.java b/platform/execution-impl/src/com/intellij/execution/impl/SingleConfigurationConfigurable.java index ea4ec9aa836e..9cef7e8cc65b 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/SingleConfigurationConfigurable.java +++ b/platform/execution-impl/src/com/intellij/execution/impl/SingleConfigurationConfigurable.java @@ -13,6 +13,8 @@ import com.intellij.execution.ui.RunnerAndConfigurationSettingsEditor; import com.intellij.icons.AllIcons; import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.openapi.actionSystem.DataSink; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.NonBlockingReadAction; import com.intellij.openapi.application.ReadAction; @@ -234,32 +236,27 @@ public final class SingleConfigurationConfigurable { - if (myComponent == null) { - return null; // disposed - } - if (ConfigurationSettingsEditorWrapper.CONFIGURATION_EDITOR_KEY.is(dataId)) { - return getEditor(); - } - if (RUN_ON_TARGET_NAME_KEY.is(dataId)) { - return TargetEnvironmentConfigurations.getEffectiveTargetName(myRunOnTargetPanel.getDefaultTargetName(), myProject); - } - if (RunConfigurationSelector.KEY.is(dataId)) { - return new RunConfigurationSelector() { - @Override - public void select(@NotNull RunConfiguration configuration) { - RunnerAndConfigurationSettingsImpl settings = RunManagerImpl.getInstanceImpl(myProject).getSettings(configuration); - RunDialog.editConfiguration(myProject, - Objects.requireNonNull(settings), - ExecutionBundle.message("edit.run.configuration.for.item.dialog.title", configuration.getName())); - } - }; - } - return null; - }); Dimension size = result.getPreferredSize(); result.setPreferredSize(new Dimension(Math.min(size.width, 800), Math.min(size.height, 600))); - return result; + return UiDataProvider.wrapComponent(result, sink -> uiDataSnapshot(sink)); + } + + private void uiDataSnapshot(@NotNull DataSink sink) { + if (myComponent == null) return; + + sink.set(ConfigurationSettingsEditorWrapper.CONFIGURATION_EDITOR_KEY, + getEditor() instanceof ConfigurationSettingsEditorWrapper o ? o : null); + sink.set(RUN_ON_TARGET_NAME_KEY, + TargetEnvironmentConfigurations.getEffectiveTargetName(myRunOnTargetPanel.getDefaultTargetName(), myProject)); + sink.set(RunConfigurationSelector.KEY, new RunConfigurationSelector() { + @Override + public void select(@NotNull RunConfiguration configuration) { + RunnerAndConfigurationSettingsImpl settings = RunManagerImpl.getInstanceImpl(myProject).getSettings(configuration); + RunDialog.editConfiguration(myProject, + Objects.requireNonNull(settings), + ExecutionBundle.message("edit.run.configuration.for.item.dialog.title", configuration.getName())); + } + }); } JComponent getValidationComponent() { diff --git a/platform/execution.serviceView/src/ServiceViewManagerImpl.java b/platform/execution.serviceView/src/ServiceViewManagerImpl.java index bfe95fab98da..201c5e9984b2 100644 --- a/platform/execution.serviceView/src/ServiceViewManagerImpl.java +++ b/platform/execution.serviceView/src/ServiceViewManagerImpl.java @@ -6,7 +6,6 @@ import com.intellij.execution.ExecutionBundle; import com.intellij.execution.services.*; import com.intellij.execution.services.ServiceEventListener.ServiceEvent; import com.intellij.icons.AllIcons; -import com.intellij.ide.DataManager; import com.intellij.ide.lightEdit.LightEditUtil; import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.util.treeView.TreeState; @@ -261,7 +260,6 @@ public final class ServiceViewManagerImpl implements ServiceViewManager, Persist myAutoScrollToSourceHandler = ServiceViewSourceScrollHelper.createAutoScrollToSourceHandler(myProject); } ToolWindowEx toolWindowEx = (ToolWindowEx)toolWindow; - Wrapper toolWindowHeaderSideComponent = setToolWindowHeaderSideComponent(toolWindowEx); ServiceViewSourceScrollHelper.installAutoScrollSupport(myProject, toolWindowEx, myAutoScrollToSourceHandler); Pair> states = getServiceViewStates(toolWindowId); @@ -270,8 +268,9 @@ public final class ServiceViewManagerImpl implements ServiceViewManager, Persist mainView.setAutoScrollToSourceHandler(myAutoScrollToSourceHandler); ContentManager contentManager = toolWindow.getContentManager(); - ServiceViewContentHolder holder = - new ServiceViewContentHolder(mainView, contentManager, contributors, toolWindowId, toolWindowHeaderSideComponent); + Wrapper toolWindowHeaderSideComponent = setToolWindowHeaderSideComponent(toolWindowEx, contentManager); + ServiceViewContentHolder holder = new ServiceViewContentHolder( + mainView, contentManager, contributors, toolWindowId, toolWindowHeaderSideComponent); myContentHolders.add(holder); contentManager.addContentManagerListener(new ServiceViewContentMangerListener(myModelFilter, myAutoScrollToSourceHandler, holder)); myProject.getMessageBus().connect(contentManager).subscribe(ToolWindowManagerListener.TOPIC, new ToolWindowManagerListener() { @@ -296,20 +295,12 @@ public final class ServiceViewManagerImpl implements ServiceViewManager, Persist } } }); - if (toolWindowHeaderSideComponent != null) { - DataManager.registerDataProvider(toolWindowHeaderSideComponent, dataId -> { - Content content = contentManager.getSelectedContent(); - ServiceView serviceView = content == null ? null : getServiceView(content); - DataProvider dataProvider = serviceView == null ? null : DataManager.getDataProvider(serviceView); - return dataProvider == null ? null : dataProvider.getData(dataId); - }); - } addMainContent(toolWindow.getContentManager(), mainView); loadViews(contentManager, mainView, contributors, states.second); ServiceViewDragHelper.installDnDSupport(myProject, toolWindowEx.getDecorator(), contentManager); } - private static Wrapper setToolWindowHeaderSideComponent(ToolWindowEx toolWindowEx) { + private static Wrapper setToolWindowHeaderSideComponent(ToolWindowEx toolWindowEx, ContentManager contentManager) { if (!Registry.is("ide.services.tool.window.header.nav.bar", true) || AppMode.isRemoteDevHost()) { return null; @@ -318,7 +309,11 @@ public final class ServiceViewManagerImpl implements ServiceViewManager, Persist if (decorator == null) return null; Wrapper wrapper = new Wrapper(); - decorator.getHeader().setSideComponent(wrapper); + decorator.getHeader().setSideComponent(UiDataProvider.wrapComponent(wrapper, sink -> { + Content content = contentManager.getSelectedContent(); + ServiceView serviceView = content == null ? null : getServiceView(content); + DataSink.uiDataSnapshot(sink, serviceView); + })); return wrapper; } diff --git a/platform/execution.serviceView/src/ServiceViewTreeUi.java b/platform/execution.serviceView/src/ServiceViewTreeUi.java index 52a0739395f4..1c4458fc9ea7 100644 --- a/platform/execution.serviceView/src/ServiceViewTreeUi.java +++ b/platform/execution.serviceView/src/ServiceViewTreeUi.java @@ -5,7 +5,6 @@ import com.intellij.execution.ExecutionBundle; import com.intellij.execution.services.ServiceViewActionUtils; import com.intellij.execution.services.ServiceViewUIUtils; import com.intellij.openapi.actionSystem.ActionToolbar; -import com.intellij.openapi.actionSystem.DataSink; import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl; import com.intellij.openapi.application.ApplicationManager; @@ -53,8 +52,10 @@ final class ServiceViewTreeUi implements ServiceViewUi { myMainPanel.add(myContentPanel, BorderLayout.CENTER); myContentPanel.setContent(mySplitter); - myMasterPanel = new MyPanel(); - mySplitter.setFirstComponent(myMasterPanel); + myMasterPanel = new JPanel(new BorderLayout()); + mySplitter.setFirstComponent(UiDataProvider.wrapComponent(myMasterPanel, sink -> { + sink.set(ServiceViewActionUtils.IS_FROM_TREE_KEY, true); + })); myDetailsPanel = new JPanel(new BorderLayout()); myContentComponentPanel = new JPanel(new BorderLayout()); @@ -241,13 +242,4 @@ final class ServiceViewTreeUi implements ServiceViewUi { } } } - - private static class MyPanel extends JPanel implements UiDataProvider { - MyPanel() { super(new BorderLayout()); } - - @Override - public void uiDataSnapshot(@NotNull DataSink sink) { - sink.set(ServiceViewActionUtils.IS_FROM_TREE_KEY, true); - } - } } diff --git a/platform/lang-api/src/com/intellij/execution/services/ServiceViewDescriptor.java b/platform/lang-api/src/com/intellij/execution/services/ServiceViewDescriptor.java index 9ae14fa20dba..859b38e8145c 100644 --- a/platform/lang-api/src/com/intellij/execution/services/ServiceViewDescriptor.java +++ b/platform/lang-api/src/com/intellij/execution/services/ServiceViewDescriptor.java @@ -63,14 +63,8 @@ public interface ServiceViewDescriptor { if (navigatable == null) return false; DataContext dataContext = DataManager.getInstance().getDataContext(event.getComponent()); - DataContext wrapper = CustomizedDataContext.withProvider(dataContext, new DataProvider() { - @Override - public @Nullable Object getData(@NotNull String dataId) { - if (CommonDataKeys.NAVIGATABLE.is(dataId)) { - return navigatable; - } - return null; - } + DataContext wrapper = CustomizedDataContext.withSnapshot(dataContext, sink -> { + sink.set(CommonDataKeys.NAVIGATABLE, navigatable); }); OpenSourceUtil.openSourcesFrom(wrapper, false); return true; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java index 1368e5614075..f808374b2cde 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java @@ -81,10 +81,6 @@ import java.util.List; @Deprecated(forRemoval = true) public class DocumentationComponent extends JPanel implements Disposable, UiCompatibleDataProvider, WidthBasedLayout { private static final Logger LOG = Logger.getInstance(DocumentationComponent.class); - static final DataProvider HELP_DATA_PROVIDER = - dataId -> PlatformCoreDataKeys.HELP_ID.is(dataId) - ? "reference.toolWindows.Documentation" - : null; public static final ColorKey COLOR_KEY = EditorColors.DOCUMENTATION_COLOR; public static final Color SECTION_COLOR = Gray.get(0x90); @@ -294,9 +290,6 @@ public class DocumentationComponent extends JPanel implements Disposable, UiComp else if (myManager.myToolWindow != null) { Disposer.register(myManager.myToolWindow.getContentManager(), this); } - DataManager.registerDataProvider(myEditorPane, HELP_DATA_PROVIDER); - DataManager.registerDataProvider(myScrollPane, HELP_DATA_PROVIDER); - updateControlState(); } @@ -356,6 +349,7 @@ public class DocumentationComponent extends JPanel implements Disposable, UiComp @Override public void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(PlatformCoreDataKeys.HELP_ID, "reference.toolWindows.Documentation"); // Javadocs often contain   symbols (non-breakable white space). We don't want to copy them as is and replace // with raw white spaces. See IDEA-86633 for more details. String selectedText = myEditorPane.getSelectedText(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUi.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUi.java index 6853fe97bb44..a76164c928cf 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUi.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUi.java @@ -9,7 +9,6 @@ import com.intellij.codeInsight.hint.HintManagerImpl; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupPositionStrategy; import com.intellij.icons.AllIcons; -import com.intellij.ide.DataManager; import com.intellij.ide.IdeEventQueue; import com.intellij.ide.ui.UISettings; import com.intellij.idea.ActionsBundle; @@ -99,14 +98,9 @@ final class LookupUi { menuAction.add(new ShowCompletionSettingsAction()); myMenuButton = new ActionButton(menuAction, null, ActionPlaces.EDITOR_POPUP, ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE); - DataManager.registerDataProvider(myMenuButton, dataId -> { - if (CommonDataKeys.PROJECT.is(dataId)) { - return this.lookup.getProject(); - } - if (CommonDataKeys.EDITOR.is(dataId)) { - return this.lookup.getEditor(); - } - return null; + JComponent menuButtonWrapper = UiDataProvider.wrapComponent(myMenuButton, sink -> { + sink.set(CommonDataKeys.PROJECT, this.lookup.getProject()); + sink.set(CommonDataKeys.EDITOR, this.lookup.getEditor()); }); AnAction hintAction = new HintAction(); @@ -121,7 +115,7 @@ final class LookupUi { myBottomPanel.add(myAdvertiser.getAdComponent()); myBottomPanel.add(processIcon); myBottomPanel.add(hintButton); - myBottomPanel.add(myMenuButton); + myBottomPanel.add(menuButtonWrapper); if (ExperimentalUI.isNewUI()) { myBottomPanel.setBackground(JBUI.CurrentTheme.CompletionPopup.Advertiser.background()); myBottomPanel.setBorder(JBUI.CurrentTheme.CompletionPopup.Advertiser.border()); diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index 3de1a7c95184..dd07bc1c78c1 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -541,7 +541,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo private static final String ATTRIBUTE_ID = "id"; private JPanel viewContentPanel; private static final Comparator PANE_WEIGHT_COMPARATOR = Comparator.comparingInt(AbstractProjectViewPane::getWeight); - private final MyPanel myDataProvider; + private final JComponent myDataProvider; private final SplitterProportionsData splitterProportions = new SplitterProportionsDataImpl(); private final Map myUninitializedPaneState = new HashMap<>(); private final Map mySelectInTargets = new ConcurrentHashMap<>(); @@ -558,8 +558,9 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo autoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler(); - myDataProvider = new MyPanel(); - myDataProvider.add(panel, BorderLayout.CENTER); + myDataProvider = UiDataProvider.wrapComponent(panel, sink -> uiDataSnapshot(sink)); + ClientProperty.put(myDataProvider, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, buildNotInHierarchyIterable()); + copyPasteDelegator = new CopyPasteDelegator(this.project, panel); myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() { @Override @@ -1377,36 +1378,30 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo return ActionCallback.REJECTED; } - private final class MyPanel extends JPanel implements UiDataProvider { - MyPanel() { - super(new BorderLayout()); - Collection snapshot = new ArrayList<>(idToPane.values()); - ComponentUtil.putClientProperty(this, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, - (Iterable)(Iterable)() -> JBIterable.from(snapshot) - .map(pane -> { - JComponent last = null; - for (Component c : UIUtil.uiParents(pane.getComponentToFocus(), false)) { - if (c == this || !(c instanceof JComponent)) return null; - last = (JComponent)c; - } - return last; - }) - .filter(Conditions.notNull()) - .iterator()); - } + private @NotNull Iterable buildNotInHierarchyIterable() { + return () -> JBIterable.from(new ArrayList<>(idToPane.values())) + .map(pane -> { + JComponent last = null; + for (Component c : UIUtil.uiParents(pane.getComponentToFocus(), false)) { + if (c == myDataProvider || !(c instanceof JComponent)) return null; + last = (JComponent)c; + } + return last; + }) + .filter(Component.class) + .iterator(); + } - @Override - public void uiDataSnapshot(@NotNull DataSink sink) { - sink.set(PlatformDataKeys.CUT_PROVIDER, copyPasteDelegator.getCutProvider()); - sink.set(PlatformDataKeys.COPY_PROVIDER, copyPasteDelegator.getCopyProvider()); - sink.set(PlatformDataKeys.PASTE_PROVIDER, copyPasteDelegator.getPasteProvider()); - sink.set(LangDataKeys.IDE_VIEW, myIdeView); - sink.set(PlatformCoreDataKeys.HELP_ID, HelpID.PROJECT_VIEWS); - sink.set(QuickActionProvider.KEY, ProjectViewImpl.this); - AbstractProjectViewPane selectedPane = getCurrentProjectViewPane(); - if (selectedPane != null) { - DataSink.uiDataSnapshot(sink, selectedPane); - } + private void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(PlatformDataKeys.CUT_PROVIDER, copyPasteDelegator.getCutProvider()); + sink.set(PlatformDataKeys.COPY_PROVIDER, copyPasteDelegator.getCopyProvider()); + sink.set(PlatformDataKeys.PASTE_PROVIDER, copyPasteDelegator.getPasteProvider()); + sink.set(LangDataKeys.IDE_VIEW, myIdeView); + sink.set(PlatformCoreDataKeys.HELP_ID, HelpID.PROJECT_VIEWS); + sink.set(QuickActionProvider.KEY, ProjectViewImpl.this); + AbstractProjectViewPane selectedPane = getCurrentProjectViewPane(); + if (selectedPane != null) { + DataSink.uiDataSnapshot(sink, selectedPane); } } diff --git a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java index 8ffb68ecefb0..e78c53badeaa 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java +++ b/platform/lang-impl/src/com/intellij/ide/util/FileStructurePopup.java @@ -541,8 +541,6 @@ public final class FileStructurePopup implements Disposable, TreeActionsOwner { JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); scrollPane.setBorder(IdeBorderFactory.createBorder(JBUI.CurrentTheme.Popup.toolbarBorderColor(), SideBorder.TOP | SideBorder.BOTTOM)); panel.add(scrollPane, BorderLayout.CENTER); - DataManager.registerDataProvider(panel, this::getData); - panel.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { @@ -550,59 +548,35 @@ public final class FileStructurePopup implements Disposable, TreeActionsOwner { } }); - return panel; + return UiDataProvider.wrapComponent(panel, sink -> uiDataSnapshot(sink)); } - private @Nullable Object getData(@NotNull String dataId) { - if (CommonDataKeys.PROJECT.is(dataId)) { - return myProject; + private void uiDataSnapshot(@NotNull DataSink sink) { + sink.set(CommonDataKeys.PROJECT, myProject); + sink.set(PlatformCoreDataKeys.FILE_EDITOR, myFileEditor); + if (myFileEditor instanceof TextEditor o) { + sink.set(OpenFileDescriptor.NAVIGATE_IN_EDITOR, o.getEditor()); } - if (PlatformCoreDataKeys.FILE_EDITOR.is(dataId)) { - return myFileEditor; - } - if (OpenFileDescriptor.NAVIGATE_IN_EDITOR.is(dataId)) { - if (myFileEditor instanceof TextEditor) { - return ((TextEditor)myFileEditor).getEditor(); - } - } - if (PlatformCoreDataKeys.BGT_DATA_PROVIDER.is(dataId)) { - TreePath[] selection = myTree.getSelectionPaths(); - return (DataProvider)slowId -> getSlowData(slowId, selection); - } - if (LangDataKeys.POSITION_ADJUSTER_POPUP.is(dataId)) { - return myPopup; - } - if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) { - return myCopyPasteDelegator.getCopyProvider(); - } - if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) { - return myTreeExpander; - } - return null; - } + sink.set(LangDataKeys.POSITION_ADJUSTER_POPUP, myPopup); + sink.set(PlatformDataKeys.COPY_PROVIDER, myCopyPasteDelegator.getCopyProvider()); + sink.set(PlatformDataKeys.TREE_EXPANDER, myTreeExpander); - private static @Nullable Object getSlowData(@NotNull String dataId, TreePath @Nullable [] selection) { + TreePath[] selection = myTree.getSelectionPaths(); JBIterable selectedElements = JBIterable.of(selection) .filterMap(o -> StructureViewComponent.unwrapValue(o.getLastPathComponent())); - if (CommonDataKeys.PSI_ELEMENT.is(dataId)) { + sink.lazy(CommonDataKeys.PSI_ELEMENT, () -> { return selectedElements.filter(PsiElement.class).first(); - } - if (PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) { + }); + sink.lazy(PlatformCoreDataKeys.PSI_ELEMENT_ARRAY, () -> { return PsiUtilCore.toPsiElementArray(selectedElements.filter(PsiElement.class).toList()); - } - if (CommonDataKeys.NAVIGATABLE.is(dataId)) { + }); + sink.lazy(CommonDataKeys.NAVIGATABLE, () -> { return selectedElements.filter(Navigatable.class).first(); - } - if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) { + }); + sink.lazy(CommonDataKeys.NAVIGATABLE_ARRAY, () -> { List result = selectedElements.filter(Navigatable.class).toList(); return result.isEmpty() ? null : result.toArray(Navigatable.EMPTY_NAVIGATABLE_ARRAY); - } - return null; - } - - private @NotNull JBIterable getSelectedElements() { - return JBIterable.of(myTree.getSelectionPaths()) - .filterMap(o -> StructureViewComponent.unwrapValue(o.getLastPathComponent())); + }); } private @NotNull JComponent createSettingsButton() { diff --git a/platform/lang-impl/src/com/intellij/internal/ImageDuplicateResultsDialog.java b/platform/lang-impl/src/com/intellij/internal/ImageDuplicateResultsDialog.java index f54e47e3eddc..5a8acc326746 100644 --- a/platform/lang-impl/src/com/intellij/internal/ImageDuplicateResultsDialog.java +++ b/platform/lang-impl/src/com/intellij/internal/ImageDuplicateResultsDialog.java @@ -3,14 +3,10 @@ package com.intellij.internal; import com.intellij.codeInsight.hint.ImplementationViewComponent; import com.intellij.codeInsight.hint.PsiImplementationViewElement; -import com.intellij.ide.DataManager; import com.intellij.ide.ui.search.SearchUtil; import com.intellij.ide.util.PropertiesComponent; import com.intellij.ide.util.PropertyName; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.CustomShortcutSet; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.module.ModuleUtil; @@ -104,28 +100,7 @@ public final class ImageDuplicateResultsDialog extends DialogWrapper { @Override protected JComponent createCenterPanel() { - final JPanel panel = new JPanel(new BorderLayout()); - DataManager.registerDataProvider(panel, dataId -> { - final TreePath path = myTree.getSelectionPath(); - if (path != null) { - Object component = path.getLastPathComponent(); - VirtualFile file = null; - if (component instanceof MyFileNode) { - component = ((MyFileNode)component).getParent(); - } - if (component instanceof MyDuplicatesNode) { - file = ((MyDuplicatesNode)component).getUserObject().iterator().next(); - } - if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) { - return file; - } - if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId) && file != null) { - return new VirtualFile[]{file}; - } - } - return null; - }); - + JPanel panel = new JPanel(new BorderLayout()); JBList list = new JBList<>(new ResourceModules().getModuleNames()); final NotNullFunction modulesRenderer = dom -> new JLabel(dom instanceof Module ? ((Module)dom).getName() : dom.toString(), PlatformIcons.SOURCE_FOLDERS_ICON, SwingConstants.LEFT); @@ -221,7 +196,16 @@ public final class ImageDuplicateResultsDialog extends DialogWrapper { final JLabel label = new JLabel( "Press Enter to preview image
Total images found: " + myImages.size() + ". Total duplicates found: " + total+""); panel.add(label, BorderLayout.SOUTH); - return panel; + return UiDataProvider.wrapComponent(panel, sink -> uiDataSnapshot(sink)); + } + + private void uiDataSnapshot(@NotNull DataSink sink) { + TreePath path = myTree.getSelectionPath(); + Object component = path == null ? null : path.getLastPathComponent(); + if (component instanceof MyFileNode o) component = o.getParent(); + VirtualFile file = component instanceof MyDuplicatesNode o ? o.getUserObject().iterator().next() : null; + sink.set(CommonDataKeys.VIRTUAL_FILE, file); + sink.set(CommonDataKeys.VIRTUAL_FILE_ARRAY, file == null ? null : new VirtualFile[]{file}); } @Override diff --git a/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationPopupUI.kt b/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationPopupUI.kt index 5c3ad01a50c8..b8c2315a3f69 100644 --- a/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationPopupUI.kt +++ b/platform/lang-impl/src/com/intellij/lang/documentation/ide/ui/DocumentationPopupUI.kt @@ -11,7 +11,6 @@ import com.intellij.codeInsight.documentation.DocumentationManager.NEW_JAVADOC_L import com.intellij.codeInsight.documentation.ToggleShowDocsOnHoverAction import com.intellij.codeInsight.hint.HintManagerImpl.ActionToIgnore import com.intellij.codeInsight.hint.LineTooltipRenderer -import com.intellij.ide.DataManager import com.intellij.lang.documentation.ide.actions.* import com.intellij.lang.documentation.ide.impl.DocumentationBrowser import com.intellij.lang.documentation.ide.impl.DocumentationToolWindowManager @@ -96,16 +95,18 @@ internal class DocumentationPopupUI( ui.trackDocumentationBackgroundChange(this) { corner.background = it } - component = DocumentationPopupPane(ui.scrollPane).also { pane -> - pane.add(scrollPaneWithCorner(this, ui.scrollPane, corner), BorderLayout.CENTER) - pane.add(ui.switcherToolbarComponent, BorderLayout.NORTH) - updatePaddings(corner) - corner.addComponentListener(object : ComponentAdapter() { - override fun componentResized(e: ComponentEvent?) { - updatePaddings(corner) - popupUpdateFlow.tryEmit(PopupUpdateEvent.ToolbarSizeChanged) - } - }) + val pane = DocumentationPopupPane(ui.scrollPane) + pane.add(scrollPaneWithCorner(this, ui.scrollPane, corner), BorderLayout.CENTER) + pane.add(ui.switcherToolbarComponent, BorderLayout.NORTH) + updatePaddings(corner) + corner.addComponentListener(object : ComponentAdapter() { + override fun componentResized(e: ComponentEvent?) { + updatePaddings(corner) + popupUpdateFlow.tryEmit(PopupUpdateEvent.ToolbarSizeChanged) + } + }) + component = UiDataProvider.wrapComponent(pane) { sink -> + sink[DOCUMENTATION_POPUP] = myPopup } openInToolwindowAction.registerCustomShortcutSet(component, this) @@ -134,18 +135,7 @@ internal class DocumentationPopupUI( fun setPopup(popup: AbstractPopup) { Disposer.register(popup, this) myPopup = popup - - DataManager.registerDataProvider(component) { dataId -> - if (DOCUMENTATION_POPUP.`is`(dataId)) { - popup - } - else { - null - } - } - - val editorPane = ui.editorPane - editorPane.setHint(popup) + ui.editorPane.setHint(popup) } fun updatePopup(updater: suspend (PopupUpdateEvent) -> Unit) { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java index dcf9bed18248..28cca80ce63c 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java @@ -54,7 +54,7 @@ public class ContentEntryTreeEditor { private final List> myEditHandlers; protected final Tree myTree; private FileSystemTreeImpl myFileSystemTree; - private final JPanel myTreePanel; + private final JComponent myComponent; protected final DefaultActionGroup myEditingActionsGroup; private ContentEntryEditor myContentEntryEditor; private final MyContentEntryEditorListener myContentEntryEditorListener = new MyContentEntryEditorListener(); @@ -99,12 +99,14 @@ public class ContentEntryTreeEditor { new JBLabel(XmlStringUtil.wrapInHtml(ProjectBundle.message("label.content.entry.separate.name.patterns"))); excludePatternsLegendLabel.setForeground(JBColor.GRAY); excludePatternsPanel.add(excludePatternsLegendLabel, gridBag.nextLine().next().next().fillCellHorizontally()); - myTreePanel = new MyPanel(new BorderLayout()); - final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree, true); - myTreePanel.add(scrollPane, BorderLayout.CENTER); - myTreePanel.add(excludePatternsPanel, BorderLayout.SOUTH); - - myTreePanel.setVisible(false); + JPanel treePanel = new JPanel(new BorderLayout()); + treePanel.add(ScrollPaneFactory.createScrollPane(myTree, true), BorderLayout.CENTER); + treePanel.add(excludePatternsPanel, BorderLayout.SOUTH); + myComponent = UiDataProvider.wrapComponent(treePanel, sink -> { + sink.set(FileSystemTree.DATA_KEY, myFileSystemTree); + sink.set(CommonDataKeys.VIRTUAL_FILE_ARRAY, myFileSystemTree == null ? null : myFileSystemTree.getSelectedFiles()); + }); + myComponent.setVisible(false); myDescriptor = FileChooserDescriptorFactory.createMultipleFoldersDescriptor(); myDescriptor.setShowFileSystemRoots(false); } @@ -146,13 +148,13 @@ public class ContentEntryTreeEditor { myContentEntryEditor = null; } if (contentEntryEditor == null) { - myTreePanel.setVisible(false); + myComponent.setVisible(false); if (myFileSystemTree != null) { Disposer.dispose(myFileSystemTree); } return; } - myTreePanel.setVisible(true); + myComponent.setVisible(true); myContentEntryEditor = contentEntryEditor; myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener); @@ -196,7 +198,7 @@ public class ContentEntryTreeEditor { public JComponent createComponent() { createEditingActions(); - return myTreePanel; + return myComponent; } public void select(VirtualFile file) { @@ -260,18 +262,6 @@ public class ContentEntryTreeEditor { } } - private final class MyPanel extends JPanel implements UiDataProvider { - private MyPanel(final LayoutManager layout) { - super(layout); - } - - @Override - public void uiDataSnapshot(@NotNull DataSink sink) { - sink.set(FileSystemTree.DATA_KEY, myFileSystemTree); - sink.set(CommonDataKeys.VIRTUAL_FILE_ARRAY, myFileSystemTree == null ? null : myFileSystemTree.getSelectedFiles()); - } - } - public DefaultActionGroup getEditingActionsGroup() { return myEditingActionsGroup; } diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java index ea59b39f0b91..c3326f562bcf 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/RevisionsList.java @@ -6,10 +6,10 @@ import com.intellij.history.integration.LocalHistoryBundle; import com.intellij.history.integration.ui.models.HistoryDialogModel; import com.intellij.history.integration.ui.models.RevisionItem; import com.intellij.ide.CopyProvider; -import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.ActionUpdateThread; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.PlatformDataKeys; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.ide.CopyPasteManager; import com.intellij.openapi.util.NlsContexts; import com.intellij.openapi.util.Pair; @@ -43,6 +43,7 @@ import java.util.*; public final class RevisionsList { public static final int RECENT_PERIOD = 12; private final JBTable table; + private final JComponent component; private volatile Set filteredRevisions; public RevisionsList(SelectionListener l) { @@ -63,16 +64,13 @@ public final class RevisionsList { addSelectionListener(l); CopyProvider copyProvider = new MyCellRenderer.MyCopyProvider(table); - DataManager.registerDataProvider(table, dataId -> { - if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) { - return copyProvider; - } - return null; + component = UiDataProvider.wrapComponent(table, sink -> { + sink.set(PlatformDataKeys.COPY_PROVIDER, copyProvider); }); } - public JComponent getComponent() { - return table; + public @NotNull JComponent getComponent() { + return component; } public boolean isEmpty() { diff --git a/platform/platform-impl/src/com/intellij/ide/lightEdit/statusBar/LightEditModeNotificationWidget.java b/platform/platform-impl/src/com/intellij/ide/lightEdit/statusBar/LightEditModeNotificationWidget.java index 057f2d384b5b..c08457814b8c 100644 --- a/platform/platform-impl/src/com/intellij/ide/lightEdit/statusBar/LightEditModeNotificationWidget.java +++ b/platform/platform-impl/src/com/intellij/ide/lightEdit/statusBar/LightEditModeNotificationWidget.java @@ -121,31 +121,20 @@ public final class LightEditModeNotificationWidget implements CustomStatusBarWid private void showPopupMenu(@NotNull JComponent actionLink) { if (!myPopupState.isRecentlyHidden()) { - addDataProvider(actionLink, dataId -> { - if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) { - return LightEditService.getInstance().getSelectedFile(); - } - return null; - }); - ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.STATUS_BAR_PLACE, - createAccessFullIdeActionGroup()); - popupMenu.setTargetComponent(actionLink); + DataContext dataContext = CustomizedDataContext.withSnapshot( + DataManager.getInstance().getDataContext(actionLink), sink -> { + sink.set(CommonDataKeys.VIRTUAL_FILE, + LightEditService.getInstance().getSelectedFile()); + }); + ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu( + ActionPlaces.STATUS_BAR_PLACE, createAccessFullIdeActionGroup()); + popupMenu.setDataContext(() -> dataContext); JPopupMenu menu = popupMenu.getComponent(); myPopupState.prepareToShow(menu); JBPopupMenu.showAbove(actionLink, menu); } } - private static void addDataProvider(@NotNull JComponent component, @NotNull DataProvider dataProvider) { - DataProvider prev = DataManager.getDataProvider(component); - DataProvider result = dataProvider; - if (prev != null) { - DataManager.removeDataProvider(component); - result = CompositeDataProvider.compose(prev, dataProvider); - } - DataManager.registerDataProvider(component, result); - } - private static @NotNull ActionGroup createAccessFullIdeActionGroup() { ActionManager actionManager = ActionManager.getInstance(); return new DefaultActionGroup( diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XSplitterWatchesViewImpl.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XSplitterWatchesViewImpl.kt index 0e79a3861e11..ad076aa5c61c 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XSplitterWatchesViewImpl.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XSplitterWatchesViewImpl.kt @@ -33,13 +33,16 @@ class XSplitterWatchesViewImpl( private fun tryGetBottomComponentProvider(session: XDebugSessionImpl) = session.debugProcess.getBottomLocalsComponentProvider() } + lateinit var splitter: OnePixelSplitter + private set + override fun createMainPanel(localsPanelComponent: JComponent): JPanel { val session = mySession.get() ?: error("Not null session is expected here") val bottomLocalsComponentProvider = tryGetBottomComponentProvider(session) ?: error("BottomLocalsComponentProvider is not implemented to use SplitterWatchesVariablesView") val evaluatorComponent = bottomLocalsComponentProvider.createBottomLocalsComponent() - val splitter = OnePixelSplitter(true, proportionKey, 0.01f, 0.99f) + splitter = OnePixelSplitter(true, proportionKey, 0.01f, 0.99f) splitter.firstComponent = localsPanelComponent splitter.secondComponent = evaluatorComponent diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesView.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesView.java index 8d9c723c652f..c251f67da090 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesView.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XVariablesView.java @@ -1,9 +1,9 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.xdebugger.impl.frame; -import com.intellij.ide.DataManager; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.DataSink; +import com.intellij.openapi.actionSystem.UiDataProvider; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.Key; import com.intellij.util.ObjectUtils; @@ -18,7 +18,6 @@ import com.intellij.xdebugger.impl.inline.InlineDebugRenderer; import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree; import com.intellij.xdebugger.impl.ui.tree.nodes.XValueContainerNode; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -28,15 +27,14 @@ import java.util.Collections; import java.util.List; @ApiStatus.Internal -public class XVariablesView extends XVariablesViewBase implements DataProvider { - protected final JPanel myComponent; +public class XVariablesView extends XVariablesViewBase { + protected final JComponent myComponent; protected final WeakReference mySession; public XVariablesView(@NotNull XDebugSessionImpl session) { super(session.getProject(), session.getDebugProcess().getEditorsProvider(), session.getValueMarkers()); mySession = new WeakReference<>(session); - myComponent = createMainPanel(super.getPanel()); - DataManager.registerDataProvider(myComponent, this); + myComponent = UiDataProvider.wrapComponent(createMainPanel(super.getPanel()), sink -> uiDataSnapshot(sink)); } protected JPanel createMainPanel(JComponent localsPanel) { @@ -44,7 +42,7 @@ public class XVariablesView extends XVariablesViewBase implements DataProvider { } @Override - public JPanel getPanel() { + public JComponent getPanel() { return myComponent; } @@ -116,19 +114,12 @@ public class XVariablesView extends XVariablesViewBase implements DataProvider { super.clear(); } - @Nullable - @Override - public Object getData(@NotNull @NonNls String dataId) { - if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) { - XDebugSessionImpl session = mySession.get(); - if (session != null) { - XSourcePosition position = session.getCurrentPosition(); - if (position != null) { - return position.getFile(); - } - } + protected void uiDataSnapshot(@NotNull DataSink sink) { + XDebugSessionImpl session = mySession.get(); + XSourcePosition position = session == null ? null : session.getCurrentPosition(); + if (position != null) { + sink.lazy(CommonDataKeys.VIRTUAL_FILE, () -> position.getFile()); } - return null; } public static final class InlineVariablesInfo { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl.java index 095869e09ef8..ac77dd1a0686 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/XWatchesViewImpl.java @@ -58,7 +58,6 @@ import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree; import com.intellij.xdebugger.impl.ui.tree.actions.XWatchTransferable; import com.intellij.xdebugger.impl.ui.tree.nodes.*; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -527,13 +526,10 @@ public class XWatchesViewImpl extends XVariablesView implements DnDNativeTarget, return expressions; } - @Nullable @Override - public Object getData(@NotNull @NonNls String dataId) { - if (XWatchesView.DATA_KEY.is(dataId)) { - return this; - } - return super.getData(dataId); + protected void uiDataSnapshot(@NotNull DataSink sink) { + super.uiDataSnapshot(sink); + sink.set(XWatchesView.DATA_KEY, this); } @Override diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XToggleEvaluateExpressionFieldAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XToggleEvaluateExpressionFieldAction.java index 753ec198622c..fdda2d3d7e2f 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XToggleEvaluateExpressionFieldAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/frame/actions/XToggleEvaluateExpressionFieldAction.java @@ -79,7 +79,7 @@ public class XToggleEvaluateExpressionFieldAction extends DumbAwareToggleAction private static void findAllFieldsAndUpdateState(DataContext context, boolean state) { XWatchesView view = context.getData(XWatchesView.DATA_KEY); if (view instanceof XWatchesViewImpl) { - JPanel panel = ((XWatchesViewImpl)view).getPanel(); + JComponent panel = ((XWatchesViewImpl)view).getPanel(); UIUtil.uiTraverser(panel) .filter(c -> c instanceof JComponent && ClientProperty.get(c, EVALUATE_EXPRESSION_FIELD) != null) .forEach(c -> c.setVisible(state));