templating improvements and actually loading the ObjectModel content via XML from a template
This commit is contained in:
parent
41fa4412f1
commit
29b8690485
@ -6,6 +6,10 @@
|
||||
<Title>Windows filesystem</Title>
|
||||
<Description>Creates a standard Windows NT file structure.</Description>
|
||||
<IconPath LargeFileName="windows_32x32.png" SmallFileName="windows_16x16.png" />
|
||||
<Path>
|
||||
<Part>General</Part>
|
||||
<Part>File system/archive</Part>
|
||||
</Path>
|
||||
</Information>
|
||||
<Content ObjectModelType="UniversalEditor.ObjectModels.FileSystem.FileSystemObjectModel">
|
||||
<Folders>
|
||||
|
||||
@ -655,6 +655,24 @@ namespace UniversalEditor.DataFormats.UEPackage
|
||||
{
|
||||
template.ObjectModelReference = new ObjectModelReference(tagContent.Attributes["ObjectModelType"].Value);
|
||||
}
|
||||
|
||||
if (tagContent.Attributes["FileName"] != null)
|
||||
{
|
||||
// TODO: load the specified file as the given ObjectModel type
|
||||
}
|
||||
else
|
||||
{
|
||||
if (template.ObjectModelReference.Type != null)
|
||||
{
|
||||
System.Reflection.ParameterModifier pmodType = new System.Reflection.ParameterModifier();
|
||||
System.Reflection.MethodInfo miFromMarkup = template.ObjectModelReference.Type.GetMethod("FromMarkup", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(MarkupTagElement) }, new System.Reflection.ParameterModifier[] { pmodType });
|
||||
if (miFromMarkup != null)
|
||||
{
|
||||
ObjectModel om = (miFromMarkup.Invoke(null, new object[] { tagContent }) as ObjectModel);
|
||||
template.ObjectModel = om;
|
||||
}
|
||||
}
|
||||
}
|
||||
template.TemplateContent.Elements.Add(tagContent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using UniversalEditor.ObjectModels.Markup;
|
||||
|
||||
namespace UniversalEditor.ObjectModels.Database
|
||||
{
|
||||
/// <summary>
|
||||
@ -37,6 +39,7 @@ namespace UniversalEditor.ObjectModels.Database
|
||||
return _omr;
|
||||
}
|
||||
|
||||
public string Name { get; set; } = null;
|
||||
public DatabaseTable.DatabaseTableCollection Tables { get; } = new DatabaseTable.DatabaseTableCollection();
|
||||
|
||||
public override void Clear()
|
||||
@ -54,5 +57,32 @@ namespace UniversalEditor.ObjectModels.Database
|
||||
clone.Tables.Add(Tables[i].Clone() as DatabaseTable);
|
||||
}
|
||||
}
|
||||
|
||||
public static DatabaseObjectModel FromMarkup(MarkupTagElement tag)
|
||||
{
|
||||
DatabaseObjectModel db = new DatabaseObjectModel();
|
||||
for (int i = 0; i < tag.Elements.Count; i++)
|
||||
{
|
||||
MarkupTagElement tag2 = (tag.Elements[i] as MarkupTagElement);
|
||||
if (tag2 == null) continue;
|
||||
if (tag2.FullName == "Tables")
|
||||
{
|
||||
foreach (MarkupElement elTable in tag2.Elements )
|
||||
{
|
||||
MarkupTagElement tagTable = (elTable as MarkupTagElement);
|
||||
if (tagTable == null) continue;
|
||||
if (tagTable.FullName != "Table") continue;
|
||||
|
||||
MarkupAttribute attName = tag2.Attributes["Name"];
|
||||
if (attName == null) continue;
|
||||
|
||||
DatabaseTable dt = new DatabaseTable();
|
||||
dt.Name = attName.Value;
|
||||
db.Tables.Add(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using MBS.Framework.Logic.Conditional;
|
||||
using UniversalEditor.Accessors;
|
||||
using UniversalEditor.ObjectModels.Markup;
|
||||
|
||||
namespace UniversalEditor.ObjectModels.FileSystem
|
||||
{
|
||||
@ -533,5 +534,55 @@ namespace UniversalEditor.ObjectModels.FileSystem
|
||||
}
|
||||
return _CriteriaObjects;
|
||||
}
|
||||
|
||||
public static ObjectModel FromMarkup(MarkupTagElement tagContent)
|
||||
{
|
||||
FileSystemObjectModel fsom = new FileSystemObjectModel();
|
||||
InitFileSystemFromMarkup(fsom, tagContent);
|
||||
return fsom;
|
||||
}
|
||||
|
||||
private static void InitFileSystemFromMarkup(IFileSystemContainer fsom, MarkupTagElement tagContent)
|
||||
{
|
||||
MarkupTagElement tagFolders = tagContent.Elements["Folders"] as MarkupTagElement;
|
||||
MarkupTagElement tagFiles = tagContent.Elements["Files"] as MarkupTagElement;
|
||||
if (tagFolders != null)
|
||||
{
|
||||
for (int i = 0; i < tagFolders.Elements.Count; i++)
|
||||
{
|
||||
MarkupTagElement tagFolder = (tagFolders.Elements[i] as MarkupTagElement);
|
||||
if (tagFolder == null) continue;
|
||||
if (tagFolder.FullName != "Folder") continue;
|
||||
|
||||
MarkupAttribute attName = tagFolder.Attributes["Name"];
|
||||
|
||||
Folder item = new Folder();
|
||||
if (attName != null)
|
||||
{
|
||||
item.Name = attName.Value;
|
||||
}
|
||||
InitFileSystemFromMarkup(item, tagFolder);
|
||||
fsom.Folders.Add(item);
|
||||
}
|
||||
}
|
||||
if (tagFiles != null)
|
||||
{
|
||||
for (int i = 0; i < tagFiles.Elements.Count; i++)
|
||||
{
|
||||
MarkupTagElement tagFile = (tagFiles.Elements[i] as MarkupTagElement);
|
||||
if (tagFile == null) continue;
|
||||
if (tagFile.FullName != "File") continue;
|
||||
|
||||
MarkupAttribute attName = tagFile.Attributes["Name"];
|
||||
|
||||
File item = new File();
|
||||
if (attName != null)
|
||||
{
|
||||
item.Name = attName.Value;
|
||||
}
|
||||
fsom.Files.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,6 +116,7 @@ namespace UniversalEditor
|
||||
if (mvarObjectModel == null) Create();
|
||||
return mvarObjectModel;
|
||||
}
|
||||
set { mvarObjectModel = value; }
|
||||
}
|
||||
|
||||
private ObjectModelReference mvarObjectModelReference = null;
|
||||
|
||||
@ -314,6 +314,10 @@ namespace UniversalEditor.UserInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
if (template.ObjectModel != null)
|
||||
{
|
||||
template.ObjectModel.CopyTo(objm);
|
||||
}
|
||||
page.Document = new Document(objm, null, null);
|
||||
page.Document.Title = String.Format(filename, iUntitledDocCount);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user