public override int SetEditLabel(string label)
{
// Validate the filename.
if (String.IsNullOrEmpty(label))
{
throw new InvalidOperationException(SR.GetString(SR.ErrorInvalidFileName, CultureInfo.CurrentUICulture));
}
else if (this.ProjectFolder.Length + label.Length + 1 > NativeMethods.MAX_PATH)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.PathTooLong, CultureInfo.CurrentUICulture), label));
}
else if (Utilities.IsFileNameInvalid(label))
{
throw new InvalidOperationException(SR.GetString(SR.ErrorInvalidFileName, CultureInfo.CurrentUICulture));
}
string fileName = Path.GetFileNameWithoutExtension(label);
// if there is no filename or it starts with a leading dot issue an error message and quit.
if (String.IsNullOrEmpty(fileName) || fileName[0] == '.')
{
throw new InvalidOperationException(SR.GetString(SR.FileNameCannotContainALeadingPeriod, CultureInfo.CurrentUICulture));
}
// Nothing to do if the name is the same
string oldFileName = Path.GetFileNameWithoutExtension(this.Url);
if (String.Compare(oldFileName, label, StringComparison.Ordinal) == 0)
{
return VSConstants.S_FALSE;
}
// Now check whether the original file is still there. It could have been renamed.
if (!File.Exists(this.Url))
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.FileOrFolderCannotBeFound, CultureInfo.CurrentUICulture), this.ProjectFile));
}
// Get the full file name and then rename the project file.
string newFile = Path.Combine(this.ProjectFolder, label);
string extension = Path.GetExtension(this.Url);
// Make sure it has the correct extension
if (String.Compare(Path.GetExtension(newFile), extension, StringComparison.OrdinalIgnoreCase) != 0)
{
newFile += extension;
}
this.RenameProjectFile(newFile);
return VSConstants.S_OK;
}