diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageFilteringRuleProviderImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageFilteringRuleProviderImpl.java index fa338c857dfe..4a7ff4ebd144 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageFilteringRuleProviderImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageFilteringRuleProviderImpl.java @@ -21,6 +21,7 @@ import java.util.List; public class UsageFilteringRuleProviderImpl implements UsageFilteringRuleProvider { private final ReadWriteState myReadWriteState = new ReadWriteState(); + private boolean readWriteActionsEnabled = true; @Override public UsageFilteringRule @NotNull [] getActiveRules(@NotNull Project project) { @@ -78,6 +79,10 @@ public class UsageFilteringRuleProviderImpl implements UsageFilteringRuleProvide } } + public void setReadWriteEnabled(boolean readWriteEnabled) { + this.readWriteActionsEnabled = readWriteEnabled; + } + private class ShowReadAccessUsagesAction extends ToggleAction implements DumbAware { private ShowReadAccessUsagesAction() { super(UsageViewBundle.messagePointer("action.show.read.access"), @@ -96,6 +101,13 @@ public class UsageFilteringRuleProviderImpl implements UsageFilteringRuleProvide if (project == null) return; project.getMessageBus().syncPublisher(RULES_CHANGED).run(); } + + @Override + public void update(@NotNull AnActionEvent e) { + super.update(e); + Presentation presentation = e.getPresentation(); + presentation.setEnabled(readWriteActionsEnabled); + } } private class ShowWriteAccessUsagesAction extends ToggleAction implements DumbAware { @@ -116,5 +128,12 @@ public class UsageFilteringRuleProviderImpl implements UsageFilteringRuleProvide if (project == null) return; project.getMessageBus().syncPublisher(RULES_CHANGED).run(); } + + @Override + public void update(@NotNull AnActionEvent e) { + super.update(e); + Presentation presentation = e.getPresentation(); + presentation.setEnabled(readWriteActionsEnabled); + } } } diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index 6b2a862da7b5..d123bc053380 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -1,6 +1,7 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.usages.impl; +import com.intellij.codeInsight.highlighting.ReadWriteAccessDetector; import com.intellij.concurrency.JobSchedulerImpl; import com.intellij.find.FindManager; import com.intellij.icons.AllIcons; @@ -666,6 +667,27 @@ public class UsageViewImpl implements UsageViewEx { return list.toArray(UsageFilteringRule.EMPTY_ARRAY); } + protected void adjustReadWriteUsageFilter(Collection usages) { + boolean b = usages.stream().anyMatch(usage -> { + if(usage instanceof PsiElementUsage){ + PsiElement element = ((PsiElementUsage) usage).getElement(); + ReadWriteAccessDetector detector = ReadWriteAccessDetector.findDetector(element); + if(detector.isDeclarationWriteAccess(element) || detector.isDeclarationWriteAccess(element)){ + return true; + } + } + return false; + }); + + for (UsageFilteringRuleProvider provider : UsageFilteringRuleProvider.EP_NAME.getExtensionList()) { + if (provider instanceof UsageFilteringRuleProvider){ + ((UsageFilteringRuleProviderImpl)provider) .setReadWriteEnabled(b); + } + + } + } + + protected static UsageGroupingRule @NotNull [] getActiveGroupingRules(@NotNull final Project project, @NotNull UsageViewSettings usageViewSettings) { final List providers = UsageGroupingRuleProvider.EP_NAME.getExtensionList(); List list = new ArrayList<>(providers.size()); @@ -1207,6 +1229,7 @@ public class UsageViewImpl implements UsageViewEx { @NotNull @Override public CompletableFuture appendUsagesInBulk(@NotNull Collection usages) { + adjustReadWriteUsageFilter(usages); CompletableFuture result = new CompletableFuture<>(); addUpdateRequest(() -> ReadAction.run(() -> { try {