Exemplo n.º 1
0
        internal static void DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("FileDrop"))
            {
                DragDropFile(sender, e);
            }
            else
            {
                TreeNode targetNode = null;
                TreeView tree       = (TreeView)sender;


                Point pt = new Point(e.X, e.Y);
                pt         = tree.PointToClient(pt);
                targetNode = tree.GetNodeAt(pt);

                if (ButtonUsed == MouseButtons.Right)
                {
                    RightClickHelper.PopulateRightClickItems(targetNode, MenuShowingAction.RightButtonDrag);
                    MainGlueWindow.Self.mElementContextMenu.Show(new Point(e.X, e.Y));
                    //ElementViewWindow.mTreeView.ContextMenu.Show(ElementViewWindow.mTreeView, pt);
                }
                else
                {
                    DragDropTreeNode((TreeView)sender, targetNode);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets any values that should not be left uninitialized.
        /// </summary>
        private void SetUnsetValues() // intentionally left blank:
        {
            // This is going to give us the .sln directory,
            // but that's okay, that way it catches all external files.
            string directoryToSet = ProjectManager.ProjectRootDirectory;

            if (!string.IsNullOrEmpty(directoryToSet))
            {
                RightClickHelper.SetExternallyBuiltFileIfHigherThanCurrent(directoryToSet, false);
            }
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public bool TryHandleKeys(Keys keyData)
        {
            switch (keyData)
            {
            // CTRL+F, control f, search focus, ctrl f, ctrl + f
            case Keys.Control | Keys.F:
                MainGlueWindow.Self.SearchTextbox.Focus();
                return(true);

            case Keys.Alt | Keys.Left:
                TreeNodeStackManager.Self.GoBack();
                return(true);

            case Keys.Alt | Keys.Right:
                TreeNodeStackManager.Self.GoForward();
                return(true);

            case Keys.Alt | Keys.Up:
                return(RightClickHelper.MoveSelectedObjectUp());

            case Keys.Alt | Keys.Down:
                return(RightClickHelper.MoveSelectedObjectDown());

            case Keys.Alt | Keys.Shift | Keys.Down:
                return(RightClickHelper.MoveToBottom());

            case Keys.Alt | Keys.Shift | Keys.Up:
                return(RightClickHelper.MoveToTop());

            case Keys.Escape:
                if (MainGlueWindow.Self.SearchTextbox.Focused)
                {
                    MainGlueWindow.Self.SearchTextbox.Focus();
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                return(false);
            }
        }
        private static void ExposeVariableClick(object sender, EventArgs e)
        {
            PropertyGrid propertyGrid = MainGlueWindow.Self.PropertyGrid;

            string label = propertyGrid.SelectedGridItem.Label;

            if (label == "ImplementsIVisible")
            {
                // We're going to make a bool Visible for this now.

                RightClickHelper.CreateAndAddNewVariable(
                    "Visible",
                    "bool",
                    null,
                    null,
                    null,
                    null);
            }
        }
        private static void ExposeVariableClick(object sender, EventArgs e)
        {
            System.Windows.Forms.PropertyGrid propertyGrid = MainGlueWindow.Self.PropertyGrid;

            string label = propertyGrid.SelectedGridItem.Label;

            if (label == "ImplementsIVisible")
            {
                // We're going to make a bool Visible for this now.

                CustomVariable newVariable = new CustomVariable();
                newVariable.Name = "Visible";
                newVariable.Type = "bool";


                RightClickHelper.CreateAndAddNewVariable(
                    newVariable);
            }
        }
Exemplo n.º 9
0
        public ReferencedFileSave AddSingleFileTo(string fileName, string rfsName, string extraCommandLineArguments,
                                                  BuildToolAssociation buildToolAssociation, bool isBuiltFile, string options, IElement sourceElement, string directoryOfTreeNode)
        {
            ReferencedFileSave toReturn = null;

            //string directoryOfTreeNode = EditorLogic.CurrentTreeNode.GetRelativePath();

            string targetDirectory = FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces.ElementCommands.GetFullPathContentDirectory(sourceElement, directoryOfTreeNode);
            string targetFile      = fileName;

            string errorMessage = null;
            bool   failed       = false;

            if (isBuiltFile)
            {
                targetFile = targetDirectory + rfsName + "." + buildToolAssociation.DestinationFileType;
            }

            string targetFileWithOriginalExtension = FileManager.RemoveExtension(targetFile) + "." + FileManager.GetExtension(fileName);

            bool copied = false;

            var projectRootDirectory = ProjectManager.ProjectRootDirectory;

            if (!FileManager.IsRelativeTo(fileName, projectRootDirectory) && isBuiltFile)
            {
                copied = PluginManager.TryCopyFile(fileName, targetFileWithOriginalExtension);

                if (!copied)
                {
                    errorMessage = $"Could not add the file\n{fileName}\n\nBecause it is not relative to\n{ProjectManager.ProjectRootDirectory}\n\nPlease move this file to a folder inside your project and try again";
                    failed       = true;
                }
                else
                {
                    // the file was copied - from now on just use the copied file name:
                    fileName = targetFileWithOriginalExtension;
                }
            }

            if (!failed)
            {
                if (isBuiltFile)
                {
                    errorMessage = buildToolAssociation.PerformBuildOn(fileName, targetFile, extraCommandLineArguments, PluginManager.ReceiveOutput, PluginManager.ReceiveError);
                    failed       = true;
                }
            }

            if (!failed)
            {
                string creationReport;

                string directoryToUse = null;

                if (!isBuiltFile)
                {
                    directoryToUse = directoryOfTreeNode;
                }

                var assetTypeInfo = AvailableAssetTypes.Self.GetAssetTypeFromExtension(FileManager.GetExtension(targetFile));


                toReturn = CreateReferencedFileSaveForExistingFile(
                    sourceElement, directoryToUse, targetFile, PromptHandleEnum.Prompt,
                    assetTypeInfo,
                    out creationReport, out errorMessage);

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    failed = true;
                }
                else if (toReturn != null && string.IsNullOrEmpty(toReturn.Name))
                {
                    errorMessage = "There was an error creating the named object for\n" + fileName;
                    failed       = true;
                }
            }

            if (!failed)
            {
                if (isBuiltFile)
                {
                    toReturn.SourceFile          = ProjectManager.MakeRelativeContent(fileName);
                    toReturn.AdditionalArguments = extraCommandLineArguments;
                    toReturn.BuildTool           = buildToolAssociation.ToString();

                    // If a background sync is happening, this can lock the thread, so we want to
                    // make sure this doesn't happen at the same time as a background sync:
                    TaskManager.Self.AddAsyncTask(() =>
                    {
                        UpdateReactor.UpdateFile(ProjectManager.MakeAbsolute(toReturn.Name));
                    },
                                                  "Updating file " + toReturn.Name);
                    string directoryOfFile = FileManager.GetDirectory(ProjectManager.MakeAbsolute(fileName));

                    RightClickHelper.SetExternallyBuiltFileIfHigherThanCurrent(directoryOfFile, false);
                }
            }

            if (!failed)
            {
                TaskManager.Self.OnUiThread(() =>
                {
                    ElementViewWindow.UpdateChangedElements();
                });

                if (sourceElement == null)
                {
                    GlueCommands.Self.RefreshCommands.RefreshGlobalContent();
                }

                PluginManager.ReactToNewFile(toReturn);
                GluxCommands.Self.SaveGlux();
                TaskManager.Self.Add(GluxCommands.Self.ProjectCommands.SaveProjects, "Saving projects after adding file");
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                PluginManager.ReceiveError(errorMessage);
                // I think we should show an error message.  I had a user
                // try to add a file and no popup appeared telling them that
                // the entity was named that.
                //MessageBox.Show(errorMessage);
                GlueCommands.Self.DialogCommands.ShowMessageBox(errorMessage);
            }

            if (toReturn != null)
            {
                ApplyOptions(toReturn, options);

                TaskManager.Self.AddSync(() =>
                                         TaskManager.Self.OnUiThread(() =>
                                                                     GlueState.Self.CurrentReferencedFileSave = toReturn), "Select new file");
            }

            return(toReturn);
        }
Exemplo n.º 10
0
        private static void HandleAddVariableOk(AddVariableWindow addVariableWindow)
        {
            string   resultName     = addVariableWindow.ResultName;
            IElement currentElement = EditorLogic.CurrentElement;
            string   failureMessage;

            bool didFailureOccur = IsVariableInvalid(addVariableWindow, resultName, currentElement, out failureMessage);


            if (!didFailureOccur)
            {
                if (!string.IsNullOrEmpty(addVariableWindow.TunnelingObject) && string.IsNullOrEmpty(addVariableWindow.TunnelingVariable))
                {
                    didFailureOccur = true;
                    failureMessage  = $"You must select a variable on {addVariableWindow.TunnelingObject}";
                }
            }

            if (didFailureOccur)
            {
                MessageBox.Show(failureMessage);
            }
            else
            {
                // See if there is already a variable in the base with this name
                CustomVariable existingVariableInBase = EditorLogic.CurrentElement.GetCustomVariableRecursively(resultName);

                bool canCreate       = true;
                bool isDefinedByBase = false;
                if (existingVariableInBase != null)
                {
                    if (existingVariableInBase.SetByDerived)
                    {
                        isDefinedByBase = true;
                    }
                    else
                    {
                        MessageBox.Show("There is already a variable named\n\n" + resultName +
                                        "\n\nin the base element, but it is not SetByDerived.\nGlue will not " +
                                        "create a variable because it would result in a name conflict.");

                        canCreate = false;
                    }
                }

                if (canCreate)
                {
                    string type                 = addVariableWindow.ResultType;
                    string sourceObject         = addVariableWindow.TunnelingObject;
                    string sourceObjectProperty = null;
                    if (!string.IsNullOrEmpty(sourceObject))
                    {
                        sourceObjectProperty = addVariableWindow.TunnelingVariable;
                    }
                    string overridingType = addVariableWindow.OverridingType;
                    string typeConverter  = addVariableWindow.TypeConverter;

                    CustomVariable newVariable = new CustomVariable();
                    newVariable.Name                 = resultName;
                    newVariable.Type                 = type;
                    newVariable.SourceObject         = sourceObject;
                    newVariable.SourceObjectProperty = sourceObjectProperty;

                    newVariable.IsShared = addVariableWindow.IsStatic;



                    if (!string.IsNullOrEmpty(overridingType))
                    {
                        newVariable.OverridingPropertyType = overridingType;
                        newVariable.TypeConverter          = typeConverter;
                    }


                    RightClickHelper.CreateAndAddNewVariable(newVariable);

                    if (isDefinedByBase)
                    {
                        newVariable.DefinedByBase = isDefinedByBase;
                        // Refresh the UI - it's refreshed above in CreateAndAddNewVariable,
                        // but we're changing the DefinedByBase property which changes the color
                        // of the variable so refresh it again
                        EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();
                    }
                    ElementViewWindow.ShowAllElementVariablesInPropertyGrid();


                    if (GlueState.Self.CurrentElement != null)
                    {
                        PluginManager.ReactToItemSelect(GlueState.Self.CurrentTreeNode);
                    }
                }
            }
        }
Exemplo n.º 11
0
        public static ReferencedFileSave AddReferencedFileSave(IElement element, string directoryPath, string fileName,
                                                               AssetTypeInfo resultAssetTypeInfo, string option, out string errorMessage)
        {
            char invalidCharacter;
            ReferencedFileSave rfs = null;

            errorMessage = null;

            #region Get directory

            string directoryRelativeToContent = "";

            if (!String.IsNullOrEmpty(directoryPath))
            {
                //string directory = directoryTreeNode.GetRelativePath().Replace("/", "\\");

                directoryRelativeToContent = directoryPath;
            }
            else if (element != null)
            {
                //string directory = elementToAddTo.GetRelativePath().Replace("/", "\\");

                directoryRelativeToContent = element.Name.Replace(@"/", @"\") + "\\";
            }
            else
            {
                directoryRelativeToContent = "GlobalContent/";
            }


            #endregion

            bool userCancelled = false;


            #region If there is some reason why the file name won't, then work show a message box

            string whyIsntValid;

            if (!NameVerifier.IsReferencedFileNameValid(fileName, resultAssetTypeInfo, rfs, element, out whyIsntValid))
            {
                errorMessage = "Invalid file name:\n" + fileName + "\n" + whyIsntValid;
            }
            else if (resultAssetTypeInfo == null)
            {
                errorMessage = "You must select a valid type for your new file.";
            }
            else if (ObjectFinder.Self.GetReferencedFileSaveFromFile(directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension) != null)
            {
                errorMessage = "There is already a file named\n\n" + directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension;
            }
            // TODO:  This currently checks for an exact match, but we should prevent different files (like a .emix and .scnx) from having the same name
            else if (EditorLogic.CurrentElement != null &&
                     EditorLogic.CurrentElement.GetReferencedFileSaveRecursively(directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension) != null)
            {
                errorMessage = "There is already a file named " + fileName;
            }
            // need to check global content for duplicates.  This is not implemented yet.
            #endregion

            #region Else, create the file

            else
            {
                string createdFile = PluginManager.CreateNewFile(resultAssetTypeInfo, option == "2D",
                                                                 directoryRelativeToContent, fileName);

                // let's just re-route this
                // to the code that adds existing
                // files now that we have a file and
                // that's exactly what we're doing.
                rfs = RightClickHelper.AddSingleFile(createdFile, ref userCancelled, option);

                if (rfs == null && !userCancelled)
                {
                    throw new NullReferenceException("The RFS shouldn't be null");
                }
            }

            #endregion



            return(rfs);
        }
        private static void DragDropFile(object sender, DragEventArgs e)
        {
            TreeNode targetNode = null;

            TreeView tree          = (TreeView)sender;
            TreeNode directoryNode = null;


            Point pt = new Point(e.X, e.Y);

            pt         = tree.PointToClient(pt);
            targetNode = tree.GetNodeAt(pt);

            TreeNode nodeDroppedOn = targetNode;

            while (targetNode != null && !targetNode.IsEntityNode() && !targetNode.IsScreenNode())
            {
                if (directoryNode == null && targetNode.IsDirectoryNode())
                {
                    directoryNode = targetNode;
                }

                targetNode = targetNode.Parent;
            }

            var directoryPath = directoryNode == null ? null : directoryNode.GetRelativePath();

            bool userCancelled = false;

            if (targetNode == null)
            {
                ElementViewWindow.SelectedNode = nodeDroppedOn;
                foreach (var fileName in (string[])e.Data.GetData("FileDrop"))
                {
                    string creationReport;

                    string extension = FileManager.GetExtension(fileName);

                    if (extension == "entz" || extension == "scrz")
                    {
                        ElementImporter.ImportElementFromFile(fileName, true);
                    }
                    else
                    {
                        string errorMessage;

                        RightClickHelper.AddSingleFile(fileName, ref userCancelled);
                    }
                }

                GluxCommands.Self.SaveGlux();
            }
            else if (targetNode is ScreenTreeNode || targetNode is EntityTreeNode)
            {
                bool any = false;
                foreach (var fileName in (string[])e.Data.GetData("FileDrop"))
                {
                    // First select the entity
                    ElementViewWindow.SelectedNode = targetNode;


                    var    element             = GlueState.Self.CurrentElement;
                    string directoryOfTreeNode = EditorLogic.CurrentTreeNode.GetRelativePath();


                    FlatRedBall.Glue.Managers.TaskManager.Self.AddSync(() =>
                    {
                        RightClickHelper.AddSingleFile(fileName, ref userCancelled, element, directoryOfTreeNode);
                    },
                                                                       "Add file " + fileName);
                    any = true;
                }
                if (any)
                {
                    FlatRedBall.Glue.Managers.TaskManager.Self.AddSync(() =>
                    {
                        GluxCommands.Self.SaveGlux();
                    },
                                                                       "Save .glux");
                }
            }
        }