mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
migrate getData to uiDataSnapshot: other
GitOrigin-RevId: 41dbf0923e201f2b8aae9ccec6368cd27a071db3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
87e4cedb39
commit
ea67bc1ceb
@@ -502,25 +502,17 @@ public final class AntExplorer extends SimpleToolWindowPanel implements DataProv
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getData(@NotNull @NonNls String dataId) {
|
||||
if (PlatformCoreDataKeys.BGT_DATA_PROVIDER.is(dataId)) {
|
||||
Tree tree = myTree;
|
||||
if (tree == null) {
|
||||
return null;
|
||||
}
|
||||
final TreePath[] paths = tree.getSelectionPaths();
|
||||
final TreePath leadPath = tree.getLeadSelectionPath();
|
||||
final AntBuildFile currentBuildFile = getCurrentBuildFile();
|
||||
return (DataProvider)id -> getSlowData(id, paths, leadPath, currentBuildFile);
|
||||
}
|
||||
else if (PlatformCoreDataKeys.HELP_ID.is(dataId)) {
|
||||
return HelpID.ANT;
|
||||
}
|
||||
else if (PlatformDataKeys.TREE_EXPANDER.is(dataId)) {
|
||||
return myProject != null? myTreeExpander : null;
|
||||
}
|
||||
return super.getData(dataId);
|
||||
public void uiDataSnapshot(@NotNull DataSink sink) {
|
||||
super.uiDataSnapshot(sink);
|
||||
sink.set(PlatformCoreDataKeys.HELP_ID, HelpID.ANT);
|
||||
sink.set(PlatformDataKeys.TREE_EXPANDER, myProject != null ? myTreeExpander : null);
|
||||
|
||||
Tree tree = myTree;
|
||||
if (tree == null) return;
|
||||
TreePath[] paths = tree.getSelectionPaths();
|
||||
TreePath leadPath = tree.getLeadSelectionPath();
|
||||
AntBuildFile currentBuildFile = getCurrentBuildFile();
|
||||
sink.set(PlatformCoreDataKeys.BGT_DATA_PROVIDER, id -> getSlowData(id, paths, leadPath, currentBuildFile));
|
||||
}
|
||||
|
||||
private Object getSlowData(@NotNull @NonNls String dataId, final TreePath @Nullable [] paths, @Nullable TreePath leadPath, @Nullable AntBuildFile currentBuildFile) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.intellij.ide.CopyProvider;
|
||||
import com.intellij.ide.DeleteProvider;
|
||||
import com.intellij.ide.actions.ContextHelpAction;
|
||||
import com.intellij.ide.structureView.newStructureView.StructureViewComponent;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.lang.properties.IProperty;
|
||||
import com.intellij.lang.properties.ResourceBundle;
|
||||
import com.intellij.lang.properties.editor.inspections.ResourceBundleEditorRenderer;
|
||||
@@ -33,9 +32,9 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ResourceBundleStructureViewComponent extends PropertiesGroupingStructureViewComponent {
|
||||
private final static Logger LOG = Logger.getInstance(ResourceBundleStructureViewComponent.class);
|
||||
@@ -102,82 +101,75 @@ public class ResourceBundleStructureViewComponent extends PropertiesGroupingStru
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getData(@NotNull String dataId) {
|
||||
if (ResourceBundle.ARRAY_DATA_KEY.is(dataId)) {
|
||||
return new ResourceBundle[]{myResourceBundle};
|
||||
}
|
||||
else if (PlatformCoreDataKeys.BGT_DATA_PROVIDER.is(dataId)) {
|
||||
DataProvider superProvider = (DataProvider)super.getData(dataId);
|
||||
JBIterable<Object> selection = JBIterable.of(getTree().getSelectionPaths()).map(TreeUtil::getLastUserObject);
|
||||
return CompositeDataProvider.compose(slowId -> getSlowData(slowId, selection, myResourceBundle), superProvider);
|
||||
}
|
||||
else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
|
||||
return new DeleteProvider() {
|
||||
@Override
|
||||
public @NotNull ActionUpdateThread getActionUpdateThread() {
|
||||
return ActionUpdateThread.BGT;
|
||||
}
|
||||
public void uiDataSnapshot(@NotNull DataSink sink) {
|
||||
super.uiDataSnapshot(sink);
|
||||
sink.set(ResourceBundle.ARRAY_DATA_KEY, new ResourceBundle[]{myResourceBundle});
|
||||
|
||||
@Override
|
||||
public void deleteElement(@NotNull DataContext dataContext) {
|
||||
PsiElement[] selectedPsiElements = PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
|
||||
if (selectedPsiElements == null) return;
|
||||
List<PsiFile> psiFiles = ContainerUtil.findAll(selectedPsiElements, PsiFile.class);
|
||||
DeleteProvider delegate;
|
||||
if (!psiFiles.isEmpty()) {
|
||||
delegate = new ResourceBundleDeleteProvider();
|
||||
JBIterable<Object> selection = JBIterable.of(getTree().getSelectionPaths()).map(TreeUtil::getLastUserObject);
|
||||
sink.set(PlatformCoreDataKeys.BGT_DATA_PROVIDER,
|
||||
slowId -> getSlowData(slowId, selection, myResourceBundle));
|
||||
sink.set(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, new DeleteProvider() {
|
||||
@Override
|
||||
public @NotNull ActionUpdateThread getActionUpdateThread() {
|
||||
return ActionUpdateThread.BGT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteElement(@NotNull DataContext dataContext) {
|
||||
PsiElement[] selectedPsiElements = PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
|
||||
if (selectedPsiElements == null) return;
|
||||
List<PsiFile> psiFiles = ContainerUtil.findAll(selectedPsiElements, PsiFile.class);
|
||||
DeleteProvider delegate;
|
||||
if (!psiFiles.isEmpty()) {
|
||||
delegate = new ResourceBundleDeleteProvider();
|
||||
}
|
||||
else {
|
||||
IProperty[] properties = IProperty.ARRAY_KEY.getData(dataContext);
|
||||
if (properties != null && properties.length != 0) {
|
||||
delegate = new PropertiesDeleteProvider(((ResourceBundleEditor)getFileEditor()).getPropertiesInsertDeleteManager(), properties);
|
||||
}
|
||||
else {
|
||||
IProperty[] properties = IProperty.ARRAY_KEY.getData(dataContext);
|
||||
if (properties != null && properties.length != 0) {
|
||||
delegate = new PropertiesDeleteProvider(((ResourceBundleEditor)getFileEditor()).getPropertiesInsertDeleteManager(), properties);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
delegate.deleteElement(dataContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDeleteElement(@NotNull DataContext dataContext) {
|
||||
return CommonDataKeys.PROJECT.getData(dataContext) != null;
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
|
||||
return new CopyProvider() {
|
||||
@Override
|
||||
public @NotNull ActionUpdateThread getActionUpdateThread() {
|
||||
return ActionUpdateThread.BGT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performCopy(@NotNull DataContext dataContext) {
|
||||
PsiElement[] selectedPsiElements = PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
|
||||
if (selectedPsiElements != null) {
|
||||
List<String> names = new ArrayList<>(selectedPsiElements.length);
|
||||
for (PsiElement element : selectedPsiElements) {
|
||||
if (element instanceof PsiNamedElement) {
|
||||
names.add(((PsiNamedElement)element).getName());
|
||||
}
|
||||
}
|
||||
CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(names, "\n")));
|
||||
return;
|
||||
}
|
||||
}
|
||||
delegate.deleteElement(dataContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyEnabled(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canDeleteElement(@NotNull DataContext dataContext) {
|
||||
return CommonDataKeys.PROJECT.getData(dataContext) != null;
|
||||
}
|
||||
});
|
||||
sink.set(PlatformDataKeys.COPY_PROVIDER, new CopyProvider() {
|
||||
@Override
|
||||
public @NotNull ActionUpdateThread getActionUpdateThread() {
|
||||
return ActionUpdateThread.BGT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyVisible(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
@Override
|
||||
public void performCopy(@NotNull DataContext dataContext) {
|
||||
PsiElement[] selectedPsiElements = PlatformCoreDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
|
||||
if (selectedPsiElements != null) {
|
||||
List<String> names = new ArrayList<>(selectedPsiElements.length);
|
||||
for (PsiElement element : selectedPsiElements) {
|
||||
if (element instanceof PsiNamedElement) {
|
||||
names.add(((PsiNamedElement)element).getName());
|
||||
}
|
||||
}
|
||||
CopyPasteManager.getInstance().setContents(new StringSelection(StringUtil.join(names, "\n")));
|
||||
}
|
||||
};
|
||||
}
|
||||
return super.getData(dataId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyEnabled(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyVisible(@NotNull DataContext dataContext) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static @Nullable Object getSlowData(@NotNull String dataId,
|
||||
|
||||
@@ -5,7 +5,8 @@ import com.intellij.find.SearchSession
|
||||
import com.intellij.ide.GeneralSettings
|
||||
import com.intellij.ide.SaveAndSyncHandler
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.actionSystem.DataProvider
|
||||
import com.intellij.openapi.actionSystem.DataSink
|
||||
import com.intellij.openapi.actionSystem.UiDataProvider
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.editor.event.DocumentEvent
|
||||
import com.intellij.openapi.editor.event.DocumentListener
|
||||
@@ -276,23 +277,20 @@ internal class BlockTerminalView(
|
||||
|
||||
private fun getDisposed(): () -> Boolean = outputView.controller.outputModel.editor.getDisposed()
|
||||
|
||||
private inner class BlockTerminalPanel : JPanel(), DataProvider {
|
||||
private inner class BlockTerminalPanel : JPanel(), UiDataProvider {
|
||||
init {
|
||||
background = TerminalUi.defaultBackground(outputView.controller.outputModel.editor)
|
||||
}
|
||||
|
||||
override fun getData(dataId: String): Any? {
|
||||
return when (dataId) {
|
||||
TerminalPromptController.KEY.name -> promptView.controller
|
||||
TerminalOutputController.KEY.name -> outputView.controller
|
||||
TerminalOutputModel.KEY.name -> outputView.controller.outputModel
|
||||
SimpleTerminalController.KEY.name -> alternateBufferView?.controller
|
||||
BlockTerminalController.KEY.name -> controller
|
||||
TerminalSelectionController.KEY.name -> selectionController
|
||||
TerminalFocusModel.KEY.name -> focusModel
|
||||
BlockTerminalSession.DATA_KEY.name -> session
|
||||
else -> null
|
||||
}
|
||||
override fun uiDataSnapshot(sink: DataSink) {
|
||||
sink[TerminalPromptController.KEY] = promptView.controller
|
||||
sink[TerminalOutputController.KEY] = outputView.controller
|
||||
sink[TerminalOutputModel.KEY] = outputView.controller.outputModel
|
||||
sink[SimpleTerminalController.KEY] = alternateBufferView?.controller
|
||||
sink[BlockTerminalController.KEY] = controller
|
||||
sink[TerminalSelectionController.KEY] = selectionController
|
||||
sink[TerminalFocusModel.KEY] = focusModel
|
||||
sink[BlockTerminalSession.DATA_KEY] = session
|
||||
}
|
||||
|
||||
override fun doLayout() {
|
||||
|
||||
@@ -4,7 +4,8 @@ package org.jetbrains.plugins.terminal.block.output
|
||||
import com.intellij.find.SearchReplaceComponent
|
||||
import com.intellij.openapi.Disposable
|
||||
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.editor.EditorFactory
|
||||
import com.intellij.openapi.editor.impl.DocumentImpl
|
||||
import com.intellij.openapi.editor.impl.EditorImpl
|
||||
@@ -123,17 +124,14 @@ internal class TerminalOutputView(
|
||||
EditorFactory.getInstance().releaseEditor(editor)
|
||||
}
|
||||
|
||||
private inner class TerminalOutputPanel : JBLayeredPane(), DataProvider {
|
||||
private inner class TerminalOutputPanel : JBLayeredPane(), UiDataProvider {
|
||||
init {
|
||||
isOpaque = false
|
||||
add(editor.component, JLayeredPane.DEFAULT_LAYER as Any) // cast to Any needed to call right method overload
|
||||
}
|
||||
|
||||
override fun getData(dataId: String): Any? {
|
||||
return if (CommonDataKeys.EDITOR.`is`(dataId)) {
|
||||
editor
|
||||
}
|
||||
else null
|
||||
override fun uiDataSnapshot(sink: DataSink) {
|
||||
sink[CommonDataKeys.EDITOR] = editor
|
||||
}
|
||||
|
||||
override fun getPreferredSize(): Dimension {
|
||||
|
||||
Reference in New Issue
Block a user