import java.util.List;
import java.util.Map;
-// Class to show the user the request for search
@SuppressWarnings({"RefusedBequest"})
public class ReplaceDialog extends SearchDialog {
private String mySavedEditorText;
+ @Override
protected String getDefaultTitle() {
return SSRBundle.message("structural.replace.title");
}
+ @Override
protected JComponent createEditorContent() {
JPanel result = new JPanel(new BorderLayout());
Splitter p;
return result;
}
+ @Override
protected int getRowsCount() {
return super.getRowsCount() + 1;
}
+ @Override
protected String getDimensionServiceKey() {
return "#com.intellij.structuralsearch.plugin.replace.ui.ReplaceDialog";
}
+ @Override
protected void buildOptions(JPanel searchOptions) {
super.buildOptions(searchOptions);
searchOptions.add(UIUtil.createOptionLine(shortenFQN = new JCheckBox(
super(searchContext, showScope, runFindActionOnClose);
}
+ @Override
protected void startSearching() {
new ReplaceCommand(model.getConfig(), searchContext).startSearching();
}
+ @Override
public Configuration createConfiguration() {
ReplaceConfiguration configuration = new ReplaceConfiguration();
configuration.setName(USER_DEFINED);
return configuration;
}
+ @Override
protected void disposeEditorContent() {
mySavedEditorText = replaceCriteriaEdit.getDocument().getText();
EditorFactory.getInstance().releaseEditor(replaceCriteriaEdit);
super.disposeEditorContent();
}
+ @Override
public void setValuesFromConfig(Configuration configuration) {
//replaceCriteriaEdit.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, configuration);
}
}
+ @Override
protected void setValuesToConfig(Configuration config) {
super.setValuesToConfig(config);
options.setToUseStaticImport(useStaticImport.isSelected());
}
+ @Override
protected boolean isRecursiveSearchEnabled() {
return false;
}
- protected java.util.List<Variable> getVariablesFromListeners() {
- ArrayList<Variable> vars = getVarsFrom(replaceCriteriaEdit);
+ @Override
+ protected List<Variable> getVariablesFromListeners() {
+ List<Variable> vars = getVarsFrom(replaceCriteriaEdit);
List<Variable> searchVars = super.getVariablesFromListeners();
Map<String, Variable> varsMap = new LinkedHashMap<>(searchVars.size());
return new ArrayList<>(varsMap.values());
}
+ @Override
protected boolean isValid() {
if (!super.isValid()) return false;
return true;
}
+ @Override
public void show() {
replaceCriteriaEdit.putUserData(SubstitutionShortInfoHandler.CURRENT_CONFIGURATION_KEY, model.getConfig());
super.show();
}
+ @Override
protected boolean isReplaceDialog() {
return true;
}
+ @Override
protected void addOrReplaceSelection(final String selection) {
super.addOrReplaceSelection(selection);
addOrReplaceSelectionForEditor(selection, replaceCriteriaEdit);
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.DocumentListener;
-import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.fileTypes.impl.FileTypeRenderer;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.TitledSeparator;
import com.intellij.util.Alarm;
+import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
private JCheckBox recursiveMatching;
private JCheckBox caseSensitiveMatch;
- private JComboBox fileTypes;
- private JComboBox contexts;
- private JComboBox dialects;
+ private JComboBox<FileType> fileTypes;
+ private JComboBox<String> contexts;
+ private JComboBox<Language> dialects;
private JLabel status;
private JLabel statusText;
}
Collections.sort(types, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
- final DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(types.toArray(new FileType[types.size()]));
- comboBoxModel.setSelectedItem(ourFtSearchVariant);
- fileTypes = new ComboBox(comboBoxModel);
+ final DefaultComboBoxModel<FileType> comboBoxModel = new DefaultComboBoxModel<>(types.toArray(new FileType[types.size()]));
+ fileTypes = new ComboBox<>(comboBoxModel);
fileTypes.setRenderer(new FileTypeRenderer());
new ComboboxSpeedSearch(fileTypes) {
@Override
return ((FileType)element).getName();
}
};
- fileTypes.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
- updateDialectsAndContexts();
- updateEditor();
- }
- });
-
- contexts = new JComboBox(new DefaultComboBoxModel());
+ contexts = new ComboBox<>();
contexts.setPreferredSize(new Dimension(60, -1));
- dialects = new JComboBox(new DefaultComboBoxModel());
- dialects.setRenderer(new ListCellRendererWrapper() {
+ dialects = new ComboBox<>();
+ dialects.setRenderer(new ListCellRendererWrapper<Language>() {
@Override
- public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
+ public void customize(JList list, Language value, int index, boolean selected, boolean hasFocus) {
if (value == null) {
setText("None");
}
- else if (value instanceof Language) {
- setText(((Language)value).getDisplayName());
+ else {
+ setText(value.getDisplayName());
}
}
});
fileTypes.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
- if (e.getStateChange() == ItemEvent.SELECTED) initiateValidation();
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ updateDialectsAndContexts();
+ updateEditor();
+ initiateValidation();
+ }
}
});
-
dialects.setSelectedItem(ourDialect);
contexts.setSelectedItem(ourContext);
if (fileType instanceof LanguageFileType) {
Language language = ((LanguageFileType)fileType).getLanguage();
Language[] languageDialects = LanguageUtil.getLanguageDialects(language);
- Arrays.sort(languageDialects, (o1, o2) -> o1.getDisplayName().compareTo(o2.getDisplayName()));
+ Arrays.sort(languageDialects, Comparator.comparing(Language::getDisplayName));
Language[] variants = new Language[languageDialects.length + 1];
variants[0] = null;
System.arraycopy(languageDialects, 0, variants, 1, languageDialects.length);
- dialects.setModel(new DefaultComboBoxModel(variants));
+ dialects.setModel(new DefaultComboBoxModel<>(variants));
dialects.setEnabled(variants.length > 1);
}
if (profile instanceof StructuralSearchProfileBase) {
final String[] contextNames = ((StructuralSearchProfileBase)profile).getContextNames();
if (contextNames.length > 0) {
- contexts.setModel(new DefaultComboBoxModel(contextNames));
+ contexts.setModel(new DefaultComboBoxModel<>(contextNames));
contexts.setSelectedItem(contextNames[0]);
contexts.setEnabled(true);
return;
ourFtSearchVariant = detectedFileType != null ?
detectedFileType :
StructuralSearchUtil.getDefaultFileType();
-
- // todo: detect dialect
-
- /*if (file.getLanguage() == StdLanguages.HTML ||
- (file.getFileType() == StdFileTypes.JSP &&
- contextLanguage == StdLanguages.HTML
- )
- ) {
- ourFileType = "html";
- }
- else if (file.getLanguage() == StdLanguages.XHTML ||
- (file.getFileType() == StdFileTypes.JSPX &&
- contextLanguage == StdLanguages.HTML
- )) {
- ourFileType = "xml";
- }
- else {
- ourFileType = DEFAULT_TYPE_NAME;
- }*/
}
}
TitledSeparator separator = new TitledSeparator(SSRBundle.message("search.dialog.scope.label"), myScopeChooserCombo.getComboBox());
scopePanel.add(separator, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(5, 0, 0, 0), 0, 0));
+ JBUI.insetsTop(5), 0, 0));
scopePanel.add(myScopeChooserCombo, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
- new Insets(0, 10, 0, 0), 0, 0));
+ JBUI.insetsLeft(10), 0, 0));
allOptions.add(
scopePanel,
return getVarsFrom(searchCriteriaEdit);
}
- protected static ArrayList<Variable> getVarsFrom(Editor searchCriteriaEdit) {
+ protected static List<Variable> getVarsFrom(Editor searchCriteriaEdit) {
SubstitutionShortInfoHandler handler = searchCriteriaEdit.getUserData(UIUtil.LISTENER_KEY);
+ if (handler == null) {
+ return Collections.emptyList();
+ }
return new ArrayList<>(handler.getVariables());
}
);
if (!useLastConfiguration) {
- final Editor editor = FileEditorManager.getInstance(searchContext.getProject()).getSelectedTextEditor();
+ final Editor editor = searchContext.getEditor();
boolean setSomeText = false;
if (editor != null) {