当前位置: 首页>>代码示例>>C#>>正文


C# TreeNode.GetContainingElementTreeNode方法代码示例

本文整理汇总了C#中System.Windows.Forms.TreeNode.GetContainingElementTreeNode方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.GetContainingElementTreeNode方法的具体用法?C# TreeNode.GetContainingElementTreeNode怎么用?C# TreeNode.GetContainingElementTreeNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.TreeNode的用法示例。


在下文中一共展示了TreeNode.GetContainingElementTreeNode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MoveEntityOn

        public static TreeNode MoveEntityOn(EntityTreeNode treeNodeMoving, TreeNode targetNode)
        {
            TreeNode newTreeNode = null;

            #region Moving the Entity into (or out of) a directory
            if (targetNode.IsDirectoryNode() || targetNode.IsRootEntityNode())
            {
                MoveEntityToDirectory(treeNodeMoving, targetNode);
            }

            #endregion

            #region Moving an Entity onto another element to create an instance

            else if (targetNode.IsEntityNode() || targetNode.IsScreenNode() || targetNode.IsRootNamedObjectNode())
            {
                bool isValidDrop = true;
                // Make sure that we don't drop an Entity into its own Objects
                if (targetNode.IsRootNamedObjectNode())
                {
                    if(treeNodeMoving == targetNode.GetContainingElementTreeNode())
                    {

                        isValidDrop = false;
                    }
                }
                if (isValidDrop)
                {
                    newTreeNode = MoveEntityOntoElement(treeNodeMoving, targetNode, newTreeNode);
                }
            }

            #endregion

            #region Moving an Entity onto a NamedObject (currently supports only Lists)

            else if (targetNode.IsNamedObjectNode())
            {
                // Allow drop only if it's a list or Layer
                NamedObjectSave targetNamedObjectSave = targetNode.Tag as NamedObjectSave;

                if (!targetNamedObjectSave.IsList && !targetNamedObjectSave.IsLayer)
                {
                    MessageBox.Show("The target is not a List or Layer so we can't add an Object to it.", "Target not valid");
                }
                if (targetNamedObjectSave.IsLayer)
                {
                    TreeNode parent = targetNode.Parent;

                    newTreeNode = MoveEntityOn(treeNodeMoving, parent);

                    // this created a new NamedObjectSave.  Let's put that on the Layer
                    MoveNamedObject(newTreeNode, targetNode);
                }
                else
                {
                    // Make sure that the two types match
                    string listType = targetNamedObjectSave.SourceClassGenericType;

                    if (listType != treeNodeMoving.EntitySave.Name)
                    {
                        MessageBox.Show("The target list type is of type\n\n" +
                            listType +
                            "\n\nBut the Entity is of type\n\n" +
                            treeNodeMoving.EntitySave.Name +
                            "\n\nCould not add an instance to the list", "Could not add instance");
                    }
                    else
                    {
                        NamedObjectSave namedObject = new NamedObjectSave();
                        namedObject.InstanceName =
                            FileManager.RemovePath(listType) + "1";

                        StringFunctions.MakeNameUnique<NamedObjectSave>(
                            namedObject, targetNamedObjectSave.ContainedObjects);

                        // Not sure if we need to set this or not, but I think 
                        // any instance added to a list will not be defined by base
                        namedObject.DefinedByBase = false;

                        NamedObjectSaveExtensionMethodsGlue.AddNamedObjectToCurrentNamedObjectList(namedObject);

                        ElementViewWindow.GenerateSelectedElementCode();
                        // Don't save the Glux, the caller of this method will take care of it
                        // GluxCommands.Self.SaveGlux();
                    }

                }
            }

            #endregion

            else if (targetNode.IsGlobalContentContainerNode())
            {
                AskAndAddAllContainedRfsToGlobalContent(treeNodeMoving.SaveObjectAsElement);
            }

            return newTreeNode;
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:99,代码来源:ElementViewWindow.DragDrop.cs

示例2: AddDirectory

        public void AddDirectory(string folderName, TreeNode treeNodeToAddTo)
        {

            if (treeNodeToAddTo.IsGlobalContentContainerNode())
            {
                string rootDirectory = FileManager.RelativeDirectory;
                if (ProjectManager.ContentProject != null)
                {
                    rootDirectory = ProjectManager.ContentProject.Directory;
                }

                string directory = rootDirectory + "GlobalContent/" + folderName;

                Directory.CreateDirectory(directory);
            }
            else if (treeNodeToAddTo.IsRootEntityNode())
            {
                string directory = FileManager.RelativeDirectory + "Entities/" +
                    folderName;

                Directory.CreateDirectory(directory);
            }
            else if (treeNodeToAddTo.IsDirectoryNode())
            {
                // This used to use RelativeDirectory, but
                // I think we want this to be content, so not
                // sure why it uses RelativeDirectory...
                //string directory = FileManager.RelativeDirectory +
                //    currentTreeNode.GetRelativePath() +
                //    tiw.Result;
                // Update October 16, 2011
                // An Enity has both folders
                // in the code folder (represented
                // by RelativeDirectory) as well as
                // in the Content project.  An Entity
                // may not have files in the Content folder,
                // but it must have code files.  Therefore, we
                // create folders in the code directory tree and
                // we worry about content when NamedObjectSaves are
                // added to a given Entity later.
                //string directory = currentTreeNode.GetRelativePath() +
                //    tiw.Result;
                // Update February 17, 2012
                // But...when we add a new folder
                // to an Entity, we want that folder
                // to show up in the tree view in Glue.
                // Glue only scans the content folder, so
                // we want to make sure this folder exists
                // so it shows up okay.

                string directory = FileManager.RelativeDirectory +
                        treeNodeToAddTo.GetRelativePath() +
                        folderName;
                directory = ProjectManager.MakeAbsolute(directory, true);

                Directory.CreateDirectory(directory);

                directory = ProjectManager.ContentDirectory +
                        treeNodeToAddTo.GetRelativePath() +
                        folderName;
                directory = ProjectManager.MakeAbsolute(directory, true);

                Directory.CreateDirectory(directory);

            }
            else if (treeNodeToAddTo.IsFilesContainerNode() || treeNodeToAddTo.IsFolderInFilesContainerNode())
            {
                string directory =
                    treeNodeToAddTo.GetRelativePath() + folderName;

                Directory.CreateDirectory(ProjectManager.MakeAbsolute(directory, true));

                if (EditorLogic.CurrentEntityTreeNode != null)
                {
                    EditorLogic.CurrentEntityTreeNode.UpdateReferencedTreeNodes();
                }
                else if (EditorLogic.CurrentScreenTreeNode != null)
                {
                    EditorLogic.CurrentScreenTreeNode.UpdateReferencedTreeNodes();
                }
            }
            else if (treeNodeToAddTo.IsFolderInFilesContainerNode())
            {

                throw new NotImplementedException();
            }

            var containingElementNode = treeNodeToAddTo.GetContainingElementTreeNode();

            IElement element = null;
            if (containingElementNode != null)
            {
                element = containingElementNode.Tag as IElement;
            }

            if (containingElementNode == null)
            {
                GlueCommands.Self.RefreshCommands.RefreshGlobalContent();
            }
            else
//.........这里部分代码省略.........
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:101,代码来源:ProjectCommands.cs

示例3: DragDropNosOnRootEventsNode

        private static bool DragDropNosOnRootEventsNode(TreeNode treeNodeMoving, TreeNode targetNode)
        {
            bool succeeded = true;

            
            if (treeNodeMoving.GetContainingElementTreeNode() != targetNode.GetContainingElementTreeNode())
            {
                succeeded = false;
            }

            if (succeeded)
            {
                // show the add new variable window and select this object
                RightClickHelper.ShowAddEventWindow(treeNodeMoving.Tag as NamedObjectSave);

            }

            return succeeded;
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:19,代码来源:ElementViewWindow.DragDrop.cs

示例4: MoveObjectOnRootCustomVariablesNode

        private static bool MoveObjectOnRootCustomVariablesNode(TreeNode treeNodeMoving, TreeNode targetNode)
        {
            bool succeeded = true;

            if (treeNodeMoving.GetContainingElementTreeNode() != targetNode.GetContainingElementTreeNode())
            {
                succeeded = false;
            }

            if (succeeded)
            {
                // show the add new variable window and select this object
                RightClickHelper.AddVariableClick( CustomVariableType.Tunneled, ((NamedObjectSave) treeNodeMoving.Tag).InstanceName);
            }

            return succeeded;
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:17,代码来源:ElementViewWindow.DragDrop.cs

示例5: MoveReferencedFile

        private static void MoveReferencedFile(TreeNode treeNodeMoving, TreeNode targetNode)
        {
            while (targetNode != null && targetNode.IsReferencedFile
                ())
            {
                targetNode = targetNode.Parent;
            }
            // If the user drops a file on a Screen or Entity, let's allow them to
            // complete the operation on the Files node
            if (targetNode is BaseElementTreeNode)
            {
                targetNode = ((BaseElementTreeNode)targetNode).FilesTreeNode;
            }

            ReferencedFileSave referencedFileSave = treeNodeMoving.Tag as ReferencedFileSave;

            if (targetNode.IsGlobalContentContainerNode())
            {
                if (targetNode.GetContainingElementTreeNode() == null)
                {
                    string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true);
                    MoveReferencedFileToDirectory(referencedFileSave, targetDirectory);
                }
                else
                {
                    DragAddFileToGlobalContent(treeNodeMoving, referencedFileSave);
                    // This means the user wants to add the file
                    // to global content.
                }
            }
            else if (targetNode.IsFolderForGlobalContentFiles())
            {
                string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true);
                MoveReferencedFileToDirectory(referencedFileSave, targetDirectory);
            }
            else if (!targetNode.IsFilesContainerNode() &&
                !targetNode.IsFolderInFilesContainerNode() &&
                !targetNode.IsFolderForGlobalContentFiles())
            {
                MessageBox.Show(@"Can't drop this file here");
                return;
            }
            else if (!string.IsNullOrEmpty(referencedFileSave.SourceFile) ||
                referencedFileSave.SourceFileCache.Count != 0)
            {
                MessageBox.Show("Can't move the file\n\n" + referencedFileSave.Name + "\n\nbecause it has source-referencing files.  These sources will be broken " +
                    "if the file is moved.  You will need to manually move the file, modify the source references, remove this file, then add the newly-created file.");
                return;
            }
            //if (targetNode.IsFolderInFilesContainerNode() || targetNode.IsFilesContainerNode())
            else
            {
                // See if we're moving the RFS from one Element to another
                IElement container = ObjectFinder.Self.GetElementContaining(referencedFileSave);
                TreeNode elementTreeNodeDroppingIn = targetNode.GetContainingElementTreeNode();
                IElement elementDroppingIn = null;
                if (elementTreeNodeDroppingIn != null)
                {
                    // User didn't drop on an entity, but instead on a node within the entity.
                    // Let's check if it's a subfolder. If so, we need to tell the user that we
                    // can't add the file in a subfolder.

                    if (targetNode.IsFolderInFilesContainerNode())
                    {
                        MessageBox.Show("Shared files cannot be added to subfolders, so it will be added directly to \"Files\"");
                    }

                    elementDroppingIn = elementTreeNodeDroppingIn.Tag as IElement;
                }

                if (container != elementDroppingIn)
                {
                    ElementViewWindow.SelectedNode = targetNode;

                    string absoluteFileName = ProjectManager.MakeAbsolute(referencedFileSave.Name, true);
                    string creationReport;
                    string errorMessage;

                    var newlyCreatedFile = ElementCommands.Self.CreateReferencedFileSaveForExistingFile(elementDroppingIn, null, absoluteFileName,
                                                                    PromptHandleEnum.Prompt, 
                                                                    referencedFileSave.GetAssetTypeInfo(),
                                                                    out creationReport,
                                                                    out errorMessage);

                    ElementViewWindow.UpdateChangedElements();

                    
                    

                    if (!String.IsNullOrEmpty(errorMessage))
                    {
                        MessageBox.Show(errorMessage);
                    }
                    else if(newlyCreatedFile != null)
                    {
                        GlueCommands.Self.TreeNodeCommands.SelectTreeNode(newlyCreatedFile);

                    }
                }
                else
//.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:101,代码来源:ElementViewWindow.DragDrop.cs

示例6: MoveState

        private static void MoveState(TreeNode nodeMoving, TreeNode targetNode)
        {
            IElement currentElement = EditorLogic.CurrentElement;
            StateSave toAdd = (StateSave)nodeMoving.Tag;

            IElement sourceContainer = nodeMoving.GetContainingElementTreeNode().Tag as IElement;
            IElement targetContainer = targetNode.GetContainingElementTreeNode().Tag as IElement;

            if (targetNode.IsStateCategoryNode() || targetNode.IsStateListNode())
            {
                if (sourceContainer == targetContainer)
                {
                    EditorLogic.CurrentElement.RemoveState(EditorLogic.CurrentStateSave);
                }
                else
                {
                    toAdd = toAdd.Clone();
                }

                if (targetNode.IsStateCategoryNode())
                {
                    ((StateSaveCategory)targetNode.Tag).States.Add(toAdd);
                }
                else
                {
                    targetContainer.States.Add(toAdd);
                }

                GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(targetContainer);
                GlueCommands.Self.RefreshCommands.RefreshUi(targetContainer);

            }


        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:35,代码来源:ElementViewWindow.DragDrop.cs

示例7: MoveCustomVariable

        private static void MoveCustomVariable(TreeNode nodeMoving, TreeNode targetNode)
        {
            CustomVariable customVariable = nodeMoving.Tag as CustomVariable;

            if (targetNode.IsRootEventsNode())
            {
                // The user dragged a variable onto the events node, so they want to make
                // an event for this.  We'll assume an "after" event since I think no one makes
                // before events
             

                if (customVariable != null)
                {
                    customVariable.CreatesEvent = true;

                    FlatRedBall.Glue.Events.EventResponseSave eventResponseSave = new Events.EventResponseSave();
                    eventResponseSave.EventName = "After" + customVariable.Name + "Set";

                    eventResponseSave.SourceObject = null;
                    eventResponseSave.SourceObjectEvent = null;

                    eventResponseSave.SourceVariable = customVariable.Name;
                    eventResponseSave.BeforeOrAfter = BeforeOrAfter.After;

                    eventResponseSave.DelegateType = null;

                    RightClickHelper.AddEventToElementAndSave(EditorLogic.CurrentElement, eventResponseSave);

                }
            }
            else if (targetNode.IsRootCustomVariablesNode())
            {
                // let's see if the user is moving a variable from one element to another
                IElement sourceElement = nodeMoving.GetContainingElementTreeNode().Tag as IElement;
                IElement targetElement = targetNode.GetContainingElementTreeNode().Tag as IElement;

                if (sourceElement != targetElement)
                {
                    // copying a variable from one element to another
                    // eventually we need to add some error checking here.
                    CustomVariable newVariable = customVariable.Clone();

                    targetElement.CustomVariables.Add(newVariable);


                    GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(targetElement);
                    GlueCommands.Self.RefreshCommands.RefreshUi(targetElement);
                }
            }
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:50,代码来源:ElementViewWindow.DragDrop.cs

示例8: MoveStateCategory

        private static void MoveStateCategory(TreeNode nodeMoving, TreeNode targetNode)
        {
            if (targetNode.IsRootCustomVariablesNode() || targetNode.IsCustomVariable())
            {
                // The user drag+dropped a state category into the variables
                // Let's make sure that it's all in the same Element though:
                if (targetNode.GetContainingElementTreeNode() == nodeMoving.GetContainingElementTreeNode())
                {
                    StateSaveCategory category = nodeMoving.Tag as StateSaveCategory;

                    // expose a variable that exposes the category
                    CustomVariable customVariable = new CustomVariable();

                    if (category.SharesVariablesWithOtherCategories)
                    {
                        customVariable.Type = "VariableState";
                        customVariable.Name = "CurrentState";
                    }
                    else
                    {
                        customVariable.Type = category.Name;
                        customVariable.Name = "Current" + category.Name + "State";
                    }

                    IElement element = targetNode.GetContainingElementTreeNode().Tag as IElement;

                    element.CustomVariables.Add(customVariable);
                    GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();

                    EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();
                }
            }
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:33,代码来源:ElementViewWindow.DragDrop.cs

示例9: PopulateRightClickItems


//.........这里部分代码省略.........

                    if (entitySave.PooledByFactory)
                    {
                        menu.Items.Add(mAddResetVariablesForPooling);
                    }
                    menu.Items.Add(mRefreshTreeNodesMenuItem);
                }
            }

            #endregion

            #region IsFileContainerNode OR IsFolderInFilesContainerNode

            else if (targetNode.IsFilesContainerNode() || targetNode.IsFolderInFilesContainerNode())
            {
                menu.Items.Add(form.addFileToolStripMenuItem);
                menu.Items.Add(form.addFolderToolStripMenuItem);
                menu.Items.Add("-");
                menu.Items.Add(form.viewInExplorerToolStripMenuItem);
                if (targetNode.IsFolderInFilesContainerNode())
                {
                    menu.Items.Add(mDeleteFolder);
                }
            }

            #endregion

            #region IsRootObjectNode

            else if (targetNode.IsRootObjectNode())
            {
                bool isSameObject = false;

                if (targetNode.GetContainingElementTreeNode() != null && ElementViewWindow.TreeNodeDraggedOff != null)
                {
                    isSameObject = targetNode.GetContainingElementTreeNode().Tag ==
                    ElementViewWindow.TreeNodeDraggedOff.Tag as ElementCommands;
                }

                if (menuShowingAction == MenuShowingAction.RightButtonDrag && !isSameObject)
                {
                    menu.Items.Add(mAddEntityInstance);
                    menu.Items.Add(mAddEntityList);
                }
                else
                {
                    menu.Items.Add(form.addObjectToolStripMenuItem);
                }
            }

            #endregion

            #region IsGlobalContentContainerNode
            else if (targetNode.IsGlobalContentContainerNode())
            {
                menu.Items.Add(form.addFileToolStripMenuItem);
                menu.Items.Add(form.addFolderToolStripMenuItem);
                menu.Items.Add(form.reGenerateCodeToolStripMenuItem);

                menu.Items.Add(form.viewInExplorerToolStripMenuItem);

                menu.Items.Add(mViewFileLoadOrder);
            }
            #endregion

            #region IsRootEntityNode
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:67,代码来源:RightClickHelper.cs


注:本文中的System.Windows.Forms.TreeNode.GetContainingElementTreeNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。