mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for bug 207605 - New Class Wizard does not handle paths properly on case insensitive filesystems
This commit is contained in:
parent
24d37ac2e7
commit
41731f51ac
2 changed files with 84 additions and 45 deletions
|
@ -95,6 +95,7 @@ NewClassCreationWizardPage.warning.NotASourceFile=''{0}'' is not a source file.
|
||||||
NewClassCreationWizardPage.warning.SourceFileNameDiscouraged=Source file name is discouraged. {0}
|
NewClassCreationWizardPage.warning.SourceFileNameDiscouraged=Source file name is discouraged. {0}
|
||||||
NewClassCreationWizardPage.warning.SourceFileExists=Source file already exists. Contents will be appended.
|
NewClassCreationWizardPage.warning.SourceFileExists=Source file already exists. Contents will be appended.
|
||||||
NewClassCreationWizardPage.error.InvalidSourceFileName=Source file name is not valid. {0}
|
NewClassCreationWizardPage.error.InvalidSourceFileName=Source file name is not valid. {0}
|
||||||
|
NewClassCreationWizardPage.error.LocationUnknown=Cannot locate resource. {0}
|
||||||
|
|
||||||
# -----------BaseClassesListDialogField -------------
|
# -----------BaseClassesListDialogField -------------
|
||||||
BaseClassesListDialogField.buttons.add=&Add...
|
BaseClassesListDialogField.buttons.add=&Add...
|
||||||
|
|
|
@ -12,12 +12,16 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.wizards;
|
package org.eclipse.cdt.ui.wizards;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.core.filesystem.EFS;
|
||||||
|
import org.eclipse.core.filesystem.IFileStore;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
@ -1381,14 +1385,19 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
|
|
||||||
// status of all used components
|
// status of all used components
|
||||||
IStatus[] status = new IStatus[] {
|
IStatus[] status = new IStatus[] {
|
||||||
|
// give priority to file-level warnings over
|
||||||
|
// class name warnings
|
||||||
|
(fHeaderFileStatus != lastStatus && fClassNameStatus == lastStatus) ? fHeaderFileStatus : STATUS_OK,
|
||||||
|
(fSourceFileStatus != lastStatus && fClassNameStatus == lastStatus) ? fSourceFileStatus : STATUS_OK,
|
||||||
|
|
||||||
lastStatus,
|
lastStatus,
|
||||||
(fSourceFolderStatus != lastStatus) ? fSourceFolderStatus : STATUS_OK,
|
(fSourceFolderStatus != lastStatus) ? fSourceFolderStatus : STATUS_OK,
|
||||||
|
(fHeaderFileStatus != lastStatus) ? fHeaderFileStatus : STATUS_OK,
|
||||||
|
(fSourceFileStatus != lastStatus) ? fSourceFileStatus : STATUS_OK,
|
||||||
(fNamespaceStatus != lastStatus) ? fNamespaceStatus : STATUS_OK,
|
(fNamespaceStatus != lastStatus) ? fNamespaceStatus : STATUS_OK,
|
||||||
(fClassNameStatus != lastStatus) ? fClassNameStatus : STATUS_OK,
|
(fClassNameStatus != lastStatus) ? fClassNameStatus : STATUS_OK,
|
||||||
(fBaseClassesStatus != lastStatus) ? fBaseClassesStatus : STATUS_OK,
|
(fBaseClassesStatus != lastStatus) ? fBaseClassesStatus : STATUS_OK,
|
||||||
(fMethodStubsStatus != lastStatus) ? fMethodStubsStatus : STATUS_OK,
|
(fMethodStubsStatus != lastStatus) ? fMethodStubsStatus : STATUS_OK,
|
||||||
(fHeaderFileStatus != lastStatus) ? fHeaderFileStatus : STATUS_OK,
|
|
||||||
(fSourceFileStatus != lastStatus) ? fSourceFileStatus : STATUS_OK
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// the mode severe status will be displayed and the ok button enabled/disabled.
|
// the mode severe status will be displayed and the ok button enabled/disabled.
|
||||||
|
@ -1686,11 +1695,11 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
*/
|
*/
|
||||||
protected IStatus headerFileChanged() {
|
protected IStatus headerFileChanged() {
|
||||||
StatusInfo status = new StatusInfo();
|
StatusInfo status = new StatusInfo();
|
||||||
if (isUseDefaultSelected()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPath path = getHeaderFileFullPath();
|
IPath path = getHeaderFileFullPath();
|
||||||
|
if (path == null && isUseDefaultSelected()) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.EnterHeaderFileName")); //$NON-NLS-1$
|
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.EnterHeaderFileName")); //$NON-NLS-1$
|
||||||
return status;
|
return status;
|
||||||
|
@ -1710,26 +1719,36 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
|
|
||||||
boolean fileExists = false;
|
boolean fileExists = false;
|
||||||
// check if file already exists
|
// check if file already exists
|
||||||
IResource file = NewClassWizardUtil.getWorkspaceRoot().findMember(path);
|
IResource file = NewClassWizardUtil.getWorkspaceRoot().getFile(path);
|
||||||
if (file != null && file.exists()) {
|
|
||||||
if (file.getType() == IResource.FILE) {
|
if (file.getType() == IResource.FILE) {
|
||||||
|
if (!file.exists()) {
|
||||||
|
URI location = file.getLocationURI();
|
||||||
|
try {
|
||||||
|
IFileStore store = EFS.getStore(location);
|
||||||
|
fileExists = store.fetchInfo().exists();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.LocationUnknown")); //$NON-NLS-1$
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fileExists = true;
|
||||||
|
}
|
||||||
|
|
||||||
IProject proj = file.getProject();
|
IProject proj = file.getProject();
|
||||||
if (!proj.isOpen()) {
|
if (!proj.isOpen()) {
|
||||||
status.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.NotAFile", path)); //$NON-NLS-1$
|
status.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.NotAFile", path)); //$NON-NLS-1$
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileExists = true;
|
|
||||||
if (!CoreModel.hasCCNature(proj) && !CoreModel.hasCNature(proj)) {
|
if (!CoreModel.hasCCNature(proj) && !CoreModel.hasCNature(proj)) {
|
||||||
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.NotInACProject")); //$NON-NLS-1$
|
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.NotInACProject")); //$NON-NLS-1$
|
||||||
} else {
|
} else if (fileExists) {
|
||||||
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.HeaderFileExists")); //$NON-NLS-1$
|
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.HeaderFileExists")); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.NotAFile")); //$NON-NLS-1$
|
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.NotAFile")); //$NON-NLS-1$
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// check if folder exists
|
// check if folder exists
|
||||||
IPath folderPath = path.removeLastSegments(1).makeRelative();
|
IPath folderPath = path.removeLastSegments(1).makeRelative();
|
||||||
|
@ -1759,9 +1778,6 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
*/
|
*/
|
||||||
protected IStatus sourceFileChanged() {
|
protected IStatus sourceFileChanged() {
|
||||||
StatusInfo status = new StatusInfo();
|
StatusInfo status = new StatusInfo();
|
||||||
if (isUseDefaultSelected()) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPath path = getSourceFileFullPath();
|
IPath path = getSourceFileFullPath();
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
|
@ -1783,26 +1799,36 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
|
|
||||||
boolean fileExists = false;
|
boolean fileExists = false;
|
||||||
// check if file already exists
|
// check if file already exists
|
||||||
IResource file = NewClassWizardUtil.getWorkspaceRoot().findMember(path);
|
IResource file = NewClassWizardUtil.getWorkspaceRoot().getFile(path);
|
||||||
if (file != null && file.exists()) {
|
|
||||||
if (file.getType() == IResource.FILE) {
|
if (file.getType() == IResource.FILE) {
|
||||||
|
if (!file.exists()) {
|
||||||
|
URI location = file.getLocationURI();
|
||||||
|
try {
|
||||||
|
IFileStore store = EFS.getStore(location);
|
||||||
|
fileExists = store.fetchInfo().exists();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.LocationUnknown")); //$NON-NLS-1$
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fileExists = true;
|
||||||
|
}
|
||||||
|
|
||||||
IProject proj = file.getProject();
|
IProject proj = file.getProject();
|
||||||
if (!proj.isOpen()) {
|
if (!proj.isOpen()) {
|
||||||
status.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.NotAFile", path)); //$NON-NLS-1$
|
status.setError(NewClassWizardMessages.getFormattedString("NewClassCreationWizardPage.error.NotAFile", path)); //$NON-NLS-1$
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileExists = true;
|
|
||||||
if (!CoreModel.hasCCNature(proj) && !CoreModel.hasCNature(proj)) {
|
if (!CoreModel.hasCCNature(proj) && !CoreModel.hasCNature(proj)) {
|
||||||
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.NotInACProject")); //$NON-NLS-1$
|
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.NotInACProject")); //$NON-NLS-1$
|
||||||
} else {
|
} else if (fileExists) {
|
||||||
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.SourceFileExists")); //$NON-NLS-1$
|
status.setWarning(NewClassWizardMessages.getString("NewClassCreationWizardPage.warning.SourceFileExists")); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.NotAFile")); //$NON-NLS-1$
|
status.setError(NewClassWizardMessages.getString("NewClassCreationWizardPage.error.NotAFile")); //$NON-NLS-1$
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// check if folder exists
|
// check if folder exists
|
||||||
IPath folderPath = path.removeLastSegments(1).makeRelative();
|
IPath folderPath = path.removeLastSegments(1).makeRelative();
|
||||||
|
@ -1839,14 +1865,26 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
|
||||||
fCreatedSourceFile = null;
|
fCreatedSourceFile = null;
|
||||||
|
|
||||||
createClass(
|
createClass(
|
||||||
getHeaderFileFullPath(),
|
getCanonicalPath(getHeaderFileFullPath()),
|
||||||
getSourceFileFullPath(),
|
getCanonicalPath(getSourceFileFullPath()),
|
||||||
getClassName(),
|
getClassName(),
|
||||||
isNamespaceSelected() ? getNamespaceText() : null,
|
isNamespaceSelected() ? getNamespaceText() : null,
|
||||||
getBaseClasses(),
|
getBaseClasses(),
|
||||||
getSelectedMethodStubs(), monitor);
|
getSelectedMethodStubs(), monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IPath getCanonicalPath(IPath path) throws CoreException {
|
||||||
|
IWorkspaceRoot root = NewClassWizardUtil.getWorkspaceRoot();
|
||||||
|
IFile file = root.getFile(path);
|
||||||
|
URI location = file.getLocationURI();
|
||||||
|
URI canonicalLocation = EFS.getStore(location).toURI();
|
||||||
|
IFile[] files = root.findFilesForLocationURI(canonicalLocation);
|
||||||
|
if (files.length > 0) {
|
||||||
|
return files[0].getFullPath();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the generated header and source files should be
|
* Returns whether the generated header and source files should be
|
||||||
* opened in editors after the finish button is pressed.
|
* opened in editors after the finish button is pressed.
|
||||||
|
|
Loading…
Add table
Reference in a new issue