1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Hoda Amer

UI: 
      The menu item could not be hidden since the "New" menu belongs to the "C Perspective". 
The wizard was disabled for C Projects.
This commit is contained in:
John Camelon 2003-09-18 19:46:12 +00:00
parent 433976a043
commit 6a5af0ed88
5 changed files with 77 additions and 27 deletions

View file

@ -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 2003-09-18 David Inglis
Add workbench build/rebuild in context menu. Add workbench build/rebuild in context menu.

View file

@ -133,9 +133,9 @@ MngCCWizard.description=Create a new Managed Make C++ Project.
MngCCWizardSettings.title=Managed Make C++ Settings MngCCWizardSettings.title=Managed Make C++ Settings
MngCCWizardSettings.description=Define the Managed Make C++ build 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.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.title=Error Creating Project
CProjectWizard.op_error.message=Project cannot be created CProjectWizard.op_error.message=Project cannot be created

View file

@ -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.warning.BaseClassNotExists=Warning: Base class does not exist in current project.
NewClassWizardPage.operations.getProjectClasses=Looking for classes in project NewClassWizardPage.operations.getProjectClasses=Looking for classes in project
NewClassWizardPage.error.NotAvailableForNonCppProjects= The wizard is not available for non C++ projects.
# ------- BaseClassSelectionDialog ----- # ------- BaseClassSelectionDialog -----
BaseClassSelectionDialog.title=Classes in this project BaseClassSelectionDialog.title=Classes in this project

View file

@ -32,7 +32,7 @@ public class NewClassWizard extends BasicNewResourceWizard implements INewWizard
private static final String WZ_TITLE = "NewClassWizard.title"; private static final String WZ_TITLE = "NewClassWizard.title";
private static final String WZ_DESC = "NewClassWizard.description"; private static final String WZ_DESC = "NewClassWizard.description";
private static final String PAGE_TITLE = "NewClassWizard.page.title"; private static final String PAGE_TITLE = "NewClassWizard.page.title";
/** /**
* "NewClassWizard" constructor. * "NewClassWizard" constructor.
*/ */
@ -50,25 +50,27 @@ public class NewClassWizard extends BasicNewResourceWizard implements INewWizard
} }
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
fPage.createClass(monitor); if(fPage.createClass(monitor)){
ITranslationUnit headerTU= fPage.getCreatedClassHeaderFile(); ITranslationUnit headerTU= fPage.getCreatedClassHeaderFile();
ITranslationUnit bodyTU= fPage.getCreatedClassBodyFile(); ITranslationUnit bodyTU= fPage.getCreatedClassBodyFile();
if (headerTU != null) { if (headerTU != null) {
IResource resource= headerTU.getResource(); IResource resource= headerTU.getResource();
selectAndReveal(resource); selectAndReveal(resource);
openResource((IFile) resource); openResource((IFile) resource);
} }
if (bodyTU != null) { if (bodyTU != null) {
IResource resource= bodyTU.getResource(); IResource resource= bodyTU.getResource();
selectAndReveal(resource); selectAndReveal(resource);
openResource((IFile) resource); openResource((IFile) resource);
} }
}
} }
/** /**
* @see Wizard#performFinish * @see Wizard#performFinish
*/ */
public boolean performFinish() { public boolean performFinish() {
if(!fPage.selectionIsCpp())
return true;
IWorkspaceRunnable op= new IWorkspaceRunnable() { IWorkspaceRunnable op= new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
try { try {

View file

@ -55,6 +55,7 @@ import org.eclipse.cdt.ui.CodeGeneration;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceStatus; import org.eclipse.core.resources.IResourceStatus;
import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRoot;
@ -126,6 +127,8 @@ public class NewClassWizardPage extends WizardPage implements Listener {
protected IStatus fClassNameStatus; protected IStatus fClassNameStatus;
protected IStatus fBaseClassStatus; protected IStatus fBaseClassStatus;
private boolean hasCppNature = false;
BasicSearchResultCollector resultCollector; BasicSearchResultCollector resultCollector;
SearchEngine searchEngine; SearchEngine searchEngine;
@ -133,7 +136,13 @@ public class NewClassWizardPage extends WizardPage implements Listener {
public NewClassWizardPage(IStructuredSelection selection) { public NewClassWizardPage(IStructuredSelection selection) {
super(PAGE_NAME); super(PAGE_NAME);
currentSelection = selection; currentSelection = selection;
hasCppNature = isSelectionCPP(currentSelection);
if(hasCppNature){
initializePageControls();
}
}
protected void initializePageControls(){
TypeFieldsAdapter adapter= new TypeFieldsAdapter(); TypeFieldsAdapter adapter= new TypeFieldsAdapter();
fClassNameDialogField= new StringDialogField(); fClassNameDialogField= new StringDialogField();
@ -174,14 +183,19 @@ public class NewClassWizardPage extends WizardPage implements Listener {
fBaseClassStatus= new StatusInfo(); fBaseClassStatus= new StatusInfo();
resultCollector = new BasicSearchResultCollector (); resultCollector = new BasicSearchResultCollector ();
searchEngine = new SearchEngine(); searchEngine = new SearchEngine();
} }
public void init() { public void init() {
fAccessButtons.setEnabled(false); if(hasCppNature){
setPageComplete(false); fAccessButtons.setEnabled(false);
eSelection = getSelectionCElement(currentSelection); setPageComplete(false);
eSelection = getSelectionCElement(currentSelection);
}else {
StatusInfo status = new StatusInfo();
status.setError(NewWizardMessages.getString("NewClassWizardPage.error.NotAvailableForNonCppProjects")); //$NON-NLS-1$
updateStatus(status);
}
} }
// ----------------- Creating Controls -------------------- // ----------------- 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) * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/ */
public void createControl(Composite parent) { public void createControl(Composite parent) {
if(!hasCppNature)
{
setControl(new Composite(parent, SWT.NULL));
return;
}
int nColumns= 5; int nColumns= 5;
initializeDialogUnits(parent); initializeDialogUnits(parent);
@ -358,6 +378,25 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
// --------------- Helper methods for creating controls ----- // --------------- 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) { private ICElement getSelectionCElement(IStructuredSelection sel) {
if (!sel.isEmpty() && sel instanceof IStructuredSelection) { if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
List list= ((IStructuredSelection)sel).toList(); List list= ((IStructuredSelection)sel).toList();
@ -521,7 +560,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
} }
// -------------- Create a new Class ---------------------- // -------------- Create a new Class ----------------------
public void createClass(IProgressMonitor monitor){ public boolean createClass(IProgressMonitor monitor){
if (monitor == null) { if (monitor == null) {
monitor= new NullProgressMonitor(); monitor= new NullProgressMonitor();
} }
@ -555,13 +594,15 @@ public class NewClassWizardPage extends WizardPage implements Listener {
bodyWC.commit(true, monitor); bodyWC.commit(true, monitor);
} }
} }
return true;
}catch(CModelException e){ }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$ 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{ }finally{
monitor.done(); monitor.done();
} }
} }
protected ITranslationUnit createTranslationUnit(LinkToFileGroup linkedGroup){ protected ITranslationUnit createTranslationUnit(LinkToFileGroup linkedGroup){
@ -766,7 +807,9 @@ public class NewClassWizardPage extends WizardPage implements Listener {
BasicSearchMatch baseClass = (BasicSearchMatch)findInList(baseClassName, null, classElements); BasicSearchMatch baseClass = (BasicSearchMatch)findInList(baseClassName, null, classElements);
// if(baseClass != null){ // if(baseClass != null){
// baseClassFileName = baseClass.getLocation().toString(); // IPath baseClassFileLocation = baseClass.getLocation();
// IPath newFilePath = getContainerFullPath(linkedResourceGroupForHeader);
// baseClassFileName = baseClassName + HEADER_EXT;
// } else { // } else {
baseClassFileName = baseClassName + HEADER_EXT; baseClassFileName = baseClassName + HEADER_EXT;
// } // }