private void TreeViewCustomDraw(ref Message msg, NMTVCUSTOMDRAW tvDraw) { try { int hTreeNode = tvDraw.nmcd.dwItemSpec; if (hTreeNode == 0) { msg.Result = new IntPtr(CommCtrl.CDRF_DODEFAULT); return; } NuGenTreeNode curNode = NuGenTreeNode.FromHandle(this, new IntPtr(hTreeNode)) as NuGenTreeNode; if (curNode == null) { msg.Result = new IntPtr(CommCtrl.CDRF_DODEFAULT); return; } TreeView tree = curNode.TreeView; if (tree != null) { if (!curNode.HasCheckBox) { NuGenTreeView.UncheckNode(curNode.TreeView.Handle, curNode.Handle.ToInt32()); } } } finally { msg.Result = new IntPtr(CommCtrl.CDRF_DODEFAULT); } }
public override object Clone() { NuGenTreeNode node = new NuGenTreeNode(); node.BackColor = this.BackColor; node.Checked = this.Checked; node.ContextMenu = this.ContextMenu; node.ContextMenuStrip = this.ContextMenuStrip; node.DefaultImageIndex = this.DefaultImageIndex; node.ExpandedImageIndex = this.ExpandedImageIndex; node.ForeColor = this.ForeColor; node.HasCheckBox = this.HasCheckBox; node.Name = this.Name; node.NodeFont = this.NodeFont; node.Tag = this.Tag; node.Text = this.Text; node.ToolTipText = this.ToolTipText; foreach (NuGenTreeNode childNode in this.Nodes) { node.Nodes.Add((NuGenTreeNode)childNode.Clone()); } return(node); }
/// <summary> /// </summary> /// <param name="serviceProvider"><para>Requires:</para> /// <para><see cref="ISampleFolder"/></para></param> /// <param name="treeView"></param> /// <param name="folderImageIndex"></param> /// <param name="expandedFolderImageIndex"></param> /// <param name="sampleImageIndex"></param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="serviceProvider"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="treeView"/> is <see langword="null"/>.</para> /// </exception> public void PopulateSampleTree( INuGenServiceProvider serviceProvider , NuGenTreeView treeView , int folderImageIndex , int expandedFolderImageIndex , int sampleImageIndex ) { if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } if (treeView == null) { throw new ArgumentNullException("treeView"); } ISampleFolderDescriptor sampleFolder = serviceProvider.GetService<ISampleFolderDescriptor>(); Debug.Assert(sampleFolder != null, "sampleFolder != null"); DirectoryInfo sampleDirInfo = new DirectoryInfo(sampleFolder.Path); Debug.Write("Scanning \""); Debug.Write(sampleDirInfo.FullName); Debug.WriteLine("\" folder..."); if (!sampleDirInfo.Exists) { Trace.Write("Sample directory does not exist."); return; } DirectoryInfo[] samples = sampleDirInfo.GetDirectories(); Debug.WriteLine("Getting the list of sub-directories..."); Debug.WriteLineIf(samples != null, "samples.Length = " + samples.Length.ToString()); if (samples != null) { Debug.WriteLine("Looping through the sub-directories..."); foreach (DirectoryInfo dirInfo in samples) { NuGenTreeNode treeNode = new NuGenTreeNode(dirInfo.Name, folderImageIndex, expandedFolderImageIndex); treeView.Nodes.Add(treeNode); Debug.Write("Examining \""); Debug.Write(dirInfo.FullName); Debug.WriteLine("\" sub-directory..."); this.BuildSampleTreeNode(sampleFolder, dirInfo, treeNode, folderImageIndex, expandedFolderImageIndex, sampleImageIndex); } } }
/* * OnAfterExpand */ /// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.AfterExpand"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.TreeViewEventArgs"></see> that contains the event data.</param> protected override void OnAfterExpand(TreeViewEventArgs e) { base.OnAfterExpand(e); if (e.Node is NuGenTreeNode) { NuGenTreeNode treeNode = (NuGenTreeNode)e.Node; treeNode.ImageIndex = treeNode.ExpandedImageIndex; treeNode.SelectedImageIndex = treeNode.ExpandedImageIndex; } }
/* * OnAfterCollapse */ /// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.AfterCollapse"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.TreeViewEventArgs"></see> that contains the event data.</param> protected override void OnAfterCollapse(TreeViewEventArgs e) { base.OnAfterCollapse(e); if (e.Node is NuGenTreeNode) { NuGenTreeNode treeNode = (NuGenTreeNode)e.Node; treeNode.ImageIndex = treeNode.DefaultImageIndex; treeNode.SelectedImageIndex = treeNode.DefaultImageIndex; } }
/* * ConvertTo */ /// <summary> /// Converts the given value object to the specified type, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param> /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see>. If null is passed, the current culture is assumed.</param> /// <param name="value">The <see cref="T:System.Object"></see> to convert.</param> /// <param name="destinationType">The <see cref="T:System.Type"></see> to convert the value parameter to.</param> /// <returns> /// An <see cref="T:System.Object"></see> that represents the converted value. /// </returns> /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception> /// <exception cref="T:System.ArgumentNullException">The destinationType parameter is null. </exception> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } NuGenTreeNode node = value as NuGenTreeNode; if (destinationType == typeof(InstanceDescriptor) && value != null) { MemberInfo info = null; object[] parameters = null; if (node.ImageIndex == -1 || node.ExpandedImageIndex == -1) { if (node.Nodes.Count == 0) { info = typeof(NuGenTreeNode).GetConstructor(new Type[] { typeof(string) }); parameters = new object[] { node.Text }; } else { info = typeof(NuGenTreeNode).GetConstructor(new Type[] { typeof(string), typeof(NuGenTreeNode[]) }); NuGenTreeNode[] nodes = new NuGenTreeNode[node.Nodes.Count]; node.Nodes.CopyTo(nodes, 0); parameters = new object[] { node.Text, nodes }; } } else if (node.Nodes.Count == 0) { info = typeof(NuGenTreeNode).GetConstructor(new Type[] { typeof(string), typeof(int), typeof(int) }); parameters = new object[] { node.Text, node.ImageIndex, node.ExpandedImageIndex }; } else { info = typeof(NuGenTreeNode).GetConstructor(new Type[] { typeof(string), typeof(int), typeof(int), typeof(NuGenTreeNode[]) }); NuGenTreeNode[] nodes = new NuGenTreeNode[node.Nodes.Count]; node.Nodes.CopyTo(nodes, 0); parameters = new object[] { node.Text, node.ImageIndex, node.ExpandedImageIndex, nodes }; } if (info != null) { return(new InstanceDescriptor(info, parameters, false)); } } return(base.ConvertTo(context, culture, value, destinationType)); }
/* * ConvertTo */ /// <summary> /// Converts the given value object to the specified type, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param> /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see>. If null is passed, the current culture is assumed.</param> /// <param name="value">The <see cref="T:System.Object"></see> to convert.</param> /// <param name="destinationType">The <see cref="T:System.Type"></see> to convert the value parameter to.</param> /// <returns> /// An <see cref="T:System.Object"></see> that represents the converted value. /// </returns> /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception> /// <exception cref="T:System.ArgumentNullException">The destinationType parameter is null. </exception> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } NuGenTreeNode node = value as NuGenTreeNode; if (destinationType == typeof(InstanceDescriptor) && value != null) { MemberInfo info = null; object[] parameters = null; if (node.ImageIndex == -1 || node.ExpandedImageIndex == -1) { if (node.Nodes.Count == 0) { info = typeof(NuGenTreeNode).GetConstructor(new Type[] { typeof(string) }); parameters = new object[] { node.Text }; } else { info = typeof(NuGenTreeNode).GetConstructor(new Type[] { typeof(string), typeof(NuGenTreeNode[]) }); NuGenTreeNode[] nodes = new NuGenTreeNode[node.Nodes.Count]; node.Nodes.CopyTo(nodes, 0); parameters = new object[] { node.Text, nodes }; } } else if (node.Nodes.Count == 0) { info = typeof(NuGenTreeNode).GetConstructor(new Type[] { typeof(string), typeof(int), typeof(int) }); parameters = new object[] { node.Text, node.ImageIndex, node.ExpandedImageIndex }; } else { info = typeof(NuGenTreeNode).GetConstructor(new Type[] { typeof(string), typeof(int), typeof(int), typeof(NuGenTreeNode[]) }); NuGenTreeNode[] nodes = new NuGenTreeNode[node.Nodes.Count]; node.Nodes.CopyTo(nodes, 0); parameters = new object[] { node.Text, node.ImageIndex, node.ExpandedImageIndex, nodes }; } if (info != null) { return new InstanceDescriptor(info, parameters, false); } } return base.ConvertTo(context, culture, value, destinationType); }
/* * Clone */ /// <summary> /// Copies the tree node and the entire subtree rooted at this tree node. /// </summary> /// <returns> /// The <see cref="T:System.Object"></see> that represents the cloned <see cref="T:System.Windows.Forms.TreeNode"></see>. /// </returns> /// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet> public override object Clone() { NuGenTreeNode node = new NuGenTreeNode(); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this); foreach (PropertyDescriptor descriptor in properties) { descriptor.SetValue(node, descriptor.GetValue(this)); } if (this.Nodes.Count > 0) { foreach (NuGenTreeNode childNode in this.Nodes) { node.Nodes.Add((NuGenTreeNode)childNode.Clone()); } } return(node); }
private void BuildSampleTreeNode( ISampleFolderDescriptor sampleFolderDescriptor , DirectoryInfo sampleDirInfo , NuGenTreeNode treeNode , int folderImageIndex , int expandedFolderImageIndex , int sampleImageIndex ) { Debug.Assert(sampleFolderDescriptor != null, "sampleFolder != null"); Debug.Assert(sampleDirInfo != null, "sampleDirInfo != null"); Debug.Assert(treeNode != null, "treeNode != null"); string samplePath = null; string descriptionPath = null; string screenShotPath = null; string exePath = null; string csProjectPath = null; string vbProjectPath = null; /* * Algorithm: * Get description if available. * Get screen-shot if available. * Get the list of folders. * If CS folder exists, search for *.csproj file inside. And EXE in bin/Debug or bin/Release as well. * If VB folder exists, search for *.vbproj file inside. And EXE in bin/Debug or bin/Release if CS project does not exist. * Call this method recursively for other folders. */ FileInfo descriptionFileInfo = new FileInfo(Path.Combine(sampleDirInfo.FullName, sampleFolderDescriptor.DescriptionFileName)); if (descriptionFileInfo.Exists) { descriptionPath = descriptionFileInfo.FullName; } Debug.WriteLine("descriptionPath = " + descriptionPath); FileInfo screenShotFileInfo = new FileInfo(Path.Combine(sampleDirInfo.FullName, sampleFolderDescriptor.ScreenshotFileName)); if (screenShotFileInfo.Exists) { screenShotPath = screenShotFileInfo.FullName; } Debug.WriteLine("screenShotPath = " + screenShotPath); if (!string.IsNullOrEmpty(descriptionPath) && !string.IsNullOrEmpty(screenShotPath)) { samplePath = sampleDirInfo.FullName; } Debug.WriteLine("samplePath = " + samplePath); DirectoryInfo[] subDirInfoCollection = sampleDirInfo.GetDirectories(); Debug.WriteLine("Getting the list of sub-directories..."); Debug.WriteLineIf(subDirInfoCollection != null, "subDirInfoCollection.Length = " + subDirInfoCollection.Length.ToString()); if (subDirInfoCollection != null) { Debug.WriteLine("Looping through the sub-directories..."); foreach (DirectoryInfo subDirInfo in subDirInfoCollection) { if (subDirInfo.Name == sampleFolderDescriptor.CSProjectFolderName) { Debug.WriteLine("CS project folder found."); csProjectPath = this.GetProjectPath(subDirInfo, sampleFolderDescriptor.CSProjectExtension); Debug.WriteLine("csProjectPath = " + csProjectPath); if (exePath == null) { exePath = this.FindExe(Path.GetDirectoryName(csProjectPath)); } Debug.WriteLine("exePath = " + exePath); } else if (subDirInfo.Name == sampleFolderDescriptor.VBProjectFolderName) { Debug.WriteLine("VB project folder found."); vbProjectPath = this.GetProjectPath(subDirInfo, sampleFolderDescriptor.VBProjectExtension); Debug.WriteLine("vbProjectPath = " + vbProjectPath); if (exePath == null) { exePath = this.FindExe(Path.GetDirectoryName(vbProjectPath)); } Debug.WriteLine("exePath = " + exePath); } else { NuGenTreeNode childNode = treeNode; if (this.ShouldCreateSubFolder(sampleFolderDescriptor, subDirInfo)) { childNode = new NuGenTreeNode(subDirInfo.Name, folderImageIndex, expandedFolderImageIndex); treeNode.Nodes.Add(childNode); } this.BuildSampleTreeNode(sampleFolderDescriptor, subDirInfo, childNode, folderImageIndex, expandedFolderImageIndex, sampleImageIndex); } } } if (samplePath != null) { SampleDescriptor sampleDescriptor = new SampleDescriptor( samplePath , descriptionPath , screenShotPath , exePath , csProjectPath , vbProjectPath ); Debug.WriteLine("Creating a node with a sample descriptor assigned to the Tag property..."); NuGenTreeNode sampleNode = new NuGenTreeNode(sampleDirInfo.Name, sampleImageIndex, sampleImageIndex); sampleNode.Tag = sampleDescriptor; Debug.WriteLine("Adding the node to the parent node..."); treeNode.Nodes.Add(sampleNode); } }
public void AddDocument(Canvas canvas) { NuGenTreeNode treeNode = new NuGenTreeNode(canvas.ParentTabPage.Text, true, true); treeNode.Tag = canvas; _documents.Nodes.Add(treeNode); }
/// <summary> /// Initializes a new instance of the <see cref="NuGenTreeNode"/> class. /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="childNodes"/> is <see langword="null"/>.</para> /// </exception> public NuGenTreeNode(string nodeText, int imageIndex, int expandedImageIndex, NuGenTreeNode[] childNodes) : this(nodeText, imageIndex, expandedImageIndex) { if (childNodes == null) { throw new ArgumentNullException("childNodes"); } this.Nodes.AddRange(childNodes); }
/// <summary> /// Initializes a new instance of the <see cref="NuGenTreeNode"/> class.<para/> /// <c>HasCheckBox = true</c>. <c>Checked = false</c>. /// </summary> /// <exception cref="ArgumentNullException"> /// <para><paramref name="childNodes"/> is <see langword="null"/>.</para> /// </exception> public NuGenTreeNode(string nodeText, NuGenTreeNode[] childNodes) : this(nodeText) { if (childNodes == null) { throw new ArgumentNullException("childNodes"); } this.Nodes.AddRange(childNodes); }
/* * Clone */ /// <summary> /// Copies the tree node and the entire subtree rooted at this tree node. /// </summary> /// <returns> /// The <see cref="T:System.Object"></see> that represents the cloned <see cref="T:System.Windows.Forms.TreeNode"></see>. /// </returns> /// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet> public override object Clone() { NuGenTreeNode node = new NuGenTreeNode(); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(this); foreach (PropertyDescriptor descriptor in properties) { descriptor.SetValue(node, descriptor.GetValue(this)); } if (this.Nodes.Count > 0) { foreach (NuGenTreeNode childNode in this.Nodes) { node.Nodes.Add((NuGenTreeNode)childNode.Clone()); } } return node; }
public override object Clone() { NuGenTreeNode node = new NuGenTreeNode(); node.BackColor = this.BackColor; node.Checked = this.Checked; node.ContextMenu = this.ContextMenu; node.ContextMenuStrip = this.ContextMenuStrip; node.DefaultImageIndex = this.DefaultImageIndex; node.ExpandedImageIndex = this.ExpandedImageIndex; node.ForeColor = this.ForeColor; node.HasCheckBox = this.HasCheckBox; node.Name = this.Name; node.NodeFont = this.NodeFont; node.Tag = this.Tag; node.Text = this.Text; node.ToolTipText = this.ToolTipText; foreach (NuGenTreeNode childNode in this.Nodes) { node.Nodes.Add((NuGenTreeNode)childNode.Clone()); } return node; }