mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Postfix templates: allow to duplicate postfix templates (IDEA-190017)
This commit is contained in:
+43
-1
@@ -319,13 +319,55 @@ public class PostfixTemplatesCheckboxTree extends CheckboxTree implements Dispos
|
||||
lastPathComponent.setTemplate(newTemplate);
|
||||
}
|
||||
myModel.nodeStructureChanged(lastPathComponent);
|
||||
|
||||
|
||||
//update before /after panel
|
||||
selectionChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canDuplicateSelectedTemplate() {
|
||||
TreePath[] selectionPaths = getSelectionModel().getSelectionPaths();
|
||||
if (!(selectionPaths == null || selectionPaths.length <= 1)) {
|
||||
return false;
|
||||
}
|
||||
PostfixTemplate selectedTemplate = getSelectedTemplate();
|
||||
if (!isEditable(selectedTemplate)) {
|
||||
return false;
|
||||
}
|
||||
PostfixTemplateProvider provider = selectedTemplate.getProvider();
|
||||
return provider != null && provider.createEditor(selectedTemplate) != null;
|
||||
}
|
||||
|
||||
public void duplicateSelectedTemplate() {
|
||||
TreePath path = getSelectionModel().getSelectionPath();
|
||||
Object lastPathComponent = path.getLastPathComponent();
|
||||
if (lastPathComponent instanceof PostfixTemplateCheckedTreeNode) {
|
||||
PostfixTemplate template = ((PostfixTemplateCheckedTreeNode)lastPathComponent).getTemplate();
|
||||
PostfixTemplateProvider provider = ((PostfixTemplateCheckedTreeNode)lastPathComponent).getTemplateProvider();
|
||||
String languageId = myProviderToLanguage.get(provider);
|
||||
if (isEditable(template) && languageId != null) {
|
||||
PostfixTemplate templateToEdit = template instanceof PostfixChangedBuiltinTemplate
|
||||
? ((PostfixChangedBuiltinTemplate)template).getDelegate()
|
||||
: template;
|
||||
PostfixTemplateEditor editor = provider.createEditor(templateToEdit);
|
||||
if (editor == null) return;
|
||||
|
||||
String providerName = StringUtil.notNullize(provider.getPresentableName());
|
||||
PostfixEditTemplateDialog dialog = new PostfixEditTemplateDialog(this, editor, providerName, templateToEdit);
|
||||
if (dialog.showAndGet()) {
|
||||
String templateKey = dialog.getTemplateName();
|
||||
PostfixTemplate newTemplate = editor.createTemplate(PostfixTemplatesUtils.generateTemplateId(templateKey, provider), templateKey);
|
||||
PostfixTemplateCheckedTreeNode createdNode = new PostfixTemplateCheckedTreeNode(newTemplate, provider, true);
|
||||
DefaultMutableTreeNode languageNode = findOrCreateLanguageNode(languageId);
|
||||
languageNode.insert(createdNode, languageNode.getIndex((PostfixTemplateCheckedTreeNode)lastPathComponent) + 1);
|
||||
myModel.nodeStructureChanged(languageNode);
|
||||
TreeUtil.selectNode(this, createdNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canRemoveSelectedTemplates() {
|
||||
TreePath[] paths = getSelectionModel().getSelectionPaths();
|
||||
if (paths == null) {
|
||||
|
||||
+25
-1
@@ -10,15 +10,19 @@ import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate;
|
||||
import com.intellij.codeInsight.template.postfix.templates.PostfixTemplateProvider;
|
||||
import com.intellij.codeInsight.template.postfix.templates.PostfixTemplatesUtils;
|
||||
import com.intellij.lang.LanguageExtensionPoint;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonShortcuts;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.ui.AnActionButton;
|
||||
import com.intellij.ui.GuiUtils;
|
||||
import com.intellij.ui.ToolbarDecorator;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -101,12 +105,32 @@ public class PostfixTemplatesConfigurable implements SearchableConfigurable, Edi
|
||||
.setEditActionUpdater(e -> myCheckboxTree.canEditSelectedTemplate())
|
||||
.setEditAction(button -> myCheckboxTree.editSelectedTemplate())
|
||||
.setRemoveActionUpdater(e -> myCheckboxTree.canRemoveSelectedTemplates())
|
||||
.setRemoveAction(button -> myCheckboxTree.removeSelectedTemplates()).createPanel());
|
||||
.setRemoveAction(button -> myCheckboxTree.removeSelectedTemplates())
|
||||
.addExtraAction(duplicateAction())
|
||||
.createPanel());
|
||||
|
||||
myTemplatesTreeContainer.setLayout(new BorderLayout());
|
||||
myTemplatesTreeContainer.add(panel);
|
||||
}
|
||||
|
||||
private AnActionButton duplicateAction() {
|
||||
AnActionButton button = new AnActionButton("Duplicate", PlatformIcons.COPY_ICON) {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
if (myCheckboxTree != null) {
|
||||
myCheckboxTree.duplicateSelectedTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateButton(AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(myCheckboxTree != null && myCheckboxTree.canDuplicateSelectedTemplate());
|
||||
}
|
||||
};
|
||||
button.registerCustomShortcutSet(CommonShortcuts.getDuplicate(), myCheckboxTree, myCheckboxTree);
|
||||
return button;
|
||||
}
|
||||
|
||||
private void resetDescriptionPanel() {
|
||||
if (null != myCheckboxTree && null != myInnerPostfixDescriptionPanel) {
|
||||
myInnerPostfixDescriptionPanel.reset(PostfixTemplateMetaData.createMetaData(myCheckboxTree.getSelectedTemplate()));
|
||||
|
||||
Reference in New Issue
Block a user