mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Added persistence for the last used template and adjusted layout of the dialog (bug 238195).
This commit is contained in:
parent
2c26884385
commit
b6b73f1b19
3 changed files with 82 additions and 17 deletions
|
@ -9,6 +9,7 @@
|
||||||
* QNX Software Systems - initial API and implementation
|
* QNX Software Systems - initial API and implementation
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.wizards.filewizard;
|
package org.eclipse.cdt.internal.ui.wizards.filewizard;
|
||||||
|
|
||||||
|
@ -80,6 +81,7 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
|
||||||
public abstract class AbstractFileCreationWizardPage extends NewElementWizardPage {
|
public abstract class AbstractFileCreationWizardPage extends NewElementWizardPage {
|
||||||
|
|
||||||
private static final int MAX_FIELD_CHARS = 50;
|
private static final int MAX_FIELD_CHARS = 50;
|
||||||
|
private static final String NO_TEMPLATE = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
private IWorkspaceRoot fWorkspaceRoot;
|
private IWorkspaceRoot fWorkspaceRoot;
|
||||||
|
|
||||||
|
@ -147,11 +149,13 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
createSourceFolderControls(composite, nColumns);
|
createSourceFolderControls(composite, nColumns);
|
||||||
|
|
||||||
createFileControls(composite, nColumns);
|
createFileControls(composite, nColumns - 1);
|
||||||
|
// Placeholder for the right column.
|
||||||
|
(new Composite(composite, SWT.NO_FOCUS)).setLayoutData(new GridData(1, 1));
|
||||||
|
|
||||||
createTemplateControls(composite, nColumns);
|
createTemplateControls(composite, nColumns);
|
||||||
|
|
||||||
composite.layout();
|
composite.layout();
|
||||||
|
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
setMessage(null);
|
setMessage(null);
|
||||||
|
@ -187,7 +191,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the controls for the file name field. Expects a <code>GridLayout</code> with at
|
* Creates the controls for the file name field. Expects a <code>GridLayout</code> with at
|
||||||
* least 3 columns.
|
* least 2 columns.
|
||||||
*
|
*
|
||||||
* @param parent the parent composite
|
* @param parent the parent composite
|
||||||
* @param nColumns number of columns to span
|
* @param nColumns number of columns to span
|
||||||
|
@ -206,6 +210,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
fTemplateDialogField.doFillIntoGrid(parent, columns - 1);
|
fTemplateDialogField.doFillIntoGrid(parent, columns - 1);
|
||||||
Button configureButton= new Button(parent, SWT.PUSH);
|
Button configureButton= new Button(parent, SWT.PUSH);
|
||||||
configureButton.setText(NewFileWizardMessages.AbstractFileCreationWizardPage_configure_label);
|
configureButton.setText(NewFileWizardMessages.AbstractFileCreationWizardPage_configure_label);
|
||||||
|
configureButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
|
||||||
configureButton.addSelectionListener(new SelectionAdapter() {
|
configureButton.addSelectionListener(new SelectionAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
|
@ -237,30 +242,41 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
protected void updateTemplates() {
|
protected void updateTemplates() {
|
||||||
Template selected= getSelectedTemplate();
|
Template selected= getSelectedTemplate();
|
||||||
|
String name = selected != null ?
|
||||||
|
selected.getName() :
|
||||||
|
getLastUsedTemplateName();
|
||||||
fTemplates= getApplicableTemplates();
|
fTemplates= getApplicableTemplates();
|
||||||
int idx= 1;
|
int idx= NO_TEMPLATE.equals(name) ? 0 : 1;
|
||||||
String[] names= new String[fTemplates.length + 1];
|
String[] names= new String[fTemplates.length + 1];
|
||||||
for (int i = 0; i < fTemplates.length; i++) {
|
for (int i = 0; i < fTemplates.length; i++) {
|
||||||
names[i + 1]= fTemplates[i].getName();
|
names[i + 1]= fTemplates[i].getName();
|
||||||
if (selected != null && selected.getName().equals(names[i + 1])) {
|
if (name != null && name.equals(names[i + 1])) {
|
||||||
idx= i;
|
idx= i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
names[0]= NewFileWizardMessages.AbstractFileCreationWizardPage_noTemplate;
|
names[0]= NewFileWizardMessages.AbstractFileCreationWizardPage_noTemplate;
|
||||||
fTemplateDialogField.setItems(names);
|
fTemplateDialogField.setItems(names);
|
||||||
fTemplateDialogField.selectItem(idx + 1);
|
fTemplateDialogField.selectItem(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the set of selectable templates.
|
* Configure the set of templates to select from.
|
||||||
* @return the set of templates
|
* @return the set of templates
|
||||||
*/
|
*/
|
||||||
protected abstract Template[] getApplicableTemplates();
|
protected abstract Template[] getApplicableTemplates();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the selected template or <code>null</code> if none
|
* Returns the selected template and saves its name for future use.
|
||||||
|
*
|
||||||
|
* @return the selected template or <code>null</code> if none.
|
||||||
*/
|
*/
|
||||||
protected Template getSelectedTemplate() {
|
protected Template getTemplate() {
|
||||||
|
Template template = getSelectedTemplate();
|
||||||
|
saveLastUsedTemplateName(template != null ? template.getName() : NO_TEMPLATE);
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Template getSelectedTemplate() {
|
||||||
if (fTemplateDialogField != null) {
|
if (fTemplateDialogField != null) {
|
||||||
int index= fTemplateDialogField.getSelectionIndex() - 1;
|
int index= fTemplateDialogField.getSelectionIndex() - 1;
|
||||||
if (index >= 0 && index < fTemplates.length) {
|
if (index >= 0 && index < fTemplates.length) {
|
||||||
|
@ -269,7 +285,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The wizard owning this page is responsible for calling this method with the
|
* The wizard owning this page is responsible for calling this method with the
|
||||||
* current selection. The selection is used to initialize the fields of the wizard
|
* current selection. The selection is used to initialize the fields of the wizard
|
||||||
|
@ -699,4 +715,16 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
* @see #createFile(IProgressMonitor)
|
* @see #createFile(IProgressMonitor)
|
||||||
*/
|
*/
|
||||||
public abstract ITranslationUnit getCreatedFileTU();
|
public abstract ITranslationUnit getCreatedFileTU();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the name of the template used in the previous dialog invocation.
|
||||||
|
*/
|
||||||
|
public abstract String getLastUsedTemplateName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the name of the last used template.
|
||||||
|
*
|
||||||
|
* @param name the name of a template, or an empty string for no template.
|
||||||
|
*/
|
||||||
|
public abstract void saveLastUsedTemplateName(String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - initial API and implementation
|
* QNX Software Systems - initial API and implementation
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
* Sergey Prigogin (Google)
|
||||||
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.wizards.filewizard;
|
package org.eclipse.cdt.internal.ui.wizards.filewizard;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CConventions;
|
import org.eclipse.cdt.core.CConventions;
|
||||||
|
@ -38,7 +39,8 @@ import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
public class NewHeaderFileCreationWizardPage extends AbstractFileCreationWizardPage {
|
public class NewHeaderFileCreationWizardPage extends AbstractFileCreationWizardPage {
|
||||||
|
private final String KEY_LAST_USED_TEMPLATE = "LastUsedHeaderTemplate"; //$NON-NLS-1$
|
||||||
|
|
||||||
private ITranslationUnit fNewFileTU = null;
|
private ITranslationUnit fNewFileTU = null;
|
||||||
private StringDialogField fNewFileDialogField;
|
private StringDialogField fNewFileDialogField;
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ public class NewHeaderFileCreationWizardPage extends AbstractFileCreationWizardP
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the controls for the file name field. Expects a <code>GridLayout</code> with at
|
* Creates the controls for the file name field. Expects a <code>GridLayout</code> with at
|
||||||
* least 3 columns.
|
* least 2 columns.
|
||||||
*
|
*
|
||||||
* @param parent the parent composite
|
* @param parent the parent composite
|
||||||
* @param nColumns number of columns to span
|
* @param nColumns number of columns to span
|
||||||
|
@ -153,7 +155,7 @@ public class NewHeaderFileCreationWizardPage extends AbstractFileCreationWizardP
|
||||||
fNewFileTU = (ITranslationUnit) CoreModel.getDefault().create(newFile);
|
fNewFileTU = (ITranslationUnit) CoreModel.getDefault().create(newFile);
|
||||||
if (fNewFileTU != null) {
|
if (fNewFileTU != null) {
|
||||||
String lineDelimiter= StubUtility.getLineDelimiterUsed(fNewFileTU);
|
String lineDelimiter= StubUtility.getLineDelimiterUsed(fNewFileTU);
|
||||||
String content= CodeGeneration.getHeaderFileContent(getSelectedTemplate(), fNewFileTU, null, null, lineDelimiter);
|
String content= CodeGeneration.getHeaderFileContent(getTemplate(), fNewFileTU, null, null, lineDelimiter);
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
fNewFileTU.getBuffer().setContents(content.toCharArray());
|
fNewFileTU.getBuffer().setContents(content.toCharArray());
|
||||||
fNewFileTU.save(monitor, true);
|
fNewFileTU.save(monitor, true);
|
||||||
|
@ -182,4 +184,20 @@ public class NewHeaderFileCreationWizardPage extends AbstractFileCreationWizardP
|
||||||
return StubUtility.getFileTemplatesForContentTypes(
|
return StubUtility.getFileTemplatesForContentTypes(
|
||||||
new String[] { CCorePlugin.CONTENT_TYPE_CXXHEADER, CCorePlugin.CONTENT_TYPE_CHEADER }, null);
|
new String[] { CCorePlugin.CONTENT_TYPE_CXXHEADER, CCorePlugin.CONTENT_TYPE_CHEADER }, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage#getPreferredTemplateName()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getLastUsedTemplateName() {
|
||||||
|
return getDialogSettings().get(KEY_LAST_USED_TEMPLATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage#savePreferredTemplateName(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveLastUsedTemplateName(String name) {
|
||||||
|
getDialogSettings().put(KEY_LAST_USED_TEMPLATE, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - initial API and implementation
|
* QNX Software Systems - initial API and implementation
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.wizards.filewizard;
|
package org.eclipse.cdt.internal.ui.wizards.filewizard;
|
||||||
|
|
||||||
|
@ -39,6 +40,8 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
|
||||||
|
|
||||||
public class NewSourceFileCreationWizardPage extends AbstractFileCreationWizardPage {
|
public class NewSourceFileCreationWizardPage extends AbstractFileCreationWizardPage {
|
||||||
|
private final String KEY_LAST_USED_TEMPLATE = "LastUsedSourceTemplate"; //$NON-NLS-1$
|
||||||
|
|
||||||
private ITranslationUnit fNewFileTU = null;
|
private ITranslationUnit fNewFileTU = null;
|
||||||
private StringDialogField fNewFileDialogField;
|
private StringDialogField fNewFileDialogField;
|
||||||
|
|
||||||
|
@ -65,7 +68,7 @@ public class NewSourceFileCreationWizardPage extends AbstractFileCreationWizardP
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the controls for the file name field. Expects a <code>GridLayout</code> with at
|
* Creates the controls for the file name field. Expects a <code>GridLayout</code> with at
|
||||||
* least 3 columns.
|
* least 2 columns.
|
||||||
*
|
*
|
||||||
* @param parent the parent composite
|
* @param parent the parent composite
|
||||||
* @param nColumns number of columns to span
|
* @param nColumns number of columns to span
|
||||||
|
@ -153,7 +156,7 @@ public class NewSourceFileCreationWizardPage extends AbstractFileCreationWizardP
|
||||||
fNewFileTU = (ITranslationUnit) CoreModel.getDefault().create(newFile);
|
fNewFileTU = (ITranslationUnit) CoreModel.getDefault().create(newFile);
|
||||||
if (fNewFileTU != null) {
|
if (fNewFileTU != null) {
|
||||||
String lineDelimiter= StubUtility.getLineDelimiterUsed(fNewFileTU);
|
String lineDelimiter= StubUtility.getLineDelimiterUsed(fNewFileTU);
|
||||||
String content= CodeGeneration.getBodyFileContent(getSelectedTemplate(), fNewFileTU, null, null, lineDelimiter);
|
String content= CodeGeneration.getBodyFileContent(getTemplate(), fNewFileTU, null, null, lineDelimiter);
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
fNewFileTU.getBuffer().setContents(content.toCharArray());
|
fNewFileTU.getBuffer().setContents(content.toCharArray());
|
||||||
fNewFileTU.save(monitor, true);
|
fNewFileTU.save(monitor, true);
|
||||||
|
@ -182,4 +185,20 @@ public class NewSourceFileCreationWizardPage extends AbstractFileCreationWizardP
|
||||||
return StubUtility.getFileTemplatesForContentTypes(
|
return StubUtility.getFileTemplatesForContentTypes(
|
||||||
new String[] { CCorePlugin.CONTENT_TYPE_CXXSOURCE, CCorePlugin.CONTENT_TYPE_CSOURCE }, null);
|
new String[] { CCorePlugin.CONTENT_TYPE_CXXSOURCE, CCorePlugin.CONTENT_TYPE_CSOURCE }, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage#getPreferredTemplateName()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getLastUsedTemplateName() {
|
||||||
|
return getDialogSettings().get(KEY_LAST_USED_TEMPLATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.internal.ui.wizards.filewizard.AbstractFileCreationWizardPage#savePreferredTemplateName(String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveLastUsedTemplateName(String name) {
|
||||||
|
getDialogSettings().put(KEY_LAST_USED_TEMPLATE, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue