private static void RegenerateCodeAndUpdateUiAccordingToRfsRename(string oldName, string newName, ReferencedFileSave fileSave) { foreach (IElement element in ProjectManager.GlueProjectSave.AllElements()) { bool wasAnythingChanged = element.ReactToRenamedReferencedFile(oldName, newName); if (wasAnythingChanged) { CodeWriter.GenerateCode(element); } if (element.ReferencedFiles.Contains(fileSave)) { BaseElementTreeNode node = GlueState.Self.Find.ElementTreeNode(element); node.UpdateReferencedTreeNodes(); } } }
private static bool DragDropNosIntoElement(NamedObjectSave movingNos, IElement elementMovingInto) { bool succeeded = true; // moving to another element, so let's copy NamedObjectSave clonedNos = movingNos.Clone(); UpdateNosAfterDragDrop(clonedNos, elementMovingInto); elementMovingInto.NamedObjects.Add(clonedNos); var referenceCheck = ProjectManager.VerifyReferenceGraph(elementMovingInto); if (referenceCheck == ProjectManager.CheckResult.Failed) { succeeded = false; // VerifyReferenceGraph (currently) shows a popup so we don't have to here //MessageBox.Show("This movement would result in a circular reference"); elementMovingInto.NamedObjects.Remove(clonedNos); } if (succeeded) { // If an object which was on a Layer // is moved into another Element, then // the cloned object probably shouldn't // be on a layer. Not sure if we want to // see if there is a Layer with the same-name // but we maybe shouldn't assume that they mean // the same thing. clonedNos.LayerOn = null; BaseElementTreeNode treeNodeForElementMovedInto = GlueState.Self.Find.ElementTreeNode(elementMovingInto); treeNodeForElementMovedInto.UpdateReferencedTreeNodes(); GlueCommands.Self.GenerateCodeCommands .GenerateElementAndReferencedObjectCodeTask(elementMovingInto); MessageBox.Show("Copied\n" + movingNos + "\n\nto\n" + clonedNos); } return(succeeded); }
internal static void AddNewNamedObjectToElementTreeNode(BaseElementTreeNode elementTreeNode, NamedObjectSave namedObject, bool modifyNamedObject) { // We no longer need to modify new named objects this way // AttachToContainer defaults to true and won't do anything // on Screens. It looks like AddToManagers was always true. //if (modifyNamedObject) //{ // if (elementTreeNode.SaveObjectAsElement is EntitySave) // { // namedObject.AddToManagers = !(elementTreeNode.SaveObjectAsElement as EntitySave).IsUnique; // namedObject.AddToManagers = true; // } // else // { // // Vic says - when a file is loaded in a Screen, // // it is added to managers. When it is loaded in // // Entities, it is not and components of it are cloned // // Therefore, if we're in a Screen, we should assume that // // we are going to load from a file for this new object and // // not set the AddToManagers to true. But IF the new object // // is going to be an Entity, then the PropetyGrid will handle // // setting its AddToManagers to true. // } //} elementTreeNode.SaveObjectAsElement.NamedObjects.Add(namedObject); elementTreeNode.UpdateReferencedTreeNodes(); CodeWriter.GenerateCode(elementTreeNode.SaveObjectAsElement); // Highlight the newly created object TreeNode treeNode = EditorLogic.CurrentElementTreeNode.GetTreeNodeFor(namedObject); if (treeNode != null) { MainGlueWindow.Self.ElementTreeView.SelectedNode = treeNode; } }
public static void RemoveNamedObject(NamedObjectSave namedObjectToRemove, bool performSave, bool updateUi, List <string> additionalFilesToRemove) { StringBuilder removalInformation = new StringBuilder(); // The additionalFilesToRemove is included for consistency with other methods. It may be used later // There are the following things that need to happen: // 1. Remove the NamedObject from the Glue project (GLUX) // 2. Remove any variables that use this NamedObject as their source // 3. Remove the named object from the GUI // 4. Update the variables for any NamedObjects that use this element containing this NamedObject // 5. Find any Elements that contain NamedObjects that are DefinedByBase - if so, see if we should remove those or make them not DefinedByBase // 6. Remove any events that tunnel into this. IElement element = namedObjectToRemove.GetContainer(); if (element != null) { if (!namedObjectToRemove.RemoveSelfFromNamedObjectList(element.NamedObjects)) { throw new ArgumentException(); } #region Remove all CustomVariables that reference the removed NamedObject for (int i = element.CustomVariables.Count - 1; i > -1; i--) { CustomVariable variable = element.CustomVariables[i]; if (variable.SourceObject == namedObjectToRemove.InstanceName) { removalInformation.AppendLine("Removed variable " + variable.ToString()); element.CustomVariables.RemoveAt(i); } } #endregion // Remove any events that use this for (int i = element.Events.Count - 1; i > -1; i--) { EventResponseSave ers = element.Events[i]; if (ers.SourceObject == namedObjectToRemove.InstanceName) { removalInformation.AppendLine("Removed event " + ers.ToString()); element.Events.RemoveAt(i); } } // Remove any objects that use this as a layer for (int i = 0; i < element.NamedObjects.Count; i++) { if (element.NamedObjects[i].LayerOn == namedObjectToRemove.InstanceName) { removalInformation.AppendLine("Removed the following object from the deleted Layer: " + element.NamedObjects[i].ToString()); element.NamedObjects[i].LayerOn = null; } } element.RefreshStatesToCustomVariables(); #region Ask the user what to do with all NamedObjects that are DefinedByBase List <IElement> derivedElements = new List <IElement>(); if (element is EntitySave) { derivedElements.AddRange(ObjectFinder.Self.GetAllEntitiesThatInheritFrom(element as EntitySave)); } else { derivedElements.AddRange(ObjectFinder.Self.GetAllScreensThatInheritFrom(element as ScreenSave)); } foreach (IElement derivedElement in derivedElements) { // At this point, namedObjectToRemove is already removed from the current Element, so this will only // return NamedObjects that exist in the derived. NamedObjectSave derivedNamedObject = derivedElement.GetNamedObjectRecursively(namedObjectToRemove.InstanceName); if (derivedNamedObject != null && derivedNamedObject != namedObjectToRemove && derivedNamedObject.DefinedByBase) { MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); mbmb.MessageText = "What would you like to do with the object " + derivedNamedObject.ToString(); mbmb.AddButton("Keep it", DialogResult.OK); mbmb.AddButton("Delete it", DialogResult.Cancel); DialogResult result = mbmb.ShowDialog(MainGlueWindow.Self); if (result == DialogResult.OK) { // Keep it derivedNamedObject.DefinedByBase = false; BaseElementTreeNode treeNode = GlueState.Self.Find.ElementTreeNode(derivedElement); if (updateUi) { treeNode.UpdateReferencedTreeNodes(); } CodeWriter.GenerateCode(derivedElement); } else { // Delete it RemoveNamedObject(derivedNamedObject, performSave, updateUi, additionalFilesToRemove); } } } #endregion var elementTreeNode = GlueState.Self.Find.ElementTreeNode(element); if (updateUi) { elementTreeNode.UpdateReferencedTreeNodes(); } CodeWriter.GenerateCode(element); if (element is EntitySave) { List <NamedObjectSave> entityNamedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(element.Name); foreach (NamedObjectSave nos in entityNamedObjects) { nos.UpdateCustomProperties(); } } } if (performSave) { GluxCommands.Self.SaveGlux(); } }