public override int SetEditLabel(string label)
{
if(String.Equals(Path.GetFileName(this.Url.TrimEnd('\\')), label, StringComparison.Ordinal))
{
// Label matches current Name
return VSConstants.S_OK;
}
string newPath = Path.Combine(new DirectoryInfo(this.Url).Parent.FullName, label);
// Verify that No Directory/file already exists with the new name among current children
for(HierarchyNode n = Parent.FirstChild; n != null; n = n.NextSibling)
{
if(n != this && String.Equals(n.Caption, label, StringComparison.OrdinalIgnoreCase))
{
return ShowFileOrFolderAlreadExistsErrorMessage(newPath);
}
}
// Verify that No Directory/file already exists with the new name on disk
if(Directory.Exists(newPath) || File.Exists(newPath))
{
return ShowFileOrFolderAlreadExistsErrorMessage(newPath);
}
try
{
RenameFolder(label);
//Refresh the properties in the properties window
IVsUIShell shell = this.ProjectManager.GetService(typeof(SVsUIShell)) as IVsUIShell;
Debug.Assert(shell != null, "Could not get the ui shell from the project");
ErrorHandler.ThrowOnFailure(shell.RefreshPropertyBrowser(0));
// Notify the listeners that the name of this folder is changed. This will
// also force a refresh of the SolutionExplorer's node.
this.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_Caption, 0);
}
catch(Exception e)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.RenameFolder, CultureInfo.CurrentUICulture), e.Message));
}
return VSConstants.S_OK;
}