diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/Template.java b/platform/lang-impl/src/com/intellij/codeInsight/template/Template.java index 794cf221ccb6..627d55c5e2fc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/Template.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/Template.java @@ -19,6 +19,7 @@ package com.intellij.codeInsight.template; import com.intellij.codeInsight.template.impl.Variable; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.EnumMap; import java.util.Map; @@ -61,6 +62,7 @@ public abstract class Template { public abstract String getId(); public abstract String getKey(); + @Nullable public abstract String getDescription(); public abstract boolean isToReformat(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplatesConfigurable.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplatesConfigurable.java index 0554ebafac35..a0424580caf6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplatesConfigurable.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplatesConfigurable.java @@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; public class LiveTemplatesConfigurable extends BaseConfigurable implements SearchableConfigurable, Configurable.NoScroll { + static final String ID = "editing.templates"; private TemplateListPanel myPanel; @Override @@ -67,7 +68,7 @@ public class LiveTemplatesConfigurable extends BaseConfigurable implements Searc @Override @NotNull public String getHelpTopic() { - return "editing.templates"; + return ID; } @Override @@ -78,8 +79,13 @@ public class LiveTemplatesConfigurable extends BaseConfigurable implements Searc @Override @Nullable - public Runnable enableSearch(String option) { - return null; + public Runnable enableSearch(final String option) { + return new Runnable() { + @Override + public void run() { + myPanel.selectNode(option); + } + }; } public TemplateListPanel getTemplateListPanel() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java index 6eeb116e2d43..d310851b8965 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java @@ -946,13 +946,30 @@ public class TemplateListPanel extends JPanel implements Disposable { selectTemplate(lastSelectedGroup, lastSelectedKey); } - private void selectTemplate(final String lastSelectedGroup, final String lastSelectedKey) { + void selectNode(@NotNull String searchQuery) { + for (TemplateGroup group : myTemplateGroups) { + for (TemplateImpl template : group.getElements()) { + if (StringUtil.startsWithIgnoreCase(template.getKey(), searchQuery)) { + selectTemplate(group.getName(), template.getKey()); + return; + } + } + } + for (TemplateGroup group : myTemplateGroups) { + if (StringUtil.startsWithIgnoreCase(group.getName(), searchQuery)) { + selectTemplate(group.getName(), null); + return; + } + } + } + + private void selectTemplate(@Nullable final String groupName, @Nullable final String templateKey) { TreeUtil.traverseDepth(myTreeRoot, new TreeUtil.Traverse() { @Override public boolean accept(Object node) { Object o = ((DefaultMutableTreeNode)node).getUserObject(); - if (lastSelectedKey == null && o instanceof TemplateGroup && Comparing.equal(lastSelectedGroup, ((TemplateGroup)o).getName()) || - o instanceof TemplateImpl && Comparing.equal(lastSelectedKey, ((TemplateImpl)o).getKey()) && Comparing.equal(lastSelectedGroup, ((TemplateImpl)o).getGroupName())) { + if (templateKey == null && o instanceof TemplateGroup && Comparing.equal(groupName, ((TemplateGroup)o).getName()) || + o instanceof TemplateImpl && Comparing.equal(templateKey, ((TemplateImpl)o).getKey()) && Comparing.equal(groupName, ((TemplateImpl)o).getGroupName())) { setSelectedNode((DefaultMutableTreeNode)node); return false; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSearchableOptionContributor.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSearchableOptionContributor.java new file mode 100644 index 000000000000..5bfadc0b1dac --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSearchableOptionContributor.java @@ -0,0 +1,51 @@ +/* + * 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.codeInsight.template.impl; + +import com.intellij.ide.ui.search.SearchableOptionContributor; +import com.intellij.ide.ui.search.SearchableOptionProcessor; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +/** + * @author peter + */ +public class TemplateSearchableOptionContributor extends SearchableOptionContributor { + @SuppressWarnings("StringToUpperCaseOrToLowerCaseWithoutLocale") + @Override + public void processOptions(@NotNull SearchableOptionProcessor processor) { + Set processedGroups = ContainerUtil.newHashSet(); + + for (TemplateImpl template : TemplateSettings.getInstance().getTemplates()) { + String groupName = template.getGroupName(); + if (processedGroups.add(groupName)) { + processor.addOptions(groupName, null, groupName + " live template group", LiveTemplatesConfigurable.ID, null, false); + } + + String key = template.getKey(); + String hit = key + " live template"; + + processor.addOptions(key, null, hit, LiveTemplatesConfigurable.ID, null, false); + + String description = template.getDescription(); + if (description != null) { + processor.addOptions(description, null, hit, LiveTemplatesConfigurable.ID, null, false); + } + } + } +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 5d7c2aba66eb..85bebce06660 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -364,6 +364,7 @@ +