use of com.intellij.codeInsight.template.impl.TemplateManagerImpl in project intellij-community by JetBrains.
the class CodeInsightTestUtil method doInlineRename.
@TestOnly
public static void doInlineRename(VariableInplaceRenameHandler handler, final String newName, @NotNull Editor editor, PsiElement elementAtCaret) {
Project project = editor.getProject();
TemplateManagerImpl templateManager = (TemplateManagerImpl) TemplateManager.getInstance(project);
try {
templateManager.setTemplateTesting(true);
handler.doRename(elementAtCaret, editor, DataManager.getInstance().getDataContext(editor.getComponent()));
if (editor instanceof EditorWindow) {
editor = ((EditorWindow) editor).getDelegate();
}
TemplateState state = TemplateManagerImpl.getTemplateState(editor);
assert state != null;
final TextRange range = state.getCurrentVariableRange();
assert range != null;
final Editor finalEditor = editor;
new WriteCommandAction.Simple(project) {
@Override
protected void run() throws Throwable {
finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName);
}
}.execute().throwException();
state = TemplateManagerImpl.getTemplateState(editor);
assert state != null;
state.gotoEnd(false);
} finally {
templateManager.setTemplateTesting(false);
}
}
use of com.intellij.codeInsight.template.impl.TemplateManagerImpl in project intellij-community by JetBrains.
the class ExpandLiveTemplateCustomAction method createExpandTemplateHandler.
public static EditorWriteActionHandler createExpandTemplateHandler(final char shortcutChar) {
return new EditorWriteActionHandler(true) {
@Override
public void executeWriteAction(Editor editor, @Nullable Caret caret, DataContext dataContext) {
Project project = editor.getProject();
assert project != null;
TemplateManager.getInstance(project).startTemplate(editor, shortcutChar);
}
@Override
protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) {
Project project = editor.getProject();
return project != null && ((TemplateManagerImpl) TemplateManager.getInstance(project)).prepareTemplate(editor, shortcutChar, null) != null;
}
};
}
Aggregations