From e9e1d8c157c7caa46171260b0ff2575dab0209a6 Mon Sep 17 00:00:00 2001 From: "Nikolay.Kuznetsov" Date: Fri, 14 Jul 2017 15:52:58 +0300 Subject: [PATCH] Rewrite inspection and intention settings to use provider-based configurable extension points --- .../src/com/intellij/ConfigurableFactory.kt | 8 +++-- .../daemon/impl/HectorComponent.java | 7 ++-- .../impl/IntentionHintComponent.java | 7 ++-- .../config/IntentionSettingsConfigurable.java | 3 +- .../impl/config/IntentionsConfigurable.java | 22 +++++++++++++ .../IntentionsConfigurableProvider.java | 25 +++++++++++++++ .../IntentionsConfigurableProviderImpl.java | 26 +++++++++++++++ .../ex/EditInspectionToolsSettingsAction.java | 22 ++++--------- .../ui/ErrorsConfigurableProviderImpl.java | 32 +++++++++++++++++++ .../src/META-INF/LangExtensions.xml | 2 +- .../src/META-INF/PlatformLangPlugin.xml | 2 +- resources/src/idea/RichPlatformPlugin.xml | 2 +- 12 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurable.java create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurableProvider.java create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurableProviderImpl.java create mode 100644 platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurableProviderImpl.java diff --git a/platform/lang-impl/src/com/intellij/ConfigurableFactory.kt b/platform/lang-impl/src/com/intellij/ConfigurableFactory.kt index 5c911d37b40f..e1e294c9c4d4 100644 --- a/platform/lang-impl/src/com/intellij/ConfigurableFactory.kt +++ b/platform/lang-impl/src/com/intellij/ConfigurableFactory.kt @@ -29,6 +29,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsProvider open class ConfigurableFactory : Disposable { companion object { + @JvmStatic fun getInstance(): ConfigurableFactory { return ServiceManager.getService(ConfigurableFactory::class.java) } @@ -37,10 +38,13 @@ open class ConfigurableFactory : Disposable { override fun dispose() { } - open fun createCodeStyleConfigurable(provider: CodeStyleSettingsProvider, codeStyleSchemesModel: CodeStyleSchemesModel, owner: CodeStyleSchemesConfigurable): CodeStyleConfigurableWrapper { + open fun createCodeStyleConfigurable(provider: CodeStyleSettingsProvider, + codeStyleSchemesModel: CodeStyleSchemesModel, + owner: CodeStyleSchemesConfigurable): CodeStyleConfigurableWrapper { val codeStyleConfigurableWrapper = CodeStyleConfigurableWrapper(provider, object : CodeStyleSettingsPanelFactory() { override fun createPanel(scheme: CodeStyleScheme): NewCodeStyleSettingsPanel { - return NewCodeStyleSettingsPanel(provider.createSettingsPage(scheme.codeStyleSettings, codeStyleSchemesModel.getCloneSettings(scheme)), codeStyleSchemesModel) + return NewCodeStyleSettingsPanel( + provider.createSettingsPage(scheme.codeStyleSettings, codeStyleSchemesModel.getCloneSettings(scheme)), codeStyleSchemesModel) } }, owner) return codeStyleConfigurableWrapper diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponent.java index af32819bc4cd..5bdbbe59f2bb 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HectorComponent.java @@ -30,6 +30,7 @@ import com.intellij.openapi.editor.HectorComponentPanelsProvider; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.ShowSettingsUtil; +import com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; @@ -37,8 +38,7 @@ import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; -import com.intellij.profile.codeInspection.ui.ProjectInspectionToolsConfigurable; +import com.intellij.profile.codeInspection.ui.ErrorsConfigurableProvider; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; @@ -161,7 +161,8 @@ public class HectorComponent extends JPanel { } if (!DaemonCodeAnalyzer.getInstance(myFile.getProject()).isHighlightingAvailable(myFile)) return; final Project project = myFile.getProject(); - ShowSettingsUtil.getInstance().editConfigurable(project, new ProjectInspectionToolsConfigurable(ProjectInspectionProfileManager.getInstance(myFile.getProject()))); + ShowSettingsUtil.getInstance().editConfigurable(project, ConfigurableExtensionPointUtil + .createProjectConfigurableForProvider(project, ErrorsConfigurableProvider.class)); } }); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java index 533398096195..286c568a114c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/IntentionHintComponent.java @@ -24,7 +24,8 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.IntentionActionDelegate; import com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper; import com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings; -import com.intellij.codeInsight.intention.impl.config.IntentionSettingsConfigurable; +import com.intellij.codeInsight.intention.impl.config.IntentionsConfigurable; +import com.intellij.codeInsight.intention.impl.config.IntentionsConfigurableProvider; import com.intellij.codeInsight.unwrap.ScopeHighlighter; import com.intellij.codeInspection.SuppressIntentionActionFromFix; import com.intellij.icons.AllIcons; @@ -40,6 +41,7 @@ import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.openapi.options.ShowSettingsUtil; +import com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.*; import com.intellij.openapi.util.Comparing; @@ -620,7 +622,8 @@ public class IntentionHintComponent implements Disposable, ScrollAwareHint { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { - final IntentionSettingsConfigurable configurable = new IntentionSettingsConfigurable(); + final IntentionsConfigurable configurable = (IntentionsConfigurable)ConfigurableExtensionPointUtil + .createApplicationConfigurableForProvider(IntentionsConfigurableProvider.class); ShowSettingsUtil.getInstance().editConfigurable(project, configurable, () -> SwingUtilities.invokeLater(() -> configurable.selectIntention(myFamilyName))); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionSettingsConfigurable.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionSettingsConfigurable.java index 097e020c177c..5ab662fa19b0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionSettingsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionSettingsConfigurable.java @@ -27,7 +27,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; -public class IntentionSettingsConfigurable extends BaseConfigurable implements SearchableConfigurable, MasterDetails { +public class IntentionSettingsConfigurable extends BaseConfigurable implements SearchableConfigurable, MasterDetails, IntentionsConfigurable { private IntentionSettingsPanel myPanel; @NonNls public static final String HELP_ID = "preferences.intentionPowerPack"; public static final String DISPLAY_NAME = CodeInsightBundle.message("intention.settings"); @@ -115,6 +115,7 @@ public class IntentionSettingsConfigurable extends BaseConfigurable implements S return HELP_ID; } + @Override public void selectIntention(String familyName) { myPanel.selectIntention(familyName); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurable.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurable.java new file mode 100644 index 000000000000..9d0f64d03dec --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurable.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl.config; + +import com.intellij.openapi.options.Configurable; + +public interface IntentionsConfigurable extends Configurable { + void selectIntention(String familyName); +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurableProvider.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurableProvider.java new file mode 100644 index 000000000000..ae43f02c6516 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurableProvider.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl.config; + +import com.intellij.openapi.options.ConfigurableProvider; +import org.jetbrains.annotations.Nullable; + +public abstract class IntentionsConfigurableProvider extends ConfigurableProvider { + @Nullable + @Override + public abstract IntentionsConfigurable createConfigurable(); +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurableProviderImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurableProviderImpl.java new file mode 100644 index 000000000000..9000cf4e9ca9 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionsConfigurableProviderImpl.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.intention.impl.config; + +import org.jetbrains.annotations.Nullable; + +public class IntentionsConfigurableProviderImpl extends IntentionsConfigurableProvider { + @Nullable + @Override + public IntentionsConfigurable createConfigurable() { + return new IntentionSettingsConfigurable(); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/EditInspectionToolsSettingsAction.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/EditInspectionToolsSettingsAction.java index d01f34e13fda..97ec0912216b 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/EditInspectionToolsSettingsAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/EditInspectionToolsSettingsAction.java @@ -23,12 +23,12 @@ import com.intellij.codeInspection.InspectionsBundle; import com.intellij.icons.AllIcons; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.options.ShowSettingsUtil; +import com.intellij.openapi.options.ex.ConfigurableExtensionPointUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Iconable; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; -import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; import com.intellij.profile.codeInspection.ui.ErrorsConfigurable; -import com.intellij.profile.codeInspection.ui.ProjectInspectionToolsConfigurable; +import com.intellij.profile.codeInspection.ui.ErrorsConfigurableProvider; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -86,19 +86,11 @@ public class EditInspectionToolsSettingsAction implements IntentionAction, Icona final InspectionProfileImpl inspectionProfile, final Consumer configurableAction) { final ShowSettingsUtil settingsUtil = ShowSettingsUtil.getInstance(); - final ErrorsConfigurable errorsConfigurable = new ProjectInspectionToolsConfigurable(ProjectInspectionProfileManager.getInstance(project)) { - - @Override - protected boolean setActiveProfileAsDefaultOnApply() { - return false; - } - - @Override - protected InspectionProfileImpl getCurrentProfile() { - return inspectionProfile; - } - }; - return settingsUtil.editConfigurable(project, errorsConfigurable, () -> configurableAction.accept(errorsConfigurable)); + final ErrorsConfigurable errorsConfigurable = (ErrorsConfigurable) ConfigurableExtensionPointUtil.createProjectConfigurableForProvider(project, ErrorsConfigurableProvider.class); + return settingsUtil.editConfigurable(project, errorsConfigurable, () -> { + errorsConfigurable.selectProfile(inspectionProfile); // profile can be selected only after the UI has been initialized + configurableAction.accept(errorsConfigurable); + }); } @Override diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurableProviderImpl.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurableProviderImpl.java new file mode 100644 index 000000000000..9828dd6b3e65 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/ErrorsConfigurableProviderImpl.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.profile.codeInspection.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; + +public class ErrorsConfigurableProviderImpl extends ErrorsConfigurableProvider { + private final Project project; + + public ErrorsConfigurableProviderImpl(Project project) { + this.project = project; + } + + @Override + public ErrorsConfigurable createConfigurable() { + return new ProjectInspectionToolsConfigurable(ProjectInspectionProfileManager.getInstance(project)); + } +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index cec8a8683760..79a2a0ddad5e 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -421,7 +421,7 @@ key="filetype.settings.title" bundle="messages.FileTypesBundle"/> - + diff --git a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml index 3a980ff3b4c8..2e06d838df75 100644 --- a/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml +++ b/platform/platform-resources/src/META-INF/PlatformLangPlugin.xml @@ -77,7 +77,7 @@ - + diff --git a/resources/src/idea/RichPlatformPlugin.xml b/resources/src/idea/RichPlatformPlugin.xml index b40ce798be0e..4bab50752f64 100644 --- a/resources/src/idea/RichPlatformPlugin.xml +++ b/resources/src/idea/RichPlatformPlugin.xml @@ -236,7 +236,7 @@ - +