diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/codeInsight/template/impl')
4 files changed, 36 insertions, 61 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; |