/// <summary> /// We need to make sure the users does not create a new group under an object /// </summary> private void PackageTreeContextMenu_Popup(object sender, CancelEventArgs e) { ContextMenuStrip contextMenu = sender as ContextMenuStrip; // Get our tree, then get our selected node, so we can then get our NodeType (which is defaulted to Class) MogControl_PackageTreeView tree = contextMenu.SourceControl as MogControl_PackageTreeView; if (tree != null) { TreeNode node = tree.SelectedNode; // If we actually have a node selected... if (node != null && node.Tag != null) { PackageNodeTypes nodeType = ((Mog_BaseTag)node.Tag).PackageNodeType; // Enable all our MenuItems foreach (ToolStripItem item in contextMenu.Items) { item.Enabled = true; } // Depending on our NodeType, decide which MenuItems will be available to the user switch (nodeType) { // For package and group, we should not be able to create a sub-package case PackageNodeTypes.Asset: case PackageNodeTypes.Package: this.PackageNewClassificationMenuItem.Enabled = false; this.PackageNewPackageMenuItem.Enabled = false; this.PackageNewPackageSubMenu.Enabled = false; this.PackageRemoveMenuItem.Enabled = true; break; case PackageNodeTypes.Group: this.PackageNewClassificationMenuItem.Enabled = false; this.PackageNewPackageMenuItem.Enabled = false; this.PackageNewPackageSubMenu.Enabled = false; this.PackageRemoveMenuItem.Enabled = true; break; // For object, we should not be able to create a package or a sub-group case PackageNodeTypes.Object: this.PackageNewClassificationMenuItem.Enabled = false; this.PackageNewPackageMenuItem.Enabled = false; this.PackageNewPackageSubMenu.Enabled = false; this.PackageNewGroupMenuItem.Enabled = false; this.PackageRemoveMenuItem.Enabled = true; break; // For class, we should only be able to add a package or remove a package default: // PackageNodeTypes.Class: this.PackageNewClassificationMenuItem.Enabled = true; this.PackageNewPackageMenuItem.Enabled = true; this.PackageNewPackageSubMenu.Enabled = true; this.PackageNewGroupMenuItem.Enabled = false; this.PackageNewObjectMenuItem.Enabled = false; this.PackageRemoveMenuItem.Enabled = false; break; } // Disable menu items we don't have privileges for MOG_Privileges privileges = MOG_ControllerProject.GetPrivileges(); bool bCanAddClassification = privileges.GetUserPrivilege(MOG_ControllerProject.GetUserName(), MOG_PRIVILEGE.AddClassification); if (!bCanAddClassification) { PackageNewClassificationMenuItem.Enabled = false; } bool bCanCreatePackage = privileges.GetUserPrivilege(MOG_ControllerProject.GetUserName(), MOG_PRIVILEGE.CreatePackage); if (!bCanCreatePackage) { PackageNewPackageMenuItem.Enabled = false; PackageNewPackageSubMenu.Enabled = false; PackageRemoveMenuItem.Enabled = false; } bool bCanCreatePackageGroup = privileges.GetUserPrivilege(MOG_ControllerProject.GetUserName(), MOG_PRIVILEGE.AddPackageGroup); if (!bCanCreatePackageGroup) { PackageNewObjectMenuItem.Enabled = false; PackageNewGroupMenuItem.Enabled = false; PackageRemoveMenuItem.Enabled = false; } // Substitute the create package submenu in the place of the create package option depending on the ShowPlatformSpecific option PackageNewPackageMenuItem.Visible = !tree.ShowPlatformSpecific; PackageNewPackageSubMenu.Visible = tree.ShowPlatformSpecific; } else { foreach (ToolStripItem item in contextMenu.Items) { item.Enabled = false; } } // Now the ContextMenu will display properly } }
private void AttachValidatedTagToNewObjectOrGroup(TreeNode package, TreeNode newNode, PackageNodeTypes nodeType) { // If this thing is a Group or Object, we need to do this algorithm string fullFilename = null; MOG_Filename assetFile = null; int imageIndex = 0; switch (nodeType) { case PackageNodeTypes.Group: imageIndex = MogUtil_AssetIcons.GetClassIconIndex(PackageGroup_ImageText); break; case PackageNodeTypes.Object: imageIndex = MogUtil_AssetIcons.GetClassIconIndex(PackageObject_ImageText); break; default: MOG_Report.ReportSilent("Got Unexpected PackageNodeTypes", "Unexpected PackageNodeTypes enum given for MOG_ControlsLibrary.Controls", Environment.StackTrace); break; } string groupPath = newNode.FullPath.Substring(package.FullPath.Length).Trim(PathSeparator.ToCharArray()).Replace(PathSeparator, "/"); fullFilename = package.FullPath + "/" + groupPath; assetFile = new MOG_Filename(((Mog_BaseTag)package.Tag).FullFilename); // Now that we've got our initial information, add our tag newNode.Tag = new Mog_BaseTag(newNode, assetFile.GetEncodedFilename(), this.FocusForAssetNodes, true); ((Mog_BaseTag)newNode.Tag).PackageNodeType = nodeType; ((Mog_BaseTag)newNode.Tag).PackageFullName = fullFilename; SetImageIndices(newNode, imageIndex); }