⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultdotnetnodebuilder.cs

📁 全功能c#编译器
💻 CS
📖 第 1 页 / 共 2 页
字号:
			switch(projectFile.Subtype) {
				case Subtype.Code:
					// add a source file
					switch (projectFile.BuildAction) {

						case BuildAction.Exclude:
							break;

						case BuildAction.EmbedAsResource:
							// no resources
							break;

						default:
							AbstractBrowserNode currentPathNode1;
							currentPathNode1 = GetPath(relativeFile, parentNode, true);

							AbstractBrowserNode newNode = new FileNode(projectFile);
							newNode.ContextmenuAddinTreePath = FileNode.ProjectFileContextMenuPath;
							//parentNode.Nodes.Add(newNode);
							
							SortUtility.SortedInsert(newNode, currentPathNode1.Nodes, TreeNodeComparer.ProjectNode);
							break;
					}
					break;
				case Subtype.Directory:
					{
						// add a directory
						string directoryName   = relativeFile;
						// if directoryname starts with ./ oder .\ //
						if (directoryName.StartsWith(".")) {
							directoryName =  directoryName.Substring(2);
						}
						
//						string parentDirectory = Path.GetFileName(directoryName);
						
						AbstractBrowserNode currentPathNode;
						currentPathNode = GetPath(Path.Combine(directoryName, "DUMMY"), parentNode, true);
						
						if (currentPathNode == null) {
							currentPathNode = parentNode;
							DirectoryNode newFolderNode  = new DirectoryNode(projectFile.Name);
							if (IsWebReference(currentPathNode)) {
								newFolderNode.OpenedImage = resourceService.GetBitmap("Icons.16x16.OpenWebReferenceFolder");
								newFolderNode.ClosedImage = resourceService.GetBitmap("Icons.16x16.ClosedWebReferenceFolder");
							} else {
								newFolderNode.OpenedImage = resourceService.GetBitmap("Icons.16x16.OpenFolderBitmap");
								newFolderNode.ClosedImage = resourceService.GetBitmap("Icons.16x16.ClosedFolderBitmap");
							}
							SortUtility.SortedInsert(newFolderNode, currentPathNode.Nodes, TreeNodeComparer.ProjectNode);
						}
					}
					break;
				case Subtype.WebReferences:
					{
						// add a web directory
						string directoryName   = relativeFile;
						// if directoryname starts with ./ oder .\ //
						if (directoryName.StartsWith(".")) {
							directoryName =  directoryName.Substring(2);
						}

						DirectoryNode newFolderNode  = new DirectoryNode(projectFile.Name);
						newFolderNode.OpenedImage = resourceService.GetBitmap("Icons.16x16.OpenWebReferenceFolder");
						newFolderNode.ClosedImage = resourceService.GetBitmap("Icons.16x16.ClosedWebReferenceFolder");

						string parentDirectory = Path.GetFileName(directoryName);
						projectNode.Nodes.Insert(2, newFolderNode);
					}
					break;
				case Subtype.WebForm:
					{
						// add the source file with the cool icon
						// set reference to the special context menu path
						AbstractBrowserNode currentPathNode1;
						currentPathNode1 = GetPath(relativeFile, parentNode, true);

						AbstractBrowserNode newNode = new FileNode(projectFile);
						newNode.IconImage = resourceService.GetBitmap("Icons.16x16.WebForm");
						newNode.ContextmenuAddinTreePath = FileNode.ProjectFileContextMenuPath;
						//parentNode.Nodes.Add(newNode);
						
						SortUtility.SortedInsert(newNode, currentPathNode1.Nodes, TreeNodeComparer.ProjectNode);
						// codeBehind?
					}

					break;

				case Subtype.WinForm:
					{
						// add the source file with the cool icon
						// set reference to the special context menu path
						AbstractBrowserNode currentPathNode1;
						currentPathNode1 = GetPath(relativeFile, parentNode, true);
						
						AbstractBrowserNode newNode = new FileNode(projectFile);
						newNode.IconImage = resourceService.GetBitmap("Icons.16x16.WinForm");
						newNode.ContextmenuAddinTreePath = FileNode.ProjectFileContextMenuPath;
						//parentNode.Nodes.Add(newNode);
						
						SortUtility.SortedInsert(newNode, currentPathNode1.Nodes, TreeNodeComparer.ProjectNode);
					}

					break;
				case Subtype.XmlForm:
					// not supported yet
					break;
				case Subtype.Dataset:
					// not supported yet
					break;
				case Subtype.WebService:
					// not supported yet
					break;
				default:
					// unknown file type
					break;
			}
			if(projectNode.TreeView != null)
				projectNode.TreeView.EndUpdate();
		}

		public static AbstractBrowserNode GetProjectNode(AbstractBrowserNode childNode) {
			// find and return the project node if it exists
			AbstractBrowserNode parentNode = childNode;
			while(parentNode != null) {
				if(parentNode is ProjectBrowserNode) {
					break;
				}
				parentNode = (AbstractBrowserNode)parentNode.Parent;
			}
			// this could be null!!!
			return parentNode;
		}

		public static AbstractBrowserNode GetNodeFromCollection(TreeNodeCollection collection, string title)
		{
			foreach (AbstractBrowserNode node in collection) {
				if (node.Text == title) {
					return node;
				}
			}
			return null;
		}


		public static AbstractBrowserNode GetPath(string filename, AbstractBrowserNode root, bool create)
		{
			string directory    = Path.GetDirectoryName(filename);
			string[] treepath   = directory.Split(Path.DirectorySeparatorChar, '\\', '/');
			AbstractBrowserNode curpathnode = root;

			foreach (string path in treepath) {
				if (path.Length == 0 || path[0] == '.') {
					continue;
				}

				AbstractBrowserNode node = GetNodeFromCollection(curpathnode.Nodes, path);

				if (node == null) {
					if (create) {
						DirectoryNode newFolderNode  = new DirectoryNode(fileUtilityService.GetDirectoryNameWithSeparator(ConstructFolderName(curpathnode)) + path);
						SortUtility.SortedInsert(newFolderNode, curpathnode.Nodes, TreeNodeComparer.ProjectNode);
						curpathnode = newFolderNode;
						continue;
					} else {
						return null;
					}
				}
				curpathnode = node;
			}

			return curpathnode;
		}

		static string ConstructFolderName(AbstractBrowserNode folderNode)
		{
			if (folderNode is DirectoryNode) {
				return ((DirectoryNode)folderNode).FolderName;
			}

			if (folderNode is ProjectBrowserNode) {
				return ((ProjectBrowserNode)folderNode).Project.BaseDirectory;
			}

			throw new ApplicationException("Folder name construction failed, got unexpected parent node :" +  folderNode);
		}

		public static AbstractBrowserNode GetNodeByName(string name) {
			return null;
		}

		public static void InitializeReferences(AbstractBrowserNode parentNode, IProject project)
		{
			parentNode.Nodes.Clear();
			foreach (ProjectReference referenceInformation in project.ProjectReferences) {
				string name = null;
				switch (referenceInformation.ReferenceType) {
					case ReferenceType.Typelib:
						int index = referenceInformation.Reference.IndexOf("|");
						if (index > 0) {
							name = referenceInformation.Reference.Substring(0, index);
						} else {
							name = referenceInformation.Reference;
						}
						break;
					case ReferenceType.Project:
						name = referenceInformation.Reference;
						break;
					case ReferenceType.Assembly:
						name = Path.GetFileName(referenceInformation.Reference);
						break;
					case ReferenceType.Gac:
						name = referenceInformation.Reference.Split(',')[0];
						break;
					default:
						throw new NotImplementedException("reference type : " + referenceInformation.ReferenceType);
				}

				AbstractBrowserNode newReferenceNode = new ReferenceNode(referenceInformation);
				ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
				newReferenceNode.IconImage = resourceService.GetBitmap("Icons.16x16.Reference");

				parentNode.Nodes.Add(newReferenceNode);
			}
			SortUtility.QuickSort(parentNode.Nodes, TreeNodeComparer.ProjectNode);
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -