Esempio n. 1
0
        public static void HandleRename(ElementSave elementSave, InstanceSave instance, string oldName, NameChangeAction action, bool askAboutRename = true)
        {
            try
            {
                isRenamingXmlFile = instance == null;

                bool shouldContinue = true;

                shouldContinue = ValidateWithPopup(elementSave, instance, shouldContinue);

                shouldContinue = AskIfToRename(oldName, askAboutRename, action, shouldContinue);

                if (shouldContinue)
                {
                    RenameAllReferencesTo(elementSave, instance, oldName);

                    // Even though this gets called from the PropertyGrid methods which eventually
                    // save this object, we want to force a save here to make sure it worked.  If it
                    // does, then we're safe to delete the old files.
                    if (ProjectManager.Self.GeneralSettingsFile.AutoSave)
                    {
                        ProjectManager.Self.SaveElement(elementSave);
                    }

                    if (isRenamingXmlFile)
                    {
                        RenameXml(elementSave, oldName);
                    }

                    GumCommands.Self.GuiCommands.RefreshElementTreeView(elementSave);
                }

                if (!shouldContinue && isRenamingXmlFile)
                {
                    elementSave.Name = oldName;
                }
                else if (!shouldContinue && instance != null)
                {
                    instance.Name = oldName;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error renaming element " + elementSave.ToString() + "\n\n" + e.ToString());
            }
            finally
            {
                isRenamingXmlFile = false;
            }
        }
Esempio n. 2
0
        public void HandleRename(ElementSave elementSave, InstanceSave instance, string oldName)
        {
            try
            {
                IsRenamingXmlFile = instance == null;

                bool shouldContinue = true;

                if (instance != null)
                {
                    string whyNot;
                    if (NameVerifier.Self.IsInstanceNameValid(instance.Name, instance, elementSave, out whyNot) == false)
                    {
                        MessageBox.Show(whyNot);
                        shouldContinue = false;
                    }
                }

                if (shouldContinue && IsRenamingXmlFile)
                {
                    string message = "Are you sure you want to rename " + oldName + "?\n\n" +
                                     "This will change the file name for " + oldName + " which may break " +
                                     "external references to this object.";
                    var result = MessageBox.Show(message, "Rename Object and File?", MessageBoxButtons.YesNo);

                    shouldContinue = result == DialogResult.Yes;
                }


                if (shouldContinue)
                {
                    // Tell the GumProjectSave to react to the rename.
                    // This changes the names of the ElementSave references.
                    ProjectManager.Self.GumProjectSave.ReactToRenamed(elementSave, instance, oldName);


                    if (instance != null)
                    {
                        string newName = SelectedState.Self.SelectedInstance.Name;

                        foreach (StateSave stateSave in SelectedState.Self.SelectedElement.AllStates)
                        {
                            stateSave.ReactToInstanceNameChange(oldName, newName);
                        }

                        foreach (var eventSave in SelectedState.Self.SelectedElement.Events)
                        {
                            if (eventSave.GetSourceObject() == oldName)
                            {
                                eventSave.Name = instance.Name + "." + eventSave.GetRootName();
                            }
                        }
                    }

                    // Even though this gets called from the PropertyGrid methods which eventually
                    // save this object, we want to force a save here to make sure it worked.  If it
                    // does, then we're safe to delete the old files.
                    if (ProjectManager.Self.GeneralSettingsFile.AutoSave)
                    {
                        ProjectManager.Self.SaveElement(elementSave);
                    }

                    if (IsRenamingXmlFile)
                    {
                        // If we got here that means all went okay, so we should delete the old files
                        string oldXml = elementSave.GetFullPathXmlFile(oldName);
                        // Delete the XML.
                        // If the file doesn't
                        // exist, no biggie - we
                        // were going to delete it
                        // anyway.
                        if (System.IO.File.Exists(oldXml))
                        {
                            System.IO.File.Delete(oldXml);
                        }

                        PluginManager.Self.ElementRename(elementSave, oldName);

                        GumCommands.Self.FileCommands.TryAutoSaveProject();

                        GumCommands.Self.GuiCommands.RefreshElementTreeView(elementSave);
                    }
                }

                if (!shouldContinue && IsRenamingXmlFile)
                {
                    elementSave.Name = oldName;
                }
                else if (!shouldContinue && instance != null)
                {
                    instance.Name = oldName;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error renaming element " + elementSave.ToString() + "\n\n" + e.ToString());
            }
            finally
            {
                IsRenamingXmlFile = false;
            }
        }
Esempio n. 3
0
        public void HandleRename(ElementSave elementSave, InstanceSave instance, string oldName, NameChangeAction action, bool askAboutRename = true)
        {
            try
            {
                IsRenamingXmlFile = instance == null;

                bool shouldContinue = true;

                shouldContinue = ValidateWithPopup(elementSave, instance, shouldContinue);

                shouldContinue = AskIfToRename(oldName, askAboutRename, action, shouldContinue);

                if (shouldContinue)
                {
                    RenameAllReferencesTo(elementSave, instance, oldName);

                    // Even though this gets called from the PropertyGrid methods which eventually
                    // save this object, we want to force a save here to make sure it worked.  If it
                    // does, then we're safe to delete the old files.
                    if (ProjectManager.Self.GeneralSettingsFile.AutoSave)
                    {
                        ProjectManager.Self.SaveElement(elementSave);
                    }

                    if (IsRenamingXmlFile)
                    {
                        // If we got here that means all went okay, so we should delete the old files
                        string oldXml = elementSave.GetFullPathXmlFile(oldName);
                        string newXml = elementSave.GetFullPathXmlFile();

                        // Delete the XML.
                        // If the file doesn't
                        // exist, no biggie - we
                        // were going to delete it
                        // anyway.
                        if (System.IO.File.Exists(oldXml))
                        {
                            System.IO.File.Delete(oldXml);
                        }

                        PluginManager.Self.ElementRename(elementSave, oldName);

                        GumCommands.Self.FileCommands.TryAutoSaveProject();

                        var oldDirectory = FileManager.GetDirectory(oldXml);
                        var newDirectory = FileManager.GetDirectory(newXml);

                        bool didMoveToNewDirectory = oldDirectory != newDirectory;

                        if (didMoveToNewDirectory)
                        {
                            // refresh the entire tree view because the node is moving:
                            GumCommands.Self.GuiCommands.RefreshElementTreeView();
                        }
                        else
                        {
                            GumCommands.Self.GuiCommands.RefreshElementTreeView(elementSave);
                        }
                    }
                }

                if (!shouldContinue && IsRenamingXmlFile)
                {
                    elementSave.Name = oldName;
                }
                else if (!shouldContinue && instance != null)
                {
                    instance.Name = oldName;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error renaming element " + elementSave.ToString() + "\n\n" + e.ToString());
            }
            finally
            {
                IsRenamingXmlFile = false;
            }
        }