Esempio n. 1
0
        private static bool AskIfToRename(string oldName, bool askAboutRename, NameChangeAction action, bool shouldContinue)
        {
            if (shouldContinue && isRenamingXmlFile && askAboutRename)
            {
                string moveOrRename;
                if (action == NameChangeAction.Move)
                {
                    moveOrRename = "move";
                }
                else
                {
                    moveOrRename = "rename";
                }

                string message = $"Are you sure you want to {moveOrRename} {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;
            }

            return(shouldContinue);
        }
Esempio n. 2
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);
                    }
                }

                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 OnNameChange(NameChangeAction nameChange)
 {
     this.Name = nameChange.Name;
     NameChanged?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 4
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;
            }
        }