use of com.intellij.structuralsearch.plugin.replace.ui.ReplaceDialog in project intellij-community by JetBrains.
the class SSBasedInspectionOptions method performEditAction.
private void performEditAction() {
final Configuration configuration = (Configuration) myTemplatesList.getSelectedValue();
if (configuration == null)
return;
SearchDialog dialog = createDialog(new SearchDialogFactory() {
@Override
public SearchDialog createDialog(SearchContext searchContext) {
if (configuration instanceof SearchConfiguration) {
return new SearchDialog(searchContext, false, false) {
@Override
public Configuration createConfiguration() {
SearchConfiguration newConfiguration = new SearchConfiguration();
copyConfiguration(configuration, newConfiguration);
return newConfiguration;
}
};
} else {
return new ReplaceDialog(searchContext, false, false) {
@Override
public Configuration createConfiguration() {
ReplaceConfiguration newConfiguration = new ReplaceConfiguration();
copyConfiguration(configuration, newConfiguration);
return newConfiguration;
}
};
}
}
});
dialog.setValuesFromConfig(configuration);
dialog.setUseLastConfiguration(true);
if (!dialog.showAndGet()) {
return;
}
final Configuration newConfiguration = dialog.getConfiguration();
final int index = myConfigurations.indexOf(configuration);
myConfigurations.remove(index);
myConfigurations.add(index, newConfiguration);
final SearchContext context = dialog.getSearchContext();
SSBasedInspectionCompiledPatternsCache.removeFromCache(configuration, context.getProject());
configurationsChanged(context);
}
use of com.intellij.structuralsearch.plugin.replace.ui.ReplaceDialog in project intellij-community by JetBrains.
the class StructuralReplaceAction method triggerAction.
public static void triggerAction(Configuration config, SearchContext searchContext) {
UsageTrigger.trigger("structural.replace");
final Project project = searchContext.getProject();
if (project == null) {
return;
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
ReplaceDialog replaceDialog = new ReplaceDialog(searchContext);
if (config != null) {
replaceDialog.setUseLastConfiguration(true);
replaceDialog.setValuesFromConfig(config);
}
replaceDialog.show();
}
use of com.intellij.structuralsearch.plugin.replace.ui.ReplaceDialog in project intellij-community by JetBrains.
the class SSBasedInspectionOptions method getComponent.
public JPanel getComponent() {
final JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel(SSRBundle.message("SSRInspection.selected.templates")));
panel.add(ToolbarDecorator.createDecorator(myTemplatesList).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final AnAction[] children = new AnAction[] { new AnAction(SSRBundle.message("SSRInspection.add.search.template.button")) {
@Override
public void actionPerformed(AnActionEvent e) {
addTemplate(new SearchDialogFactory() {
public SearchDialog createDialog(SearchContext searchContext) {
return new SearchDialog(searchContext, false, false);
}
});
}
}, new AnAction(SSRBundle.message("SSRInspection.add.replace.template.button")) {
@Override
public void actionPerformed(AnActionEvent e) {
addTemplate(new SearchDialogFactory() {
public SearchDialog createDialog(SearchContext searchContext) {
return new ReplaceDialog(searchContext, false, false);
}
});
}
} };
JBPopupFactory.getInstance().createActionGroupPopup(null, new DefaultActionGroup(children), DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true).show(button.getPreferredPopupPoint());
}
}).setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performEditAction();
}
}).setEditActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
final Project project = e.getProject();
return project != null && !DumbService.isDumb(project);
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final SearchContext context = createSearchContext();
final Object[] selected = myTemplatesList.getSelectedValues();
for (Object o : selected) {
final Configuration configuration = (Configuration) o;
myConfigurations.remove(configuration);
SSBasedInspectionCompiledPatternsCache.removeFromCache(configuration, context.getProject());
}
configurationsChanged(context);
}
}).setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
final Project project = e.getProject();
return project != null && !DumbService.isDumb(project);
}
}).setMoveUpAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performMoveUpDown(false);
}
}).setMoveDownAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performMoveUpDown(true);
}
}).setPreferredSize(new Dimension(-1, 100)).createPanel());
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
final Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(panel));
if (project != null && !DumbService.isDumb(project)) {
performEditAction();
}
return true;
}
}.installOn(myTemplatesList);
return panel;
}
Aggregations