diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CopyAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CopyAction.java index e6368b1f65e8..bf47e04ff21f 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CopyAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CopyAction.java @@ -9,6 +9,8 @@ import com.intellij.openapi.project.DumbAware; import com.intellij.util.ui.EDT; import org.jetbrains.annotations.NotNull; +import java.util.function.BiConsumer; + public class CopyAction extends AnAction implements DumbAware, LightEditCompatible { public CopyAction() { @@ -32,42 +34,31 @@ public class CopyAction extends AnAction implements DumbAware, LightEditCompatib @Override public void update(@NotNull AnActionEvent event) { + updateFromProvider(event, PlatformDataKeys.COPY_PROVIDER, (provider, presentation) -> { + presentation.setEnabled(provider.isCopyEnabled(event.getDataContext())); + boolean isEditorPopup = event.getPlace().equals(ActionPlaces.EDITOR_POPUP); + presentation.setVisible(!isEditorPopup || provider.isCopyVisible(event.getDataContext())); + }); + } + + static void updateFromProvider(@NotNull AnActionEvent event, + DataKey key, + BiConsumer presentationUpdater) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); - CopyProvider provider = PlatformDataKeys.COPY_PROVIDER.getData(dataContext); + T provider = key.getData(dataContext); if (provider == null) { presentation.setEnabled(false); presentation.setVisible(true); return; } - boolean isEditorPopup = event.getPlace().equals(ActionPlaces.EDITOR_POPUP); if (provider instanceof UpdateInBackground && ((UpdateInBackground)provider).isUpdateInBackground() || EDT.isCurrentThreadEdt()) { - ProviderState providerState = ProviderState.create(dataContext, isEditorPopup, provider); - presentation.setEnabled(providerState.isCopyEnabled); - presentation.setVisible(providerState.isVisible); + presentationUpdater.accept(provider, presentation); } else { - ProviderState providerState = Utils.getOrCreateUpdateSession(event).computeOnEdt( - "ProviderState#create", () -> ProviderState.create(dataContext, isEditorPopup, provider)); - presentation.setEnabled(providerState.isCopyEnabled); - presentation.setVisible(providerState.isVisible); - } - } - - private static class ProviderState { - final boolean isCopyEnabled; - final boolean isVisible; - - ProviderState(boolean enabled, boolean visible) { - isCopyEnabled = enabled; - isVisible = visible; - } - - static @NotNull ProviderState create(@NotNull DataContext dataContext, boolean isEditorPopup, @NotNull CopyProvider provider) { - boolean isCopyEnabled = provider.isCopyEnabled(dataContext); - boolean isVisible = !isEditorPopup || provider.isCopyVisible(dataContext); - return new ProviderState(isCopyEnabled, isVisible); + Utils.getOrCreateUpdateSession(event).computeOnEdt( + "ProviderState#create", () -> {presentationUpdater.accept(provider, presentation); return presentation;}); } } } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CutAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CutAction.java index 7c4d6ae63791..e9c5695de11b 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CutAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CutAction.java @@ -39,16 +39,17 @@ public class CutAction extends DumbAwareAction implements LightEditCompatible { @Override public void update(@NotNull AnActionEvent event) { - Presentation presentation = event.getPresentation(); - DataContext dataContext = event.getDataContext(); - CutProvider provider = getAvailableCutProvider(event); - Project project = CommonDataKeys.PROJECT.getData(dataContext); - presentation.setEnabled(project != null && project.isOpen() && provider != null && provider.isCutEnabled(dataContext)); - if (event.getPlace().equals(ActionPlaces.EDITOR_POPUP) && provider != null) { - presentation.setVisible(provider.isCutVisible(dataContext)); - } - else { - presentation.setVisible(true); - } + CopyAction.updateFromProvider(event, PlatformDataKeys.CUT_PROVIDER, (provider, presentation) -> { + DataContext dataContext = event.getDataContext(); + Project project = CommonDataKeys.PROJECT.getData(dataContext); + boolean notDumbAware = project != null && DumbService.isDumb(project) && !DumbService.isDumbAware(provider); + presentation.setEnabled(!notDumbAware && project != null && project.isOpen() && provider != null && provider.isCutEnabled(dataContext)); + if (event.getPlace().equals(ActionPlaces.EDITOR_POPUP) && provider != null) { + presentation.setVisible(provider.isCutVisible(dataContext)); + } + else { + presentation.setVisible(true); + } + }); } } diff --git a/platform/platform-impl/src/com/intellij/ide/actions/DeleteAction.java b/platform/platform-impl/src/com/intellij/ide/actions/DeleteAction.java index d43a1d45b1bf..d8d349eddbe4 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/DeleteAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/DeleteAction.java @@ -65,34 +65,40 @@ public class DeleteAction extends AnAction implements DumbAware, LightEditCompat return; } - DataContext dataContext = e.getDataContext(); - DeleteProvider provider = getDeleteProvider(dataContext); - if (e.getInputEvent() instanceof KeyEvent) { - KeyEvent keyEvent = (KeyEvent)e.getInputEvent(); - Object component = PlatformCoreDataKeys.CONTEXT_COMPONENT.getData(dataContext); - if (component instanceof JTextComponent) provider = null; // Do not override text deletion - if (keyEvent.getKeyCode() == KeyEvent.VK_BACK_SPACE) { - // Do not override text deletion in speed search - if (component instanceof JComponent) { - SpeedSearchSupply searchSupply = SpeedSearchSupply.getSupply((JComponent)component); - if (searchSupply != null) provider = null; - } + CopyAction.updateFromProvider(e, PlatformDataKeys.DELETE_ELEMENT_PROVIDER, (provider, p) -> { + DataContext dataContext = e.getDataContext(); + if (e.getInputEvent() instanceof KeyEvent) { + KeyEvent keyEvent = (KeyEvent)e.getInputEvent(); + Object component = PlatformCoreDataKeys.CONTEXT_COMPONENT.getData(dataContext); + if (component instanceof JTextComponent) provider = null; // Do not override text deletion + if (keyEvent.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + // Do not override text deletion in speed search + if (component instanceof JComponent) { + SpeedSearchSupply searchSupply = SpeedSearchSupply.getSupply((JComponent)component); + if (searchSupply != null) provider = null; + } - String activeSpeedSearchFilter = SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY.getData(dataContext); - if (!StringUtil.isEmpty(activeSpeedSearchFilter)) { - provider = null; + String activeSpeedSearchFilter = SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY.getData(dataContext); + if (!StringUtil.isEmpty(activeSpeedSearchFilter)) { + provider = null; + } } } - } - if (provider instanceof TitledHandler) { - presentation.setText(((TitledHandler)provider).getActionTitle()); - } - boolean canDelete = provider != null && provider.canDeleteElement(dataContext); - if (ActionPlaces.isPopupPlace(e.getPlace())) { - presentation.setVisible(canDelete); - } - else { - presentation.setEnabled(canDelete); - } + if (provider instanceof TitledHandler) { + presentation.setText(((TitledHandler)provider).getActionTitle()); + } + boolean canDelete = provider != null && provider.canDeleteElement(dataContext); + if (ActionPlaces.isPopupPlace(e.getPlace())) { + presentation.setVisible(canDelete); + } + else { + presentation.setEnabled(canDelete); + } + }); + } + + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/actions/PasteAction.java b/platform/platform-impl/src/com/intellij/ide/actions/PasteAction.java index 5f904261ccbe..58f897848c09 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/PasteAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/PasteAction.java @@ -14,17 +14,20 @@ public class PasteAction extends AnAction implements DumbAware, LightEditCompati @Override public void update(@NotNull AnActionEvent event) { - Presentation presentation = event.getPresentation(); - DataContext dataContext = event.getDataContext(); + CopyAction.updateFromProvider(event, PlatformDataKeys.PASTE_PROVIDER, (provider, presentation) -> { + presentation.setEnabled(provider != null && provider.isPastePossible(event.getDataContext())); + if (event.getPlace().equals(ActionPlaces.EDITOR_POPUP) && provider != null) { + presentation.setVisible(presentation.isEnabled()); + } + else { + presentation.setVisible(true); + } + }); + } - PasteProvider provider = PlatformDataKeys.PASTE_PROVIDER.getData(dataContext); - presentation.setEnabled(provider != null && provider.isPastePossible(dataContext)); - if (event.getPlace().equals(ActionPlaces.EDITOR_POPUP) && provider != null) { - presentation.setVisible(presentation.isEnabled()); - } - else { - presentation.setVisible(true); - } + @Override + public @NotNull ActionUpdateThread getActionUpdateThread() { + return ActionUpdateThread.BGT; } @Override