/// <summary> /// Handle the 'New package' menu item click /// </summary> private void PackageNewPackageMenuItem_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; if (ProjectPackagesTreeView.SelectedNode != null) { Mog_BaseTag tag = ProjectPackagesTreeView.SelectedNode.Tag as Mog_BaseTag; if (tag != null && tag.PackageNodeType == PackageNodeTypes.Class) { PackageCreator creator = new PackageCreator(); creator.Classification = ProjectPackagesTreeView.SelectedNode.FullPath; if (menuItem != null) { if (MOG_ControllerProject.IsValidPlatform(menuItem.Text) || String.Compare(menuItem.Text, MOG_ControllerProject.GetAllPlatformsString(), true) == 0) { creator.Platform = menuItem.Text; } } if (creator.ShowDialog(this) == DialogResult.OK) { if (creator.AssetName != null) { // Re-create the tree then drill down to the newly created package ProjectPackagesTreeView.DeInitialize(); ProjectPackagesTreeView.LastNodePath = creator.AssetName.GetAssetClassification() + ProjectPackagesTreeView.PathSeparator + creator.AssetName.GetAssetName(); ProjectPackagesTreeView.Initialize(); } } } } }
protected TreeNode CreateSyncTargetTreeNode(MOG_DBSyncTargetInfo info, string platform) { bool ableToGetSourceFileAssetLinks = false; string currentVersionStamp = info.mVersion; MOG_Filename tempFilename = MOG_Filename.CreateAssetName(info.mAssetClassification, info.mAssetPlatform, info.mAssetLabel); MOG_Filename assetRealFile = MOG_ControllerRepository.GetAssetBlessedVersionPath(tempFilename, currentVersionStamp); // Create node with FocusLevel that does not plug into the BaseLeafTreeView TreeNode node = new TreeNode(info.FilenameOnly, new TreeNode[] { new TreeNode(Blank_Node_Text) }); Mog_BaseTag tag = new Mog_BaseTag(node, assetRealFile.GetEncodedFilename(), RepositoryFocusLevel.Classification, true); node.Name = tempFilename.GetAssetFullName(); tag.AttachedSyncTargetInfo = info; node.Tag = tag; string gamedataFilePath; if (ableToGetSourceFileAssetLinks) { gamedataFilePath = assetRealFile.GetEncodedFilename() + "\\Files.Imported\\" + info.mSyncTargetFile; } else { gamedataFilePath = assetRealFile.GetEncodedFilename() + "\\Files.Imported\\" + info.FilenameOnly; } //This is either a file or an asset SetImageIndices(node, base.GetAssetFileImageIndex(gamedataFilePath)); return(node); }
/// <summary> /// Make sure that we keep our currently selected node's FullPath stored in our global variable. /// </summary> private void MogControl_BaseTreeView_AfterSelect(object sender, TreeViewEventArgs e) { // If we are not ignoring events... if (!bIgnoreEvents) { // Save the path of our last selected node Mog_BaseTag tag = e.Node.Tag as Mog_BaseTag; if (tag != null) { MOG_Filename filename = new MOG_Filename(tag.FullFilename); mLastNodePath = filename.GetAssetFullName(); } } }
private void MogControl_BaseTreeView_DragDrop(object sender, DragEventArgs e) { // We will only accept a ArrayListAssetManager type object if (e.Data.GetDataPresent("ProjectTreeView")) { // Get our array list ArrayList items = (ArrayList)e.Data.GetData("ProjectTreeView"); foreach (TreeNode classObj in items) { Mog_BaseTag objInfo = classObj.Tag as Mog_BaseTag; bool success = false; // If we are a classification if (objInfo != null && objInfo.PackageNodeType == PackageNodeTypes.Class) { // Prompt user to make sure they did this intentionally string message = "Are you sure you want to move this classification?\n\n" + "CLASSIFICATION: " + classObj.Text + "\n" + "TARGET: " + SelectedNode.FullPath; if (MOG_Prompt.PromptResponse("Move Classification?", message, MOGPromptButtons.YesNoCancel) == MOGPromptResult.Yes) { // Do classification move here!!! success = MOG_ControllerProject.GetProject().ClassificationRename(classObj.FullPath, SelectedNode.FullPath + "~" + classObj.Text); } } // Is it an asset else if (objInfo != null && (objInfo.PackageNodeType == PackageNodeTypes.Asset || objInfo.PackageNodeType == PackageNodeTypes.Package)) { // Prompt user to make sure they did this intentionally string message = "Are you sure you want to move this asset?\n\n" + "ASSET: " + classObj.Text + "\n" + "NEW CLASSIFICATION: " + SelectedNode.FullPath; if (MOG_Prompt.PromptResponse("Move Asset?", message, MOGPromptButtons.YesNoCancel) == MOGPromptResult.Yes) { // Do Asset move here!!! MOG_Filename assetFullname = new MOG_Filename(objInfo.FullFilename); success = MOG_ControllerProject.GetProject().AssetRename(classObj.FullPath, SelectedNode.FullPath + "~" + classObj.Text); } } AllowDrop = false; } } AllowDrop = true; }
/// <summary> /// Walk up the parent chain putting together our class /// </summary> private string FindClassification(TreeNode node) { try { Mog_BaseTag tag = (Mog_BaseTag)node.Tag; if (tag.PackageNodeType == PackageNodeTypes.Class) { if (node.Parent != null) { return(FindClassification(node.Parent) + "~" + node.Text); } else { return(node.Text); } } else { if (node.Parent != null) { return(FindClassification(node.Parent)); } else { return(""); } } } catch { if (node != null) { if (node.Parent != null) { return(FindClassification(node.Parent)); } else { return(""); } } } return(""); }
protected override void ExpandTreeDown(TreeNode node) { if (node != null && node.Nodes.Count > 0 && node.Nodes[0].Text == Blank_Node_Text) { UseWaitCursor = true; this.Cursor = System.Windows.Forms.Cursors.WaitCursor; if (IsAtAssetLevel(node) && this.ExpandAssets) { // Expand our Asset/Package nodes base.ExpandTreeDown(node); } else { node.Nodes.Clear(); if (node.FullPath.IndexOf(PathSeparator) == -1) { // This is our first node, populate platform(s) ExpandSyncTargetPlatforms(node); } else { //This is a platform-specific node... string nodePlatform = GetPlatformNameFromFullPath(node.FullPath); Mog_BaseTag tag = node.Tag as Mog_BaseTag; if (tag != null) { MOG_Filename filename = new MOG_Filename(tag.FullFilename); if (filename.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset) { ExpandSyncTargetAssetNode(node, nodePlatform); } else { ExpandSyncTargetSubNodes(node, nodePlatform); } } } } this.Cursor = System.Windows.Forms.Cursors.Default; UseWaitCursor = false; } }
/// <summary> /// Prepare a drag object to recieve any driped items from the package tree /// </summary> public DataObject GetItemDragEventDataObject() { if (Nodes.Count > 0) { Mog_BaseTag tag = SelectedNode.Tag as Mog_BaseTag; if (tag != null) { string packageFullPath = tag.PackageFullName; ArrayList packages = new ArrayList(); packages.Add(packageFullPath); // Create a new Data object for the send return new DataObject("Package", packages); } } return null; }
public virtual void MakeAssetCurrent(MOG_Filename assetFilename) { // Make sure this assetFilename has the info we want if (assetFilename != null && assetFilename.GetVersionTimeStamp().Length > 0) { TreeNode foundNode = FindNode(assetFilename.GetAssetFullName()); if (foundNode != null) { // Update this parent node with the new information concerning this asset Mog_BaseTag assetTag = foundNode.Tag as Mog_BaseTag; if (assetTag != null) { assetTag.FullFilename = assetFilename.GetOriginalFilename(); } } else { // Try to find the asset's classification node? foundNode = FindNode(assetFilename.GetAssetClassification()); if (foundNode != null) { // Create a new asset node TreeNode assetNode = CreateAssetNode(assetFilename); // Find the right spot in the list for this new asset int insertPosition = 0; foreach (TreeNode node in foundNode.Nodes) { if (string.Compare(node.Text, assetNode.Text, true) < 0) { insertPosition++; } break; } // Insert the new asset node foundNode.Nodes.Insert(insertPosition, assetNode); } } } }
/// <summary> /// Used to get an Asset node with a good node.Tag for this TreeView or any inheriting classes. /// Does not use full filename. /// </summary> protected override TreeNode CreateAssetNode(MOG_Filename asset) { TreeNode assetNode = base.CreateAssetNode(asset); // If we are expandingAssets or expandingPackageGroups, we need to be able to expand down if (ExpandAssets || ExpandPackageGroups) { // Add the dummy node so the usere will be given the opportunity to expand it assetNode.Nodes.Add(new TreeNode(Blank_Node_Text)); } // Rebuild the node's tag MOG_Filename assetFile = MOG_ControllerProject.GetAssetCurrentBlessedPath(asset); Mog_BaseTag tag = new Mog_BaseTag(assetNode, assetFile.GetEncodedFilename(), FocusForAssetNodes, true); tag.PackageNodeType = PackageNodeTypes.Asset; tag.PackageFullName = assetFile.GetAssetFullName(); assetNode.Tag = tag; return(assetNode); }
private void ExpandSyncTargetAssetNode(TreeNode gamedataNode, string platform) { Mog_BaseTag gamedataTag = (Mog_BaseTag)gamedataNode.Tag; // If we have valid data... if (gamedataTag.AttachedSyncTargetInfo != null) { // Key is gamedataFilename, Value is gamedataFilenameOnly MOG_DBSyncTargetInfo gamedataInfo = gamedataTag.AttachedSyncTargetInfo; string currentVersionStamp = gamedataInfo.mVersion; MOG_Filename tempFilename = MOG_Filename.CreateAssetName(gamedataInfo.mAssetClassification, gamedataInfo.mAssetPlatform, gamedataInfo.mAssetLabel); MOG_Filename assetRealFile = MOG_ControllerRepository.GetAssetBlessedVersionPath(tempFilename, currentVersionStamp); // Add the asset this gamedata file is associated with under the oldGamedataNode TreeNode assetNode = new TreeNode(assetRealFile.GetAssetFullName(), new TreeNode[] { new TreeNode(Blank_Node_Text) }); assetNode.Tag = new Mog_BaseTag(assetNode, assetRealFile.GetEncodedFilename(), LeafFocusLevel.RepositoryItems, true); assetNode.Name = assetRealFile.GetAssetFullName(); gamedataNode.Nodes.Add(assetNode); SetImageIndices(assetNode, GetAssetFileImageIndex(assetRealFile.GetEncodedFilename())); } }
private void ExpandArchivalTreeDown(TreeNode node) { // Create names for our lookup into the DB string parentClassification = node.FullPath; string branchName = MOG_ControllerProject.GetBranchName(); // Make our node.Tag easy to use Mog_BaseTag parentTag = (Mog_BaseTag)node.Tag; // Get a list of the classifications for our regular views ArrayList classifications; // If we have attached classifications, use them if (parentTag.AttachedClassifications != null && parentTag.AttachedClassifications.Count > 0) { classifications = parentTag.AttachedClassifications; } else { classifications = MOG_ControllerProject.GetProject().GetSubClassifications(parentClassification, branchName); } // Get a list of archived classifications to compare our regular classifications to ArrayList archiveClassifications = MOG_ControllerProject.GetProject().GetArchivedSubClassifications(parentClassification); // If we have null classifcations, quit our function if (classifications == null || archiveClassifications == null) { return; } FillInClassifications(node, classifications, archiveClassifications); //Populate assets for this classification // If classificationNode is in a treeView (so we can use the FullPath property) AND we want Assets... if (node.TreeView != null && ExpandAssets) { FillInAssets(node); } }
/// <summary> /// Remove a Package from the PackageManagement Tree. /// Adapted from MogControl_AssetContextMenu.cs::MenuItemRemoveFromProject_Click() /// </summary> private void RemovePackageFromProject(Mog_BaseTag packageTag) { try { string message = "Are you sure you want to remove this package from the game?\r\n" + packageTag.PackageFullName; // If user OKs our removal... if (MOG_Prompt.PromptResponse("Remove Asset From Project", message, MOGPromptButtons.OKCancel) == MOGPromptResult.OK) { if (packageTag.Execute) { MOG_Filename filename = new MOG_Filename(packageTag.FullFilename); // Make sure we are an asset before showing log if (filename.GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset) { // Proceed to remove this package from the project; skiping the unpackage merge event if (MOG_ControllerProject.RemoveAssetFromProject(filename, "No longer needed", false)) { // Go ahead and actually remove the node packageTag.ItemRemove(); } else { MOG_Prompt.PromptMessage("Remove Package From Project Failed", "The package could not be removed from the project.\n" + "PACKAGE: " + filename.GetAssetFullName() + "\n\n" + "We are now aborting the remove process.\n", Environment.StackTrace); return; } } } } } catch (Exception ex) { MOG_Report.ReportMessage("Remove From Project", ex.Message, ex.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.CRITICAL); } }
private void FillInClassifications(TreeNode node, ArrayList classifications, ArrayList archiveClassifications) { string parentClassification = node.FullPath; string branchName = MOG_ControllerProject.GetBranchName(); Mog_BaseTag parentTag = (Mog_BaseTag)node.Tag; // Fill in our classifications, comparing to archive classifications foreach (string childTempClassification in archiveClassifications) { // Hold the childClassification name in a mutable variable string childClassification = parentClassification + PathSeparator + childTempClassification; TreeNode classificationNode = new TreeNode(); // Add our classification node classificationNode.Text = childTempClassification; classificationNode.Tag = new Mog_BaseTag(classificationNode, childClassification); ((Mog_BaseTag)classificationNode.Tag).PackageNodeType = PackageNodeTypes.Class; // If we are in the Archive View and this classification is not in our classifications, // change our color to Archive_Color if (!classifications.Contains(childTempClassification)) { classificationNode.ForeColor = Archive_Color; } node.Nodes.Add(classificationNode); classificationNode.Name = classificationNode.FullPath; SetImageIndices(classificationNode, GetClassificationImageIndex(classificationNode.FullPath)); // JohnRen - Speed up trees (This is a lot of extra work just so we can know if there is anything inside) if (true) { // Add our node classificationNode.Nodes.Add(new TreeNode(Blank_Node_Text)); } } }
private void MogControl_BaseTreeView_DragOver(object sender, DragEventArgs e) { // Make sure we only display the drag-n-drop icon (via Windows) if we have the right data... if (e.Data.GetData("ProjectTreeView") != null) { TreeView tree = sender as TreeView; // Get the node at the location of our drag tree.SelectedNode = tree.GetNodeAt(PointToClient(new Point(e.X, e.Y))); if (tree.SelectedNode != null) { Mog_BaseTag classObj = tree.SelectedNode.Tag as Mog_BaseTag; // Make sure this target is a class if (classObj != null && classObj.PackageNodeType == PackageNodeTypes.Class) { e.Effect = DragDropEffects.Move; // Chedk if it has been enough time hovering over this classification, if it has expand it. if (hoverTarget != tree.SelectedNode.FullPath) { hoverTarget = tree.SelectedNode.FullPath; hoverTargetChanged = DateTime.Now.AddMilliseconds(500); } else if (hoverTarget == tree.SelectedNode.FullPath && DateTime.Now >= hoverTargetChanged) { tree.SelectedNode.Expand(); } return; } } } e.Effect = DragDropEffects.None; }
public override void MakeAssetCurrent(MOG_Filename assetFilename) { // Call our parent's MakeAssetCurrent base.MakeAssetCurrent(assetFilename); // Make sure this assetFilename has the info we want if (assetFilename != null && assetFilename.GetVersionTimeStamp().Length > 0) { TreeNode foundNode = FindNode(assetFilename.GetAssetFullName()); if (foundNode != null) { // Check if this node was previously marked as a deleted version? if (foundNode.ForeColor == Archive_Color) { // Collapse this baby and let it get rebuilt the next time the user expands it because it needs to change it internal structure foundNode.Collapse(); foundNode.Nodes.Clear(); foundNode.Nodes.Add(Blank_Node_Text); } // Reset the color foundNode.ForeColor = Color.Black; // Update this parent node with the new information concerning this asset Mog_BaseTag assetTag = foundNode.Tag as Mog_BaseTag; if (assetTag != null) { // Create a dateFormat just like that used in standard MS Windows USA regional date settings string dateFormat = MOG_Tokens.GetMonth_1() + "/" + MOG_Tokens.GetDay_1() + "/" + MOG_Tokens.GetYear_4() + " " + MOG_Tokens.GetHour_1() + ":" + MOG_Tokens.GetMinute_2() + " " + MOG_Tokens.GetAMPM(); // Scan the children nodes looking for other places needing to be fixed up foreach (TreeNode node in foundNode.Nodes) { // Make sure this is a valid node? if (node != null) { // Checkif this is the 'All Revisions'? if (node.Text == Revisions_Text) { bool bFoundCurrentRevisionNode = false; // Fixup this list of revisions foreach (TreeNode revisionNode in node.Nodes) { Mog_BaseTag baseTag = revisionNode.Tag as Mog_BaseTag; if (baseTag != null) { MOG_Filename revisionFilename = new MOG_Filename(baseTag.FullFilename); if (revisionFilename.GetVersionTimeStamp() == assetFilename.GetVersionTimeStamp()) { revisionNode.ForeColor = CurrentVersion_Color; bFoundCurrentRevisionNode = true; } else { revisionNode.ForeColor = Color.Black; } } } // Check if we need to add our new revision node? if (!bFoundCurrentRevisionNode) { // Looks like this is a new revision and needs to be added // Hey Whipple - What do I do here? // It seems like this is already added by an earlier event so I suspect we will never hit this. } } else { // Check if this is the 'Current <' node if (node.Text.StartsWith(Current_Text + " <")) { node.Text = Current_Text + " <" + assetFilename.GetVersionTimeStampString(dateFormat) + ">"; } // Update it's tag Mog_BaseTag currentTag = node.Tag as Mog_BaseTag; if (currentTag != null) { assetTag.FullFilename = assetFilename.GetOriginalFilename(); } // Finally collapse this baby and let it get rebuilt the next time the user expands it node.Collapse(); node.Nodes.Clear(); node.Nodes.Add(Blank_Node_Text); } } } } } } }
private void PackageRemoveMenuItem_Click(object sender, System.EventArgs e) { try { TreeNode selectedNode = ProjectPackagesTreeView.SelectedNode; // If we have not expanded this node, go ahead and do so... if (selectedNode != null && !selectedNode.IsExpanded) { // Get rid of any Blank node selectedNode.Expand(); } // Make sure we have a selected node and that that node does not have sub nodes other than the blank node if (selectedNode != null && selectedNode.Nodes.Count == 0) { Mog_BaseTag packageTag = (Mog_BaseTag)ProjectPackagesTreeView.SelectedNode.Tag; // Are we a package? if (packageTag.PackageNodeType == PackageNodeTypes.Asset || packageTag.PackageNodeType == PackageNodeTypes.Package) { RemovePackageFromProject(packageTag); return; } // Are we a classification? else if (packageTag.PackageNodeType == PackageNodeTypes.Class) { MessageBox.Show(this, "Cannot remove a Classification node. Please go to Project Tab | Project Trees " + "to be able to do this."); return; } string removeCandidate = ProjectPackagesTreeView.SelectedNode.Text; // Find our parent package TreeNode package = ProjectPackagesTreeView.FindPackage(ProjectPackagesTreeView.SelectedNode); if (package != null) { MOG_Filename packageAsset = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename); // Remove the classification from our fullPath string objectPath = ProjectPackagesTreeView.SelectedNode.FullPath.Replace(packageAsset.GetAssetClassification() + "/", ""); // First, get the index of our package name int assetNameIndex = objectPath.IndexOf(packageAsset.GetAssetName()); // If we have a valid index for the package's name... if (assetNameIndex > -1) { // Remove everything before our package name objectPath = objectPath.Substring(assetNameIndex); } // Now remove our package name objectPath = objectPath.Replace(packageAsset.GetAssetName(), ""); // Add back in our Group/Object separator objectPath = objectPath.Replace("~", "/"); // If we have an initial forward slash... if (objectPath.IndexOf("/") == 0) { // Get rid of it objectPath = objectPath.Substring(1); } // If we can remove it from the databse, remove the treenode? if (ProjectPackagesTreeView.RemoveGroupFromDatabase(objectPath, packageAsset)) { // Remove the node ProjectPackagesTreeView.SelectedNode.Remove(); } } } else { MOG_Prompt.PromptMessage("Remove node", "Could not remove this node because:\n\tNode must not contain any sub-nodes before removal."); } } catch (Exception ex) { MOG_Report.ReportMessage("Remove node", "MOG encountered an unexpected problem. Aborting node remove.\nSystem Message:" + ex.Message, ex.StackTrace, MOG.PROMPT.MOG_ALERT_LEVEL.CRITICAL); } }
/// <summary> /// Parses through our mSyncTargetFiles to figure out what should be added where /// </summary> private void ExpandSyncTargetSubNodes(TreeNode node, string platformName) { SyncTargetPlatform platform = mSyncTargetFileManager.GetPlatform(platformName); ArrayList fileNodes = new ArrayList(); int baseFolderIndex = MogUtil_AssetIcons.GetClassIconIndex(BaseFolder_ImageText); // Go through each entry we created when we initialized foreach (KeyValuePair <string, SyncTargetFolder> entry in platform.Folders) { SyncTargetFolder folder = entry.Value as SyncTargetFolder; string relativePath = folder.Path; string nodePath = node.FullPath; if (String.Compare(relativePath, node.FullPath, true) == 0) { //This is the folder that matches the node we're expanding //Go through and get all the files from the folder so we can add nodes for them //We will add these to the current node after we finish going through and adding all the folders foreach (MOG_DBSyncTargetInfo info in folder.Files) { TreeNode fileNode = CreateSyncTargetTreeNode(info, platformName); fileNodes.Add(fileNode); } } else if (relativePath.StartsWith(nodePath + PathSeparator, StringComparison.CurrentCultureIgnoreCase)) { // We found a node with a path that is a parent to us in the hiererchy // Get rid of our current node's path (preparatory to using relativePath as a node.Text) relativePath = relativePath.Substring(nodePath.Length + PathSeparator.Length); if (relativePath.Length > 0) { //If there's a path separator we only want the first part before the separator if (relativePath.Contains(PathSeparator)) { //Just grab the first part of the string, everything before the ~ relativePath = relativePath.Substring(0, relativePath.IndexOf(PathSeparator)); } if (!SyncTargetSubNodeExists(node, relativePath)) { // create a new subnode to represent this folder TreeNode temp = new TreeNode(relativePath, new TreeNode[] { new TreeNode(Blank_Node_Text) }); temp.Tag = new Mog_BaseTag(temp, temp.Text); node.Nodes.Add(temp); temp.ImageIndex = baseFolderIndex; temp.SelectedImageIndex = temp.ImageIndex; } } } } // Add all the file nodes we found above... foreach (TreeNode fileNode in fileNodes) { // Add each node and set its icon node.Nodes.Add(fileNode); Mog_BaseTag tag = fileNode.Tag as Mog_BaseTag; if (tag != null) { string assetFullFilename = tag.FullFilename; string foundFilename = FindAssetsFile(fileNode.Text, assetFullFilename); //Set the image for this node if (foundFilename.Length > 0 || (new MOG_Filename(assetFullFilename)).GetFilenameType() == MOG_FILENAME_TYPE.MOG_FILENAME_Asset) { //This is either a file or an asset SetImageIndices(fileNode, GetAssetFileImageIndex(foundFilename)); } else { //This is a folder fileNode.ImageIndex = baseFolderIndex; fileNode.SelectedImageIndex = fileNode.ImageIndex; } } } }