diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/codeInsight/template')
5 files changed, 38 insertions, 23 deletions
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/actions/NextVariableAction.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/actions/NextVariableAction.java index 6605dacbc209..102626785a24 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/actions/NextVariableAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/actions/NextVariableAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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,11 +28,13 @@ import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class NextVariableAction extends EditorAction { public NextVariableAction() { @@ -42,16 +44,17 @@ public class NextVariableAction extends EditorAction { private static class Handler extends EditorWriteActionHandler { @Override - public void executeWriteAction(Editor editor, DataContext dataContext) { + public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) { TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); + assert templateState != null; CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("template.next.variable.command")); templateState.nextTab(); } - } - @Override - public void update(Editor editor, Presentation presentation, DataContext dataContext) { - TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); - presentation.setEnabled(templateState != null && !templateState.isFinished() && templateState.isToProcessTab()); + @Override + protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { + TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); + return templateState != null && !templateState.isFinished() && templateState.isToProcessTab(); + } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/actions/PreviousVariableAction.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/actions/PreviousVariableAction.java index bbb1f6a2bdf7..04a19bdd9b65 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/actions/PreviousVariableAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/actions/PreviousVariableAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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,11 +28,12 @@ import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; +import org.jetbrains.annotations.NotNull; public class PreviousVariableAction extends EditorAction { public PreviousVariableAction() { @@ -42,16 +43,17 @@ public class PreviousVariableAction extends EditorAction { private static class Handler extends EditorWriteActionHandler { @Override - public void executeWriteAction(Editor editor, DataContext dataContext) { + public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); + assert templateState != null; CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("template.previous.variable.command")); templateState.previousTab(); } - } - @Override - public void update(Editor editor, Presentation presentation, DataContext dataContext) { - final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); - presentation.setEnabled(templateState != null && !templateState.isFinished()); + @Override + protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { + final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); + return templateState != null && !templateState.isFinished(); + } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EnterHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EnterHandler.java index d071b24416b3..de503d125f30 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EnterHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/EnterHandler.java @@ -26,6 +26,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; +import org.jetbrains.annotations.NotNull; public class EnterHandler extends BaseEnterHandler { private final EditorActionHandler myOriginalHandler; @@ -36,8 +37,8 @@ public class EnterHandler extends BaseEnterHandler { } @Override - public boolean isEnabled(Editor editor, DataContext dataContext) { - return myOriginalHandler.isEnabled(editor, dataContext); + public boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { + return myOriginalHandler.isEnabled(editor, caret, dataContext); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/ExpandLiveTemplateByTabAction.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/ExpandLiveTemplateByTabAction.java index 13798639227f..326daba46e1e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/ExpandLiveTemplateByTabAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/editorActions/ExpandLiveTemplateByTabAction.java @@ -19,11 +19,13 @@ import com.intellij.codeInsight.template.TemplateManager; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateSettings; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.actionSystem.EditorAction; import com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; +import org.jetbrains.annotations.Nullable; /** * @author peter @@ -32,7 +34,7 @@ public class ExpandLiveTemplateByTabAction extends EditorAction { public ExpandLiveTemplateByTabAction() { super(new EditorWriteActionHandler(true) { @Override - public void executeWriteAction(Editor editor, DataContext dataContext) { + public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) { Project project = editor.getProject(); assert project != null; PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesCheckboxTree.java b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesCheckboxTree.java index b6a507ec67a2..68d5e7417d2a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesCheckboxTree.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/postfix/settings/PostfixTemplatesCheckboxTree.java @@ -17,6 +17,7 @@ package com.intellij.codeInsight.template.postfix.settings; import com.intellij.codeInsight.template.postfix.templates.PostfixTemplate; import com.intellij.ide.util.treeView.TreeState; +import com.intellij.lang.Language; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.CheckboxTree; import com.intellij.ui.CheckedTreeNode; @@ -35,7 +36,10 @@ import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.awt.*; -import java.util.*; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Map; +import java.util.Set; public class PostfixTemplatesCheckboxTree extends CheckboxTree { @@ -102,7 +106,7 @@ public class PostfixTemplatesCheckboxTree extends CheckboxTree { getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override - public void valueChanged(TreeSelectionEvent event) { + public void valueChanged(@NotNull TreeSelectionEvent event) { selectionChanged(); } }); @@ -117,10 +121,13 @@ public class PostfixTemplatesCheckboxTree extends CheckboxTree { public void initTree(@NotNull MultiMap<String, PostfixTemplate> langToTemplates) { myRoot.removeAllChildren(); for (Map.Entry<String, Collection<PostfixTemplate>> entry : langToTemplates.entrySet()) { - CheckedTreeNode langNode = new CheckedTreeNode(entry.getKey()); + String id = entry.getKey(); + Language language = Language.findLanguageByID(id); + String langName = language != null ? language.getDisplayName() : id; + CheckedTreeNode langNode = new CheckedTreeNode(langName); myRoot.add(langNode); for (PostfixTemplate template : entry.getValue()) { - CheckedTreeNode templateNode = new PostfixTemplateCheckedTreeNode(template, entry.getKey()); + CheckedTreeNode templateNode = new PostfixTemplateCheckedTreeNode(template, langName); langNode.add(templateNode); } } |