diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/AbstractFileCreationWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/AbstractFileCreationWizardPage.java index e968ea48337..fdd033d5ff8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/AbstractFileCreationWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/AbstractFileCreationWizardPage.java @@ -242,7 +242,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag Template selected= getSelectedTemplate(); String name = selected != null ? selected.getName() : - getLastUsedTemplateName(); + getDefaultTemplateName(); fTemplates= getApplicableTemplates(); int idx= NO_TEMPLATE.equals(name) ? 0 : 1; String[] names= new String[fTemplates.length + 1]; @@ -716,9 +716,10 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag public abstract ITranslationUnit getCreatedFileTU(); /** - * @return the name of the template used in the previous dialog invocation. + * @return the name of the template used in the previous dialog invocation, or + * the name of the default template. */ - public abstract String getLastUsedTemplateName(); + public abstract String getDefaultTemplateName(); /** * Saves the name of the last used template. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewHeaderFileCreationWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewHeaderFileCreationWizardPage.java index dd9d38b3db5..719d5487739 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewHeaderFileCreationWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewHeaderFileCreationWizardPage.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.CodeGeneration; +import org.eclipse.cdt.internal.core.model.CProject; import org.eclipse.cdt.internal.corext.codemanipulation.StubUtility; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; @@ -186,11 +187,21 @@ public class NewHeaderFileCreationWizardPage extends AbstractFileCreationWizardP } /* - * @see org.eclipse.cdt.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage#getPreferredTemplateName() + * @see org.eclipse.cdt.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage#getDefaultTemplateName() */ @Override - public String getLastUsedTemplateName() { - return getDialogSettings().get(KEY_LAST_USED_TEMPLATE); + public String getDefaultTemplateName() { + String name = getDialogSettings().get(KEY_LAST_USED_TEMPLATE); + if (name == null) { + String contentType = CProject.hasCCNature(getCurrentProject()) ? + CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER; + Template[] templates = + StubUtility.getFileTemplatesForContentTypes(new String[] { contentType }, null); + if (templates.length != 0) { + name = templates[0].getName(); + } + } + return name; } /* diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewSourceFileCreationWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewSourceFileCreationWizardPage.java index e7d079bb92c..919e1bd6ada 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewSourceFileCreationWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/filewizard/NewSourceFileCreationWizardPage.java @@ -31,6 +31,7 @@ import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.ui.CodeGeneration; +import org.eclipse.cdt.internal.core.model.CProject; import org.eclipse.cdt.internal.corext.codemanipulation.StubUtility; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; @@ -187,11 +188,21 @@ public class NewSourceFileCreationWizardPage extends AbstractFileCreationWizardP } /* - * @see org.eclipse.cdt.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage#getPreferredTemplateName() + * @see org.eclipse.cdt.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage#getDefaultTemplateName() */ @Override - public String getLastUsedTemplateName() { - return getDialogSettings().get(KEY_LAST_USED_TEMPLATE); + public String getDefaultTemplateName() { + String name = getDialogSettings().get(KEY_LAST_USED_TEMPLATE); + if (name == null) { + String contentType = CProject.hasCCNature(getCurrentProject()) ? + CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER; + Template[] templates = + StubUtility.getFileTemplatesForContentTypes(new String[] { contentType }, null); + if (templates.length != 0) { + name = templates[0].getName(); + } + } + return name; } /*