mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: autocompletion for "contained in search template" text field
This commit is contained in:
+16
-4
@@ -32,6 +32,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@State(name = "StructuralSearchPlugin", storages = @Storage(StoragePathMacros.WORKSPACE_FILE))
|
||||
public class ConfigurationManager implements PersistentStateComponent<Element> {
|
||||
@@ -131,6 +133,14 @@ public class ConfigurationManager implements PersistentStateComponent<Element> {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the names of all configurations, both user defined and built in.
|
||||
*/
|
||||
public List<String> getAllConfigurationNames() {
|
||||
final Stream<Configuration> stream = Stream.concat(StructuralSearchUtil.getPredefinedTemplates().stream(), configurations.stream());
|
||||
return stream.map(c -> c.getName()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<Configuration> getConfigurations() {
|
||||
return Collections.unmodifiableList(configurations);
|
||||
@@ -158,13 +168,14 @@ public class ConfigurationManager implements PersistentStateComponent<Element> {
|
||||
return Collections.unmodifiableList(historyConfigurations);
|
||||
}
|
||||
|
||||
public static @Nullable String findAppropriateName(@NotNull final Collection<Configuration> configurations, @NotNull String _name,
|
||||
@NotNull final Project project) {
|
||||
@Nullable
|
||||
public static String findAppropriateName(@NotNull final Collection<Configuration> configurations, @NotNull String _name,
|
||||
@NotNull final Project project) {
|
||||
Configuration config;
|
||||
String name = _name;
|
||||
|
||||
while ((config = findConfigurationByName(configurations, name)) != null) {
|
||||
int i = Messages.showYesNoDialog(
|
||||
final int i = Messages.showYesNoDialog(
|
||||
project,
|
||||
SSRBundle.message("overwrite.message"),
|
||||
SSRBundle.message("overwrite.title"),
|
||||
@@ -181,7 +192,8 @@ public class ConfigurationManager implements PersistentStateComponent<Element> {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static @Nullable String showSaveTemplateAsDialog(@NotNull String initial, @NotNull Project project) {
|
||||
@Nullable
|
||||
public static String showSaveTemplateAsDialog(@NotNull String initial, @NotNull Project project) {
|
||||
return Messages.showInputDialog(
|
||||
project,
|
||||
SSRBundle.message("template.name.button"),
|
||||
|
||||
+4
-2
@@ -37,7 +37,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComponentWithBrowseButton;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
@@ -96,7 +95,7 @@ class EditVarConstraintsDialog extends DialogWrapper {
|
||||
ComponentWithBrowseButton<EditorTextField> customScriptCode;
|
||||
JCheckBox maxoccursUnlimited;
|
||||
|
||||
TextFieldWithBrowseButton withinTextField;
|
||||
TextFieldWithAutoCompletionWithBrowseButton withinTextField;
|
||||
private JPanel containedInConstraints;
|
||||
private JCheckBox invertWithinIn;
|
||||
private JPanel expressionConstraints;
|
||||
@@ -169,6 +168,8 @@ class EditVarConstraintsDialog extends DialogWrapper {
|
||||
|
||||
containedInConstraints.setVisible(false);
|
||||
|
||||
final List<String> names = ConfigurationManager.getInstance(project).getAllConfigurationNames();
|
||||
withinTextField.setAutoCompletionItems(names);
|
||||
withinTextField.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull final ActionEvent e) {
|
||||
@@ -541,6 +542,7 @@ class EditVarConstraintsDialog extends DialogWrapper {
|
||||
|
||||
myRegExHelpLabel = RegExHelpPopup.createRegExLink(SSRBundle.message("regular.expression.help.label"), regexp, LOG);
|
||||
myRegExHelpLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
|
||||
withinTextField = new TextFieldWithAutoCompletionWithBrowseButton(myProject);
|
||||
}
|
||||
|
||||
private EditorTextField createRegexComponent() {
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.structuralsearch.plugin.ui;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComponentWithBrowseButton;
|
||||
import com.intellij.ui.TextAccessor;
|
||||
import com.intellij.ui.TextFieldWithAutoCompletion;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class TextFieldWithAutoCompletionWithBrowseButton
|
||||
extends ComponentWithBrowseButton<TextFieldWithAutoCompletion<String>> implements TextAccessor {
|
||||
|
||||
public TextFieldWithAutoCompletionWithBrowseButton(Project project) {
|
||||
super(TextFieldWithAutoCompletion.create(project, Collections.emptyList(), false, null), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return getChildComponent().getText();
|
||||
}
|
||||
|
||||
public void setAutoCompletionItems(Collection<String> items) {
|
||||
System.out.println("names = " + items);
|
||||
getChildComponent().setVariants(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
getChildComponent().setText(text);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -302,7 +302,7 @@
|
||||
</clientProperties>
|
||||
<border type="none" title-resource-bundle="messages/SSRBundle" title-key="var.constraints.within.pattern.border"/>
|
||||
<children>
|
||||
<component id="ecda0" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="withinTextField">
|
||||
<component id="bfd62" class="com.intellij.structuralsearch.plugin.ui.TextFieldWithAutoCompletionWithBrowseButton" binding="withinTextField" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
|
||||
Reference in New Issue
Block a user