mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Selection of default template based on project type. Bug 238195.
This commit is contained in:
parent
ca99741025
commit
63d969e8fb
3 changed files with 32 additions and 9 deletions
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue