mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Chis Wiebe: New class wizard fixes
This commit is contained in:
parent
9a2fdef54b
commit
15cee9ff6a
3 changed files with 72 additions and 65 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2004-04-13 Hoda Amer
|
||||||
|
From Chris Wiebe
|
||||||
|
This patch makes sure the class wizard works as long as the selection
|
||||||
|
supports IAdaptable. It also prevents the class wizard from attempting
|
||||||
|
to generate new source files without a valid source path.
|
||||||
|
|
||||||
2004-04-13 Andrew Niefer
|
2004-04-13 Andrew Niefer
|
||||||
fix src/org/eclipse/cdt/internal/corext/template/default-templates.xml to restore changes lost in
|
fix src/org/eclipse/cdt/internal/corext/template/default-templates.xml to restore changes lost in
|
||||||
string externalization (restore for loops to use preincrement)
|
string externalization (restore for loops to use preincrement)
|
||||||
|
|
|
@ -34,5 +34,6 @@ public class BaseClassSelectionDialog extends TypeSelectionDialog {
|
||||||
setMessage(NewWizardMessages.getString("BaseClassSelectionDialog.message")); //$NON-NLS-1$
|
setMessage(NewWizardMessages.getString("BaseClassSelectionDialog.message")); //$NON-NLS-1$
|
||||||
setDialogSettings(DIALOG_SETTINGS);
|
setDialogSettings(DIALOG_SETTINGS);
|
||||||
setVisibleTypes(fVisibleTypes);
|
setVisibleTypes(fVisibleTypes);
|
||||||
|
setFilter("*", true); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CConventions;
|
import org.eclipse.cdt.core.CConventions;
|
||||||
import org.eclipse.cdt.core.browser.AllTypesCache;
|
import org.eclipse.cdt.core.browser.AllTypesCache;
|
||||||
|
@ -29,7 +28,6 @@ import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.IOpenable;
|
|
||||||
import org.eclipse.cdt.core.model.IStructure;
|
import org.eclipse.cdt.core.model.IStructure;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
|
@ -61,6 +59,7 @@ 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;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
@ -105,6 +104,8 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
private IStructuredSelection currentSelection;
|
private IStructuredSelection currentSelection;
|
||||||
// cache of C Model current selection
|
// cache of C Model current selection
|
||||||
private ICElement eSelection = null;
|
private ICElement eSelection = null;
|
||||||
|
// default location where source files will be created
|
||||||
|
private IPath defaultSourceFolder = null;
|
||||||
|
|
||||||
// cache of newly-created files
|
// cache of newly-created files
|
||||||
private ITranslationUnit parentHeaderTU = null;
|
private ITranslationUnit parentHeaderTU = null;
|
||||||
|
@ -183,11 +184,16 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
if(hasCppNature){
|
eSelection = getSelectionCElement(currentSelection);
|
||||||
|
IResource resource = getSelectionResourceElement(currentSelection);
|
||||||
|
if (resource != null)
|
||||||
|
defaultSourceFolder = resource.getLocation().makeAbsolute();
|
||||||
|
if (hasCppNature && defaultSourceFolder != null) {
|
||||||
fAccessButtons.setEnabled(false);
|
fAccessButtons.setEnabled(false);
|
||||||
setPageComplete(false);
|
setPageComplete(false);
|
||||||
eSelection = getSelectionCElement(currentSelection);
|
|
||||||
} else {
|
} else {
|
||||||
|
eSelection = null;
|
||||||
|
defaultSourceFolder = null;
|
||||||
StatusInfo status = new StatusInfo();
|
StatusInfo status = new StatusInfo();
|
||||||
status.setError(NewWizardMessages.getString("NewClassWizardPage.error.NotAvailableForNonCppProjects")); //$NON-NLS-1$
|
status.setError(NewWizardMessages.getString("NewClassWizardPage.error.NotAvailableForNonCppProjects")); //$NON-NLS-1$
|
||||||
updateStatus(status);
|
updateStatus(status);
|
||||||
|
@ -379,46 +385,68 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSelectionCPP(IStructuredSelection sel){
|
private boolean isSelectionCPP(IStructuredSelection sel){
|
||||||
IProject project = null;
|
IProject project = getSelectionProject(sel);
|
||||||
ICElement element = getSelectionCElement(sel);
|
|
||||||
if (element == null){
|
|
||||||
IResource resource = getSelectionResourceElement(sel);
|
|
||||||
project = resource.getProject();
|
|
||||||
}else {
|
|
||||||
project = element.getCProject().getProject();
|
|
||||||
}
|
|
||||||
if (project != null)
|
if (project != null)
|
||||||
return CoreModel.getDefault().hasCCNature(project);
|
return CoreModel.getDefault().hasCCNature(project);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICElement getSelectionCElement(IStructuredSelection sel) {
|
private ICElement getSelectionCElement(IStructuredSelection selection) {
|
||||||
if (!sel.isEmpty()) {
|
ICElement elem= null;
|
||||||
List list= sel.toList();
|
if (selection != null && !selection.isEmpty()) {
|
||||||
if (list.size() == 1) {
|
Object selectedElement= selection.getFirstElement();
|
||||||
Object element= list.get(0);
|
if (selectedElement instanceof IAdaptable) {
|
||||||
if (element instanceof ICElement) {
|
IAdaptable adaptable= (IAdaptable) selectedElement;
|
||||||
return (ICElement)element;
|
elem= (ICElement) adaptable.getAdapter(ICElement.class);
|
||||||
|
if (elem == null) {
|
||||||
|
IResource resource= (IResource) adaptable.getAdapter(IResource.class);
|
||||||
|
if (resource != null && resource.getType() != IResource.ROOT) {
|
||||||
|
while (elem == null && resource.getType() != IResource.PROJECT) {
|
||||||
|
resource= resource.getParent();
|
||||||
|
elem= (ICElement) resource.getAdapter(ICElement.class);
|
||||||
|
}
|
||||||
|
if (elem == null) {
|
||||||
|
elem= CoreModel.getDefault().create(resource); // C project
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IResource getSelectionResourceElement(IStructuredSelection sel) {
|
if (elem == null || elem.getElementType() == ICElement.C_MODEL) {
|
||||||
if (!sel.isEmpty()) {
|
ICProject[] projects= CoreModel.create(CUIPlugin.getWorkspace().getRoot()).getCProjects();
|
||||||
List list= sel.toList();
|
if (projects.length == 1) {
|
||||||
if (list.size() == 1) {
|
elem= projects[0];
|
||||||
Object element= list.get(0);
|
|
||||||
if (element instanceof IResource) {
|
|
||||||
if(element instanceof IFile){
|
|
||||||
IFile file = (IFile)element;
|
|
||||||
return (IResource) file.getParent();
|
|
||||||
}else {
|
|
||||||
return (IResource)element;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IResource getSelectionResourceElement(IStructuredSelection selection) {
|
||||||
|
IResource resource= null;
|
||||||
|
if (selection != null && !selection.isEmpty()) {
|
||||||
|
Object selectedElement= selection.getFirstElement();
|
||||||
|
if (selectedElement instanceof IAdaptable) {
|
||||||
|
IAdaptable adaptable= (IAdaptable) selectedElement;
|
||||||
|
resource= (IResource) adaptable.getAdapter(IResource.class);
|
||||||
|
if (resource != null && resource instanceof IFile)
|
||||||
|
resource= resource.getParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IProject getSelectionProject(IStructuredSelection selection) {
|
||||||
|
IProject project= null;
|
||||||
|
if (selection != null && !selection.isEmpty()) {
|
||||||
|
Object selectedElement= selection.getFirstElement();
|
||||||
|
if (selectedElement instanceof IAdaptable) {
|
||||||
|
IAdaptable adaptable= (IAdaptable) selectedElement;
|
||||||
|
IResource resource= (IResource) adaptable.getAdapter(IResource.class);
|
||||||
|
if (resource != null) {
|
||||||
|
return resource.getProject();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -686,34 +714,6 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------Helper methods for creating the class -------
|
|
||||||
protected IPath getSelectionPath(){
|
|
||||||
if(eSelection == null){
|
|
||||||
IResource resourceSelection = getSelectionResourceElement(currentSelection);
|
|
||||||
if(resourceSelection != null){
|
|
||||||
return resourceSelection.getLocation().makeAbsolute();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// if it is a file, return the parent path
|
|
||||||
if(eSelection instanceof ITranslationUnit)
|
|
||||||
return (eSelection.getParent().getPath());
|
|
||||||
// if it is a root, project, or folder, return its path
|
|
||||||
if(eSelection instanceof IOpenable){
|
|
||||||
return (eSelection.getPath());
|
|
||||||
}else {
|
|
||||||
// if it is an element in a file, return its openable parent's path
|
|
||||||
ICElement current = eSelection.getParent();
|
|
||||||
while (current != null){
|
|
||||||
if ((current instanceof IOpenable) && !(current instanceof ITranslationUnit)){
|
|
||||||
return current.getPath();
|
|
||||||
}
|
|
||||||
current = current.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* returns the path without the file name
|
* returns the path without the file name
|
||||||
|
@ -726,7 +726,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
IPath containerPath = new Path (pathName);
|
IPath containerPath = new Path (pathName);
|
||||||
return containerPath.removeLastSegments(1).removeTrailingSeparator().makeAbsolute();
|
return containerPath.removeLastSegments(1).removeTrailingSeparator().makeAbsolute();
|
||||||
}else {
|
}else {
|
||||||
return (getSelectionPath());
|
return defaultSourceFolder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,7 +743,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
return (new Path(pathName)).makeAbsolute();
|
return (new Path(pathName)).makeAbsolute();
|
||||||
} else {
|
} else {
|
||||||
String pathName = linkedGroup.getText();
|
String pathName = linkedGroup.getText();
|
||||||
IPath containerPath = getSelectionPath();
|
IPath containerPath = defaultSourceFolder;
|
||||||
containerPath.addTrailingSeparator();
|
containerPath.addTrailingSeparator();
|
||||||
return ((containerPath.append(pathName)).makeAbsolute());
|
return ((containerPath.append(pathName)).makeAbsolute());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue