diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SaveFileAsTemplateAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SaveFileAsTemplateAction.java index 974c15e61efe..f0d99a3a2976 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SaveFileAsTemplateAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SaveFileAsTemplateAction.java @@ -21,23 +21,25 @@ import com.intellij.ide.fileTemplates.ui.ConfigureTemplatesDialog; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; +import static com.intellij.util.ObjectUtils.assertNotNull; + public class SaveFileAsTemplateAction extends AnAction{ @Override public void actionPerformed(AnActionEvent e){ Project project = e.getData(CommonDataKeys.PROJECT); - String fileText = e.getData(PlatformDataKeys.FILE_TEXT); - VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); - String extension = file.getExtension(); + String fileText = assertNotNull(e.getData(PlatformDataKeys.FILE_TEXT)); + VirtualFile file = assertNotNull(e.getData(CommonDataKeys.VIRTUAL_FILE)); + String extension = assertNotNull(file.getExtension()); String nameWithoutExtension = file.getNameWithoutExtension(); AllFileTemplatesConfigurable fileTemplateOptions = new AllFileTemplatesConfigurable(); ConfigureTemplatesDialog dialog = new ConfigureTemplatesDialog(project, fileTemplateOptions); + fileTemplateOptions.selectTemplatesTab(); PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE); for(SaveFileAsTemplateHandler handler: Extensions.getExtensions(SaveFileAsTemplateHandler.EP_NAME)) { String textFromHandler = handler.getTemplateText(psiFile, fileText, nameWithoutExtension); @@ -54,6 +56,6 @@ public class SaveFileAsTemplateAction extends AnAction{ public void update(AnActionEvent e) { VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE); String fileText = e.getData(PlatformDataKeys.FILE_TEXT); - e.getPresentation().setEnabled((fileText != null) && (file != null)); + e.getPresentation().setEnabled(fileText != null && file != null && file.getExtension() != null); } } diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/AllFileTemplatesConfigurable.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/AllFileTemplatesConfigurable.java index 6ef0f909450e..925183c4a5ce 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/AllFileTemplatesConfigurable.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/AllFileTemplatesConfigurable.java @@ -570,28 +570,37 @@ public class AllFileTemplatesConfigurable implements SearchableConfigurable, Con } } + public void selectTemplatesTab() { + selectTab(TEMPLATES_TITLE); + } + + private boolean selectTab(String tabName) { + int idx = 0; + for (FileTemplateTab tab : myTabs) { + if (Comparing.strEqual(tab.getTitle(), tabName)) { + myCurrentTab = tab; + myTabbedPane.setSelectedIndex(idx); + return true; + } + idx++; + } + return false; + } + @Override public void reset() { myEditor.reset(); initLists(); final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(); final String tabName = propertiesComponent.getValue(CURRENT_TAB); - int idx = 0; - for (FileTemplateTab tab : myTabs) { - if (Comparing.strEqual(tab.getTitle(), tabName)) { - myCurrentTab = tab; - myTabbedPane.setSelectedIndex(idx); - final String selectedTemplateName = propertiesComponent.getValue(SELECTED_TEMPLATE); - final FileTemplate[] templates = myCurrentTab.getTemplates(); - for (FileTemplate template : templates) { - if (Comparing.strEqual(template.getName(), selectedTemplateName)) { - tab.selectTemplate(template); - break; - } + if (selectTab(tabName)) { + final String selectedTemplateName = propertiesComponent.getValue(SELECTED_TEMPLATE); + for (FileTemplate template : myCurrentTab.getTemplates()) { + if (Comparing.strEqual(template.getName(), selectedTemplateName)) { + myCurrentTab.selectTemplate(template); + break; } - break; } - idx++; } myModified = false; }