private void GameDataTreeView_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e) { try { // Make sure an edit actually occured if (e.Label != null) { guiAssetTreeTag tag = (guiAssetTreeTag)e.Node.Tag; string sourceDirectoryName = tag.FullFilename; string targetDirectoryName = tag.FullFilename.Replace(e.Node.Text, e.Label); e.Node.Tag = new guiAssetTreeTag(targetDirectoryName, e.Node, false); if (!DosUtils.DirectoryMove(sourceDirectoryName, targetDirectoryName)) { MOG.PROMPT.MOG_Prompt.PromptResponse("Rename Directory", DosUtils.GetLastError(), MOGPromptButtons.OK); e.Node.Remove(); e.CancelEdit = true; } // Fire off our AfterSelect, so that it updates everything propertly e.Node.Text = e.Label; this.GameDataTreeView_AfterSelect(this.GameDataTreeView, new TreeViewEventArgs(e.Node, TreeViewAction.Unknown)); } GameDataTreeView.LabelEdit = false; } catch (Exception ex) { MOG.PROMPT.MOG_Prompt.PromptResponse("Rename Directory", ex.Message, MOGPromptButtons.OK); e.CancelEdit = true; e.Node.Remove(); GameDataTreeView.LabelEdit = false; } }
private TreeNode FindTreeNode(TreeNode parentNode, string title) { bool root = false; try { if (parentNode == null) { if (this.GameDataTreeView.Nodes != null && this.GameDataTreeView.Nodes.Count > 0) { parentNode = this.GameDataTreeView.Nodes[0]; root = true; } } if (parentNode != null) { if (root) { foreach (TreeNode node in this.GameDataTreeView.Nodes) { if (string.Compare(node.Text, Path.GetFileName(title), true) == 0) { if (node.Tag != null) { guiAssetTreeTag tag = (guiAssetTreeTag)node.Tag; if (string.Compare(tag.FullFilename, title, true) == 0) { return(node); } } } } } else { foreach (TreeNode node in parentNode.Nodes) { if (string.Compare(node.Text, Path.GetFileName(title), true) == 0) { if (node.Tag != null) { guiAssetTreeTag tag = (guiAssetTreeTag)node.Tag; if (string.Compare(tag.FullFilename, title, true) == 0) { return(node); } } } } } } } catch { } return(null); }
private void GameDataCreateMenuItem_Click(object sender, System.EventArgs e) { try { // Create a directory as a child directory of a node if (GameDataTreeView.SelectedNode != null) { guiAssetTreeTag tag = GameDataTreeView.SelectedNode.Tag as guiAssetTreeTag; string directoryPath = tag.FullFilename + "\\NewDirectory"; TreeNode directory = CreateDirectoryNode(tag.FullFilename + "\\NewDirectory"); // Now create the folder if (!DosUtils.DirectoryCreate(directoryPath)) { MOG_Prompt.PromptResponse("Create Directory", DosUtils.GetLastError(), MOGPromptButtons.OK); } else { // Now edit the name of this node GameDataTreeView.LabelEdit = true; GameDataTreeView.SelectedNode.Nodes.Add(directory); GameDataTreeView.SelectedNode = directory; GameDataTreeView.SelectedNode.BeginEdit(); } } else { // Create a directory at the root of the project string directoryPath = MOG_ControllerProject.GetCurrentSyncDataController().GetSyncDirectory() + "\\NewDirectory"; TreeNode directory = CreateDirectoryNode(directoryPath); // Now create the folder if (!DosUtils.DirectoryCreate(directoryPath)) { MOG_Prompt.PromptResponse("Create Directory", DosUtils.GetLastError(), MOGPromptButtons.OK); } else { // Now edit the name of this node GameDataTreeView.LabelEdit = true; GameDataTreeView.SelectedNode = directory; directory.BeginEdit(); } } } catch (Exception ex) { MOG_Report.ReportMessage("Create Directory", ex.Message, ex.StackTrace, MOG_ALERT_LEVEL.CRITICAL); } }
private void GameDataDeleteMenuItem_Click(object sender, System.EventArgs e) { try { guiAssetTreeTag tag = (guiAssetTreeTag)GameDataTreeView.SelectedNode.Tag; if (MOG_Prompt.PromptResponse("Delete Directory", "Are you sure you wan to delete this directory with all its contents?\n\nDirectory:\n\n" + tag.FullFilename, MOGPromptButtons.YesNo) == MOGPromptResult.Yes) { // Remove the node GameDataTreeView.SelectedNode.Remove(); } } catch (Exception ex) { MOG_Prompt.PromptMessage("Delete Directory", "Could not delete this directory!\n\nMessage:" + ex.Message); } }
private void ExpandTreeNode(System.Windows.Forms.TreeViewCancelEventArgs e) { // Get our initial root path from our treeView Tag string rootPath = (string)e.Node.TreeView.Tag; if (e.Node.Nodes[0].Text == "BLANK") { try { guiAssetTreeTag info = null; if (mVirtual) { info = (guiAssetTreeTag)e.Node.Tag; if (info != null) { // Clear out the temp node if (e.Node.Nodes.Count == 1 && e.Node.Nodes[0].Text == "BLANK") { e.Node.Nodes.Clear(); } string workspaceDirectory = info.Object as string; VirtualExpand(e.Node, info.FullFilename, workspaceDirectory); // Add any non MOG files FillDirectory(e.Node, info.FullFilename, SystemColors.GrayText); } } else if (Path.IsPathRooted(e.Node.FullPath)) { //info = (guiAssetTreeTag)e.Node.Tag; FillDirectory(e.Node, e.Node.FullPath, SystemColors.ControlText); } else { string[] parts = rootPath.Split(":".ToCharArray()); string drive = parts[0]; FillDirectory(e.Node, drive + ":\\" + e.Node.FullPath, SystemColors.ControlText); } } catch { } } }
private void GameDataContextMenu_Opening(object sender, CancelEventArgs e) { GameDataCreateMenuItem.Enabled = true; this.GameDataDeleteMenuItem.Enabled = false; this.GameDataRenameMenuItem.Enabled = false; if (GameDataTreeView.SelectedNode != null && GameDataTreeView.SelectedNode.Tag != null) { guiAssetTreeTag tag = GameDataTreeView.SelectedNode.Tag as guiAssetTreeTag; // We can only rename and delete directories that both exist and are non mog controlled (SystemColors.GrayText) if (Directory.Exists(tag.FullFilename) && GameDataTreeView.SelectedNode.ForeColor == SystemColors.GrayText) { this.GameDataDeleteMenuItem.Enabled = true; this.GameDataRenameMenuItem.Enabled = true; } } }
/// <summary> /// Create a virtual node of directories only based on its fullpath /// </summary> /// <param name="tree"></param> /// <param name="parent"></param> /// <param name="controller"></param> /// <param name="delimiter"></param> /// <param name="fullPath"></param> /// <param name="verifyFilename"></param> /// <param name="VirtualImageIndex"></param> /// <param name="NonVirtualImageIndex"></param> /// <param name="VirtualFileImageIndex"></param> /// <param name="NonVirtualFileImageIndex"></param> /// <returns></returns> private TreeNode CreateTreeNodeFullPath(TreeView tree, TreeNode parent, string workspaceDirectory, string delimiter, string fullPath, string verifyFilename, DirectorySetInfo fileInfo, int VirtualImageIndex, int NonVirtualImageIndex, int VirtualFileImageIndex, int NonVirtualFileImageIndex, bool directoriesOnly) { TreeNodeCollection topNodes = null; // Get our collections to search if (parent != null) { topNodes = parent.Nodes; } else { topNodes = tree.Nodes; } // Split the full path by the delimiter passed in string[] lastNodeParts = fullPath.Split(delimiter.ToCharArray()); // find the first name TreeNode alreadyExistNode = null; if (parent != null && string.Compare(parent.Text, lastNodeParts[0], true) == 0) { alreadyExistNode = parent; } else { alreadyExistNode = FindTreeNode(topNodes, lastNodeParts[0]); } // if exist find then next from the children of the first if (alreadyExistNode != null) { // Is this a file or directory if (fileInfo.Type == DirectorySetInfo.TYPE.Folder || fileInfo.Type == DirectorySetInfo.TYPE.FolderName) { // Must be a directory if (!DosUtils.PathIsDriveRooted(verifyFilename) || Directory.Exists(verifyFilename)) { alreadyExistNode.ImageIndex = NonVirtualImageIndex; alreadyExistNode.SelectedImageIndex = NonVirtualImageIndex; alreadyExistNode.ForeColor = SystemColors.ControlText; } else { alreadyExistNode.ImageIndex = VirtualImageIndex; alreadyExistNode.SelectedImageIndex = VirtualImageIndex; alreadyExistNode.ForeColor = SystemColors.GrayText; } } else { // Must be a file if (!DosUtils.PathIsDriveRooted(verifyFilename) || File.Exists(verifyFilename)) { alreadyExistNode.ImageIndex = NonVirtualFileImageIndex; alreadyExistNode.SelectedImageIndex = NonVirtualFileImageIndex; alreadyExistNode.ForeColor = SystemColors.ControlText; } else { alreadyExistNode.ImageIndex = VirtualFileImageIndex; alreadyExistNode.SelectedImageIndex = VirtualFileImageIndex; alreadyExistNode.ForeColor = SystemColors.GrayText; } } string LastNodePath = ""; // Update our path to be less than what it was for (int i = 1; i < lastNodeParts.Length; i++) { if (LastNodePath.Length == 0) { LastNodePath = lastNodeParts[i]; } else { LastNodePath = LastNodePath + "\\" + lastNodeParts[i]; } } if (LastNodePath.Length > 0) { // recurse into this function for the next node parent = CreateTreeNodeFullPath(tree, alreadyExistNode, workspaceDirectory, delimiter, LastNodePath, verifyFilename, fileInfo, VirtualImageIndex, NonVirtualImageIndex, VirtualFileImageIndex, NonVirtualFileImageIndex, directoriesOnly); } } // if not, create it and all its children right here else { foreach (string nodeLeafName in lastNodeParts) { if (nodeLeafName.Length > 0) { // If we are a file and this is a directoriesOnly create, skip if (fileInfo.Type == DirectorySetInfo.TYPE.File && directoriesOnly) { break; } // Create a node TreeNode newChild = new TreeNode(nodeLeafName); guiAssetTreeTag info = new guiAssetTreeTag(verifyFilename, newChild, workspaceDirectory, true); // Is this a file or directory if (fileInfo.Type == DirectorySetInfo.TYPE.Folder || fileInfo.Type == DirectorySetInfo.TYPE.FolderName) { // Set our type info.TagType = guiAssetTreeTag.TREE_FOCUS.FOLDER; // Must be a directory if (!DosUtils.PathIsDriveRooted(verifyFilename) || Directory.Exists(verifyFilename)) { newChild.ImageIndex = NonVirtualImageIndex; newChild.SelectedImageIndex = NonVirtualImageIndex; newChild.ForeColor = SystemColors.ControlText; } else { newChild.ImageIndex = VirtualImageIndex; newChild.SelectedImageIndex = VirtualImageIndex; newChild.ForeColor = SystemColors.GrayText; } } else { // Set our type info.TagType = guiAssetTreeTag.TREE_FOCUS.FILE; // Must be a file if (!DosUtils.PathIsDriveRooted(verifyFilename) || File.Exists(verifyFilename)) { newChild.ImageIndex = NonVirtualFileImageIndex; newChild.SelectedImageIndex = NonVirtualFileImageIndex; newChild.ForeColor = SystemColors.ControlText; } else { newChild.ImageIndex = VirtualFileImageIndex; newChild.SelectedImageIndex = VirtualFileImageIndex; newChild.ForeColor = SystemColors.GrayText; } } if (parent != null) { parent.Nodes.Add(newChild); parent = newChild; } else { int index = tree.Nodes.Add(newChild); parent = tree.Nodes[index]; } newChild.Tag = info; } } // If we are a file and this is a directoriesOnly create, skip if (fileInfo.Type == DirectorySetInfo.TYPE.File && directoriesOnly) { return(null); } return(parent); } return(null); }
/// <summary> /// Fetch the next set of files and folders for this parent folder /// </summary> /// <param name="parent"></param> /// <param name="fullPath"></param> /// <param name="targetGameData"></param> private void VirtualExpand(TreeNode parent, string fullPath, string workspaceDirectory) { try { // If we have a gameData target we need to remove it from our path prepatory to the Dictionary lookup of the children of this folder if (DosUtils.PathIsWithinPath(workspaceDirectory, fullPath)) { // Also remove any begininng backslashes fullPath = DosUtils.PathMakeRelativePath(workspaceDirectory, fullPath); } HybridDictionary dic = mSyncTargetFiles.GetFiles(fullPath); if (dic != null) { // Search our btree for the children of this folder IDictionaryEnumerator file = dic.GetEnumerator(); // Now itterate through those children while (file.MoveNext()) { string fullDirectoryName = ""; // we now need to reconstruct the full path to this file or folder if (fullPath.Length == 0) { fullDirectoryName = workspaceDirectory + "\\" + file.Key; } else { fullDirectoryName = workspaceDirectory + "\\" + fullPath + "\\" + file.Key; } DirectorySetInfo fileInfo = (DirectorySetInfo)file.Value; // Create the node TreeNode newNode = CreateTreeNodeFullPath(GameDataTreeView, parent, workspaceDirectory, "\\", file.Key as string, fullDirectoryName, fileInfo, 0, 0, 0, 0, true); // If this is a newly created node and it is a folder, we assume it has children and create a black node beneath it if (newNode != null && newNode.Nodes.Count == 0) { guiAssetTreeTag info = (guiAssetTreeTag)newNode.Tag; string relationalPath = ""; // Get a relational path to this folder if (fullPath.Length == 0) { relationalPath = file.Key as string; } else { relationalPath = fullPath + "\\" + file.Key; } // If this file is a folder and has children, create a place holder 'blank' if (info != null && info.TagType == guiAssetTreeTag.TREE_FOCUS.FOLDER && mSyncTargetFiles.HasFolderChildren(relationalPath, false)) { newNode.Nodes.Add("BLANK"); } } } } } catch { } }