mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[codeInspection.ui] Register InspectionProfileActionProvider#getAddActions in the inspection profile panel
IJ-CR-117041 GitOrigin-RevId: 7075cd66dd8019673dff9542b7c717a5b2b1a4a5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
af6f095623
commit
c38cdeb515
@@ -125,7 +125,8 @@ inspection.warning.single.character.alternation.in.regexp=Single character alter
|
||||
inspection.warning.unnecessary.non.capturing.group=Unnecessary non-capturing group <code>{0}</code>
|
||||
inspection.tree.create.inspection=Using a RegExp\u2026
|
||||
inspection.tree.group.description=Use the + button in the toolbar to create a new RegExp inspection.<br>\
|
||||
RegExp inspections highlight code snippets matching the specified regular expression. A quick-fix can be provided by adding a second regular expression.
|
||||
RegExp inspections highlight code snippets matching the specified regular expression. A quick-fix can be provided by adding a string template which may contain group references (e.g. <code>$1</code>).<br><br>\
|
||||
<a href="action://regexp.profile.action.provider.add.group">Add Custom RegExp Inspection\u2026</a>
|
||||
intention.family.name.replace=Replace
|
||||
intention.name.check.regexp=Check RegExp
|
||||
label.any=Any
|
||||
|
||||
@@ -3,27 +3,29 @@ package org.intellij.lang.regexp.inspection.custom;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModel;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.NlsActions;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.profile.codeInspection.ui.InspectionMetaDataDialog;
|
||||
import com.intellij.profile.codeInspection.ui.InspectionProfileActionProvider;
|
||||
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
|
||||
import org.intellij.lang.regexp.RegExpBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class RegExpProfileActionProvider extends InspectionProfileActionProvider {
|
||||
@Override
|
||||
public @NotNull List<AnAction> getAddActions(@NotNull SingleInspectionProfilePanel panel) {
|
||||
return List.of(
|
||||
public @Nullable Pair<@NotNull ActionGroup, @NotNull String> getAddActions(@NotNull SingleInspectionProfilePanel panel) {
|
||||
final var group = new DefaultActionGroup(
|
||||
new AddCustomRegExpInspectionAction(panel, RegExpBundle.message("action.add.regexp.search.inspection.text"), false),
|
||||
new AddCustomRegExpInspectionAction(panel, RegExpBundle.message("action.add.regexp.replace.inspection.text"), true)
|
||||
);
|
||||
return Pair.create(group, "regexp.profile.action.provider.add.group");
|
||||
}
|
||||
|
||||
static final class AddCustomRegExpInspectionAction extends DumbAwareAction {
|
||||
|
||||
@@ -20,12 +20,14 @@ public final class CustomInspectionActions {
|
||||
@Nullable
|
||||
public static ActionGroup getAddActionGroup(SingleInspectionProfilePanel panel) {
|
||||
final DefaultActionGroup actionGroup = new DefaultActionGroup();
|
||||
var addActions = ContainerUtil.flatMap(
|
||||
InspectionProfileActionProvider.EP_NAME.getExtensionList(),
|
||||
provider -> provider.getAddActions(panel)
|
||||
);
|
||||
if (addActions.isEmpty()) return null;
|
||||
actionGroup.addAll(addActions);
|
||||
InspectionProfileActionProvider.EP_NAME.getExtensionList().forEach(provider -> {
|
||||
final var groupInfo = provider.getAddActions(panel);
|
||||
if (groupInfo != null) {
|
||||
panel.registerAction(groupInfo.second, groupInfo.first);
|
||||
actionGroup.add(groupInfo.first);
|
||||
}
|
||||
});
|
||||
if (actionGroup.getChildrenCount() == 0) return null;
|
||||
actionGroup.setPopup(true);
|
||||
actionGroup.registerCustomShortcutSet(CommonShortcuts.getNew(), panel);
|
||||
final Presentation presentation = actionGroup.getTemplatePresentation();
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
package com.intellij.profile.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,9 +34,9 @@ public abstract class InspectionProfileActionProvider {
|
||||
/**
|
||||
* @return actions to add custom inspections in the given inspection profile panel.
|
||||
*/
|
||||
@NotNull
|
||||
public List<AnAction> getAddActions(@NotNull SingleInspectionProfilePanel panel) {
|
||||
return List.of();
|
||||
@Nullable
|
||||
public Pair<@NotNull ActionGroup, @NotNull String> getAddActions(@NotNull SingleInspectionProfilePanel panel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,6 +81,7 @@ import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
@@ -92,7 +93,6 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
|
||||
private static final float DIVIDER_PROPORTION_DEFAULT = 0.5f;
|
||||
private static final int SECTION_GAP = 20;
|
||||
public static final String ADD_CUSTOM_INSPECTION_ACTION_ID = "sipp.add.custom.inspection";
|
||||
|
||||
private final Map<String, ToolDescriptors> myInitialToolDescriptors = new HashMap<>();
|
||||
private final InspectionConfigTreeNode myRoot = new InspectionConfigTreeNode.Group(InspectionsBundle.message("inspection.root.node.title"));
|
||||
@@ -159,6 +159,13 @@ public class SingleInspectionProfilePanel extends JPanel {
|
||||
return myProjectProfileManager.getProject();
|
||||
}
|
||||
|
||||
public void registerAction(@NotNull String id, @NotNull AnAction action) {
|
||||
ActionManager.getInstance().registerAction(id, action);
|
||||
Disposer.register(myDisposable, new Disposable() {
|
||||
@Override public void dispose() { ActionManager.getInstance().unregisterAction(id); }
|
||||
});
|
||||
}
|
||||
|
||||
private static VisibleTreeState getExpandedNodes(InspectionProfileImpl profile) {
|
||||
if (profile.isProjectLevel()) {
|
||||
return ProjectInspectionProfilesVisibleTreeState.getInstance(((ProjectBasedInspectionProfileManager)profile.getProfileManager()).getProject()).getVisibleTreeState(profile);
|
||||
|
||||
@@ -336,4 +336,5 @@ replace.configuration.display.text={0} \u21E8 {1}
|
||||
inspection.tree.create.inspection.search.template=Using a Structural Search Template\u2026
|
||||
inspection.tree.create.inspection.replace.template=Using a Structural Replace Template\u2026
|
||||
inspection.tree.group.description=Use the + button in the toolbar to create a new Structural Search inspection.<br>\
|
||||
Structural Search inspections highlight code snippets matching the specified search template. A quick-fix can be provided by adding a replace template.
|
||||
Structural Search inspections highlight code snippets matching the specified search template. A quick-fix can be provided by adding a replace template.<br><br>\
|
||||
<a href="action://ssr.profile.action.provider.add.group">Add Custom Structural Search Inspection\u2026</a>
|
||||
@@ -7,12 +7,14 @@ import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionProfileModifiableModel;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ex.ScopeToolState;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.NlsActions;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.profile.codeInspection.ui.CustomInspectionActions;
|
||||
import com.intellij.profile.codeInspection.ui.InspectionMetaDataDialog;
|
||||
@@ -24,9 +26,9 @@ import com.intellij.structuralsearch.plugin.ui.Configuration;
|
||||
import com.intellij.structuralsearch.plugin.ui.SearchContext;
|
||||
import com.intellij.structuralsearch.plugin.ui.StructuralSearchDialog;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
@@ -48,12 +50,13 @@ public class StructuralSearchProfileActionProvider extends InspectionProfileActi
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<AnAction> getAddActions(@NotNull SingleInspectionProfilePanel panel) {
|
||||
public @Nullable Pair<@NotNull ActionGroup, @NotNull String> getAddActions(@NotNull SingleInspectionProfilePanel panel) {
|
||||
enableSSIfDisabled(panel.getProfile(), panel.getProject());
|
||||
return List.of(
|
||||
final var group = new DefaultActionGroup(
|
||||
new AddInspectionAction(panel, SSRBundle.message("SSRInspection.add.search.template.button"), false),
|
||||
new AddInspectionAction(panel, SSRBundle.message("SSRInspection.add.replace.template.button"), true)
|
||||
);
|
||||
return Pair.create(group, "ssr.profile.action.provider.add.group");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user