mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 00:36:16 +02:00
Fixed initialization of the folder text box in the New Source File
dialog.
This commit is contained in:
parent
faf497d361
commit
e6f0a47c44
1 changed files with 101 additions and 108 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2009 QNX Software Systems and others.
|
* Copyright (c) 2004, 2012 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -70,6 +70,7 @@ import org.eclipse.cdt.internal.ui.preferences.CodeTemplatePreferencePage;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
|
import org.eclipse.cdt.internal.ui.viewsupport.IViewPartInputProvider;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.NewElementWizardPage;
|
import org.eclipse.cdt.internal.ui.wizards.NewElementWizardPage;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.SourceFolderSelectionDialog;
|
import org.eclipse.cdt.internal.ui.wizards.SourceFolderSelectionDialog;
|
||||||
|
import org.eclipse.cdt.internal.ui.wizards.classwizard.NewClassWizardUtil;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ComboDialogField;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.ComboDialogField;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
|
||||||
|
@ -82,22 +83,22 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
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 static final String NO_TEMPLATE = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
private IWorkspaceRoot fWorkspaceRoot;
|
private final IWorkspaceRoot fWorkspaceRoot;
|
||||||
|
|
||||||
// field IDs
|
// field IDs
|
||||||
private static final int SOURCE_FOLDER_ID = 1;
|
private static final int SOURCE_FOLDER_ID = 1;
|
||||||
protected static final int NEW_FILE_ID = 2;
|
protected static final int NEW_FILE_ID = 2;
|
||||||
private static final int ALL_FIELDS = SOURCE_FOLDER_ID | NEW_FILE_ID;
|
private static final int ALL_FIELDS = SOURCE_FOLDER_ID | NEW_FILE_ID;
|
||||||
int fLastFocusedField = 0;
|
int fLastFocusedField = 0;
|
||||||
private StringButtonDialogField fSourceFolderDialogField;
|
private final StringButtonDialogField fSourceFolderDialogField;
|
||||||
private IStatus fSourceFolderStatus;
|
private IStatus fSourceFolderStatus;
|
||||||
private IStatus fNewFileStatus;
|
private IStatus fNewFileStatus;
|
||||||
private final IStatus STATUS_OK = new StatusInfo();
|
private final IStatus STATUS_OK = new StatusInfo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This flag isFirstTime is used to keep a note
|
* This flag isFirstTime is used to keep a note
|
||||||
* that the file creation wizard has just been
|
* that the file creation wizard has just been
|
||||||
* created.
|
* created.
|
||||||
*/
|
*/
|
||||||
private boolean isFirstTime = true;
|
private boolean isFirstTime = true;
|
||||||
|
@ -105,19 +106,19 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
private Template[] fTemplates;
|
private Template[] fTemplates;
|
||||||
|
|
||||||
private ComboDialogField fTemplateDialogField;
|
private ComboDialogField fTemplateDialogField;
|
||||||
|
|
||||||
public AbstractFileCreationWizardPage(String name) {
|
public AbstractFileCreationWizardPage(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
||||||
setDescription(NewFileWizardMessages.AbstractFileCreationWizardPage_description);
|
setDescription(NewFileWizardMessages.AbstractFileCreationWizardPage_description);
|
||||||
|
|
||||||
fWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
|
fWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
|
||||||
|
|
||||||
SourceFolderFieldAdapter sourceFolderAdapter = new SourceFolderFieldAdapter();
|
SourceFolderFieldAdapter sourceFolderAdapter = new SourceFolderFieldAdapter();
|
||||||
fSourceFolderDialogField = new StringButtonDialogField(sourceFolderAdapter);
|
fSourceFolderDialogField = new StringButtonDialogField(sourceFolderAdapter);
|
||||||
fSourceFolderDialogField.setDialogFieldListener(sourceFolderAdapter);
|
fSourceFolderDialogField.setDialogFieldListener(sourceFolderAdapter);
|
||||||
fSourceFolderDialogField.setLabelText(NewFileWizardMessages.AbstractFileCreationWizardPage_sourceFolder_label);
|
fSourceFolderDialogField.setLabelText(NewFileWizardMessages.AbstractFileCreationWizardPage_sourceFolder_label);
|
||||||
fSourceFolderDialogField.setButtonLabel(NewFileWizardMessages.AbstractFileCreationWizardPage_sourceFolder_button);
|
fSourceFolderDialogField.setButtonLabel(NewFileWizardMessages.AbstractFileCreationWizardPage_sourceFolder_button);
|
||||||
|
|
||||||
fTemplates= getApplicableTemplates();
|
fTemplates= getApplicableTemplates();
|
||||||
if (fTemplates != null && fTemplates.length > 0) {
|
if (fTemplates != null && fTemplates.length > 0) {
|
||||||
|
@ -129,24 +130,24 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
fNewFileStatus = STATUS_OK;
|
fNewFileStatus = STATUS_OK;
|
||||||
fLastFocusedField = 0;
|
fLastFocusedField = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------- UI Creation ---------
|
// -------- UI Creation ---------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createControl(Composite parent) {
|
public void createControl(Composite parent) {
|
||||||
initializeDialogUnits(parent);
|
initializeDialogUnits(parent);
|
||||||
|
|
||||||
Composite composite = new Composite(parent, SWT.NONE);
|
Composite composite = new Composite(parent, SWT.NONE);
|
||||||
int nColumns = 3;
|
int nColumns = 3;
|
||||||
|
|
||||||
GridLayout layout = new GridLayout();
|
GridLayout layout = new GridLayout();
|
||||||
layout.numColumns = nColumns;
|
layout.numColumns = nColumns;
|
||||||
composite.setLayout(layout);
|
composite.setLayout(layout);
|
||||||
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
composite.setFont(parent.getFont());
|
composite.setFont(parent.getFont());
|
||||||
|
|
||||||
createSourceFolderControls(composite, nColumns);
|
createSourceFolderControls(composite, nColumns);
|
||||||
|
|
||||||
createFileControls(composite, nColumns - 1);
|
createFileControls(composite, nColumns - 1);
|
||||||
// Placeholder for the right column.
|
// Placeholder for the right column.
|
||||||
(new Composite(composite, SWT.NO_FOCUS)).setLayoutData(new GridData(1, 1));
|
(new Composite(composite, SWT.NO_FOCUS)).setLayoutData(new GridData(1, 1));
|
||||||
|
@ -159,15 +160,15 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
setMessage(null);
|
setMessage(null);
|
||||||
setControl(composite);
|
setControl(composite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a separator line. Expects a <code>GridLayout</code> with at least 1 column.
|
* Creates a separator line. Expects a <code>GridLayout</code> with at least 1 column.
|
||||||
*
|
*
|
||||||
* @param composite the parent composite
|
* @param composite the parent composite
|
||||||
* @param nColumns number of columns to span
|
* @param nColumns number of columns to span
|
||||||
*/
|
*/
|
||||||
protected void createSeparator(Composite composite, int nColumns) {
|
protected void createSeparator(Composite composite, int nColumns) {
|
||||||
(new Separator(SWT.SEPARATOR | SWT.HORIZONTAL)).doFillIntoGrid(composite, nColumns, convertHeightInCharsToPixels(1));
|
(new Separator(SWT.SEPARATOR | SWT.HORIZONTAL)).doFillIntoGrid(composite, nColumns, convertHeightInCharsToPixels(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,7 +176,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
* the source folder location. The method expects that the parent composite
|
* the source folder location. The method expects that the parent composite
|
||||||
* uses a <code>GridLayout</code> as its layout manager and that the
|
* uses a <code>GridLayout</code> as its layout manager and that the
|
||||||
* grid layout has at least 3 columns.
|
* grid layout has at least 3 columns.
|
||||||
*
|
*
|
||||||
* @param parent the parent composite
|
* @param parent the parent composite
|
||||||
* @param nColumns the number of columns to span. This number must be
|
* @param nColumns the number of columns to span. This number must be
|
||||||
* greater or equal three
|
* greater or equal three
|
||||||
|
@ -186,23 +187,23 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
LayoutUtil.setWidthHint(textControl, getMaxFieldWidth());
|
LayoutUtil.setWidthHint(textControl, getMaxFieldWidth());
|
||||||
textControl.addFocusListener(new StatusFocusListener(SOURCE_FOLDER_ID));
|
textControl.addFocusListener(new StatusFocusListener(SOURCE_FOLDER_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 2 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
|
||||||
*/
|
*/
|
||||||
protected abstract void createFileControls(Composite parent, int nColumns);
|
protected abstract void createFileControls(Composite parent, int nColumns);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the controls for the file template field. Expects a <code>GridLayout</code> with at
|
* Creates the controls for the file template field. Expects a <code>GridLayout</code> with at
|
||||||
* least 3 columns.
|
* least 3 columns.
|
||||||
*
|
*
|
||||||
* @param parent the parent composite
|
* @param parent the parent composite
|
||||||
* @param columns number of columns to span
|
* @param columns number of columns to span
|
||||||
*/
|
*/
|
||||||
protected void createTemplateControls(Composite parent, int columns) {
|
protected void createTemplateControls(Composite parent, int columns) {
|
||||||
if (fTemplateDialogField != null) {
|
if (fTemplateDialogField != null) {
|
||||||
fTemplateDialogField.doFillIntoGrid(parent, columns - 1);
|
fTemplateDialogField.doFillIntoGrid(parent, columns - 1);
|
||||||
|
@ -267,7 +268,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the selected template and saves its name for future use.
|
* Returns the selected template and saves its name for future use.
|
||||||
*
|
*
|
||||||
* @return the selected template or <code>null</code> if none.
|
* @return the selected template or <code>null</code> if none.
|
||||||
*/
|
*/
|
||||||
protected Template getTemplate() {
|
protected Template getTemplate() {
|
||||||
|
@ -285,12 +286,12 @@ 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
|
||||||
* page.
|
* page.
|
||||||
*
|
*
|
||||||
* @param selection used to initialize the fields
|
* @param selection used to initialize the fields
|
||||||
*/
|
*/
|
||||||
public void init(IStructuredSelection selection) {
|
public void init(IStructuredSelection selection) {
|
||||||
|
@ -298,10 +299,10 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
initFields(celem);
|
initFields(celem);
|
||||||
doStatusUpdate();
|
doStatusUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to inspect a selection to find a C element.
|
* Utility method to inspect a selection to find a C element.
|
||||||
*
|
*
|
||||||
* @param selection the selection to be inspected
|
* @param selection the selection to be inspected
|
||||||
* @return a C element to be used as the initial selection, or <code>null</code>,
|
* @return a C element to be used as the initial selection, or <code>null</code>,
|
||||||
* if no C element exists in the given selection
|
* if no C element exists in the given selection
|
||||||
|
@ -311,8 +312,8 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
if (selection != null && !selection.isEmpty()) {
|
if (selection != null && !selection.isEmpty()) {
|
||||||
Object selectedElement = selection.getFirstElement();
|
Object selectedElement = selection.getFirstElement();
|
||||||
if (selectedElement instanceof IAdaptable) {
|
if (selectedElement instanceof IAdaptable) {
|
||||||
IAdaptable adaptable = (IAdaptable) selectedElement;
|
IAdaptable adaptable = (IAdaptable) selectedElement;
|
||||||
|
|
||||||
celem = (ICElement) adaptable.getAdapter(ICElement.class);
|
celem = (ICElement) adaptable.getAdapter(ICElement.class);
|
||||||
if (celem == null) {
|
if (celem == null) {
|
||||||
IResource resource = (IResource) adaptable.getAdapter(IResource.class);
|
IResource resource = (IResource) adaptable.getAdapter(IResource.class);
|
||||||
|
@ -333,7 +334,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
if (part instanceof ContentOutline) {
|
if (part instanceof ContentOutline) {
|
||||||
part = CUIPlugin.getActivePage().getActiveEditor();
|
part = CUIPlugin.getActivePage().getActiveEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part instanceof IViewPartInputProvider) {
|
if (part instanceof IViewPartInputProvider) {
|
||||||
Object elem = ((IViewPartInputProvider)part).getViewPartInput();
|
Object elem = ((IViewPartInputProvider)part).getViewPartInput();
|
||||||
if (elem instanceof ICElement) {
|
if (elem instanceof ICElement) {
|
||||||
|
@ -351,7 +352,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (celem == null || celem.getElementType() == ICElement.C_MODEL) {
|
if (celem == null || celem.getElementType() == ICElement.C_MODEL) {
|
||||||
try {
|
try {
|
||||||
ICProject[] projects = CoreModel.create(getWorkspaceRoot()).getCProjects();
|
ICProject[] projects = CoreModel.create(getWorkspaceRoot()).getCProjects();
|
||||||
|
@ -367,7 +368,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes all fields provided by the page with a given selection.
|
* Initializes all fields provided by the page with a given selection.
|
||||||
*
|
*
|
||||||
* @param elem the selection used to initialize this page or <code>
|
* @param elem the selection used to initialize this page or <code>
|
||||||
* null</code> if no selection was available
|
* null</code> if no selection was available
|
||||||
*/
|
*/
|
||||||
|
@ -379,40 +380,32 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the source folder field.
|
* Initializes the source folder field.
|
||||||
*
|
*
|
||||||
* @param elem the C element used to compute the initial folder
|
* @param elem the C element used to compute the initial folder
|
||||||
*/
|
*/
|
||||||
protected void initSourceFolder(ICElement elem) {
|
protected void initSourceFolder(ICElement elem) {
|
||||||
ICContainer folder = null;
|
IPath folderPath = null;
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
folder = CModelUtil.getSourceFolder(elem);
|
ICContainer folder = NewClassWizardUtil.getSourceFolder(elem);
|
||||||
if (folder == null) {
|
if (folder == null) {
|
||||||
ICProject cproject = elem.getCProject();
|
ICProject cproject = elem.getCProject();
|
||||||
if (cproject != null) {
|
if (cproject != null) {
|
||||||
try {
|
folder = NewClassWizardUtil.getFirstSourceRoot(cproject);
|
||||||
if (cproject.exists()) {
|
}
|
||||||
ISourceRoot[] roots = cproject.getSourceRoots();
|
}
|
||||||
if (roots != null && roots.length > 0)
|
if (folder != null) {
|
||||||
folder = roots[0];
|
folderPath = folder.getResource().getFullPath();
|
||||||
}
|
}
|
||||||
} catch (CModelException e) {
|
}
|
||||||
CUIPlugin.log(e);
|
setSourceFolderFullPath(folderPath, false);
|
||||||
}
|
|
||||||
if (folder == null) {
|
|
||||||
folder = cproject.findSourceRoot(cproject.getResource());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setSourceFolderFullPath(folder != null ? folder.getResource().getFullPath() : null, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the recommended maximum width for text fields (in pixels). This
|
* Returns the recommended maximum width for text fields (in pixels). This
|
||||||
* method requires that createContent has been called before this method is
|
* method requires that createContent has been called before this method is
|
||||||
* call. Subclasses may override to change the maximum width for text
|
* call. Subclasses may override to change the maximum width for text
|
||||||
* fields.
|
* fields.
|
||||||
*
|
*
|
||||||
* @return the recommended maximum width for text fields.
|
* @return the recommended maximum width for text fields.
|
||||||
*/
|
*/
|
||||||
protected int getMaxFieldWidth() {
|
protected int getMaxFieldWidth() {
|
||||||
|
@ -424,7 +417,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
* when the current editor does not have focus or does not return a text selection.
|
* when the current editor does not have focus or does not return a text selection.
|
||||||
* @return Returns the test selection of the current editor or <code>null</code>.
|
* @return Returns the test selection of the current editor or <code>null</code>.
|
||||||
*
|
*
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
protected ITextSelection getCurrentTextSelection() {
|
protected ITextSelection getCurrentTextSelection() {
|
||||||
IWorkbenchPart part = CUIPlugin.getActivePage().getActivePart();
|
IWorkbenchPart part = CUIPlugin.getActivePage().getActivePart();
|
||||||
|
@ -439,21 +432,21 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the focus to the source folder's text field.
|
* Sets the focus to the source folder's text field.
|
||||||
*/
|
*/
|
||||||
protected void setFocusOnSourceFolder() {
|
protected void setFocusOnSourceFolder() {
|
||||||
fSourceFolderDialogField.setFocus();
|
fSourceFolderDialogField.setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final class StatusFocusListener implements FocusListener {
|
protected final class StatusFocusListener implements FocusListener {
|
||||||
private int fieldID;
|
private final int fieldID;
|
||||||
|
|
||||||
public StatusFocusListener(int fieldID) {
|
public StatusFocusListener(int fieldID) {
|
||||||
this.fieldID = fieldID;
|
this.fieldID = fieldID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusGained(FocusEvent e) {
|
public void focusGained(FocusEvent e) {
|
||||||
fLastFocusedField = this.fieldID;
|
fLastFocusedField = this.fieldID;
|
||||||
|
@ -463,7 +456,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
}
|
}
|
||||||
doStatusUpdate();
|
doStatusUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusLost(FocusEvent e) {
|
public void focusLost(FocusEvent e) {
|
||||||
fLastFocusedField = 0;
|
fLastFocusedField = 0;
|
||||||
|
@ -481,29 +474,29 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
handleFieldChanged(ALL_FIELDS);
|
handleFieldChanged(ALL_FIELDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dialogFieldChanged(DialogField field) {
|
public void dialogFieldChanged(DialogField field) {
|
||||||
handleFieldChanged(ALL_FIELDS);
|
handleFieldChanged(ALL_FIELDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------- validation ----------
|
// ----------- validation ----------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is a hook which gets called after the source folder's
|
* This method is a hook which gets called after the source folder's
|
||||||
* text input field has changed. This default implementation updates
|
* text input field has changed. This default implementation updates
|
||||||
* the model and returns an error status. The underlying model
|
* the model and returns an error status. The underlying model
|
||||||
* is only valid if the returned status is OK.
|
* is only valid if the returned status is OK.
|
||||||
*
|
*
|
||||||
* @return the model's error status
|
* @return the model's error status
|
||||||
*/
|
*/
|
||||||
protected IStatus sourceFolderChanged() {
|
protected IStatus sourceFolderChanged() {
|
||||||
StatusInfo status = new StatusInfo();
|
StatusInfo status = new StatusInfo();
|
||||||
|
|
||||||
IPath folderPath = getSourceFolderFullPath();
|
IPath folderPath = getSourceFolderFullPath();
|
||||||
if (folderPath == null) {
|
if (folderPath == null) {
|
||||||
status.setError(NewFileWizardMessages.AbstractFileCreationWizardPage_error_EnterSourceFolderName);
|
status.setError(NewFileWizardMessages.AbstractFileCreationWizardPage_error_EnterSourceFolderName);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,36 +506,36 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
if (resType == IResource.PROJECT || resType == IResource.FOLDER) {
|
if (resType == IResource.PROJECT || resType == IResource.FOLDER) {
|
||||||
IProject proj = res.getProject();
|
IProject proj = res.getProject();
|
||||||
if (!proj.isOpen()) {
|
if (!proj.isOpen()) {
|
||||||
status.setError(NLS.bind(NewFileWizardMessages.AbstractFileCreationWizardPage_error_NotAFolder, folderPath));
|
status.setError(NLS.bind(NewFileWizardMessages.AbstractFileCreationWizardPage_error_NotAFolder, folderPath));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
if (!CoreModel.hasCCNature(proj) && !CoreModel.hasCNature(proj)) {
|
if (!CoreModel.hasCCNature(proj) && !CoreModel.hasCNature(proj)) {
|
||||||
if (resType == IResource.PROJECT) {
|
if (resType == IResource.PROJECT) {
|
||||||
status.setError(NewFileWizardMessages.AbstractFileCreationWizardPage_warning_NotACProject);
|
status.setError(NewFileWizardMessages.AbstractFileCreationWizardPage_warning_NotACProject);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
status.setWarning(NewFileWizardMessages.AbstractFileCreationWizardPage_warning_NotInACProject);
|
status.setWarning(NewFileWizardMessages.AbstractFileCreationWizardPage_warning_NotInACProject);
|
||||||
}
|
}
|
||||||
ICElement e = CoreModel.getDefault().create(res.getFullPath());
|
ICElement e = CoreModel.getDefault().create(res.getFullPath());
|
||||||
if (CModelUtil.getSourceFolder(e) == null) {
|
if (CModelUtil.getSourceFolder(e) == null) {
|
||||||
status.setError(NLS.bind(NewFileWizardMessages.AbstractFileCreationWizardPage_error_NotASourceFolder, folderPath));
|
status.setError(NLS.bind(NewFileWizardMessages.AbstractFileCreationWizardPage_error_NotASourceFolder, folderPath));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status.setError(NLS.bind(NewFileWizardMessages.AbstractFileCreationWizardPage_error_NotAFolder, folderPath));
|
status.setError(NLS.bind(NewFileWizardMessages.AbstractFileCreationWizardPage_error_NotAFolder, folderPath));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status.setError(NLS.bind(NewFileWizardMessages.AbstractFileCreationWizardPage_error_FolderDoesNotExist, folderPath));
|
status.setError(NLS.bind(NewFileWizardMessages.AbstractFileCreationWizardPage_error_FolderDoesNotExist, folderPath));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook method that gets called when a field on this page has changed.
|
* Hook method that gets called when a field on this page has changed.
|
||||||
*
|
*
|
||||||
* @param fields Bitwise-OR'd ids of the fields that changed.
|
* @param fields Bitwise-OR'd ids of the fields that changed.
|
||||||
*/
|
*/
|
||||||
protected void handleFieldChanged(int fields) {
|
protected void handleFieldChanged(int fields) {
|
||||||
|
@ -572,7 +565,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
(fSourceFolderStatus != lastStatus) ? fSourceFolderStatus : STATUS_OK,
|
(fSourceFolderStatus != lastStatus) ? fSourceFolderStatus : STATUS_OK,
|
||||||
(fNewFileStatus != lastStatus) ? fNewFileStatus : STATUS_OK,
|
(fNewFileStatus != lastStatus) ? fNewFileStatus : STATUS_OK,
|
||||||
};
|
};
|
||||||
|
|
||||||
// the mode severe status will be displayed and the ok button enabled/disabled.
|
// the mode severe status will be displayed and the ok button enabled/disabled.
|
||||||
updateStatus(status);
|
updateStatus(status);
|
||||||
}
|
}
|
||||||
|
@ -602,7 +595,7 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
fSourceFolderDialogField.dialogFieldChanged();
|
fSourceFolderDialogField.dialogFieldChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IProject getCurrentProject() {
|
protected IProject getCurrentProject() {
|
||||||
IPath folderPath = getSourceFolderFullPath();
|
IPath folderPath = getSourceFolderFullPath();
|
||||||
if (folderPath != null) {
|
if (folderPath != null) {
|
||||||
|
@ -613,13 +606,13 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the workspace root.
|
* Returns the workspace root.
|
||||||
*
|
*
|
||||||
* @return the workspace root
|
* @return the workspace root
|
||||||
*/
|
*/
|
||||||
protected IWorkspaceRoot getWorkspaceRoot() {
|
protected IWorkspaceRoot getWorkspaceRoot() {
|
||||||
return fWorkspaceRoot;
|
return fWorkspaceRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see WizardPage#becomesVisible
|
* @see WizardPage#becomesVisible
|
||||||
*/
|
*/
|
||||||
|
@ -633,9 +626,9 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the focus on the starting input field.
|
* Sets the focus on the starting input field.
|
||||||
*/
|
*/
|
||||||
protected abstract void setFocus();
|
protected abstract void setFocus();
|
||||||
|
|
||||||
IPath chooseSourceFolder(IPath initialPath) {
|
IPath chooseSourceFolder(IPath initialPath) {
|
||||||
ICElement initElement = getSourceFolderFromPath(initialPath);
|
ICElement initElement = getSourceFolderFromPath(initialPath);
|
||||||
if (initElement instanceof ISourceRoot) {
|
if (initElement instanceof ISourceRoot) {
|
||||||
|
@ -644,11 +637,11 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
if (projRoot != null && projRoot.equals(initElement))
|
if (projRoot != null && projRoot.equals(initElement))
|
||||||
initElement = cProject;
|
initElement = cProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceFolderSelectionDialog dialog = new SourceFolderSelectionDialog(getShell());
|
SourceFolderSelectionDialog dialog = new SourceFolderSelectionDialog(getShell());
|
||||||
dialog.setInput(CoreModel.create(fWorkspaceRoot));
|
dialog.setInput(CoreModel.create(fWorkspaceRoot));
|
||||||
dialog.setInitialSelection(initElement);
|
dialog.setInitialSelection(initElement);
|
||||||
|
|
||||||
if (dialog.open() == Window.OK) {
|
if (dialog.open() == Window.OK) {
|
||||||
Object result = dialog.getFirstResult();
|
Object result = dialog.getFirstResult();
|
||||||
if (result instanceof ICElement) {
|
if (result instanceof ICElement) {
|
||||||
|
@ -690,45 +683,45 @@ public abstract class AbstractFileCreationWizardPage extends NewElementWizardPag
|
||||||
/**
|
/**
|
||||||
* Returns the full path computed from the file name field
|
* Returns the full path computed from the file name field
|
||||||
* and the source folder.
|
* and the source folder.
|
||||||
*
|
*
|
||||||
* @return the file path
|
* @return the file path
|
||||||
*/
|
*/
|
||||||
public abstract IPath getFileFullPath();
|
public abstract IPath getFileFullPath();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook method that gets called when the file name has changed. The method validates the
|
* Hook method that gets called when the file name has changed. The method validates the
|
||||||
* file name and returns the status of the validation.
|
* file name and returns the status of the validation.
|
||||||
*
|
*
|
||||||
* @return the status of the validation
|
* @return the status of the validation
|
||||||
*/
|
*/
|
||||||
protected abstract IStatus fileNameChanged();
|
protected abstract IStatus fileNameChanged();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the new file using the entered field values.
|
* Creates the new file using the entered field values.
|
||||||
*
|
*
|
||||||
* @param monitor a progress monitor to report progress.
|
* @param monitor a progress monitor to report progress.
|
||||||
* @throws CoreException Thrown when the creation failed.
|
* @throws CoreException Thrown when the creation failed.
|
||||||
*/
|
*/
|
||||||
public abstract void createFile(IProgressMonitor monitor) throws CoreException;
|
public abstract void createFile(IProgressMonitor monitor) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the created file. The method only returns a valid translation unit
|
* Returns the created file. The method only returns a valid translation unit
|
||||||
* after <code>createFile</code> has been called.
|
* after <code>createFile</code> has been called.
|
||||||
*
|
*
|
||||||
* @return the created translation unit
|
* @return the created translation unit
|
||||||
* @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, or
|
* @return the name of the template used in the previous dialog invocation, or
|
||||||
* the name of the default template.
|
* the name of the default template.
|
||||||
*/
|
*/
|
||||||
public abstract String getDefaultTemplateName();
|
public abstract String getDefaultTemplateName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the name of the last used template.
|
* Saves the name of the last used template.
|
||||||
*
|
*
|
||||||
* @param name the name of a template, or an empty string for no template.
|
* @param name the name of a template, or an empty string for no template.
|
||||||
*/
|
*/
|
||||||
public abstract void saveLastUsedTemplateName(String name);
|
public abstract void saveLastUsedTemplateName(String name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue