diff --git a/platform/lang-api/resources/messages/DaemonBundle.properties b/platform/lang-api/resources/messages/DaemonBundle.properties index f0ce930f3b72..637844ab05b7 100644 --- a/platform/lang-api/resources/messages/DaemonBundle.properties +++ b/platform/lang-api/resources/messages/DaemonBundle.properties @@ -67,4 +67,7 @@ label.code.analysis.is.disabled.in.power.save.mode=Code analysis is disabled in label.no.analysis.has.been.performed=No analysis has been performed label.code.analysis.has.been.suspended=Code analysis has been suspended label.shallow.analysis.completed=Shallow analysis completed -label.complete.results.will.be.available.after.indexing=Complete results will be available after indexing \ No newline at end of file +label.complete.results.will.be.available.after.indexing=Complete results will be available after indexing + +popup.action.configure.inspections=Configure Inspections... +popup.title.configure.highlighting.level=Highlighting Level for {0} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ConfigureHighlightingLevel.kt b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ConfigureHighlightingLevel.kt new file mode 100644 index 000000000000..755f525a0914 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ConfigureHighlightingLevel.kt @@ -0,0 +1,80 @@ +// 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.codeInsight.daemon.impl + +import com.intellij.codeInsight.daemon.DaemonBundle.message +import com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting +import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil.forceRootHighlighting +import com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager +import com.intellij.lang.Language +import com.intellij.openapi.actionSystem.* +import com.intellij.openapi.actionSystem.CommonDataKeys.PSI_FILE +import com.intellij.openapi.editor.markup.InspectionsLevel +import com.intellij.openapi.roots.ProjectFileIndex +import com.intellij.openapi.ui.popup.JBPopup +import com.intellij.openapi.ui.popup.JBPopupFactory +import com.intellij.psi.FileViewProvider + +fun getConfigureHighlightingLevelPopup(context: DataContext): JBPopup? { + val psi = context.getData(PSI_FILE) ?: return null + if (!psi.isValid || psi.project.isDisposed) return null + + val provider = psi.viewProvider + val languages = provider.languages + if (languages.isEmpty()) return null + + val file = psi.virtualFile ?: return null + val index = ProjectFileIndex.getInstance(psi.project) + val isAllInspectionsEnabled = index.isInContent(file) || !index.isInLibrary(file) + val isSeparatorNeeded = languages.count() > 1 + + val group = DefaultActionGroup() + languages.sortedBy { it.displayName }.forEach { + if (isSeparatorNeeded) group.add(Separator.create(it.displayName)) + group.add(LevelAction(InspectionsLevel.NONE, provider, it)) + group.add(LevelAction(InspectionsLevel.ERRORS, provider, it)) + if (isAllInspectionsEnabled) group.add(LevelAction(InspectionsLevel.ALL, provider, it)) + } + group.add(Separator.create()) + group.add(ConfigureInspectionsAction()) + val title = message("popup.title.configure.highlighting.level", psi.virtualFile.presentableName) + return JBPopupFactory.getInstance().createActionGroupPopup(title, group, context, true, null, 100) +} + + +private class LevelAction(val level: InspectionsLevel, val provider: FileViewProvider, val language: Language) + : ToggleAction(level.toString()) { + + override fun isSelected(event: AnActionEvent): Boolean { + val file = provider.getPsi(language) ?: return false + val manager = HighlightingLevelManager.getInstance(file.project) ?: return false + return level == when { + manager.shouldInspect(file) -> InspectionsLevel.ALL + manager.shouldHighlight(file) -> InspectionsLevel.ERRORS + else -> InspectionsLevel.NONE + } + } + + override fun setSelected(event: AnActionEvent, state: Boolean) { + if (!state) return + val file = provider.getPsi(language) ?: return + forceRootHighlighting(file, when (level) { + InspectionsLevel.NONE -> FileHighlightingSetting.SKIP_HIGHLIGHTING + InspectionsLevel.ERRORS -> FileHighlightingSetting.SKIP_INSPECTION + InspectionsLevel.ALL -> FileHighlightingSetting.FORCE_HIGHLIGHTING + }) + } +} + + +internal class ConfigureHighlightingLevelAction : AnAction() { + + override fun update(event: AnActionEvent) { + val enabled = event.getData(PSI_FILE)?.viewProvider?.languages?.isNotEmpty() + event.presentation.isEnabled = enabled == true + } + + override fun actionPerformed(event: AnActionEvent) { + val popup = getConfigureHighlightingLevelPopup(event.dataContext) + popup?.showInBestPositionFor(event.dataContext) + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ConfigureInspectionsAction.kt b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ConfigureInspectionsAction.kt new file mode 100644 index 000000000000..31518cd61a86 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ConfigureInspectionsAction.kt @@ -0,0 +1,22 @@ +// 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.codeInsight.daemon.impl + +import com.intellij.codeInsight.daemon.DaemonBundle.message +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.options.ShowSettingsUtil +import com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil.createProjectConfigurableForProvider +import com.intellij.openapi.project.DumbAwareAction +import com.intellij.profile.codeInspection.ui.ErrorsConfigurableProvider + +class ConfigureInspectionsAction : DumbAwareAction(message("popup.action.configure.inspections")) { + + override fun update(event: AnActionEvent) { + event.presentation.isEnabled = event.project != null + } + + override fun actionPerformed(event: AnActionEvent) { + val project = event.project ?: return + val provider = createProjectConfigurableForProvider(project, ErrorsConfigurableProvider::class.java) ?: return + ShowSettingsUtil.getInstance().editConfigurable(project, provider) + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponentImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponentImpl.java index b38e654b711e..d23b58d97624 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponentImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponentImpl.java @@ -2,6 +2,7 @@ package com.intellij.codeInsight.daemon.impl; +import com.intellij.codeInsight.daemon.DaemonBundle; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.impl.analysis.FileHighlightingSetting; import com.intellij.codeInsight.daemon.impl.analysis.HighlightLevelUtil; @@ -119,7 +120,7 @@ class HectorComponentImpl extends JPanel implements HectorComponent { gc.gridy = GridBagConstraints.RELATIVE; gc.weighty = 0; - final HyperlinkLabel configurator = new HyperlinkLabel(EditorBundle.message("iw.configure.inspections")); + HyperlinkLabel configurator = new HyperlinkLabel(DaemonBundle.message("popup.action.configure.inspections")); gc.insets.right = 5; gc.insets.bottom = 10; gc.weightx = 0; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PopupHectorAction.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PopupHectorAction.java deleted file mode 100644 index 9b4255050de9..000000000000 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PopupHectorAction.java +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2000-2019 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.codeInsight.daemon.impl; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.psi.PsiFile; -import org.jetbrains.annotations.NotNull; - -public class PopupHectorAction extends AnAction { - - @Override - public void actionPerformed(@NotNull final AnActionEvent e) { - final DataContext dataContext = e.getDataContext(); - final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); - - HectorComponent hector = ServiceManager.getService(file.getProject(), HectorComponentFactory.class).create(file); - hector.showComponent(JBPopupFactory.getInstance().guessBestPopupLocation(dataContext)); - } - - @Override - public void update(@NotNull final AnActionEvent e) { - e.getPresentation().setEnabled(e.getData(CommonDataKeys.PSI_FILE) != null); - } -} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java index 8742af913588..b8abf766cfff 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/TrafficLightRenderer.java @@ -28,12 +28,8 @@ import com.intellij.openapi.editor.impl.EditorMarkupModelImpl; import com.intellij.openapi.editor.impl.event.MarkupModelListener; import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.options.ShowSettingsUtil; -import com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil; import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; @@ -41,7 +37,6 @@ import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.profile.codeInspection.ui.ErrorsConfigurableProvider; import com.intellij.psi.*; import com.intellij.util.ArrayUtil; import com.intellij.util.ArrayUtilRt; @@ -621,24 +616,7 @@ public class TrafficLightRenderer implements ErrorStripeRenderer, Disposable { private @NotNull List initActions() { List result = new ArrayList<>(); - result.add(new DumbAwareAction(EditorBundle.message("iw.configure.inspections")) { - @Override - public void update(@NotNull AnActionEvent e) { - e.getPresentation().setEnabled(myDaemonCodeAnalyzer.isHighlightingAvailable(getPsiFile())); - } - - @Override - public void actionPerformed(@NotNull AnActionEvent e) { - if (!getProject().isDisposed()) { - Configurable projectConfigurable = ConfigurableExtensionPointUtil.createProjectConfigurableForProvider(getProject(), - ErrorsConfigurableProvider.class); - if (projectConfigurable != null) { - ShowSettingsUtil.getInstance().editConfigurable(getProject(), projectConfigurable); - } - } - } - }); - + result.add(new ConfigureInspectionsAction()); result.add(DaemonEditorPopup.createGotoGroup()); result.add(Separator.create()); diff --git a/platform/platform-api/resources/messages/EditorBundle.properties b/platform/platform-api/resources/messages/EditorBundle.properties index 6332eb884761..a4cf27f294e1 100644 --- a/platform/platform-api/resources/messages/EditorBundle.properties +++ b/platform/platform-api/resources/messages/EditorBundle.properties @@ -163,7 +163,6 @@ large.file.editor.message.found.some.matches.in.the.whole.file=Found {0} matches large.file.editor.message.found.some.matches.in.some.bounds.of.file=Found {0} matches in bounds {1}% to {2}% of file. message.warning.about.regex.search.limitations=Search with Regex in large file can''t find matches with length longer then {0}Kb -iw.configure.inspections=Configure Inspections... iw.show.import.tooltip=Show Auto-Import Tooltip iw.compact.view=Compact View iw.highlight.label=Highlight: diff --git a/platform/platform-resources/src/idea/PlatformLangActionManager.xml b/platform/platform-resources/src/idea/PlatformLangActionManager.xml index a75947ae006c..6c0c238986d4 100644 --- a/platform/platform-resources/src/idea/PlatformLangActionManager.xml +++ b/platform/platform-resources/src/idea/PlatformLangActionManager.xml @@ -51,7 +51,7 @@ - +