Ejemplo n.º 1
0
 public void CallDeleteOptionsWindowShow(DeleteOptionsWindow optionsWindow, object objectToDelete)
 {
     if (DeleteOptionsWindowShow != null)
     {
         DeleteOptionsWindowShow(optionsWindow, objectToDelete);
     }
 }
Ejemplo n.º 2
0
 public void CallDeleteConfirm(DeleteOptionsWindow optionsWindow, object deletedObject)
 {
     if (DeleteConfirm != null)
     {
         DeleteConfirm(optionsWindow, deletedObject);
     }
 }
Ejemplo n.º 3
0
        DialogResult ShowDeleteDialog(object objectToDelete, out DeleteOptionsWindow optionsWindow)
        {
            string titleText;

            if (objectToDelete is ComponentSave)
            {
                titleText = "Delete Component?";
            }
            else if (objectToDelete is ScreenSave)
            {
                titleText = "Delete Screen?";
            }
            else if (objectToDelete is InstanceSave)
            {
                titleText = "Delete Instance?";
            }
            else
            {
                titleText = "Delete?";
            }

            optionsWindow                = new DeleteOptionsWindow();
            optionsWindow.Text           = titleText;
            optionsWindow.Message        = "Are you sure you want to delete:\n" + objectToDelete.ToString();
            optionsWindow.ObjectToDelete = objectToDelete;

            PluginManager.Self.ShowDeleteDialog(optionsWindow, objectToDelete);

            DialogResult result = optionsWindow.ShowDialog();


            return(result);
        }
Ejemplo n.º 4
0
 internal void DeleteConfirm(DeleteOptionsWindow window, object objectToDelete)
 {
     CallMethodOnPlugin(
         delegate(PluginBase plugin)
     {
         plugin.CallDeleteConfirm(window, objectToDelete);
     },
         "ConfirmDelete"
         );
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Allows all plugins to adjust the DeleteOptionsWindow whenever any object is deleted, including
 /// elements, instances, and behaviors.
 /// </summary>
 /// <param name="window">The window to modify.</param>
 /// <param name="objectToDelete">The object that may be deleted, which could be any Gum type.</param>
 internal void ShowDeleteDialog(DeleteOptionsWindow window, object objectToDelete)
 {
     CallMethodOnPlugin(
         delegate(PluginBase plugin)
     {
         plugin.CallDeleteOptionsWindowShow(window, objectToDelete);
     },
         nameof(ShowDeleteDialog)
         );
 }
Ejemplo n.º 6
0
        public void HandleDelete()
        {
            object objectDeleted = null;
            DeleteOptionsWindow optionsWindow = null;

            if (SelectedState.Self.SelectedInstances.Count() > 1)
            {
                AskToDeleteInstances(SelectedState.Self.SelectedInstances);
            }
            else if (SelectedState.Self.SelectedInstance != null)
            {
                objectDeleted = SelectedState.Self.SelectedInstance;
                AskToDeleteInstance(SelectedState.Self.SelectedInstance);
            }
            else if (SelectedState.Self.SelectedComponent != null)
            {
                DialogResult result = ShowDeleteDialog(SelectedState.Self.SelectedComponent, out optionsWindow);

                if (result == DialogResult.Yes || result == DialogResult.OK)
                {
                    objectDeleted = SelectedState.Self.SelectedComponent;
                    // We need to remove the reference
                    EditingManager.Self.RemoveSelectedElement();
                }
            }
            else if (SelectedState.Self.SelectedScreen != null)
            {
                DialogResult result = ShowDeleteDialog(SelectedState.Self.SelectedScreen, out optionsWindow);

                if (result == DialogResult.Yes || result == DialogResult.OK)
                {
                    objectDeleted = SelectedState.Self.SelectedScreen;
                    // We need to remove the reference
                    EditingManager.Self.RemoveSelectedElement();
                }
            }

            if (objectDeleted != null)
            {
                PluginManager.Self.DeleteConfirm(optionsWindow, objectDeleted);
            }
        }
Ejemplo n.º 7
0
        bool?ShowDeleteDialog(object objectToDelete, out DeleteOptionsWindow optionsWindow)
        {
            string titleText;

            if (objectToDelete is ComponentSave)
            {
                titleText = "Delete Component?";
            }
            else if (objectToDelete is ScreenSave)
            {
                titleText = "Delete Screen?";
            }
            else if (objectToDelete is InstanceSave)
            {
                titleText = "Delete Instance?";
            }
            else if (objectToDelete is BehaviorSave)
            {
                titleText = "Delete Behavior?";
            }
            else
            {
                titleText = "Delete?";
            }

            optionsWindow                = new DeleteOptionsWindow();
            optionsWindow.Title          = titleText;
            optionsWindow.Message        = "Are you sure you want to delete:\n" + objectToDelete.ToString();
            optionsWindow.ObjectToDelete = objectToDelete;

            GumCommands.Self.GuiCommands.PositionWindowByCursor(optionsWindow);

            PluginManager.Self.ShowDeleteDialog(optionsWindow, objectToDelete);

            var result = optionsWindow.ShowDialog();


            return(result);
        }
Ejemplo n.º 8
0
        private void DoDeletingLogic()
        {
            object objectDeleted = null;
            DeleteOptionsWindow optionsWindow = null;

            var selectedElement  = SelectedState.Self.SelectedElement;
            var selectedInstance = SelectedState.Self.SelectedInstance;

            if (SelectedState.Self.SelectedInstances.Count() > 1)
            {
                AskToDeleteInstances(SelectedState.Self.SelectedInstances);
            }
            else if (selectedInstance != null)
            {
                objectDeleted = selectedInstance;
                //AskToDeleteInstance(SelectedState.Self.SelectedInstance);

                if (selectedInstance.DefinedByBase)
                {
                    MessageBox.Show($"The instance {selectedInstance.Name} cannot be deleted becuase it is defined in a base object.");
                }
                else
                {
                    //DialogResult result =
                    //    MessageBox.Show("Are you sure you'd like to delete " + instance.Name + "?", "Delete instance?", MessageBoxButtons.YesNo);
                    var result = ShowDeleteDialog(selectedInstance, out optionsWindow);


                    if (result == true)
                    {
                        var siblings       = selectedInstance.GetSiblingsIncludingThis();
                        var parentInstance = selectedInstance.GetParentInstance();

                        // This will delete all references to this, meaning, all
                        // instances attached to the deleted object will be detached,
                        // but we don't want that, we want to only do that if the user wants to do it, which
                        // will be handled in a plugin
                        //Gum.ToolCommands.ElementCommands.Self.RemoveInstance(instance, selectedElement);
                        selectedElement.Instances.Remove(selectedInstance);
                        var instanceName = selectedInstance.Name;

                        selectedElement.Events.RemoveAll(item => item.GetSourceObject() == instanceName);

                        // March 17, 2019
                        // Let's also delete
                        // any variables referencing
                        // this object
                        var objectName = selectedInstance.Name;


                        foreach (var state in selectedElement.AllStates)
                        {
                            state.Variables.RemoveAll(item => item.SourceObject == instanceName);
                        }



                        PluginManager.Self.InstanceDelete(selectedElement, selectedInstance);

                        var deletedSelection = SelectedState.Self.SelectedInstance == selectedInstance;

                        RefreshAndSaveAfterInstanceRemoval(selectedElement);

                        if (deletedSelection)
                        {
                            var index = siblings.IndexOf(selectedInstance);
                            if (index + 1 < siblings.Count)
                            {
                                SelectedState.Self.SelectedInstance = siblings[index + 1];
                            }
                            else if (index > 0)
                            {
                                SelectedState.Self.SelectedInstance = siblings[index - 1];
                            }
                            else
                            {
                                // no siblings so select the container or null if none exists:
                                SelectedState.Self.SelectedInstance = parentInstance;
                            }
                        }
                    }
                }
            }
            else if (SelectedState.Self.SelectedComponent != null)
            {
                var result = ShowDeleteDialog(SelectedState.Self.SelectedComponent, out optionsWindow);

                if (result == true)
                {
                    objectDeleted = SelectedState.Self.SelectedComponent;
                    // We need to remove the reference
                    EditingManager.Self.RemoveSelectedElement();
                }
            }
            else if (SelectedState.Self.SelectedScreen != null)
            {
                var result = ShowDeleteDialog(SelectedState.Self.SelectedScreen, out optionsWindow);

                if (result == true)
                {
                    objectDeleted = SelectedState.Self.SelectedScreen;
                    // We need to remove the reference
                    EditingManager.Self.RemoveSelectedElement();
                }
            }
            else if (SelectedState.Self.SelectedBehavior != null)
            {
                var result = ShowDeleteDialog(SelectedState.Self.SelectedBehavior, out optionsWindow);

                if (result == true)
                {
                    objectDeleted = SelectedState.Self.SelectedBehavior;
                    // We need to remove the reference
                    EditingManager.Self.RemoveSelectedBehavior();
                }
            }

            var shouldDelete = objectDeleted != null;

            if (shouldDelete && selectedInstance != null)
            {
                shouldDelete = selectedInstance.DefinedByBase == false;
            }

            if (shouldDelete)
            {
                PluginManager.Self.DeleteConfirm(optionsWindow, objectDeleted);
            }
        }
Ejemplo n.º 9
0
        private void DoDeletingLogic()
        {
            object objectDeleted = null;
            DeleteOptionsWindow optionsWindow = null;

            var selectedElement  = SelectedState.Self.SelectedElement;
            var selectedInstance = SelectedState.Self.SelectedInstance;

            if (SelectedState.Self.SelectedInstances.Count() > 1)
            {
                AskToDeleteInstances(SelectedState.Self.SelectedInstances);
            }
            else if (selectedInstance != null)
            {
                objectDeleted = selectedInstance;
                //AskToDeleteInstance(SelectedState.Self.SelectedInstance);

                if (selectedInstance.DefinedByBase)
                {
                    MessageBox.Show($"The instance {selectedInstance.Name} cannot be deleted becuase it is defined in a base object.");
                }
                else
                {
                    //DialogResult result =
                    //    MessageBox.Show("Are you sure you'd like to delete " + instance.Name + "?", "Delete instance?", MessageBoxButtons.YesNo);
                    var result = ShowDeleteDialog(selectedInstance, out optionsWindow);


                    if (result == true)
                    {
                        // This will delete all references to this, meaning, all
                        // instances attached to the deleted object will be detached,
                        // but we don't want that, we want to only do that if the user wants to do it, which
                        // will be handled in a plugin
                        //Gum.ToolCommands.ElementCommands.Self.RemoveInstance(instance, selectedElement);
                        selectedElement.Instances.Remove(selectedInstance);
                        selectedElement.Events.RemoveAll(item => item.GetSourceObject() == selectedInstance.Name);
                        PluginManager.Self.InstanceDelete(selectedElement, selectedInstance);
                        if (SelectedState.Self.SelectedInstance == selectedInstance)
                        {
                            SelectedState.Self.SelectedInstance = null;
                        }

                        RefreshAndSaveAfterInstanceRemoval(selectedElement);
                    }
                }
            }
            else if (SelectedState.Self.SelectedComponent != null)
            {
                var result = ShowDeleteDialog(SelectedState.Self.SelectedComponent, out optionsWindow);

                if (result == true)
                {
                    objectDeleted = SelectedState.Self.SelectedComponent;
                    // We need to remove the reference
                    EditingManager.Self.RemoveSelectedElement();
                }
            }
            else if (SelectedState.Self.SelectedScreen != null)
            {
                var result = ShowDeleteDialog(SelectedState.Self.SelectedScreen, out optionsWindow);

                if (result == true)
                {
                    objectDeleted = SelectedState.Self.SelectedScreen;
                    // We need to remove the reference
                    EditingManager.Self.RemoveSelectedElement();
                }
            }
            else if (SelectedState.Self.SelectedBehavior != null)
            {
                var result = ShowDeleteDialog(SelectedState.Self.SelectedBehavior, out optionsWindow);

                if (result == true)
                {
                    objectDeleted = SelectedState.Self.SelectedBehavior;
                    // We need to remove the reference
                    EditingManager.Self.RemoveSelectedBehavior();
                }
            }
            if (objectDeleted != null)
            {
                PluginManager.Self.DeleteConfirm(optionsWindow, objectDeleted);
            }
        }