예제 #1
0
        internal void HandleTreeViewRightClick(System.Windows.Forms.TreeNode rightClickedTreeNode, System.Windows.Forms.ContextMenuStrip menuToModify)
        {
            bool shouldShowMenu = rightClickedTreeNode.IsScreenNode();

            if (!shouldShowMenu)
            {
                bool isPartOfScreen = rightClickedTreeNode.GetContainingElementTreeNode().IsScreenNode();

                if (isPartOfScreen)
                {
                    shouldShowMenu = rightClickedTreeNode.IsFilesContainerNode() ||
                                     rightClickedTreeNode.IsFolderInFilesContainerNode();
                }
            }



            // Tiled levels was a nice idea, but it tied the developer's hands
            // too much.
            //if (shouldShowMenu)
            //{
            //    var menuToAdd = new ToolStripMenuItem("Add Tiled Level");

            //    menuToModify.Items.Add(menuToAdd);

            //    menuToAdd.Click += HandleAddTiledLevelClick;

            //}
        }
예제 #2
0
        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
            {
                GlueCommands.Self.RefreshCommands.RefreshUi(element);
            }

            GlueCommands.Self.RefreshCommands.RefreshDirectoryTreeNodes();
        }
예제 #3
0
        ///////////////////////////////////////////////////////////
        public static void PopulateRightClickItems(TreeNode node, MenuShowingAction menuShowingAction = MenuShowingAction.RegularRightClick)
        {

            MainGlueWindow.Self.ElementTreeView.SelectedNode = node;
            MainGlueWindow form = MainGlueWindow.Self;

            ContextMenuStrip menu = MainGlueWindow.Self.mElementContextMenu;

            menu.Items.Clear();


            #region IsScreenNode

            if (node.IsScreenNode())
            {
                if (menuShowingAction == MenuShowingAction.RightButtonDrag)
                {
                    menu.Items.Add(mAddEntityInstance);
                    menu.Items.Add(mAddEntityList);
                }
                else
                {
                    menu.Items.Add(form.setAsStartUpScreenToolStripMenuItem);
                    menu.Items.Add(mMakeRequiredAtStartup);
                    mExportElement.Text = "Export Screen";
                    menu.Items.Add(mExportElement);

                    AddRemoveFromProjectItems(form, menu);

                    if (EditorLogic.CurrentScreenSave.IsRequiredAtStartup)
                    {
                        mMakeRequiredAtStartup.Text = "Remove StartUp Requirement";
                    }
                    else
                    {
                        mMakeRequiredAtStartup.Text = "Make Required at StartUp";
                    }


                    menu.Items.Add("-");
                    menu.Items.Add(mFindAllReferences);
                    menu.Items.Add(mRefreshTreeNodesMenuItem);
                }
            }

            #endregion

            #region IsEntityNode

            else if (node.IsEntityNode())
            {
                if (menuShowingAction == MenuShowingAction.RightButtonDrag)
                {
                    menu.Items.Add(mAddEntityInstance);
                    menu.Items.Add(mAddEntityList);
                }
                else
                {
                    AddRemoveFromProjectItems(form, menu);

                    menu.Items.Add("-");
                    mExportElement.Text = "Export Entity";
                    menu.Items.Add(mExportElement);
                    menu.Items.Add(mFindAllReferences);

                    EntitySave entitySave = ((EntityTreeNode)node).EntitySave;

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

            #endregion

            #region IsFileContainerNode OR IsFolderInFilesContainerNode

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

            #endregion

            #region IsScreenObjectContainerNode

            else if (node.IsRootObjectNode())
            {
                if (menuShowingAction == MenuShowingAction.RightButtonDrag)
                {
                    menu.Items.Add(mAddEntityInstance);
                    menu.Items.Add(mAddEntityList);
                }
                else
                {
                    menu.Items.Add(form.addObjectToolStripMenuItem);
                }
            }

            #endregion

            #region IsGlobalContentContainerNode
            else if (node.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
            else if (node.IsRootEntityNode())
            {
                menu.Items.Add(form.addEntityToolStripMenuItem);

                mImportElement.Text = "Import Entity";
                menu.Items.Add(mImportElement);

                menu.Items.Add(form.addFolderToolStripMenuItem);
            }
            #endregion

            #region IsRootScreenNode
            else if (node.IsRootScreenNode())
            {
                menu.Items.Add(form.addScreenToolStripMenuItem);

                mImportElement.Text = "Import Screen";
                menu.Items.Add(mImportElement);

            }
            #endregion

            #region IsRootBehaviorsNode
            else if (node.IsRootBehaviorsNode())
            {
                menu.Items.Add(form.addBehaviorToolStripMenuItem);
                menu.Items.Add(form.openBehaviorFolderToolStripMenuItem);
                menu.Items.Add(form.importBehaviorToolStripMenuItem);
            }
            #endregion

            #region IsRootCustomVariables

            else if (node.IsRootCustomVariablesNode())
            {
                menu.Items.Add(form.addVariableToolStripMenuItem);
            }

            #endregion

            #region IsRootEventNode
            else if (node.IsRootEventsNode())
            {
                menu.Items.Add(mAddEventMenuItem);
            }
            #endregion

            #region IsNamedObjectNode

            else if (node.IsNamedObjectNode())
            {
                AddRemoveFromProjectItems(form, menu);

                menu.Items.Add(form.editResetVariablesToolStripMenuItem);
                menu.Items.Add(mFindAllReferences);

                menu.Items.Add("-");

                menu.Items.Add(mDuplicate);

                menu.Items.Add("-");

                menu.Items.Add(mMoveToTop);
                menu.Items.Add(mMoveUp);
                menu.Items.Add(mMoveDown);
                menu.Items.Add(mMoveToBottom);

                menu.Items.Add("-");

                NamedObjectSave currentNamedObject = EditorLogic.CurrentNamedObject;

                if (currentNamedObject.SourceType == SourceType.FlatRedBallType &&
                    currentNamedObject.SourceClassType == "PositionedObjectList<T>" &&
                    !string.IsNullOrEmpty(currentNamedObject.SourceClassGenericType) &&
                    !currentNamedObject.SetByDerived)
                {
                    menu.Items.Add(form.addObjectToolStripMenuItem);
                }

            }

            #endregion

            #region IsReferencedFileNode
            else if (node.IsReferencedFile())
            {
                menu.Items.Add(form.viewInExplorerToolStripMenuItem);
                menu.Items.Add(mFindAllReferences);
                menu.Items.Add("Copy path to clipboard", null, HandleCopyToClipboardClick);
                menu.Items.Add("-");

                menu.Items.Add(mCreateZipPackage);
                menu.Items.Add(mRecreateCompanionFiles);

                menu.Items.Add("-");

                AddRemoveFromProjectItems(form, menu);

                menu.Items.Add(mUseContentPipeline);
                //menu.Items.Add(form.openWithDEFAULTToolStripMenuItem);

                ReferencedFileSave rfs = (ReferencedFileSave)node.Tag;

                if (FileManager.GetExtension(rfs.Name) == "csv" || rfs.TreatAsCsv)
                {
                    menu.Items.Add("-");
                    menu.Items.Add(form.setCreatedClassToolStripMenuItem);
                    menu.Items.Add(form.reGenerateCodeToolStripMenuItem);
                }


                if (!string.IsNullOrEmpty(rfs.SourceFile) || rfs.SourceFileCache.Count != 0)
                {
                    menu.Items.Add("-");
                    menu.Items.Add(mViewSourceInExplorer);
                    menu.Items.Add(mRebuildFile);
                }

                menu.Items.Add(mCopyToBuildFolder);

                if (!File.Exists(ProjectManager.MakeAbsolute(rfs.Name, true)))
                {
                    menu.Items.Add(mCreateNewFileForMissingFile);
                }
            }

            #endregion

            #region IsCustomVariable
            else if (node.IsCustomVariable())
            {
                AddRemoveFromProjectItems(form, menu);

                menu.Items.Add("-");


                menu.Items.Add(mFindAllReferences);

                menu.Items.Add("-");
                    
                menu.Items.Add(mMoveToTop);
                menu.Items.Add(mMoveUp);
                menu.Items.Add(mMoveDown);
                menu.Items.Add(mMoveToBottom);
            }

            #endregion

            #region IsBehaviorNode
            else if (node.IsBehaviorNode())
            {

                AddRemoveFromProjectItems(form, menu);

            }

            #endregion

            #region IsCodeNode
            else if (node.IsCodeNode())
            {

                menu.Items.Add(form.viewInExplorerToolStripMenuItem);
                menu.Items.Add(form.reGenerateCodeToolStripMenuItem);
            }

            #endregion

            #region IsRootCodeNode

            else if (node.IsRootCodeNode())
            {
                menu.Items.Add(form.reGenerateCodeToolStripMenuItem);
            }


            #endregion

            #region IsDirectoryNode
            else if (node.IsDirectoryNode())
            {
                //menu.Items.Add(form.viewInExplorerToolStripMenuItem);
                menu.Items.Add(mViewContentFilesInExplorer);
                menu.Items.Add(mViewCodeFolderInExplorer);
                menu.Items.Add("-");


                menu.Items.Add(form.addFolderToolStripMenuItem);

                if (node.Root().IsRootEntityNode())
                {
                    menu.Items.Add(form.addEntityToolStripMenuItem);


                    mImportElement.Text = "Import Entity";
                    menu.Items.Add(mImportElement);
                }
                else
                {
                    // If not in the Entities tree structure, assume global content
                    menu.Items.Add(form.addFileToolStripMenuItem);
                }

                menu.Items.Add("-");

                menu.Items.Add(mDeleteFolder);

            }

            #endregion

            #region IsStateListNode

            else if (node.IsStateListNode())
            {
                menu.Items.Add(mAddState);
                menu.Items.Add(mAddStateCategory);
            }

            #endregion

            #region IsStateCategoryNode
            else if (node.IsStateCategoryNode())
            {
                menu.Items.Add(mAddState);
                AddRemoveFromProjectItems(form, menu);

            }
            #endregion

            #region IsStateNode

            else if (node.IsStateNode())
            {
                AddRemoveFromProjectItems(form, menu);

                menu.Items.Add("-");
                menu.Items.Add(mDuplicate);
                menu.Items.Add("-");
                menu.Items.Add(mFillValuesFromDefault);
            }

            #endregion

            #region IsEventTreeNode

            else if (node.IsEventResponseTreeNode())
            {
                AddRemoveFromProjectItems(form, menu);

            }

            #endregion
            PluginManager.ReactToTreeViewRightClick(node, menu);
        }
        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
                {
                    // Not moving into or out of an element
                    string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true);
                    MoveReferencedFileToDirectory(referencedFileSave, targetDirectory);
                }
            }
        }