本文整理汇总了C#中HierarchyNode.FindChild方法的典型用法代码示例。如果您正苦于以下问题:C# HierarchyNode.FindChild方法的具体用法?C# HierarchyNode.FindChild怎么用?C# HierarchyNode.FindChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HierarchyNode
的用法示例。
在下文中一共展示了HierarchyNode.FindChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDirectory
/// <summary>
/// Adds a directory to the project hierarchy with the specified parent.
/// </summary>
protected void AddDirectory(HierarchyNode parent, bool isSearchPath, string subfolder) {
var existing = parent.FindChild(Path.GetFileName(subfolder));
if (existing == null) {
FolderNode folderNode = CreateFolderNode(subfolder);
parent.AddChild(folderNode);
CreateHierarchy(folderNode, subfolder, isSearchPath);
}
}
示例2: AddFile
/// <summary>
/// Adds a file to the project hierarchy with the specified parent.
/// </summary>
/// <param name="parent"></param>
/// <param name="isSearchPath"></param>
/// <param name="file"></param>
protected void AddFile(HierarchyNode parent, bool isSearchPath, string file) {
var existing = parent.FindChild(file);
if (existing == null) {
FileNode fileNode = CreateFileNode(file);
//Files in search path are not considered memebers of the project itself
fileNode.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, isSearchPath);
parent.AddChild(fileNode);
}
}
示例3: TryFindParentFileNode
private bool TryFindParentFileNode(HierarchyNode root, string child, out HierarchyNode parent)
{
parent = null;
var childName = Path.GetFileName(child);
var childDirectory = Path.GetDirectoryName(child);
// the standart layout, used for most file types (aspx, ashx, master, xaml etc)
// + - page.aspx
// | + - page.aspx.n
// | + - page.aspx.designer.n
var parentName = Path.GetFileNameWithoutExtension(childName);
while (parentName.IndexOf('.') > 0 && parent == null)
{
parent = root.FindChild(Path.Combine(childDirectory, parentName));
parentName = Path.GetFileNameWithoutExtension(parentName);
}
if (parent == null)
{
// Windows forms layout:
// + - form.n
// | + - form.designer.n
var childNameWithoutExtension = Path.GetFileNameWithoutExtension(child);
// look for suffix position (".Designer", etc)
var suffixIndex = childNameWithoutExtension.LastIndexOf(root.NameRelationSeparator);
if (suffixIndex < 0)
return false;
parentName = string.Format("{0}.n", childNameWithoutExtension.Substring(0, suffixIndex));
var parentPath = Path.Combine(childDirectory, parentName);
parent = root.FindChild(parentPath);
}
return parent != null;
}
示例4: AddDirectory
/// <summary>
/// Adds a folder into the project recursing and adding any sub-files and sub-directories.
///
/// The user can be prompted to overwrite the existing files if the folder already exists
/// in the project. They will be initially prompted to overwrite - if they answer no t
/// we'll set promptOverwrite to false and when we recurse we won't prompt. If they say
/// yes then we'll set it to true and we will prompt for individual files.
/// </summary>
private int AddDirectory(VSADDRESULT[] result, HierarchyNode n, string file, bool? promptOverwrite)
{
// need to recursively add all of the directory contents
var fullPath = Path.Combine(GetBaseDirectoryForAddingFiles(n), Path.GetFileName(file));
HierarchyNode targetFolder = n.FindChild(fullPath, false);
if (targetFolder == null)
{
var newChild = CreateFolderNode(fullPath);
n.AddChild(newChild);
targetFolder = newChild;
}
else if (promptOverwrite == null)
{
var res = MessageBox.Show(
String.Format(
@"This folder already contains a folder called '{0}'.
If the files in the existing folder have the same names as files in the folder you are copying, do you want to replace the existing files?", Path.GetFileName(file)),
"Merge Folders",
MessageBoxButtons.YesNoCancel
);
// yes means prompt for each file
// no means don't prompt for any of the files
// cancel means forget what I'm doing
switch (res)
{
case DialogResult.Cancel:
result[0] = VSADDRESULT.ADDRESULT_Cancel;
return (int)OleConstants.OLECMDERR_E_CANCELED;
case DialogResult.No:
promptOverwrite = false;
return VSConstants.S_OK;
case DialogResult.Yes:
promptOverwrite = true;
break;
}
}
// add the files...
var dirFiles = Directory.GetFiles(file);
Guid empty = Guid.Empty;
var subRes = AddItemWithSpecificInternal(
targetFolder.ID,
VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE,
null,
(uint)dirFiles.Length,
dirFiles,
IntPtr.Zero,
0,
ref empty,
null,
ref empty,
result,
promptOverwrite: promptOverwrite
);
if (ErrorHandler.Failed(subRes))
{
return subRes;
}
// add any subdirectories...
var subDirs = Directory.GetDirectories(file);
return AddItemWithSpecificInternal(
targetFolder.ID,
VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE,
null,
(uint)subDirs.Length,
subDirs,
IntPtr.Zero,
0,
ref empty,
null,
ref empty,
result,
promptOverwrite: promptOverwrite
);
}
示例5: AddNewFileNodeToHierarchy
protected override void AddNewFileNodeToHierarchy(HierarchyNode parentNode, string fileName)
{
// We have to take care of Dependant Files here
// So any .Designer.prg, or .Xaml.Prg is depending from a parent which has the same prefix name
// then we must set that parent as parentNode;
Utilities.ArgumentNotNull("parentNode", parentNode);
Dictionary<string, string> Dependencies = new Dictionary<string, string>();
Dependencies.Add(".designer.prg", ".prg");
Dependencies.Add(".xaml.prg", ".xaml");
Dependencies.Add(".vh", ".prg");
// Check if we can find the Parent
int dotPos = fileName.IndexOf(".");
string parentFile = fileName.Substring(0, dotPos);
string extension = fileName.Substring(dotPos).ToLower();
//
if ( Dependencies.ContainsKey(extension) )
{
//
HierarchyNode newParent = parentNode.FindChild(parentFile + Dependencies[extension]);
if (newParent != null)
{
parentNode = newParent;
// Ok, is it a XSharp node or something else ?
var xsharpParent = parentNode as XSharpFileNode;
if (xsharpParent != null)
{
xsharpParent.UpdateHasDesigner();
}
}
}
// there are other possible parents. For Example Window1.prg is the parent of Window1.Windows.vnfrm
// In this case the children are a VOBinary, Header or NativeResource
switch (XSharpFileNode.GetFileType(fileName))
{
case XSharpFileType.Header:
case XSharpFileType.NativeResource:
case XSharpFileType.VOFieldSpec:
case XSharpFileType.VOForm:
case XSharpFileType.VODBServer:
case XSharpFileType.VOMenu:
case XSharpFileType.VOOrder:
case XSharpFileType.VOIndex:
// dependent file
HierarchyNode newParent = parentNode.FindChild(parentFile + ".prg");
if (newParent != null)
{
parentNode = newParent;
}
break;
}
base.AddNewFileNodeToHierarchy(parentNode, fileName);
}
示例6: SetBoldStartup
private static void SetBoldStartup(HierarchyNode parent)
{
string startupFile;
CommonProjectNode comProj = (CommonProjectNode)parent.ProjectMgr;
HierarchyNode startupItem;
if (!comProj._boldedStartupItem &&
(startupFile = comProj.GetStartupFile()) != null &&
(startupItem = parent.FindChild(CommonUtils.GetAbsoluteFilePath(comProj.ProjectFolder, startupFile), false)) != null) {
// we're expanding the parent of the
comProj.BoldStartupItem(startupItem);
}
}