public static string ReferencedFileSaveToString(ReferencedFileSave instance) { string containerText = ""; if (instance.GetContainerType() == SaveClasses.ContainerType.None) { containerText = " (in GlobalContent)"; } else { containerText = " (in " + instance.GetContainer() + ")"; } return(instance.Name + containerText); }
public static string GetInstanceName(this ReferencedFileSave instance) { string toReturn = FileManager.RemoveExtension(instance.Name).Replace(" ", "").Replace("-", "_"); if (instance.IncludeDirectoryRelativeToContainer) { IElement container = instance.GetContainer(); if (container != null) { string directoryToMakeRelativeTo = container.Name; bool isRelativeTo = FileManager.IsRelativeTo(toReturn, directoryToMakeRelativeTo); if (isRelativeTo) { toReturn = FileManager.MakeRelative(toReturn, directoryToMakeRelativeTo); toReturn = toReturn.Replace("/", "_"); } else { toReturn = FileManager.RemovePath(toReturn); } //string modifiedName = FileManager.Relativethis.Name; } else { // Might be something like: "GlobalContent/FolderInGlobalContent/SceneFileInFolder" if (toReturn.StartsWith("GlobalContent/")) { toReturn = toReturn.Substring("GlobalContent/".Length); } toReturn = toReturn.Replace("/", "_"); } } else { toReturn = FileManager.RemovePath(toReturn); } return(toReturn); }
public static ContainerType GetContainerType(this ReferencedFileSave instance) { IElement element = instance.GetContainer(); if (element != null) { if (element is ScreenSave) { return(SaveClasses.ContainerType.Screen); } else { return(SaveClasses.ContainerType.Entity); } } else { return(SaveClasses.ContainerType.None); } }
public void RemoveReferencedFile(ReferencedFileSave referencedFileToRemove, List<string> additionalFilesToRemove, bool regenerateCode) { // There are some things that need to happen: // 1. Remove the ReferencedFileSave from the Glue project (GLUX) // 2. Remove the GUI item // 3. Remove the item from the Visual Studio project. #region Remove the file from the current Screen or Entity if there is a current Screen or Entity IElement container = referencedFileToRemove.GetContainer(); if (container != null) { // The referenced file better be a globally referenced file if (!container.ReferencedFiles.Contains(referencedFileToRemove)) { throw new ArgumentException(); } else { container.ReferencedFiles.Remove(referencedFileToRemove); } // Ask about any NamedObjects that reference this file. for (int i = container.NamedObjects.Count - 1; i > -1; i--) { var nos = container.NamedObjects[i]; if (nos.SourceType == SourceType.File && nos.SourceFile == referencedFileToRemove.Name) { MainGlueWindow.Self.Invoke(() => { // Ask the user what to do here - remove it? Keep it and not compile? MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); mbmb.MessageText = "The object\n" + nos.ToString() + "\nreferences the file\n" + referencedFileToRemove.Name + "\nWhat would you like to do?"; mbmb.AddButton("Remove this object", DialogResult.Yes); mbmb.AddButton("Keep it (object will not be valid until changed)", DialogResult.No); var result = mbmb.ShowDialog(); if (result == DialogResult.Yes) { container.NamedObjects.RemoveAt(i); } }); } nos.ResetVariablesReferencing(referencedFileToRemove); } MainGlueWindow.Self.Invoke(() => { if (EditorLogic.CurrentScreenTreeNode != null) { EditorLogic.CurrentScreenTreeNode.UpdateReferencedTreeNodes(); } else if (EditorLogic.CurrentEntityTreeNode != null) { EditorLogic.CurrentEntityTreeNode.UpdateReferencedTreeNodes(false); } if (regenerateCode) { ElementViewWindow.GenerateSelectedElementCode(); } }); } #endregion #region else, the file is likely part of the GlobalContentFile else { ProjectManager.GlueProjectSave.GlobalFiles.Remove(referencedFileToRemove); ProjectManager.GlueProjectSave.GlobalContentHasChanged = true; // Much faster to just remove the tree node. This was done // to reuse code and make things reactive, but this has gotten // slow on bigger projects. //ElementViewWindow.UpdateGlobalContentTreeNodes(false); // don't save here because projects will get saved below Action refreshUiAction = () => { TreeNode treeNode = GlueState.Self.Find.ReferencedFileSaveTreeNode(referencedFileToRemove); if (treeNode.Tag != referencedFileToRemove) { throw new Exception("Error removing the tree node - the selected tree node doesn't reference the file being removed"); } treeNode.Parent.Nodes.Remove(treeNode); }; MainGlueWindow.Self.Invoke((MethodInvoker)delegate { refreshUiAction(); } ); ContentLoadWriter.UpdateLoadGlobalContentCode(); List<IElement> elements = ObjectFinder.Self.GetAllElementsReferencingFile(referencedFileToRemove.Name); foreach (IElement element in elements) { if (regenerateCode) { CodeWriter.GenerateCode(element); } } } #endregion // November 10, 2015 // I feel like this may // have been old code before // we had full dependency tracking // in Glue. This file should only be // removed from the project if nothing // else references it, including no entities. // This code does just entities/screens/global // content, but doesn't check the full dependency // tree. I think we can just remove it and depend on // the code below. // Actually, removing this seems to cause problems - files // that should be removed aren't. So instead we'll chnage the // call to use the dependency tree: // replace: List<string> referencedFiles = GlueCommands.Self.FileCommands.GetAllReferencedFileNames().Select(item=>item.ToLowerInvariant()).ToList(); string absoluteToLower = GlueCommands.Self.GetAbsoluteFileName(referencedFileToRemove).ToLowerInvariant(); string relativeToProject = FileManager.MakeRelative(absoluteToLower, GlueState.Self.ContentDirectory); bool isReferencedByOtherContent = referencedFiles.Contains(relativeToProject); if (isReferencedByOtherContent == false) { additionalFilesToRemove.Add(referencedFileToRemove.GetRelativePath()); string itemName = referencedFileToRemove.GetRelativePath(); string absoluteName = ProjectManager.MakeAbsolute(referencedFileToRemove.Name, true); // I don't know why we were removing the file from the ProjectBase - it should // be from the Content project //ProjectManager.RemoveItemFromProject(ProjectManager.ProjectBase, itemName); ProjectManager.RemoveItemFromProject(ProjectManager.ProjectBase.ContentProject, itemName, performSave: false); foreach (ProjectBase syncedProject in ProjectManager.SyncedProjects) { ProjectManager.RemoveItemFromProject(syncedProject.ContentProject, absoluteName); } } if (ProjectManager.IsContent(referencedFileToRemove.GetRelativePath())) { UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false); foreach (var file in UnreferencedFilesManager.LastAddedUnreferencedFiles) { additionalFilesToRemove.Add(file.FilePath); } } ReactToRemovalIfCsv(referencedFileToRemove, additionalFilesToRemove); GluxCommands.Self.SaveGlux(); }
public TreeNode ReferencedFileSaveTreeNode(ReferencedFileSave referencedFileSave) { IElement container = referencedFileSave.GetContainer(); if (container == null) { return TreeNodeByTagIn(referencedFileSave, ElementViewWindow.GlobalContentFileNode.Nodes); } else if (container is ScreenSave) { ScreenTreeNode screenTreeNode = GlueState.Self.Find.ScreenTreeNode((ScreenSave)container); return screenTreeNode.GetTreeNodeFor(referencedFileSave); } else if (container is EntitySave) { EntityTreeNode entityTreeNode = GlueState.Self.Find.EntityTreeNode((EntitySave)container); return entityTreeNode.GetTreeNodeFor(referencedFileSave); } return null; }
public static string ReferencedFileSaveToString(ReferencedFileSave instance) { string containerText = ""; if (instance.GetContainerType() == SaveClasses.ContainerType.None) { containerText = " (in GlobalContent)"; } else { containerText = " (in " + instance.GetContainer() + ")"; } return instance.Name + containerText; }
private static void DragAddFileToGlobalContent(TreeNode treeNodeMoving, ReferencedFileSave referencedFileSave) { if (referencedFileSave.GetContainerType() == ContainerType.None) { // This means the user dragged a file from global content onto the global content tree node - // we shouldn't do anything here. It's not a valid operation, but at the same time, it may have // happened accidentally and we don't want to burden the user with popups. } else { bool isAlreadyPartOfReferencedFiles = false; // If the file is already part of GlobalContent, then warn the user and do nothing foreach (ReferencedFileSave fileInGlobalContent in ObjectFinder.Self.GlueProject.GlobalFiles) { if (fileInGlobalContent.Name == referencedFileSave.Name) { isAlreadyPartOfReferencedFiles = true; break; } } if (isAlreadyPartOfReferencedFiles) { MessageBox.Show("The file\n\n" + referencedFileSave.Name + "\n\nis already a Global Content File"); } else { // If we got here, that means that the file that // the user is dragging in to Global Content Files // can be added to Global Content Files; however, the // owner of the file may not be using global content. We // should ask the user if the containing IElement should use // global content IElement container = referencedFileSave.GetContainer(); if (!container.UseGlobalContent) { string screenOrEntity = "Screen"; if (container is EntitySave) { screenOrEntity = "Entity"; } DialogResult result = MessageBox.Show("The " + screenOrEntity + " " + container.ToString() + "does not UseGlobalContent. Would you like " + " to set UseGlobalContent to true?", "Set UseGlobalContent to true?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { container.UseGlobalContent = true; } } bool useFullPathAsName = true; ElementCommands.Self.AddReferencedFileToGlobalContent(referencedFileSave.Name, useFullPathAsName); ContentLoadWriter.UpdateLoadGlobalContentCode(); ProjectManager.SaveProjects(); GluxCommands.Self.SaveGlux(); } } }