Rewrite inspection and intention settings to use provider-based configurable extension points

This commit is contained in:
Nikolay.Kuznetsov
2017-07-19 17:20:02 +03:00
parent 3681cfbc3c
commit e9e1d8c157
12 changed files with 132 additions and 26 deletions
@@ -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
@@ -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));
}
});
@@ -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)));
}
}
@@ -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);
}
@@ -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);
}
@@ -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();
}
@@ -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();
}
}
@@ -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<ErrorsConfigurable> 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
@@ -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));
}
}
@@ -421,7 +421,7 @@
key="filetype.settings.title" bundle="messages.FileTypesBundle"/>
<search.topHitProvider implementation="com.intellij.codeInsight.intention.impl.config.IntentionsOptionsTopHitProvider"/>
<applicationConfigurable groupId="editor" key="intention.settings" bundle="messages.CodeInsightBundle" instance="com.intellij.codeInsight.intention.impl.config.IntentionSettingsConfigurable" id="preferences.intentionPowerPack"/>
<applicationConfigurable groupId="editor" key="intention.settings" bundle="messages.CodeInsightBundle" provider="com.intellij.codeInsight.intention.impl.config.IntentionsConfigurableProviderImpl" id="preferences.intentionPowerPack"/>
<!-- Live Templates -->
<search.topHitProvider implementation="com.intellij.codeInsight.template.impl.LiveTemplatesOptionsTopHitProvider"/>
@@ -77,7 +77,7 @@
<programRunner implementation="com.intellij.execution.runners.DefaultRunProgramRunner" order="last"/>
<projectConfigurable groupId="editor" groupWeight="160" displayName="Inspections" id="Errors" instance="com.intellij.profile.codeInspection.ui.ProjectInspectionToolsConfigurable" order="before preferences.intentionPowerPack"/>
<projectConfigurable groupId="editor" groupWeight="160" displayName="Inspections" id="Errors" provider="com.intellij.profile.codeInspection.ui.ErrorsConfigurableProviderImpl" order="before preferences.intentionPowerPack"/>
<projectConfigurable groupId="appearance" groupWeight="111" instance="com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable" id="project.scopes" key="scopes.display.name" bundle="messages.IdeBundle" />
<checkoutCompletedListener implementation="com.intellij.openapi.vcs.checkout.PlatformProjectCheckoutListener" id="PlatformProjectCheckoutListener"/>
+1 -1
View File
@@ -236,7 +236,7 @@
<!-- Errors -->
<!-- Show full error options configurable only in full IDEA - platform supports only default IDE profile for now -->
<projectConfigurable groupId="editor" groupWeight="160" displayName="Inspections" id="Errors" instance="com.intellij.profile.codeInspection.ui.ProjectInspectionToolsConfigurable"/>
<projectConfigurable groupId="editor" groupWeight="160" displayName="Inspections" id="Errors" provider="com.intellij.profile.codeInspection.ui.ErrorsConfigurableProviderImpl"/>
<!-- Compiler -->
<projectConfigurable groupId="build" groupWeight="130" instance="com.intellij.compiler.options.CompilerConfigurable" id="project.propCompiler" order="after project"