mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-61368 Settings search doesn't find live templates
This commit is contained in:
@@ -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();
|
||||
|
||||
+9
-3
@@ -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() {
|
||||
|
||||
+20
-3
@@ -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;
|
||||
}
|
||||
|
||||
+51
@@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,6 +364,7 @@
|
||||
<!-- Live Templates -->
|
||||
<applicationConfigurable groupId="editor" groupWeight="130" instance="com.intellij.codeInsight.template.impl.LiveTemplatesConfigurable" id="editing.templates"
|
||||
key="templates.settings.page.title" bundle="messages.CodeInsightBundle"/>
|
||||
<search.optionContributor implementation="com.intellij.codeInsight.template.impl.TemplateSearchableOptionContributor"/>
|
||||
<lookup.actionProvider implementation="com.intellij.codeInsight.template.impl.LiveTemplateLookupActionProvider"/>
|
||||
<documentationProvider implementation="com.intellij.codeInsight.template.impl.LiveTemplateDocumentationProvider"/>
|
||||
<projectService serviceInterface="com.intellij.codeInsight.template.TemplateManager"
|
||||
|
||||
Reference in New Issue
Block a user