diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 7a09b22f589..3e35030d5a0 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,6 @@ +2003-09-18 Hoda Amer + Solution to bug#42611 : New Class Wizard should be hidden for C projects + 2003-09-18 David Inglis Add workbench build/rebuild in context menu. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties index 8e46d13357d..e7ab948574f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties @@ -133,9 +133,9 @@ MngCCWizard.description=Create a new Managed Make C++ Project. MngCCWizardSettings.title=Managed Make C++ Settings MngCCWizardSettings.description=Define the Managed Make C++ build settings. -NewClassWizard.title=New Class +NewClassWizard.title=New C++ Class NewClassWizard.description=Create a new C++ Class. -NewClassWizard.page.title=Class +NewClassWizard.page.title=C++ Class CProjectWizard.op_error.title=Error Creating Project CProjectWizard.op_error.message=Project cannot be created diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties index de8f9285496..ad39e78b7a7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties @@ -162,6 +162,8 @@ NewClassWizardPage.error.InvalidBaseClassName=Base class name is not valid. NewClassWizardPage.warning.BaseClassNotExists=Warning: Base class does not exist in current project. NewClassWizardPage.operations.getProjectClasses=Looking for classes in project + +NewClassWizardPage.error.NotAvailableForNonCppProjects= The wizard is not available for non C++ projects. # ------- BaseClassSelectionDialog ----- BaseClassSelectionDialog.title=Classes in this project diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java index 9f2624ac65b..08b3cbe756f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java @@ -32,7 +32,7 @@ public class NewClassWizard extends BasicNewResourceWizard implements INewWizard private static final String WZ_TITLE = "NewClassWizard.title"; private static final String WZ_DESC = "NewClassWizard.description"; private static final String PAGE_TITLE = "NewClassWizard.page.title"; - + /** * "NewClassWizard" constructor. */ @@ -50,25 +50,27 @@ public class NewClassWizard extends BasicNewResourceWizard implements INewWizard } protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { - fPage.createClass(monitor); - ITranslationUnit headerTU= fPage.getCreatedClassHeaderFile(); - ITranslationUnit bodyTU= fPage.getCreatedClassBodyFile(); - if (headerTU != null) { - IResource resource= headerTU.getResource(); - selectAndReveal(resource); - openResource((IFile) resource); - } - if (bodyTU != null) { - IResource resource= bodyTU.getResource(); - selectAndReveal(resource); - openResource((IFile) resource); - } - + if(fPage.createClass(monitor)){ + ITranslationUnit headerTU= fPage.getCreatedClassHeaderFile(); + ITranslationUnit bodyTU= fPage.getCreatedClassBodyFile(); + if (headerTU != null) { + IResource resource= headerTU.getResource(); + selectAndReveal(resource); + openResource((IFile) resource); + } + if (bodyTU != null) { + IResource resource= bodyTU.getResource(); + selectAndReveal(resource); + openResource((IFile) resource); + } + } } /** * @see Wizard#performFinish */ public boolean performFinish() { + if(!fPage.selectionIsCpp()) + return true; IWorkspaceRunnable op= new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { try { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java index 725acb47a22..8f00ebaf686 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java @@ -55,6 +55,7 @@ import org.eclipse.cdt.ui.CodeGeneration; import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceStatus; import org.eclipse.core.resources.IWorkspaceRoot; @@ -126,6 +127,8 @@ public class NewClassWizardPage extends WizardPage implements Listener { protected IStatus fClassNameStatus; protected IStatus fBaseClassStatus; + private boolean hasCppNature = false; + BasicSearchResultCollector resultCollector; SearchEngine searchEngine; @@ -133,7 +136,13 @@ public class NewClassWizardPage extends WizardPage implements Listener { public NewClassWizardPage(IStructuredSelection selection) { super(PAGE_NAME); currentSelection = selection; - + hasCppNature = isSelectionCPP(currentSelection); + if(hasCppNature){ + initializePageControls(); + } + } + + protected void initializePageControls(){ TypeFieldsAdapter adapter= new TypeFieldsAdapter(); fClassNameDialogField= new StringDialogField(); @@ -174,14 +183,19 @@ public class NewClassWizardPage extends WizardPage implements Listener { fBaseClassStatus= new StatusInfo(); resultCollector = new BasicSearchResultCollector (); - searchEngine = new SearchEngine(); - + searchEngine = new SearchEngine(); } public void init() { - fAccessButtons.setEnabled(false); - setPageComplete(false); - eSelection = getSelectionCElement(currentSelection); + if(hasCppNature){ + fAccessButtons.setEnabled(false); + setPageComplete(false); + eSelection = getSelectionCElement(currentSelection); + }else { + StatusInfo status = new StatusInfo(); + status.setError(NewWizardMessages.getString("NewClassWizardPage.error.NotAvailableForNonCppProjects")); //$NON-NLS-1$ + updateStatus(status); + } } // ----------------- Creating Controls -------------------- @@ -189,6 +203,12 @@ public class NewClassWizardPage extends WizardPage implements Listener { * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) */ public void createControl(Composite parent) { + if(!hasCppNature) + { + setControl(new Composite(parent, SWT.NULL)); + return; + } + int nColumns= 5; initializeDialogUnits(parent); @@ -358,6 +378,25 @@ public class NewClassWizardPage extends WizardPage implements Listener { } // --------------- Helper methods for creating controls ----- + public boolean selectionIsCpp(){ + return hasCppNature; + } + + private boolean isSelectionCPP(IStructuredSelection sel){ + IProject project = null; + ICElement element = getSelectionCElement(sel); + if (element == null){ + IResource resource = getSelectionResourceElement(sel); + project = resource.getProject(); + }else { + project = element.getCProject().getProject(); + } + if (project != null) + return CoreModel.getDefault().hasCCNature(project); + else + return false; + } + private ICElement getSelectionCElement(IStructuredSelection sel) { if (!sel.isEmpty() && sel instanceof IStructuredSelection) { List list= ((IStructuredSelection)sel).toList(); @@ -521,7 +560,7 @@ public class NewClassWizardPage extends WizardPage implements Listener { } // -------------- Create a new Class ---------------------- - public void createClass(IProgressMonitor monitor){ + public boolean createClass(IProgressMonitor monitor){ if (monitor == null) { monitor= new NullProgressMonitor(); } @@ -555,13 +594,15 @@ public class NewClassWizardPage extends WizardPage implements Listener { bodyWC.commit(true, monitor); } } - + + return true; }catch(CModelException e){ MessageDialog.openError(getContainer().getShell(), WorkbenchMessages.getString("WizardNewFileCreationPage.internalErrorTitle"), WorkbenchMessages.format("WizardNewFileCreationPage.internalErrorMessage", new Object[] {e.getMessage()})); //$NON-NLS-2$ //$NON-NLS-1$ + return false; }finally{ monitor.done(); } - + } protected ITranslationUnit createTranslationUnit(LinkToFileGroup linkedGroup){ @@ -766,7 +807,9 @@ public class NewClassWizardPage extends WizardPage implements Listener { BasicSearchMatch baseClass = (BasicSearchMatch)findInList(baseClassName, null, classElements); // if(baseClass != null){ -// baseClassFileName = baseClass.getLocation().toString(); +// IPath baseClassFileLocation = baseClass.getLocation(); +// IPath newFilePath = getContainerFullPath(linkedResourceGroupForHeader); +// baseClassFileName = baseClassName + HEADER_EXT; // } else { baseClassFileName = baseClassName + HEADER_EXT; // }