diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java index 2a4594ed7550..134143df4782 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java @@ -30,6 +30,7 @@ import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupAdapter; import com.intellij.openapi.ui.popup.JBPopupFactory; @@ -232,7 +233,7 @@ public class LiveTemplateSettingsEditor extends JPanel { gbConstraints.gridx = 1; gbConstraints.insets = new Insets(0, 4, 0, 0); - myExpandByCombo = new JComboBox(new Object[]{myDefaultShortcutItem, SPACE, TAB, ENTER}); + myExpandByCombo = new ComboBox(new Object[]{myDefaultShortcutItem, SPACE, TAB, ENTER}, -1); myExpandByCombo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { @@ -309,6 +310,9 @@ public class LiveTemplateSettingsEditor extends JPanel { final Runnable updateLabel = new Runnable() { @Override public void run() { + myExpandByCombo.setEnabled(isExpandableFromEditor()); + updateHighlighter(); + StringBuilder sb = new StringBuilder(); String oldPrefix = ""; for (TemplateContextType type : getApplicableContexts()) { @@ -343,7 +347,7 @@ public class LiveTemplateSettingsEditor extends JPanel { public boolean onClick(MouseEvent e, int clickCount) { if (disposeContextPopup()) return false; - final JPanel content = createPopupContextPanel(updateLabel); + final JPanel content = createPopupContextPanel(updateLabel, myContext); Dimension prefSize = content.getPreferredSize(); if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) { content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height))); @@ -374,7 +378,7 @@ public class LiveTemplateSettingsEditor extends JPanel { return false; } - private JPanel createPopupContextPanel(final Runnable onChange) { + static JPanel createPopupContextPanel(final Runnable onChange, final Map context) { JPanel panel = new JPanel(new BorderLayout()); MultiMap hierarchy = new MultiMap() { @@ -383,7 +387,7 @@ public class LiveTemplateSettingsEditor extends JPanel { return new LinkedHashMap>(); } }; - for (TemplateContextType type : myContext.keySet()) { + for (TemplateContextType type : context.keySet()) { hierarchy.putValue(type.getBaseContextType(), type); } @@ -401,17 +405,15 @@ public class LiveTemplateSettingsEditor extends JPanel { protected void onNodeStateChanged(CheckedTreeNode node) { final TemplateContextType type = (TemplateContextType)((Pair)node.getUserObject()).first; if (type != null) { - myContext.put(type, node.isChecked()); + context.put(type, node.isChecked()); } - myExpandByCombo.setEnabled(isExpandableFromEditor()); - updateHighlighter(); onChange.run(); } }; for (TemplateContextType type : hierarchy.get(null)) { - addContextNode(hierarchy, root, type); + addContextNode(hierarchy, root, type, context); } ((DefaultTreeModel)checkboxTree.getModel()).nodeStructureChanged(root); @@ -434,23 +436,23 @@ public class LiveTemplateSettingsEditor extends JPanel { return panel; } - private void addContextNode(MultiMap hierarchy, - CheckedTreeNode parent, - TemplateContextType type) { + private static void addContextNode(MultiMap hierarchy, + CheckedTreeNode parent, + TemplateContextType type, Map context) { final Collection children = hierarchy.get(type); final String name = UIUtil.removeMnemonic(type.getPresentableName()); final CheckedTreeNode node = new CheckedTreeNode(Pair.create(children.isEmpty() ? type : null, name)); parent.add(node); if (children.isEmpty()) { - node.setChecked(myContext.get(type)); + node.setChecked(context.get(type)); } else { for (TemplateContextType child : children) { - addContextNode(hierarchy, node, child); + addContextNode(hierarchy, node, child, context); } final CheckedTreeNode other = new CheckedTreeNode(Pair.create(type, "Other")); - other.setChecked(myContext.get(type)); + other.setChecked(context.get(type)); node.add(other); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java index 19033d975977..76a423a50444 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java @@ -30,12 +30,11 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SchemesManager; import com.intellij.openapi.project.DumbAwareAction; -import com.intellij.openapi.ui.InputValidator; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.ui.Splitter; +import com.intellij.openapi.ui.*; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.EmptyRunnable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.*; import com.intellij.util.Alarm; @@ -848,12 +847,43 @@ public class TemplateListPanel extends JPanel implements Disposable { } }; + final DumbAwareAction changeContext = new DumbAwareAction("Change context...") { + + @Override + public void update(AnActionEvent e) { + boolean enabled = !getSelectedTemplates().isEmpty(); + e.getPresentation().setEnabled(enabled); + super.update(e); + } + + @Override + public void actionPerformed(AnActionEvent e) { + Map templates = getSelectedTemplates(); + Map context = ContainerUtil.newHashMap(); + for (TemplateContextType type : TemplateManagerImpl.getAllContextTypes()) { + context.put(type, Boolean.FALSE); + } + JPanel contextPanel = LiveTemplateSettingsEditor.createPopupContextPanel(EmptyRunnable.INSTANCE, context); + DialogBuilder builder = new DialogBuilder(TemplateListPanel.this); + builder.setCenterPanel(contextPanel); + builder.setTitle("Change Context Type For Selected Templates"); + int result = builder.show(); + if (result == DialogWrapper.OK_EXIT_CODE) { + for (TemplateImpl template : templates.keySet()) { + getTemplateContext(template).putAll(context); + } + } + } + }; + + myTree.addMouseListener(new PopupHandler() { @Override public void invokePopup(Component comp, int x, int y) { final DefaultActionGroup group = new DefaultActionGroup(); group.add(rename); group.add(move); + group.add(changeContext); ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, group).getComponent().show(comp, x, y); } });