mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-237117: Replace Hector popup with Highlighting Level list popup
GitOrigin-RevId: e211d76c8f3e93eb7f1c5bcef96b6d17d09d1fc5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7be390022e
commit
55d34f5363
@@ -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
|
||||
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}
|
||||
|
||||
+80
@@ -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)
|
||||
}
|
||||
}
|
||||
+22
@@ -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)
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
-23
@@ -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<AnAction> initActions() {
|
||||
List<AnAction> 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());
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<action id="CodeCleanup" class="com.intellij.codeInspection.actions.CodeCleanupAction"/>
|
||||
<action id="SilentCodeCleanup" class="com.intellij.codeInspection.actions.SilentCodeCleanupAction" />
|
||||
<action id="RunInspection" class="com.intellij.codeInspection.actions.RunInspectionAction" />
|
||||
<action id="PopupHector" class="com.intellij.codeInsight.daemon.impl.PopupHectorAction"/>
|
||||
<action id="PopupHector" class="com.intellij.codeInsight.daemon.impl.ConfigureHighlightingLevelAction"/>
|
||||
<action id="ViewOfflineInspection" class="com.intellij.codeInspection.actions.ViewOfflineResultsAction"/>
|
||||
</group>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user