Java Code Examples for com.intellij.ide.fileTemplates.FileTemplate#isLiveTemplateEnabled()

The following examples show how to use com.intellij.ide.fileTemplates.FileTemplate#isLiveTemplateEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileReferenceQuickFixProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void openFile(@Nonnull Project project, PsiDirectory directory, PsiFile newFile, String text) {
  super.openFile(project, directory, newFile, text);
  if (!isDirectory && myNewFileTemplateName != null) {
    FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
    FileTemplate template = findTemplate(fileTemplateManager);

    if (template != null && template.isLiveTemplateEnabled()) {
      CreateFromTemplateActionBase.startLiveTemplate(newFile);
    }
  }
}
 
Example 2
Source File: CreateFromTemplateActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public final void actionPerformed(@Nonnull AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  IdeView view = dataContext.getData(LangDataKeys.IDE_VIEW);
  if (view == null) return;
  PsiDirectory dir = getTargetDirectory(dataContext, view);
  if (dir == null) return;
  Project project = dir.getProject();

  FileTemplate selectedTemplate = getTemplate(project, dir);
  if (selectedTemplate != null) {
    AnAction action = getReplacedAction(selectedTemplate);
    if (action != null) {
      action.actionPerformed(e);
    }
    else {
      FileTemplateManager.getInstance(project).addRecentName(selectedTemplate.getName());
      AttributesDefaults defaults = getAttributesDefaults(dataContext);
      Map<String, Object> properties = defaults != null ? defaults.getDefaultProperties() : null;
      CreateFromTemplateDialog dialog = new CreateFromTemplateDialog(dir, selectedTemplate, defaults, properties);
      PsiElement createdElement = dialog.create();
      if (createdElement != null) {
        elementCreated(dialog, createdElement);
        view.selectElement(createdElement);
        if (selectedTemplate.isLiveTemplateEnabled() && createdElement instanceof PsiFile) {
          Map<String, String> defaultValues = getLiveTemplateDefaults(dataContext, ((PsiFile)createdElement));
          startLiveTemplate((PsiFile)createdElement, notNull(defaultValues, Collections.emptyMap()));
        }
      }
    }
  }
}