IDEA-57301: jsp: extract tag: support "introduce parameter" inside tag files
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Tue, 17 Aug 2010 09:38:50 +0000 (13:38 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Tue, 17 Aug 2010 09:44:48 +0000 (13:44 +0400)
java/jsp-base-openapi/src/com/intellij/psi/jsp/JspDirectiveKind.java
platform/lang-impl/src/com/intellij/codeInsight/template/TemplateManager.java
platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditTemplateDialog.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java

index 8699ddca9a0bb6b09e6bb7d3ad028481fb514aee..9a6a53966be9098b0facc1e2ae7a3cd0b181648f 100644 (file)
@@ -24,6 +24,5 @@ public enum JspDirectiveKind {
   INCLUDE,
   TAGLIB,
   ATTRIBUTE,
-  VARIABLE,
-  PARAMETER
+  VARIABLE
 }
index 8caeba8c6095c22c9412d377071ff8984fdb7b1f..7a73098179c401cbf2d499bbdf5604966e0f55fd 100644 (file)
@@ -41,7 +41,7 @@ public abstract class TemplateManager {
                                      @NotNull final Template template,
                                      boolean inSeparateCommand,
                                      Map<String, String> predefinedVarValues,
-                                     TemplateEditingListener listener);
+                                     @Nullable TemplateEditingListener listener);
 
   public abstract void startTemplate(@NotNull Editor editor,
                                      @NotNull Template template,
index ffccbbb8c73024a2733e842b7460dc69b1f257d2..ed9c81274c3bc86060a67bb4105f4472e8e0b16c 100644 (file)
@@ -46,12 +46,11 @@ import com.intellij.psi.*;
 import com.intellij.psi.util.PsiElementFilter;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.util.containers.HashMap;
-import org.jetbrains.annotations.NonNls;
 
+import javax.swing.*;
 import java.util.Map;
 
 public class SaveAsTemplateAction extends AnAction {
-  public static final @NonNls String JAVA_LANG_PACKAGE_PREFIX = "java.lang";
 
   public void actionPerformed(AnActionEvent e) {
     DataContext dataContext = e.getDataContext();
@@ -120,6 +119,13 @@ public class SaveAsTemplateAction extends AnAction {
       template.getTemplateContext().setEnabled(contextType, contextType.isInContext(fileType));
     }
 
+    if (editTemplate(template, editor.getComponent(), true)) return;
+    templateSettings.addTemplate(template);
+  }
+
+  public static boolean editTemplate(TemplateImpl template, JComponent component, final boolean newTemplate) {
+
+    TemplateSettings templateSettings = TemplateSettings.getInstance();
     String defaultShortcut = "";
     if (templateSettings.getDefaultShortcutChar() == TemplateSettings.ENTER_CHAR) {
       defaultShortcut = CodeInsightBundle.message("template.shortcut.enter");
@@ -135,20 +141,20 @@ public class SaveAsTemplateAction extends AnAction {
     Map<TemplateContextType, Boolean> context = template.createContext();
 
     EditTemplateDialog dialog = new EditTemplateDialog(
-      editor.getComponent(),
+      component,
       CodeInsightBundle.message("dialog.edit.live.template.title"),
       template,
       templateSettings.getTemplateGroups(),
-      defaultShortcut, options, context);
+      defaultShortcut, options, context, newTemplate);
     dialog.show();
     if (!dialog.isOK()) {
-      return;
+      return true;
     }
     dialog.apply();
     template.applyOptions(options);
     template.applyContext(context);
-    templateSettings.addTemplate(template);
     templateSettings.setLastSelectedTemplateKey(template.getKey());
+    return false;
   }
 
   public void update(AnActionEvent e) {
index 34a2449309d462175c673ed62ecd4685e064d588..229b5e0f33dcc0dc636ddfb0a8724830514e3d1a 100644 (file)
@@ -33,6 +33,7 @@ import com.intellij.openapi.ui.ComboBox;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.ui.IdeBorderFactory;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import javax.swing.event.ChangeEvent;
@@ -67,12 +68,16 @@ public class EditTemplateDialog extends DialogWrapper {
   private static final String ENTER = CodeInsightBundle.message("template.shortcut.enter");
   private final Map<TemplateOptionalProcessor, Boolean> myOptions;
   private final Map<TemplateContextType, Boolean> myContext;
+  private final boolean myNewTemplate;
 
   public EditTemplateDialog(Component parent, String title, TemplateImpl template, List<TemplateGroup> groups, String defaultShortcut,
-                            Map<TemplateOptionalProcessor, Boolean> options, Map<TemplateContextType, Boolean> context) {
+                            Map<TemplateOptionalProcessor, Boolean> options,
+                            Map<TemplateContextType, Boolean> context,
+                            boolean newTemplate) {
     super(parent, true);
     myOptions = options;
     myContext = context;
+    myNewTemplate = newTemplate;
     setOKButtonText(CommonBundle.getOkButtonText());
     setTitle(title);
 
@@ -137,13 +142,17 @@ public class EditTemplateDialog extends DialogWrapper {
     myEditVariablesButton.setMaximumSize(myEditVariablesButton.getPreferredSize());
     panel.add(myEditVariablesButton, gbConstraints);
 
-    gbConstraints.weighty = 0;
-    gbConstraints.gridwidth = 1;
-    gbConstraints.gridy++;
-    panel.add(createTemplateOptionsPanel(), gbConstraints);
+    JPanel templateOptionsPanel = createTemplateOptionsPanel();
+    JPanel contextPanel = createContextPanel();
+    if (myNewTemplate) {
+      gbConstraints.weighty = 0;
+      gbConstraints.gridwidth = 1;
+      gbConstraints.gridy++;
+      panel.add(templateOptionsPanel, gbConstraints);
 
-    gbConstraints.gridx = 1;
-    panel.add(createContextPanel(), gbConstraints);
+      gbConstraints.gridx = 1;
+      panel.add(contextPanel, gbConstraints);
+    }
 
     myKeyField.getDocument().addDocumentListener(new com.intellij.ui.DocumentAdapter() {
       protected void textChanged(javax.swing.event.DocumentEvent e) {
@@ -170,7 +179,11 @@ public class EditTemplateDialog extends DialogWrapper {
     return panel;
   }
 
+  @Nullable
   protected JComponent createNorthPanel() {
+    if (!myNewTemplate) {
+      return null;
+    }
     JPanel panel = new JPanel(new GridBagLayout());
     GridBagConstraints gbConstraints = new GridBagConstraints();
     gbConstraints.insets = new Insets(4,4,4,4);
index e212476b5c043f3cd4a5eece0e5c4f57265509b4..e5781ea9ed0bcd64b8de3607553a9d11ff598094 100644 (file)
@@ -452,7 +452,7 @@ class TemplateListPanel extends JPanel {
     String oldGroupName = template.getGroupName();
 
     EditTemplateDialog dialog = new EditTemplateDialog(this, CodeInsightBundle.message("dialog.edit.live.template.title"), template, getTemplateGroups(),
-                                                       (String)myExpandByCombo.getSelectedItem(), getOptions(template), getContext(template));
+                                                       (String)myExpandByCombo.getSelectedItem(), getOptions(template), getContext(template), true);
     dialog.show();
     if (!dialog.isOK()) return;
 
@@ -536,7 +536,7 @@ class TemplateListPanel extends JPanel {
     myTemplateOptions.put(getKey(template), template.createOptions());
     myTemplateContext.put(getKey(template), template.createContext());
     EditTemplateDialog dialog = new EditTemplateDialog(this, CodeInsightBundle.message("dialog.add.live.template.title"), template, getTemplateGroups(),
-                                                       (String)myExpandByCombo.getSelectedItem(), getOptions(template), getContext(template));
+                                                       (String)myExpandByCombo.getSelectedItem(), getOptions(template), getContext(template), true);
     dialog.show();
     if (!dialog.isOK()) return;
     dialog.apply();
@@ -558,7 +558,7 @@ class TemplateListPanel extends JPanel {
     myTemplateOptions.put(getKey(template), getOptions(orTemplate));
     myTemplateContext.put(getKey(template), getContext(orTemplate));
     EditTemplateDialog dialog = new EditTemplateDialog(this, CodeInsightBundle.message("dialog.copy.live.template.title"), template, getTemplateGroups(),
-                                                       (String)myExpandByCombo.getSelectedItem(), getOptions(template), getContext(template));
+                                                       (String)myExpandByCombo.getSelectedItem(), getOptions(template), getContext(template), true);
     dialog.show();
     if (!dialog.isOK()) return;