Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Solution to bug#42611 : New Class Wizard should be hidden for C projects


UI:
      The menu item could not be hidden since the "New" menu belongs to the "C Perspective".
The wizard was disabled for C Projects.

Hoda Amer
Staff Software Engineer
Rational Software - IBM Software Group


Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/ChangeLog,v
retrieving revision 1.176
diff -u -r1.176 ChangeLog
--- ChangeLog	18 Sep 2003 18:25:39 -0000	1.176
+++ ChangeLog	18 Sep 2003 18:53:09 -0000
@@ -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.
 	
Index: src/org/eclipse/cdt/internal/ui/CPluginResources.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties,v
retrieving revision 1.22
diff -u -r1.22 CPluginResources.properties
--- src/org/eclipse/cdt/internal/ui/CPluginResources.properties	15 Sep 2003 20:40:16 -0000	1.22
+++ src/org/eclipse/cdt/internal/ui/CPluginResources.properties	18 Sep 2003 18:53:09 -0000
@@ -133,9 +133,9 @@
 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
Index: src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties,v
retrieving revision 1.3
diff -u -r1.3 NewWizardMessages.properties
--- src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties	6 Jun 2003 01:16:10 -0000	1.3
+++ src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties	18 Sep 2003 18:53:10 -0000
@@ -162,6 +162,8 @@
 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
Index: src/org/eclipse/cdt/ui/wizards/NewClassWizard.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizard.java,v
retrieving revision 1.2
diff -u -r1.2 NewClassWizard.java
--- src/org/eclipse/cdt/ui/wizards/NewClassWizard.java	12 Aug 2003 20:20:12 -0000	1.2
+++ src/org/eclipse/cdt/ui/wizards/NewClassWizard.java	18 Sep 2003 18:53:10 -0000
@@ -32,7 +32,7 @@
 	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 @@
 	}
 	
 	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 {
Index: src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java,v
retrieving revision 1.7
diff -u -r1.7 NewClassWizardPage.java
--- src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java	4 Sep 2003 14:39:20 -0000	1.7
+++ src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java	18 Sep 2003 18:53:11 -0000
@@ -55,6 +55,7 @@
 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 @@
 	protected IStatus fClassNameStatus;
 	protected IStatus fBaseClassStatus;
 
+	private boolean hasCppNature = false;
+	
 	BasicSearchResultCollector  resultCollector;
 	SearchEngine searchEngine;
 
@@ -133,7 +136,13 @@
 	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 @@
 		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 @@
 	 * @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 @@
 	}		
 	
 	// --------------- 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 @@
 	}
 	// -------------- Create a new Class  ----------------------	
 	
-	public void createClass(IProgressMonitor monitor){
+	public boolean createClass(IProgressMonitor monitor){		
 		if (monitor == null) {
 			monitor= new NullProgressMonitor();
 		}
@@ -555,13 +594,15 @@
 					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 @@
 			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;
 //			}

Back to the top