private static void RenameXml(ElementSave elementSave, string oldName) { // 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); } }
private void HandleDroppedElementOnFolder(ElementSave draggedAsElementSave, TreeNode treeNodeDroppedOn, out bool handled) { if (draggedAsElementSave is StandardElementSave) { MessageBox.Show("Cannot move standard elements to different folders"); handled = true; } else { var fullFolderPath = treeNodeDroppedOn.GetFullFilePath(); var fullElementFilePath = FileManager.GetDirectory(draggedAsElementSave.GetFullPathXmlFile()); handled = false; if (FileManager.Standardize(fullFolderPath) != FileManager.Standardize(fullElementFilePath)) { var projectFolder = FileManager.GetDirectory(ProjectManager.Self.GumProjectSave.FullFileName); string nodeRelativeToProject = FileManager.MakeRelative(fullFolderPath, projectFolder + draggedAsElementSave.Subfolder + "\\", preserveCase: true); string oldName = draggedAsElementSave.Name; draggedAsElementSave.Name = nodeRelativeToProject + FileManager.RemovePath(draggedAsElementSave.Name); RenameLogic.HandleRename(draggedAsElementSave, (InstanceSave)null, oldName, NameChangeAction.Move); handled = true; } } }
private static FilePath GetCodeSettingsFileFor(ElementSave element) { FilePath fileName = element.GetFullPathXmlFile(); fileName = fileName.RemoveExtension() + ".codsj"; return(fileName); }
public string GetAbsoluteAnimationFileNameFor(ElementSave elementSave) { var fullPathXmlForElement = elementSave.GetFullPathXmlFile(); if (fullPathXmlForElement == null) { return(null); } else { var absoluteFileName = fullPathXmlForElement.RemoveExtension() + "Animations.ganx"; return(absoluteFileName); } }
public string GetAbsoluteAnimationFileNameFor(ElementSave elementSave) { var fullPathXmlForElement = elementSave.GetFullPathXmlFile(); if (string.IsNullOrEmpty(fullPathXmlForElement)) { return(null); } else { var absoluteFileName = FileManager.RemoveExtension(fullPathXmlForElement) + "Animations.ganx"; return(absoluteFileName); } }
public string GetFileNameForObject(object deletedObject) { if (deletedObject is ElementSave) { ElementSave asElement = deletedObject as ElementSave; return(asElement.GetFullPathXmlFile()); } else if (deletedObject is InstanceSave) { return(null); } else { throw new NotImplementedException(); } }
internal void SaveElement(ElementSave elementSave) { if (elementSave.IsSourceFileMissing) { MessageBox.Show("Cannot save " + elementSave + " because its source file is missing"); } else { bool succeeded = true; UndoManager.Self.RecordUndo(); bool doesProjectNeedToSave = false; bool shouldSave = AskUserForProjectNameIfNecessary(out doesProjectNeedToSave); if (doesProjectNeedToSave) { SaveProject(); } if (shouldSave) { PluginManager.Self.BeforeElementSave(elementSave); string fileName = elementSave.GetFullPathXmlFile(); // if it's readonly, let's warn the user bool isReadOnly = IsFileReadOnly(fileName); if (isReadOnly) { ShowReadOnlyDialog(fileName); } else { FileWatchLogic.Self.IgnoreNextChangeOn(fileName); const int maxNumberOfTries = 5; const int msBetweenSaves = 100; int numberOfTimesTried = 0; succeeded = false; Exception exception = null; while (numberOfTimesTried < maxNumberOfTries) { try { elementSave.Save(fileName); succeeded = true; break; } catch (Exception e) { exception = e; System.Threading.Thread.Sleep(msBetweenSaves); numberOfTimesTried++; } } if (succeeded == false) { MessageBox.Show("Unknown error trying to save the file\n\n" + fileName + "\n\n" + exception.ToString()); succeeded = false; } } if (succeeded) { OutputManager.Self.AddOutput("Saved " + elementSave + " to " + fileName); PluginManager.Self.AfterElementSave(elementSave); } } PluginManager.Self.Export(elementSave); } }
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; } }
public string GetFullFileName(ElementSave element) { return(element.GetFullPathXmlFile()); }
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; } }