From 08c60e59ee7f10dde64d4e0422c162a56af9acaa Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 5 Sep 2011 20:40:22 +0200 Subject: [PATCH] prettier template context presentation in settings --- .../template/JavaCodeContextType.java | 8 ++--- .../template/JavaCommentContextType.java | 3 +- .../template/JavaStringContextType.java | 2 +- .../impl/LiveTemplateSettingsEditor.java | 32 +++++++++++++++---- .../src/messages/CodeInsightBundle.properties | 3 -- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java b/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java index 4dddf67e39bb..d5aac60c111b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/JavaCodeContextType.java @@ -78,7 +78,7 @@ public abstract class JavaCodeContextType extends TemplateContextType { public static class Generic extends JavaCodeContextType { public Generic() { - super("JAVA_CODE", CodeInsightBundle.message("dialog.edit.template.checkbox.java.code"), EverywhereContextType.class); + super("JAVA_CODE", "Java", EverywhereContextType.class); } @Override @@ -89,7 +89,7 @@ public abstract class JavaCodeContextType extends TemplateContextType { public static class Statement extends JavaCodeContextType { public Statement() { - super("JAVA_STATEMENT", "Statement", JavaCodeContextType.class); + super("JAVA_STATEMENT", "Statement", Generic.class); } @Override @@ -103,7 +103,7 @@ public abstract class JavaCodeContextType extends TemplateContextType { } public static class Expression extends JavaCodeContextType { public Expression() { - super("JAVA_EXPRESSION", "Expression", JavaCodeContextType.class); + super("JAVA_EXPRESSION", "Expression", Generic.class); } @Override @@ -135,7 +135,7 @@ public abstract class JavaCodeContextType extends TemplateContextType { } public static class Declaration extends JavaCodeContextType { public Declaration() { - super("JAVA_DECLARATION", "Declaration", JavaCodeContextType.class); + super("JAVA_DECLARATION", "Declaration", Generic.class); } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/template/JavaCommentContextType.java b/java/java-impl/src/com/intellij/codeInsight/template/JavaCommentContextType.java index c29ed5258f04..149bc6caa0c8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/JavaCommentContextType.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/JavaCommentContextType.java @@ -22,7 +22,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.codeInsight.CodeInsightBundle; import org.jetbrains.annotations.NotNull; /** @@ -30,7 +29,7 @@ import org.jetbrains.annotations.NotNull; */ public class JavaCommentContextType extends TemplateContextType { public JavaCommentContextType() { - super("JAVA_COMMENT", CodeInsightBundle.message("dialog.edit.template.checkbox.java.comment"), JavaCodeContextType.class); + super("JAVA_COMMENT", "Comment", JavaCodeContextType.Generic.class); } public boolean isInContext(@NotNull final PsiFile file, final int offset) { diff --git a/java/java-impl/src/com/intellij/codeInsight/template/JavaStringContextType.java b/java/java-impl/src/com/intellij/codeInsight/template/JavaStringContextType.java index 319991028b79..3dfeeee560cc 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/JavaStringContextType.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/JavaStringContextType.java @@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull; */ public class JavaStringContextType extends TemplateContextType { public JavaStringContextType() { - super("JAVA_STRING", CodeInsightBundle.message("dialog.edit.template.checkbox.java.string"), JavaCodeContextType.class); + super("JAVA_STRING", "String", JavaCodeContextType.Generic.class); } public boolean isInContext(@NotNull final PsiFile file, final int offset) { 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 8fbfa58f937b..6f5385ad98d9 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 @@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.impl; import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.template.EverywhereContextType; import com.intellij.codeInsight.template.TemplateContextType; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; @@ -32,7 +33,10 @@ import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.IdeFocusManager; -import com.intellij.ui.*; +import com.intellij.ui.CheckboxTree; +import com.intellij.ui.CheckedTreeNode; +import com.intellij.ui.IdeBorderFactory; +import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -262,15 +266,31 @@ public class LiveTemplateSettingsEditor extends JPanel { final Runnable updateLabel = new Runnable() { public void run() { - List contexts = new ArrayList(); + StringBuilder sb = new StringBuilder(); + String oldPrefix = ""; for (TemplateContextType type : myContext.keySet()) { if (myContext.get(type).booleanValue()) { - contexts.add(UIUtil.removeMnemonic(type.getPresentableName())); + final TemplateContextType base = type.getBaseContextType(); + String ownName = UIUtil.removeMnemonic(type.getPresentableName()); + String prefix = ""; + if (base != null && !(base instanceof EverywhereContextType)) { + prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": "; + ownName = StringUtil.decapitalize(ownName); + } + if (sb.length() > 0) { + sb.append(oldPrefix.equals(prefix) ? ", " : "; "); + } + if (!oldPrefix.equals(prefix)) { + sb.append(prefix); + oldPrefix = prefix; + } + sb.append(ownName); } } - ctxLabel.setText((contexts.isEmpty() ? "No applicable contexts yet" : "Applicable in " + StringUtil.join(contexts, ", ")) + ". "); - ctxLabel.setForeground(contexts.isEmpty() ? Color.RED : UIUtil.getLabelForeground()); - change.setText(contexts.isEmpty() ? "Define" : "Change"); + final boolean noContexts = sb.length() == 0; + ctxLabel.setText((noContexts ? "No applicable contexts yet" : "Applicable in " + sb.toString()) + ". "); + ctxLabel.setForeground(noContexts ? Color.GRAY : UIUtil.getLabelForeground()); + change.setText(noContexts ? "Define" : "Change"); } }; diff --git a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties index 0f31ad894ba4..9267f4cc55a8 100644 --- a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties +++ b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties @@ -294,11 +294,8 @@ dialog.edit.template.checkbox.reformat.according.to.style=&Reformat according to dialog.edit.template.checkbox.shorten.fq.names=Shorten &FQ names dialog.edit.template.checkbox.use.static.import=Use static import if possible dialog.edit.template.context.title=Context -dialog.edit.template.checkbox.java.code=&Java code dialog.edit.template.checkbox.html=&HTML -dialog.edit.template.checkbox.java.comment=Java &comment dialog.edit.template.checkbox.xml=&XML -dialog.edit.template.checkbox.java.string=Java &string dialog.edit.template.checkbox.jsp=JS&P dialog.edit.template.checkbox.smart.type.completion=Smart type c&ompletion dialog.edit.template.error.title=Cannot Save