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

2004-08-27 Chris Wiebe

class wizard fixes
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationWizardPage.java
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassWizardMessages.properties
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationCodeGenerator.java
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/SourceFileSelectionDialog.java
	* src/org/eclipse/cdt/internal/ui/wizards/classwizard/SourceFolderSelectionDialog.java
This commit is contained in:
Chris Wiebe 2004-08-27 23:46:37 +00:00
parent 57e7bc44fc
commit 973bfa0ac3
6 changed files with 543 additions and 385 deletions

View file

@ -1,4 +1,4 @@
2004-08-25 Chris Wiebe
2004-08-27 Chris Wiebe
class wizard fixes
* src/org/eclipse/cdt/internal/ui/wizards/classwizard/NewClassCreationWizardPage.java

View file

@ -393,7 +393,7 @@ public class NewClassCodeGenerator {
isSystemIncludePath = true;
} else if (projectLocation.isPrefixOf(baseClassLocation)
&& projectLocation.isPrefixOf(headerLocation)) {
includePath = PathUtil.makeRelativePath(baseClassLocation, headerLocation);
includePath = PathUtil.makeRelativePath(baseClassLocation, headerLocation.removeLastSegments(1));
}
if (includePath == null)
includePath = baseClassLocation;
@ -605,7 +605,7 @@ public class NewClassCodeGenerator {
isSystemIncludePath = true;
} else if (projectLocation.isPrefixOf(headerLocation)
&& projectLocation.isPrefixOf(sourceLocation)) {
includePath = PathUtil.makeRelativePath(headerLocation, sourceLocation);
includePath = PathUtil.makeRelativePath(headerLocation, sourceLocation.removeLastSegments(1));
}
if (includePath == null)
includePath = headerLocation;

View file

@ -29,7 +29,6 @@ NewClassCreationWizardPage.sourceFolder.button=Br&owse...
NewClassCreationWizardPage.ChooseSourceFolderDialog.title=Folder Selection
NewClassCreationWizardPage.ChooseSourceFolderDialog.description=&Choose a source folder:
NewClassCreationWizardPage.error.EnterSourceFolderName=Source folder name is empty.
NewClassCreationWizardPage.error.FolderDoesNotExist=Folder ''{0}'' does not exist.
NewClassCreationWizardPage.error.NotAFolder=''{0}'' is not a project or folder.
NewClassCreationWizardPage.error.NotASourceFolder=Folder ''{0}'' is not a source folder.
NewClassCreationWizardPage.error.ProjectClosed=Project ''{0}'' must be accessible.
@ -83,6 +82,7 @@ NewClassCreationWizardPage.convention.headerFilename.filetype=File extension doe
NewClassCreationWizardPage.convention.sourceFilename.filetype=File extension does not correspond to known source file types
NewClassCreationWizardPage.error.NotAFile=''{0}'' is not a file.
NewClassCreationWizardPage.error.FolderDoesNotExist=Folder ''{0}'' does not exist.
NewClassCreationWizardPage.error.SourceFolderRequired=The source folder is required.
NewClassCreationWizardPage.useDefaultLocation.label=&Use Default
@ -90,6 +90,7 @@ NewClassCreationWizardPage.headerFile.label=&Header:
NewClassCreationWizardPage.headerFile.button=Br&owse...
NewClassCreationWizardPage.ChooseHeaderFileDialog.title=Header File Selection
NewClassCreationWizardPage.error.EnterHeaderFileName=Header file name is empty.
NewClassCreationWizardPage.error.HeaderFileNotInSourceFolder=Header file must be inside source folder.
NewClassCreationWizardPage.warning.NotAHeaderFile=''{0}'' is not a header file.
NewClassCreationWizardPage.warning.HeaderFileNameDiscouraged=Header file name is discouraged. {0}.
NewClassCreationWizardPage.warning.HeaderFileExists=Header file already exists. Contents will be appended.
@ -99,6 +100,7 @@ NewClassCreationWizardPage.sourceFile.button=Br&owse...
NewClassCreationWizardPage.sourceFile.label=&Source:
NewClassCreationWizardPage.ChooseSourceFileDialog.title=Source File Selection
NewClassCreationWizardPage.error.EnterSourceFileName=Source file name is empty.
NewClassCreationWizardPage.error.SourceFileNotInSourceFolder=Source file must be inside source folder.
NewClassCreationWizardPage.warning.NotASourceFile=''{0}'' is not a header file.
NewClassCreationWizardPage.warning.SourceFileNameDiscouraged=Source file name is discouraged. {0}
NewClassCreationWizardPage.warning.SourceFileExists=Source file already exists. Contents will be appended.

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.ui.wizards.classwizard;
import java.util.ArrayList;
import org.eclipse.cdt.core.browser.PathUtil;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
@ -82,7 +83,6 @@ public class SourceFileSelectionDialog extends SelectionStatusDialog {
private String fInitialFolderName = null;
private String fInitialFileName = null;
private final class FieldsAdapter extends SelectionAdapter
implements ISelectionChangedListener, IDoubleClickListener, IDialogFieldListener {
@ -506,60 +506,54 @@ public class SourceFileSelectionDialog extends SelectionStatusDialog {
/**
* Sets the initial selection. Convenience method.
*
* @param selection
* @param initialPath
* the initial selection.
*/
public void setInitialFields(String folderName, String fileName) {
fInitialFolderName = folderName;
fInitialFileName = fileName;
final IPath folderPath;
final IPath filePath;
public void setInitialSelection(String folderName, String fileName) {
fInitialFileName = (fileName != null && fileName.length() > 0) ? fileName : null;
fInitialFolderName = null;
if (folderName != null && folderName.length() > 0) {
folderPath = new Path(folderName);
} else {
folderPath = null;
}
if (folderPath != null && fileName != null && fileName.length() > 0) {
filePath = folderPath.append(fileName);
} else {
filePath = null;
}
if (fInput != null && folderPath != null) {
final ICElement[] foundElem = {/*base_folder*/ null, /*exact_folder*/ null, /*exact_file*/ null};
try {
fInput.accept(new ICElementVisitor() {
public boolean visit(ICElement elem) {
IPath path = elem.getPath();
if (path.isPrefixOf(folderPath)) {
if (foundElem[0] == null || path.segmentCount() > foundElem[0].getPath().segmentCount()) {
foundElem[0] = elem; /*base_folder*/
}
if (path.equals(folderPath)) {
foundElem[1] = elem; /*exact_folder*/
if (filePath == null)
return false; // no need to search children
} else if (filePath != null && path.equals(filePath)) {
foundElem[2] = elem; /*exact_file*/
return false; // no need to search children
}
return true;
}
return false;
}
});
ICElement selectedElement = foundElem[2]; /*exact_file*/
if (selectedElement == null)
selectedElement = foundElem[1]; /*exact_folder*/
if (selectedElement == null)
selectedElement = foundElem[0]; /*base_folder*/
if (selectedElement != null) {
setInitialSelections(new Object[] { selectedElement });
}
} catch (CoreException e) {
// find a folder that actually exists
IPath initialFolderPath = new Path(folderName);
final IPath folderPath = PathUtil.getValidEnclosingFolder(initialFolderPath);
if (folderPath != null) {
fInitialFolderName = folderPath.toString();
if (fInput != null) {
final ICElement[] foundElem = {/*base_folder*/ null, /*exact_folder*/ null, /*exact_file*/ null};
try {
fInput.accept(new ICElementVisitor() {
public boolean visit(ICElement elem) {
IPath path = elem.getPath();
if (path.isPrefixOf(folderPath)) {
if (foundElem[0] == null || path.segmentCount() > foundElem[0].getPath().segmentCount()) {
foundElem[0] = elem; /*base_folder*/
}
if (path.equals(folderPath)) {
foundElem[1] = elem; /*exact_folder*/
if (fInitialFileName == null)
return false; // no need to search children
} else if (fInitialFileName != null && elem.getElementName().equals(fInitialFileName)) {
foundElem[2] = elem; /*exact_file*/
return false; // no need to search children
}
return true;
}
return false;
}
});
ICElement selectedElement = foundElem[2]; /*exact_file*/
if (selectedElement == null)
selectedElement = foundElem[1]; /*exact_folder*/
if (selectedElement == null)
selectedElement = foundElem[0]; /*base_folder*/
if (selectedElement != null) {
setInitialSelections(new Object[] { selectedElement });
}
} catch (CoreException e) {
}
}
}
}
}

View file

@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Common Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors: QNX Software Systems - initial API and implementation
******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.classwizard;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.ui.wizards.TypedElementSelectionValidator;
import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter;
import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CElementSorter;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
public class SourceFolderSelectionDialog extends ElementTreeSelectionDialog {
private static final Class[] VALIDATOR_CLASSES = new Class[] { ICContainer.class, ICProject.class };
private static final TypedElementSelectionValidator fValidator = new TypedElementSelectionValidator(VALIDATOR_CLASSES, false) {
public boolean isSelectedValid(Object element) {
if (element instanceof ICProject) {
ICProject cproject = (ICProject) element;
IPath path = cproject.getProject().getFullPath();
return (cproject.findSourceRoot(path) != null);
} else if (element instanceof ICContainer) {
// if (CModelUtil.getSourceFolder((ICContainer)obj) != null)
return true;
}
return false;
}
};
private static final Class[] FILTER_CLASSES = new Class[] { ICModel.class, ICContainer.class, ICProject.class };
private static final ViewerFilter fFilter = new TypedViewerFilter(FILTER_CLASSES) {
public boolean select(Viewer viewer, Object parent, Object element) {
// if (obj instanceof ICContainer
// && CModelUtil.getSourceFolder((ICContainer)obj) != null) {
// return true;
// }
return super.select(viewer, parent, element);
}
};
private static final CElementContentProvider fContentProvider = new CElementContentProvider();
private static final ILabelProvider fLabelProvider = new CElementLabelProvider(CElementLabelProvider.SHOW_DEFAULT);
private static final ViewerSorter fSorter = new CElementSorter();
public SourceFolderSelectionDialog(Shell parent) {
super(parent, fLabelProvider, fContentProvider);
setValidator(fValidator);
setSorter(fSorter);
addFilter(fFilter);
setTitle(NewClassWizardMessages.getString("NewClassCreationWizardPage.ChooseSourceFolderDialog.title")); //$NON-NLS-1$
setMessage(NewClassWizardMessages.getString("NewClassCreationWizardPage.ChooseSourceFolderDialog.description")); //$NON-NLS-1$
}
}