private void ReactToFontSet(NamedObjectSave namedObjectSave, object oldValue) { string value = namedObjectSave.GetCustomVariable("Font").Value as string; if (!string.IsNullOrEmpty(value)) { IElement element = EditorLogic.CurrentElement; ReferencedFileSave referencedFileSave = element.GetReferencedFileSaveByInstanceNameRecursively(value); if (referencedFileSave != null) { string file = referencedFileSave.GetRelativePath(); file = ProjectManager.MakeAbsolute(file, true); string contents = FileManager.FromFileText(file); int size = StringFunctions.GetIntAfter( "size=", contents); float lineHeightInPixels = StringFunctions.GetIntAfter( "lineHeight=", contents); lineHeightInPixels /= 2.0f; namedObjectSave.SetPropertyValue("Scale", (float)lineHeightInPixels); namedObjectSave.SetPropertyValue("Spacing", (float)lineHeightInPixels); namedObjectSave.SetPropertyValue("NewLineDistance", (float)(lineHeightInPixels * 1.5f)); } } }
public ReferencedFileSave ShowAddNewFileDialog() { ReferencedFileSave rfs = null; NewFileWindow nfw = CreateNewFileWindow(); if (nfw.ShowDialog(MainGlueWindow.Self) == DialogResult.OK) { string name = nfw.ResultName; AssetTypeInfo resultAssetTypeInfo = nfw.ResultAssetTypeInfo; string errorMessage; string directory = null; IElement element = EditorLogic.CurrentElement; if (EditorLogic.CurrentTreeNode.IsDirectoryNode()) { directory = EditorLogic.CurrentTreeNode.GetRelativePath().Replace("/", "\\"); } var option = nfw.GetOptionFor(resultAssetTypeInfo); rfs = GlueProjectSaveExtensionMethods.AddReferencedFileSave( element, directory, name, resultAssetTypeInfo, option, out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { MessageBox.Show(errorMessage); } else if (rfs != null) { var createdFile = ProjectManager.MakeAbsolute(rfs.GetRelativePath()); if (createdFile.EndsWith(".csv")) { string location = ProjectManager.MakeAbsolute(createdFile); CsvCodeGenerator.GenerateAndSaveDataClass(rfs, AvailableDelimiters.Comma); } ElementViewWindow.UpdateChangedElements(); ElementViewWindow.SelectedNode = GlueState.Self.Find.ReferencedFileSaveTreeNode(rfs); PluginManager.ReactToNewFile(rfs); GluxCommands.Self.SaveGlux(); } } return(rfs); }
public void RemoveReferencedFile(ReferencedFileSave referencedFileToRemove, List <string> additionalFilesToRemove, bool regenerateCode) { var isContained = GlueState.Self.Find.IfReferencedFileSaveIsReferenced(referencedFileToRemove); /////////////////////////Early Out////////////////////////////// if (!isContained) { return; } ////////////////////////End Early Out///////////////////////////// // 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. IElement container = referencedFileToRemove.GetContainer(); #region Remove the file from the current Screen or Entity if there is a current Screen or Entity 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(); } 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 != null) { // treeNode can be null if the user presses delete + enter really really fast, stacking 2 remove // actions 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(); } ); GlobalContentCodeGenerator.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.Name)) { UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false); foreach (var file in UnreferencedFilesManager.LastAddedUnreferencedFiles) { additionalFilesToRemove.Add(file.FilePath); } } ReactToRemovalIfCsv(referencedFileToRemove, additionalFilesToRemove); GluxCommands.Self.SaveGlux(); }
/// <summary> /// Updates the presence of the RFS in the main project. If the RFS has project specific files, then those /// files are updated in the appropriate synced project. /// </summary> /// <remarks> /// This method does not update synced projects if the synced projects use the same file. The reason is because /// this is taken care of when the projects are saved later on. /// </remarks> /// <param name="referencedFileSave">The RFS representing the file to update membership on.</param> /// <returns>Whether anything was added to any projects.</returns> public bool UpdateFileMembershipInProject(ReferencedFileSave referencedFileSave) { var assetTypeInfo = referencedFileSave.GetAssetTypeInfo(); bool shouldSkip = assetTypeInfo != null && assetTypeInfo.ExcludeFromContentProject; bool wasAnythingAdded = false; if (!shouldSkip) { bool useContentPipeline = referencedFileSave.UseContentPipeline || (assetTypeInfo != null && assetTypeInfo.MustBeAddedToContentPipeline); wasAnythingAdded = UpdateFileMembershipInProject(GlueState.Self.CurrentMainProject, referencedFileSave.GetRelativePath(), useContentPipeline, false); foreach (ProjectSpecificFile projectSpecificFile in referencedFileSave.ProjectSpecificFiles) { wasAnythingAdded |= UpdateFileMembershipInProject(ProjectManager.GetProjectByName(projectSpecificFile.ProjectName), projectSpecificFile.FilePath, useContentPipeline, true); } if (wasAnythingAdded) { int m = 3; } } return(wasAnythingAdded); }