prettier template context presentation in settings

This commit is contained in:
peter
2011-09-06 09:03:41 +02:00
parent 736daa2cd7
commit 08c60e59ee
5 changed files with 32 additions and 16 deletions
@@ -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
@@ -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) {
@@ -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) {
@@ -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<String> contexts = new ArrayList<String>();
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");
}
};
@@ -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