diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/codeInsight/template')
6 files changed, 53 insertions, 66 deletions
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateLookupElementImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateLookupElementImpl.java index 9ce023727820..2ddf92cfe1ff 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateLookupElementImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateLookupElementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ public class LiveTemplateLookupElementImpl extends LiveTemplateLookupElement { private final TemplateImpl myTemplate; public LiveTemplateLookupElementImpl(@NotNull TemplateImpl template, boolean sudden) { - super(template.getKey(), StringUtil.notNullize(template.getDescription()), sudden, false); + super(template.getKey(), StringUtil.notNullize(template.getDescription()), sudden, LiveTemplateCompletionContributor.shouldShowAllTemplates()); myTemplate = template; } 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 1988c9d1d8a4..c14eca966e5f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,6 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; 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; @@ -52,7 +51,6 @@ import com.intellij.util.ui.tree.TreeUtil; import com.intellij.util.ui.update.Activatable; import com.intellij.util.ui.update.UiNotifyConnector; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; @@ -182,7 +180,7 @@ public class LiveTemplateSettingsEditor extends JPanel { myEditVariablesButton.addActionListener( new ActionListener(){ @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { editVariables(); } } @@ -201,7 +199,7 @@ public class LiveTemplateSettingsEditor extends JPanel { myTemplate.parseSegments(); } - @Nullable + @NotNull private JComponent createNorthPanel() { JPanel panel = new JPanel(new GridBagLayout()); @@ -240,7 +238,7 @@ public class LiveTemplateSettingsEditor extends JPanel { myExpandByCombo = new ComboBox(new String[]{myDefaultShortcutItem, SPACE, TAB, ENTER}); myExpandByCombo.addItemListener(new ItemListener() { @Override - public void itemStateChanged(ItemEvent e) { + public void itemStateChanged(@NotNull ItemEvent e) { Object selectedItem = myExpandByCombo.getSelectedItem(); if(myDefaultShortcutItem.equals(selectedItem)) { myTemplate.setShortcutChar(TemplateSettings.DEFAULT_CHAR); @@ -278,7 +276,7 @@ public class LiveTemplateSettingsEditor extends JPanel { cb.setSelected(myOptions.get(processor).booleanValue()); cb.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { myOptions.put(processor, cb.isSelected()); } }); @@ -469,14 +467,7 @@ public class LiveTemplateSettingsEditor extends JPanel { } private void updateHighlighter() { - List<TemplateContextType> applicableContexts = getApplicableContexts(); - if (!applicableContexts.isEmpty()) { - TemplateContext contextByType = new TemplateContext(); - contextByType.setEnabled(applicableContexts.get(0), true); - TemplateEditorUtil.setHighlighter(myTemplateEditor, contextByType); - return; - } - ((EditorEx) myTemplateEditor).repaint(0, myTemplateEditor.getDocument().getTextLength()); + TemplateEditorUtil.setHighlighter(myTemplateEditor, ContainerUtil.getFirstItem(getApplicableContexts())); } private void validateEditVariablesButton() { @@ -520,7 +511,7 @@ public class LiveTemplateSettingsEditor extends JPanel { myCbReformat.setSelected(myTemplate.isToReformat()); myCbReformat.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { + public void actionPerformed(@NotNull ActionEvent e) { myTemplate.setToReformat(myCbReformat.isSelected()); } }); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java index 1570bb18c040..dd30df23a493 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateEditorUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package com.intellij.codeInsight.template.impl; import com.intellij.codeInsight.template.TemplateContextType; import com.intellij.ide.DataManager; -import com.intellij.lexer.CompositeLexer; import com.intellij.lexer.Lexer; import com.intellij.lexer.MergingLexerAdapter; import com.intellij.openapi.actionSystem.CommonDataKeys; @@ -31,7 +30,8 @@ import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; +import com.intellij.openapi.editor.ex.util.LayerDescriptor; +import com.intellij.openapi.editor.ex.util.LayeredLexerEditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -42,6 +42,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; +import com.intellij.util.ObjectUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -87,54 +88,41 @@ public class TemplateEditorUtil { if (file != null) { EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project); ((EditorEx) editor).setHighlighter(highlighter); + } return editor; } - public static void setHighlighter(Editor editor, TemplateContext templateContext) { - SyntaxHighlighter baseHighlighter = null; - for(TemplateContextType type: TemplateManagerImpl.getAllContextTypes()) { - if (templateContext.isEnabled(type)) { - baseHighlighter = type.createHighlighter(); - if (baseHighlighter != null) break; + public static void setHighlighter(Editor editor, @Nullable TemplateContext templateContext) { + SyntaxHighlighter highlighter = null; + if (templateContext != null) { + for(TemplateContextType type: TemplateManagerImpl.getAllContextTypes()) { + if (templateContext.isEnabled(type)) { + highlighter = type.createHighlighter(); + if (highlighter != null) break; + } } } - if (baseHighlighter == null) { - baseHighlighter = new PlainSyntaxHighlighter(); - } - - SyntaxHighlighter highlighter = createTemplateTextHighlighter(baseHighlighter); - ((EditorEx)editor).setHighlighter(new LexerEditorHighlighter(highlighter, EditorColorsManager.getInstance().getGlobalScheme())); + setHighlighter((EditorEx)editor, highlighter); } - private final static TokenSet TOKENS_TO_MERGE = TokenSet.create(TemplateTokenType.TEXT); + public static void setHighlighter(@NotNull Editor editor, @Nullable TemplateContextType templateContextType) { + setHighlighter((EditorEx)editor, templateContextType != null ? templateContextType.createHighlighter() : null); + } - private static SyntaxHighlighter createTemplateTextHighlighter(final SyntaxHighlighter original) { - return new TemplateHighlighter(original); + private static void setHighlighter(EditorEx editor, @Nullable SyntaxHighlighter highlighter) { + EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); + LayeredLexerEditorHighlighter layeredHighlighter = new LayeredLexerEditorHighlighter(new TemplateHighlighter(), editorColorsScheme); + layeredHighlighter.registerLayer(TemplateTokenType.TEXT, new LayerDescriptor(ObjectUtils.notNull(highlighter, new PlainSyntaxHighlighter()), "")); + editor.setHighlighter(layeredHighlighter); } private static class TemplateHighlighter extends SyntaxHighlighterBase { private final Lexer myLexer; - private final SyntaxHighlighter myOriginalHighlighter; - - public TemplateHighlighter(SyntaxHighlighter original) { - myOriginalHighlighter = original; - Lexer originalLexer = original.getHighlightingLexer(); - Lexer templateLexer = new TemplateTextLexer(); - templateLexer = new MergingLexerAdapter(templateLexer, TOKENS_TO_MERGE); - - myLexer = new CompositeLexer(originalLexer, templateLexer) { - @Override - protected IElementType getCompositeTokenType(IElementType type1, IElementType type2) { - if (type2 == TemplateTokenType.VARIABLE) { - return type2; - } - else { - return type1; - } - } - }; + + public TemplateHighlighter() { + myLexer = new MergingLexerAdapter(new TemplateTextLexer(), TokenSet.create(TemplateTokenType.TEXT)); } @Override @@ -146,11 +134,7 @@ public class TemplateEditorUtil { @Override @NotNull public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { - if (tokenType == TemplateTokenType.VARIABLE) { - return pack(myOriginalHighlighter.getTokenHighlights(tokenType), TemplateColors.TEMPLATE_VARIABLE_ATTRIBUTES); - } - - return myOriginalHighlighter.getTokenHighlights(tokenType); + return tokenType == TemplateTokenType.VARIABLE ? pack(TemplateColors.TEMPLATE_VARIABLE_ATTRIBUTES) : EMPTY; } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java index e5f2fd4ae23d..abf28256aaef 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java @@ -105,7 +105,7 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo private int myMaxKeyLength = 0; private char myDefaultShortcutChar = TAB_CHAR; private final SchemesManager<TemplateGroup, TemplateGroup> mySchemesManager; - private static final String FILE_SPEC = "$ROOT_CONFIG$/templates"; + private static final String FILE_SPEC = StoragePathMacros.ROOT_CONFIG + "/templates"; public static class TemplateKey { private String groupName; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.form b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.form index cd60a7de70f4..519481484dc7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.form +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixDescriptionPanel.form @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.codeInsight.template.postfix.settings.PostfixDescriptionPanel"> - <grid id="d0bf1" binding="myPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> + <grid id="d0bf1" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> <xy x="26" y="23" width="498" height="354"/> @@ -19,7 +19,9 @@ <xy id="a6fdd" binding="myAfterPanel" layout-manager="XYLayout" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> - <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> + <minimum-size width="-1" height="125"/> + </grid> </constraints> <properties/> <border type="none"/> @@ -28,7 +30,9 @@ <xy id="fa495" binding="myBeforePanel" layout-manager="XYLayout" hgap="-1" vgap="-1"> <margin top="0" left="0" bottom="0" right="0"/> <constraints> - <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> + <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> + <minimum-size width="-1" height="125"/> + </grid> </constraints> <properties/> <border type="none"/> @@ -77,6 +81,11 @@ </component> </children> </grid> + <vspacer id="53ca7"> + <constraints> + <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> + </constraints> + </vspacer> </children> </grid> </form> diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java index 5cd822130538..0190fadbcf02 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java @@ -22,6 +22,7 @@ import com.intellij.codeInsight.template.impl.CustomLiveTemplateLookupElement; import com.intellij.codeInsight.template.impl.TemplateSettings; import com.intellij.codeInsight.template.postfix.completion.PostfixTemplateLookupElement; import com.intellij.codeInsight.template.postfix.settings.PostfixTemplatesSettings; +import com.intellij.diagnostic.AttachmentFactory; import com.intellij.featureStatistics.FeatureUsageTracker; import com.intellij.lang.Language; import com.intellij.openapi.application.ApplicationManager; @@ -137,7 +138,8 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase { } // don't care about errors in multiCaret mode else if (editor.getCaretModel().getAllCarets().size() == 1) { - LOG.error("Template not found by key: " + key); + LOG.error("Template not found by key: " + key + "; offset = " + callback.getOffset(), + AttachmentFactory.createAttachment(callback.getFile().getVirtualFile())); } return; } @@ -145,7 +147,8 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase { // don't care about errors in multiCaret mode if (editor.getCaretModel().getAllCarets().size() == 1) { - LOG.error("Template not found by key: " + key); + LOG.error("Template not found by key: " + key + "; offset = " + callback.getOffset(), + AttachmentFactory.createAttachment(callback.getFile().getVirtualFile())); } } |