Automatic creation of top hit providers

This commit is contained in:
Sergey Malenkov
2015-05-19 21:46:27 +03:00
parent 6b8582969e
commit 15c59870ee
10 changed files with 456 additions and 61 deletions
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2015 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 org.intellij.images.options.impl;
import com.intellij.ide.ui.ConfigurableOptionsTopHitProvider;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
/**
* @author Sergey.Malenkov
*/
public class ImagesOptionsTopHitProvider extends ConfigurableOptionsTopHitProvider {
@Override
public String getId() {
return "editor";
}
@Override
protected Configurable getConfigurable(Project project) {
return new OptionsConfigurabe();
}
}
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2015 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.application.options.editor;
import com.intellij.ide.ui.ConfigurableOptionsTopHitProvider;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
/**
* @author Sergey.Malenkov
*/
public class AutoImportOptionsTopHitProvider extends ConfigurableOptionsTopHitProvider {
@Override
public String getId() {
return "editor";
}
@Override
protected Configurable getConfigurable(Project project) {
return new AutoImportOptionsConfigurable();
}
}
@@ -0,0 +1,54 @@
/*
* Copyright 2000-2015 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.application.options.editor;
import com.intellij.ide.ui.ConfigurableOptionsTopHitProvider;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
import javax.swing.*;
/**
* @author Sergey.Malenkov
*/
public class CodeFoldingOptionsTopHitProvider extends ConfigurableOptionsTopHitProvider {
private int myCount;
@Override
public String getId() {
return "editor";
}
@Override
protected Configurable getConfigurable(Project project) {
myCount = 0;
return new CodeFoldingConfigurable();
}
@Override
protected String getName(Configurable configurable) {
return null;
}
@Override
protected String getOptionName(JCheckBox checkbox) {
String name = super.getOptionName(checkbox);
if (name != null && 0 < myCount++) {
name = "Collapse by default: " + name;
}
return name;
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2000-2015 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.application.options.editor;
import com.intellij.ide.ui.ConfigurableOptionsTopHitProvider;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
/**
* @author Sergey.Malenkov
*/
public class EditorOptionsTopHitProvider extends ConfigurableOptionsTopHitProvider {
@Override
public String getId() {
return "editor";
}
@Override
protected Configurable getConfigurable(Project project) {
return new EditorOptions();
}
@Override
protected String getName(Configurable configurable) {
return null;
}
}
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2015 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.application.options.editor;
import com.intellij.ide.ui.ConfigurableOptionsTopHitProvider;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
/**
* @author Sergey.Malenkov
*/
public class EditorSmartKeysOptionsTopHitProvider extends ConfigurableOptionsTopHitProvider {
@Override
public String getId() {
return "editor";
}
@Override
protected Configurable getConfigurable(Project project) {
return new EditorSmartKeysConfigurable();
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2000-2015 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.application.options.editor;
import com.intellij.ide.ui.ConfigurableOptionsTopHitProvider;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
/**
* @author Sergey.Malenkov
*/
public class EditorTabsOptionsTopHitProvider extends ConfigurableOptionsTopHitProvider {
@Override
public String getId() {
return "editor";
}
@Override
protected Configurable getConfigurable(Project project) {
return new EditorTabsConfigurable();
}
@Override
protected String getName(Configurable configurable) {
return null;
}
}
@@ -0,0 +1,171 @@
/*
* Copyright 2000-2015 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.ide.ui;
import com.intellij.ide.ui.search.BooleanOptionDescription;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.ex.ConfigurableVisitor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.util.*;
/**
* @author Sergey.Malenkov
*/
public abstract class ConfigurableOptionsTopHitProvider extends OptionsTopHitProvider {
private static final Logger LOG = Logger.getInstance(ConfigurableOptionsTopHitProvider.class);
private final Deque<String> myPrefix = new ArrayDeque<String>();
protected abstract Configurable getConfigurable(Project project);
/**
* Returns a name that will be added to all option names.
* This implementation returns the display name of the configurable.
*
* @param configurable the configurable to process
* @return a main prefix or {@code null} to ignore
*/
protected String getName(Configurable configurable) {
return configurable.getDisplayName();
}
/**
* Returns a section name that will be added to some option names,
* which are located within the specified container.
* This implementation returns the border title of the component.
*
* @param component the component to process
* @return a section prefix or {@code null} to ignore
*/
protected String getSection(Component component) {
if (component instanceof JComponent) {
Border border = ((JComponent)component).getBorder();
if (border instanceof TitledBorder) {
return ((TitledBorder)border).getTitle();
}
}
return null;
}
/**
* Returns an option name that will be used to create an option.
*
* @param checkbox the candidate to create an option
* @return an option prefix or {@code null} to ignore this option
*/
protected String getOptionName(JCheckBox checkbox) {
String name = StringUtil.stripHtml(checkbox.getText(), false);
if (StringUtil.isEmpty(name)) {
return null;
}
if (myPrefix.isEmpty()) {
return name;
}
StringBuilder sb = new StringBuilder();
Iterator<String> iterator = myPrefix.descendingIterator();
while (iterator.hasNext()) {
sb.append(iterator.next()).append(": ");
}
return sb.append(name).toString();
}
protected void init(Collection<BooleanOptionDescription> options, Configurable configurable, Component component) {
initRecursively(options, configurable, component);
}
private void initRecursively(Collection<BooleanOptionDescription> options, Configurable configurable, Component component) {
String section = getSection(component);
if (section != null) {
myPrefix.push(section);
}
if (component instanceof JCheckBox) {
JCheckBox checkbox = (JCheckBox)component;
String option = getOptionName(checkbox);
if (option != null) {
options.add(new Option(configurable, checkbox, option));
}
}
else if (component instanceof Container) {
Container container = (Container)component;
for (int i = 0; i < container.getComponentCount(); i++) {
initRecursively(options, configurable, container.getComponent(i));
}
}
if (section != null) {
myPrefix.pop();
}
}
@NotNull
@Override
public Collection<BooleanOptionDescription> getOptions(@Nullable Project project) {
try {
Configurable configurable = getConfigurable(project);
Component component = configurable.createComponent();
configurable.reset();
myPrefix.clear();
String name = getName(configurable);
if (name != null) {
myPrefix.push(name);
}
Collection<BooleanOptionDescription> options = new ArrayList<BooleanOptionDescription>();
init(options, configurable, component);
return Collections.unmodifiableCollection(options);
}
catch (Exception exception) {
LOG.debug(exception);
}
return Collections.emptyList();
}
private static final class Option extends BooleanOptionDescription {
private final Configurable myConfigurable;
private final JCheckBox myCheckBox;
private Option(Configurable configurable, JCheckBox checkbox, String option) {
super(option, ConfigurableVisitor.ByID.getID(configurable));
myConfigurable = configurable;
myCheckBox = checkbox;
}
@Override
public boolean isOptionEnabled() {
return myCheckBox.isSelected();
}
@Override
public void setOptionState(boolean selected) {
if (selected != myCheckBox.isSelected()) {
myCheckBox.setSelected(selected);
try {
myConfigurable.apply();
}
catch (ConfigurationException exception) {
LOG.debug(exception);
}
}
}
}
}
@@ -16,10 +16,7 @@
package com.intellij.ide.ui;
import com.intellij.ide.ui.search.BooleanOptionDescription;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -31,54 +28,8 @@ import java.util.Collection;
*/
public class EditorOptionsTopHitProvider extends OptionsTopHitProvider {
private static final String ID = "editor";
private static final Collection<BooleanOptionDescription> ourOptions = ContainerUtil.immutableList(
editor("Mouse: " + messageApp("checkbox.honor.camelhumps.words.settings.on.double.click"),
"IS_MOUSE_CLICK_SELECTION_HONORS_CAMEL_WORDS"),
editor("Mouse: " + messageApp(SystemInfo.isMac
? "checkbox.enable.ctrl.mousewheel.changes.font.size.macos"
: "checkbox.enable.ctrl.mousewheel.changes.font.size"), "IS_WHEEL_FONTCHANGE_ENABLED"),
editor("Mouse: " + messageApp("checkbox.enable.drag.n.drop.functionality.in.editor"), "IS_DND_ENABLED"),
new EditorOptionDescription(null, messageApp("checkbox.use.soft.wraps.at.editor.action.text"), "preferences.editor") {
@Override
public boolean isOptionEnabled() {
return EditorSettingsExternalizable.getInstance().isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR);
}
@Override
public void setOptionState(boolean enabled) {
EditorSettingsExternalizable.getInstance().setUseSoftWraps(enabled, SoftWrapAppliancePlaces.MAIN_EDITOR);
fireUpdated();
}
},
new EditorOptionDescription(null, messageApp("checkbox.use.soft.wraps.at.console.action.text"), "preferences.editor") {
@Override
public boolean isOptionEnabled() {
return EditorSettingsExternalizable.getInstance().isUseSoftWraps(SoftWrapAppliancePlaces.CONSOLE);
}
@Override
public void setOptionState(boolean enabled) {
EditorSettingsExternalizable.getInstance().setUseSoftWraps(enabled, SoftWrapAppliancePlaces.CONSOLE);
fireUpdated();
}
},
editor(messageApp("checkbox.use.custom.soft.wraps.indent.action.text"), "USE_CUSTOM_SOFT_WRAP_INDENT"),
new EditorOptionDescription(null, messageApp("checkbox.show.softwraps.only.for.caret.line.action.text"), "preferences.editor") {
@Override
public boolean isOptionEnabled() {
return !EditorSettingsExternalizable.getInstance().isAllSoftWrapsShown();
}
@Override
public void setOptionState(boolean enabled) {
EditorSettingsExternalizable.getInstance().setAllSoftwrapsShown(!enabled);
fireUpdated();
}
},
editor("Virtual Space: " + messageApp("checkbox.allow.placement.of.caret.after.end.of.line"), "IS_VIRTUAL_SPACE"),
editor("Virtual Space: " + messageApp("checkbox.allow.placement.of.caret.inside.tabs"), "IS_CARET_INSIDE_TABS"),
editor("Virtual Space: " + messageApp("checkbox.show.virtual.space.at.file.bottom"), "ADDITIONAL_PAGE_AT_BOTTOM"),
editorUI("Appearance: " + messageIde("checkbox.use.antialiased.font.in.editor"), "ANTIALIASING_IN_EDITOR"),
editorUI("Appearance: " + messageIde("checkbox.use.lcd.rendered.font.in.editor"), "USE_LCD_RENDERING_IN_EDITOR"),
editorApp("Appearance: Caret blinking", "IS_CARET_BLINKING"),
@@ -91,16 +42,8 @@ public class EditorOptionsTopHitProvider extends OptionsTopHitProvider {
editorApp("Appearance: Show trailing whitespaces", "IS_TRAILING_WHITESPACES_SHOWN"),
editorApp("Appearance: Show vertical indent guides", "IS_INDENT_GUIDES_SHOWN"),
editorCode("Appearance: " + messageApp("checkbox.show.small.icons.in.gutter"), "SHOW_SMALL_ICONS_IN_GUTTER"),
option("Appearance: " + messageApp("checkbox.show.code.folding.outline"), "IS_FOLDING_OUTLINE_SHOWN", "editor.preferences.folding"),
editorTabs("Tabs: " + messageApp("checkbox.editor.tabs.in.single.row"), "SCROLL_TAB_LAYOUT_IN_EDITOR"),
editorTabs("Tabs: " + messageApp("checkbox.editor.scroll.if.need"), "HIDE_TABS_IF_NEED"),
editorTabs("Tabs: " + messageApp("checkbox.hide.file.extension.in.editor.tabs"), "HIDE_KNOWN_EXTENSION_IN_TABS"),
editorTabs("Tabs: Show directory in editor tabs for non-unique filenames", "SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES"),
editorTabs("Tabs: " + messageApp("checkbox.editor.tabs.show.close.button"), "SHOW_CLOSE_BUTTON"),
editorTabs("Tabs: " + messageApp("checkbox.mark.modified.tabs.with.asterisk"), "MARK_MODIFIED_TABS_WITH_ASTERISK"),
editorTabs("Tabs: " + messageApp("checkbox.show.tabs.tooltips"), "SHOW_TABS_TOOLTIPS"),
editorTabs("Tabs: " + messageApp("checkbox.smart.tab.reuse"), "REUSE_NOT_MODIFIED_TABS"),
editorTabs("Tabs: " + messageApp("radio.close.non.modified.files.first"), "CLOSE_NON_MODIFIED_FILES_FIRST")
editorTabs(messageApp("group.tab.closing.policy") + ": " +
messageApp("radio.close.non.modified.files.first"), "CLOSE_NON_MODIFIED_FILES_FIRST")
);
@NotNull
@@ -137,7 +80,7 @@ public class EditorOptionsTopHitProvider extends OptionsTopHitProvider {
static BooleanOptionDescription editorCode(String option, String field) {
return new DaemonCodeAnalyzerOptionDescription(field, option, "editor.preferences.appearance");
}
public static class Ex extends OptionsTopHitProvider implements CoveredByToggleActions {
private static final Collection<BooleanOptionDescription> ourOptions = ContainerUtil.immutableList(
editorApp("Appearance: " + messageApp("checkbox.show.line.numbers"), "ARE_LINE_NUMBERS_SHOWN")
@@ -377,6 +377,13 @@
<search.topHitProvider implementation="com.intellij.ide.ui.InspectionsTopHitProvider"/>
<search.topHitProvider implementation="com.intellij.ide.ui.RegistryOptionsTopHitProvider"/>
<search.topHitProvider implementation="com.intellij.ide.ui.PluginOptionsTopHitProvider"/>
<search.topHitProvider implementation="com.intellij.application.options.editor.EditorOptionsTopHitProvider"/>
<search.topHitProvider implementation="com.intellij.application.options.editor.EditorSmartKeysOptionsTopHitProvider"/>
<search.topHitProvider implementation="com.intellij.application.options.editor.EditorTabsOptionsTopHitProvider"/>
<search.topHitProvider implementation="com.intellij.application.options.editor.CodeFoldingOptionsTopHitProvider"/>
<search.topHitProvider implementation="com.intellij.application.options.editor.AutoImportOptionsTopHitProvider"/>
<search.topHitProvider implementation="com.intellij.uiDesigner.GuiDesignerOptionsTopHitProvider"/>
<search.topHitProvider implementation="org.intellij.images.options.impl.ImagesOptionsTopHitProvider"/>
<projectService serviceImplementation="com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.UnknownFeaturesCollector"/>
<postStartupActivity implementation="com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.PluginsAdvertiser" order="before OpenFilesActivity"/>
<actionPromoter implementation="com.intellij.ui.ToolbarDecoratorActionPromoter"/>
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2015 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.uiDesigner;
import com.intellij.ide.ui.ConfigurableOptionsTopHitProvider;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
/**
* @author Sergey.Malenkov
*/
public class GuiDesignerOptionsTopHitProvider extends ConfigurableOptionsTopHitProvider {
@Override
public String getId() {
return "editor";
}
@Override
protected Configurable getConfigurable(Project project) {
return new GuiDesignerConfigurable(project);
}
}