From 35549b10596869baeb0bd0957e0d8c88e7969573 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 16 Mar 2022 12:37:55 -0400 Subject: [PATCH] refactor Template subclasses and add ObjectModel empty template prefix parameter --- ...els.FileSystem.FileSystemObjectModel.uexml | 2 +- .../FileSystem/WindowsFileSystem.uexml | 1 + .../File Distribution/EmptyFileSystem.uexml | 2 +- .../File Distribution/EmptyTorrent.uexml | 2 +- .../Project/General/EmptyProject.uexml | 2 +- .../Project/SCE/PSM/BasicProject.uexml | 2 +- .../ObjectModelReference.cs | 1 + .../UEPackage/UEPackageXMLDataFormat.cs | 189 +++++++----------- .../UniversalEditor.Essential/Template.cs | 27 ++- .../Dialogs/NewDialog.cs | 25 ++- .../EditorApplication.cs | 12 +- 11 files changed, 118 insertions(+), 147 deletions(-) diff --git a/Content/UniversalEditor.Content.PlatformIndependent/ObjectModels/UniversalEditor.ObjectModels.FileSystem.FileSystemObjectModel.uexml b/Content/UniversalEditor.Content.PlatformIndependent/ObjectModels/UniversalEditor.ObjectModels.FileSystem.FileSystemObjectModel.uexml index c633896e..65ebf088 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/ObjectModels/UniversalEditor.ObjectModels.FileSystem.FileSystemObjectModel.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/ObjectModels/UniversalEditor.ObjectModels.FileSystem.FileSystemObjectModel.uexml @@ -2,6 +2,6 @@ + Visible="true" EmptyTemplatePrefix="EmptyFileSystem" /> diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Document/FileSystem/WindowsFileSystem.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Document/FileSystem/WindowsFileSystem.uexml index aa692340..72e10e6e 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Document/FileSystem/WindowsFileSystem.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Document/FileSystem/WindowsFileSystem.uexml @@ -6,6 +6,7 @@ Windows filesystem Creates a standard Windows NT file structure. + WindowsFileSystem General File system/archive diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/File Distribution/EmptyFileSystem.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/File Distribution/EmptyFileSystem.uexml index d1fa4813..f67368d0 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/File Distribution/EmptyFileSystem.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/File Distribution/EmptyFileSystem.uexml @@ -4,7 +4,7 @@ Empty File System - FileSystem + FileSystem Creates an empty FileSystem project for packaging files in various archive formats. diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/File Distribution/EmptyTorrent.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/File Distribution/EmptyTorrent.uexml index c33bac18..2a323350 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/File Distribution/EmptyTorrent.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/File Distribution/EmptyTorrent.uexml @@ -4,7 +4,7 @@ Empty Torrent - Torrent + Torrent Creates an empty Torrent project for distributing files over peer-to-peer networks. diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/General/EmptyProject.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/General/EmptyProject.uexml index ab9cab8d..18e4332c 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/General/EmptyProject.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/General/EmptyProject.uexml @@ -4,7 +4,7 @@ Empty Project - Project + Project Creates an empty project. diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/SCE/PSM/BasicProject.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/SCE/PSM/BasicProject.uexml index 30ee89c8..1eeae90b 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/SCE/PSM/BasicProject.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Templates/Project/SCE/PSM/BasicProject.uexml @@ -11,7 +11,7 @@ Basic PlayStation(R) Mobile Project - PsmApp + PsmApp Creates a basic PlayStation Mobile app for developing on PlayStation Vita and PlayStation 3. diff --git a/Libraries/UniversalEditor.Core/ObjectModelReference.cs b/Libraries/UniversalEditor.Core/ObjectModelReference.cs index a72ad77d..60e65298 100644 --- a/Libraries/UniversalEditor.Core/ObjectModelReference.cs +++ b/Libraries/UniversalEditor.Core/ObjectModelReference.cs @@ -238,6 +238,7 @@ namespace UniversalEditor private bool mvarVisible = true; public bool Visible { get { return mvarVisible; } set { mvarVisible = value; } } + public string EmptyTemplatePrefix { get; set; } = null; private static Dictionary _referencesByGUID = new Dictionary(); private static Dictionary _referencesByTypeName = new Dictionary(); diff --git a/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs b/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs index 509ff0b5..99cdb6cb 100644 --- a/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs +++ b/Libraries/UniversalEditor.Essential/DataFormats/UEPackage/UEPackageXMLDataFormat.cs @@ -531,61 +531,8 @@ namespace UniversalEditor.DataFormats.UEPackage template.ID = new Guid(attID.Value); } - MarkupTagElement tagInformation = (tagTemplate.Elements["Information"] as MarkupTagElement); + LoadTemplateCommonInformation(template, tagTemplate); - #region Information - { - if (tagInformation != null) - { - if (tagInformation.Elements["Title"] != null) - { - template.Title = tagInformation.Elements["Title"].Value; - } - if (tagInformation.Elements["Description"] != null) - { - template.Description = tagInformation.Elements["Description"].Value; - } - - MarkupTagElement tagPath = (tagInformation.Elements["Path"] as MarkupTagElement); - if (tagPath != null) - { - List pathParts = new List(); - foreach (MarkupElement elPart in tagPath.Elements) - { - MarkupTagElement tagPart = (elPart as MarkupTagElement); - if (tagPart == null) continue; - if (tagPart.FullName != "Part") continue; - pathParts.Add(tagPart.Value); - } - template.Path = pathParts.ToArray(); - } - - MarkupTagElement tagIconPath = (tagInformation.Elements["IconPath"] as MarkupTagElement); - if (tagIconPath != null) - { - MarkupAttribute attFileName = tagIconPath.Attributes["FileName"]; - if (attFileName != null) - { - string ImageFileName = attFileName.Value; - template.LargeIconImageFileName = ImageFileName; - template.SmallIconImageFileName = ImageFileName; - } - MarkupAttribute attLargeFileName = tagIconPath.Attributes["LargeFileName"]; - if (attLargeFileName != null) - { - string ImageFileName = attLargeFileName.Value; - template.LargeIconImageFileName = ImageFileName; - } - MarkupAttribute attSmallFileName = tagIconPath.Attributes["SmallFileName"]; - if (attSmallFileName != null) - { - string ImageFileName = attSmallFileName.Value; - template.SmallIconImageFileName = ImageFileName; - } - } - } - } - #endregion #region Variables { MarkupTagElement tagVariables = (tagTemplate.Elements["Variables"] as MarkupTagElement); @@ -727,72 +674,8 @@ namespace UniversalEditor.DataFormats.UEPackage } } - #region Information - MarkupTagElement tagInformation = (tagTemplate.Elements["Information"] as MarkupTagElement); - if (tagInformation != null) - { - MarkupTagElement tagTitle = (tagInformation.Elements["Title"] as MarkupTagElement); - if (tagTitle != null) template.Title = tagTitle.Value; + LoadTemplateCommonInformation(template, tagTemplate); - MarkupTagElement tagDescription = (tagInformation.Elements["Description"] as MarkupTagElement); - if (tagDescription != null) template.Description = tagDescription.Value; - - if (tagInformation.Elements["ProjectNamePrefix"] != null) - { - template.ProjectNamePrefix = tagInformation.Elements["ProjectNamePrefix"].Value; - } - - MarkupTagElement tagPath = (tagInformation.Elements["Path"] as MarkupTagElement); - if (tagPath != null) - { - List pathParts = new List(); - foreach (MarkupElement elPart in tagPath.Elements) - { - MarkupTagElement tagPart = (elPart as MarkupTagElement); - if (tagPart == null) continue; - if (tagPart.FullName != "Part") continue; - pathParts.Add(tagPart.Value); - } - template.Path = pathParts.ToArray(); - } - - MarkupTagElement tagIconPath = (tagInformation.Elements["IconPath"] as MarkupTagElement); - if (tagIconPath != null) - { - #region All Icons - { - MarkupAttribute attFileName = tagIconPath.Attributes["FileName"]; - if (attFileName != null) - { - string FileName = attFileName.Value; - if (System.IO.File.Exists(FileName)) template.LargeIconImageFileName = FileName; - if (System.IO.File.Exists(FileName)) template.SmallIconImageFileName = FileName; - } - } - #endregion - #region Large Icon - { - MarkupAttribute attLargeFileName = tagIconPath.Attributes["LargeFileName"]; - if (attLargeFileName != null) - { - string FileName = attLargeFileName.Value; - if (System.IO.File.Exists(FileName)) template.LargeIconImageFileName = FileName; - } - } - #endregion - #region Small Icon - { - MarkupAttribute attSmallFileName = tagIconPath.Attributes["SmallFileName"]; - if (attSmallFileName != null) - { - string FileName = attSmallFileName.Value; - if (System.IO.File.Exists(FileName)) template.SmallIconImageFileName = FileName; - } - } - #endregion - } - } - #endregion #region FileSystem { MarkupTagElement tagFileSystem = (tagTemplate.Elements["FileSystem"] as MarkupTagElement); @@ -1126,6 +1009,74 @@ namespace UniversalEditor.DataFormats.UEPackage #endregion } + private void LoadTemplateCommonInformation(Template template, MarkupTagElement tagTemplate) + { + MarkupTagElement tagInformation = (tagTemplate.Elements["Information"] as MarkupTagElement); + if (tagInformation != null) + { + MarkupTagElement tagTitle = (tagInformation.Elements["Title"] as MarkupTagElement); + if (tagTitle != null) template.Title = tagTitle.Value; + + MarkupTagElement tagDescription = (tagInformation.Elements["Description"] as MarkupTagElement); + if (tagDescription != null) template.Description = tagDescription.Value; + + if (tagInformation.Elements["Prefix"] != null) + { + template.Prefix = tagInformation.Elements["Prefix"].Value; + } + + MarkupTagElement tagPath = (tagInformation.Elements["Path"] as MarkupTagElement); + if (tagPath != null) + { + List pathParts = new List(); + foreach (MarkupElement elPart in tagPath.Elements) + { + MarkupTagElement tagPart = (elPart as MarkupTagElement); + if (tagPart == null) continue; + if (tagPart.FullName != "Part") continue; + pathParts.Add(tagPart.Value); + } + template.Path = pathParts.ToArray(); + } + + MarkupTagElement tagIconPath = (tagInformation.Elements["IconPath"] as MarkupTagElement); + if (tagIconPath != null) + { + #region All Icons + { + MarkupAttribute attFileName = tagIconPath.Attributes["FileName"]; + if (attFileName != null) + { + string FileName = attFileName.Value; + if (System.IO.File.Exists(FileName)) template.LargeIconImageFileName = FileName; + if (System.IO.File.Exists(FileName)) template.SmallIconImageFileName = FileName; + } + } + #endregion + #region Large Icon + { + MarkupAttribute attLargeFileName = tagIconPath.Attributes["LargeFileName"]; + if (attLargeFileName != null) + { + string FileName = attLargeFileName.Value; + if (System.IO.File.Exists(FileName)) template.LargeIconImageFileName = FileName; + } + } + #endregion + #region Small Icon + { + MarkupAttribute attSmallFileName = tagIconPath.Attributes["SmallFileName"]; + if (attSmallFileName != null) + { + string FileName = attSmallFileName.Value; + if (System.IO.File.Exists(FileName)) template.SmallIconImageFileName = FileName; + } + } + #endregion + } + } + } + private CustomDataFormatStructure CreateStructure(MarkupTagElement tag, Dictionary localVariables) { MarkupAttribute attID = tag.Attributes["ID"]; diff --git a/Libraries/UniversalEditor.Essential/Template.cs b/Libraries/UniversalEditor.Essential/Template.cs index 27d8d66c..e65b56f8 100644 --- a/Libraries/UniversalEditor.Essential/Template.cs +++ b/Libraries/UniversalEditor.Essential/Template.cs @@ -70,6 +70,18 @@ namespace UniversalEditor private Guid mvarID = Guid.Empty; public Guid ID { get { return mvarID; } set { mvarID = value; } } + private string[] mvarPath = null; + /// + /// + /// + public string[] Path { get { return mvarPath; } set { mvarPath = value; } } + + /// + /// Gets or sets the template file name prefix. + /// + /// The template file name prefix. + public string Prefix { get; set; } = String.Empty; + private string mvarTitle = String.Empty; /// /// The title of the document template. @@ -131,12 +143,6 @@ namespace UniversalEditor /// public MarkupObjectModel TemplateContent { get { return mvarTemplateContent; } } - private string[] mvarPath = null; - /// - /// - /// - public string[] Path { get { return mvarPath; } set { mvarPath = value; } } - /// /// Initializes the template's ObjectModel with the content specified in . /// @@ -223,17 +229,8 @@ namespace UniversalEditor } - private string[] mvarPath = null; - /// - /// - /// - public string[] Path { get { return mvarPath; } set { mvarPath = value; } } - public ProjectType.ProjectTypeCollection ProjectTypes { get; } = new ProjectType.ProjectTypeCollection(); - private string mvarProjectNamePrefix = String.Empty; - public string ProjectNamePrefix { get { return mvarProjectNamePrefix; } set { mvarProjectNamePrefix = value; } } - private ProjectFileSystem mvarFileSystem = new ProjectFileSystem(); public ProjectFileSystem FileSystem { get { return mvarFileSystem; } } diff --git a/Libraries/UniversalEditor.UserInterface/Dialogs/NewDialog.cs b/Libraries/UniversalEditor.UserInterface/Dialogs/NewDialog.cs index 72f60a2b..89daa940 100644 --- a/Libraries/UniversalEditor.UserInterface/Dialogs/NewDialog.cs +++ b/Libraries/UniversalEditor.UserInterface/Dialogs/NewDialog.cs @@ -230,15 +230,24 @@ namespace UniversalEditor.UserInterface.Dialogs row.SetExtraData>("dts", dts); } - DocumentTemplate dtEmpty = new DocumentTemplate(); - dtEmpty.ObjectModelReference = omr; - dtEmpty.Title = String.Format("Blank {0} Document", path[path.Length - 1]); + DocumentTemplate dtEmpty = CreateEmptyDocumentTemplate(omr); dts.Add(dtEmpty); } InitializeObjectModelTreeViewRow(tm, row, omr, index + 1); } + private DocumentTemplate CreateEmptyDocumentTemplate(ObjectModelReference omr) + { + string[] path = omr.Path; + DocumentTemplate dtEmpty = new DocumentTemplate(); + dtEmpty.ObjectModelReference = omr; + + dtEmpty.Title = String.Format("Blank {0} Document", path[path.Length - 1]); + dtEmpty.Prefix = omr.EmptyTemplatePrefix ?? String.Format("Empty{0}Document", path[path.Length - 1]); + return dtEmpty; + } + [EventHandler(nameof(cmdOK), "Click")] private void cmdOK_Click(object sender, EventArgs e) { @@ -512,7 +521,7 @@ namespace UniversalEditor.UserInterface.Dialogs if (!txtFileName.IsChangedByUser) { - string projectNamePrefix = pt.ProjectNamePrefix; + string projectNamePrefix = pt.Prefix; if (String.IsNullOrEmpty(projectNamePrefix)) { projectNamePrefix = pt.Title.Replace(" ", String.Empty); @@ -527,7 +536,13 @@ namespace UniversalEditor.UserInterface.Dialogs if (pt == null) return; if (!txtFileName.IsChangedByUser) { - // txtFileName.Text = projectNamePrefix + "1"; + string projectNamePrefix = pt.Prefix; + if (String.IsNullOrEmpty(projectNamePrefix)) + { + projectNamePrefix = pt.Title.Replace(" ", String.Empty).Replace("/", String.Empty); + // projectNamePrefix = "Project"; + } + txtFileName.Text = projectNamePrefix + "1"; } } } diff --git a/Libraries/UniversalEditor.UserInterface/EditorApplication.cs b/Libraries/UniversalEditor.UserInterface/EditorApplication.cs index 59fb74ef..e30cce72 100644 --- a/Libraries/UniversalEditor.UserInterface/EditorApplication.cs +++ b/Libraries/UniversalEditor.UserInterface/EditorApplication.cs @@ -509,16 +509,22 @@ namespace UniversalEditor.UserInterface MarkupAttribute attTypeName = tag.Attributes["TypeName"]; MarkupAttribute attID = tag.Attributes["ID"]; MarkupAttribute attVisible = tag.Attributes["Visible"]; + MarkupAttribute attEmptyTemplatePrefix = tag.Attributes["EmptyTemplatePrefix"]; + ObjectModelReference omr = null; if (attTypeName != null) { - ObjectModelReference omr = UniversalEditor.Common.Reflection.GetAvailableObjectModelByTypeName(attTypeName.Value); - if (attVisible != null) omr.Visible = (attVisible.Value == "true"); + omr = UniversalEditor.Common.Reflection.GetAvailableObjectModelByTypeName(attTypeName.Value); } else { - ObjectModelReference omr = UniversalEditor.Common.Reflection.GetAvailableObjectModelByID(new Guid(attID.Value)); + omr = UniversalEditor.Common.Reflection.GetAvailableObjectModelByID(new Guid(attID.Value)); + } + + if (omr != null) + { if (attVisible != null) omr.Visible = (attVisible.Value == "true"); + if (attEmptyTemplatePrefix != null) omr.EmptyTemplatePrefix = attEmptyTemplatePrefix.Value; } } }