public virtual int GenerateUniqueItemName(uint itemIdLoc, string ext, string suggestedRoot, out string itemName)
{
var rootName = string.Empty;
var extToUse = string.Empty;
itemName = string.Empty;
//force new items to have a number
var cb = 1;
var found = false;
var fFolderCase = false;
var parent = NodeFromItemId(itemIdLoc);
if (!string.IsNullOrEmpty(ext))
{
extToUse = ext.Trim();
}
if (!string.IsNullOrEmpty(suggestedRoot))
{
suggestedRoot = suggestedRoot.Trim();
}
if (suggestedRoot == null || suggestedRoot.Length == 0)
{
// foldercase, we assume...
suggestedRoot = "NewFolder";
fFolderCase = true;
}
while (!found)
{
rootName = suggestedRoot;
if (cb > 0)
rootName += cb.ToString(CultureInfo.CurrentCulture);
if (extToUse.Length > 0)
{
rootName += extToUse;
}
cb++;
found = true;
for (var n = parent.FirstChild; n != null; n = n.NextSibling)
{
if (rootName == n.GetEditLabel())
{
found = false;
break;
}
//if parent is a folder, we need the whole url
var parentFolder = parent.Url;
if (parent is ProjectNode)
parentFolder = Path.GetDirectoryName(parent.Url);
var checkFile = Path.Combine(parentFolder, rootName);
if (fFolderCase)
{
if (Directory.Exists(checkFile))
{
found = false;
break;
}
}
else
{
if (File.Exists(checkFile))
{
found = false;
break;
}
}
}
}
itemName = rootName;
return VSConstants.S_OK;
}