Another major hacking session on StoryWriter plugins

This commit is contained in:
Michael Becker 2014-09-19 15:53:25 -04:00
parent b54e23c510
commit 123dd11e25
16 changed files with 766 additions and 67 deletions

View File

@ -28,12 +28,30 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tv = new System.Windows.Forms.TreeView();
this.mnuContextTreeView = new AwesomeControls.CommandBars.CBContextMenu(this.components);
this.mnuContextTreeViewAdd = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewAddNewItem = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewAddExistingItem = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewSep1 = new System.Windows.Forms.ToolStripSeparator();
this.mnuContextTreeViewExclude = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewSep2 = new System.Windows.Forms.ToolStripSeparator();
this.mnuContextTreeViewCut = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewCopy = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewPaste = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewDelete = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewRename = new System.Windows.Forms.ToolStripMenuItem();
this.mnuContextTreeViewSep3 = new System.Windows.Forms.ToolStripSeparator();
this.mnuContextTreeViewProperties = new System.Windows.Forms.ToolStripMenuItem();
this.lv = new System.Windows.Forms.ListView();
this.imlSmallIcons = new System.Windows.Forms.ImageList(this.components);
this.imlLargeIcons = new System.Windows.Forms.ImageList(this.components);
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.mnuContextTreeView.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
@ -56,12 +74,111 @@
//
// tv
//
this.tv.ContextMenuStrip = this.mnuContextTreeView;
this.tv.Dock = System.Windows.Forms.DockStyle.Fill;
this.tv.Location = new System.Drawing.Point(0, 0);
this.tv.Name = "tv";
this.tv.Size = new System.Drawing.Size(205, 306);
this.tv.TabIndex = 0;
this.tv.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tv_AfterSelect);
this.tv.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tv_MouseDown);
//
// mnuContextTreeView
//
this.mnuContextTreeView.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuContextTreeViewAdd,
this.mnuContextTreeViewSep1,
this.mnuContextTreeViewExclude,
this.mnuContextTreeViewSep2,
this.mnuContextTreeViewCut,
this.mnuContextTreeViewCopy,
this.mnuContextTreeViewPaste,
this.mnuContextTreeViewDelete,
this.mnuContextTreeViewRename,
this.mnuContextTreeViewSep3,
this.mnuContextTreeViewProperties});
this.mnuContextTreeView.Name = "mnuContextTreeView";
this.mnuContextTreeView.Size = new System.Drawing.Size(190, 198);
this.mnuContextTreeView.Opening += new System.ComponentModel.CancelEventHandler(this.mnuContextTreeView_Opening);
//
// mnuContextTreeViewAdd
//
this.mnuContextTreeViewAdd.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuContextTreeViewAddNewItem,
this.mnuContextTreeViewAddExistingItem});
this.mnuContextTreeViewAdd.Name = "mnuContextTreeViewAdd";
this.mnuContextTreeViewAdd.Size = new System.Drawing.Size(189, 22);
this.mnuContextTreeViewAdd.Text = "A&dd";
//
// mnuContextTreeViewAddNewItem
//
this.mnuContextTreeViewAddNewItem.Name = "mnuContextTreeViewAddNewItem";
this.mnuContextTreeViewAddNewItem.Size = new System.Drawing.Size(152, 22);
this.mnuContextTreeViewAddNewItem.Text = "Ne&w Item...";
//
// mnuContextTreeViewAddExistingItem
//
this.mnuContextTreeViewAddExistingItem.Name = "mnuContextTreeViewAddExistingItem";
this.mnuContextTreeViewAddExistingItem.Size = new System.Drawing.Size(152, 22);
this.mnuContextTreeViewAddExistingItem.Text = "Existin&g Item...";
//
// mnuContextTreeViewSep1
//
this.mnuContextTreeViewSep1.Name = "mnuContextTreeViewSep1";
this.mnuContextTreeViewSep1.Size = new System.Drawing.Size(186, 6);
//
// mnuContextTreeViewExclude
//
this.mnuContextTreeViewExclude.Name = "mnuContextTreeViewExclude";
this.mnuContextTreeViewExclude.Size = new System.Drawing.Size(189, 22);
this.mnuContextTreeViewExclude.Text = "Exclude From Pro&ject";
//
// mnuContextTreeViewSep2
//
this.mnuContextTreeViewSep2.Name = "mnuContextTreeViewSep2";
this.mnuContextTreeViewSep2.Size = new System.Drawing.Size(186, 6);
//
// mnuContextTreeViewCut
//
this.mnuContextTreeViewCut.Name = "mnuContextTreeViewCut";
this.mnuContextTreeViewCut.Size = new System.Drawing.Size(189, 22);
this.mnuContextTreeViewCut.Text = "Cu&t";
//
// mnuContextTreeViewCopy
//
this.mnuContextTreeViewCopy.Name = "mnuContextTreeViewCopy";
this.mnuContextTreeViewCopy.Size = new System.Drawing.Size(189, 22);
this.mnuContextTreeViewCopy.Text = "&Copy";
//
// mnuContextTreeViewPaste
//
this.mnuContextTreeViewPaste.Name = "mnuContextTreeViewPaste";
this.mnuContextTreeViewPaste.Size = new System.Drawing.Size(189, 22);
this.mnuContextTreeViewPaste.Text = "&Paste";
//
// mnuContextTreeViewDelete
//
this.mnuContextTreeViewDelete.Name = "mnuContextTreeViewDelete";
this.mnuContextTreeViewDelete.Size = new System.Drawing.Size(189, 22);
this.mnuContextTreeViewDelete.Text = "&Delete";
//
// mnuContextTreeViewRename
//
this.mnuContextTreeViewRename.Name = "mnuContextTreeViewRename";
this.mnuContextTreeViewRename.Size = new System.Drawing.Size(189, 22);
this.mnuContextTreeViewRename.Text = "Rena&me";
//
// mnuContextTreeViewSep3
//
this.mnuContextTreeViewSep3.Name = "mnuContextTreeViewSep3";
this.mnuContextTreeViewSep3.Size = new System.Drawing.Size(186, 6);
//
// mnuContextTreeViewProperties
//
this.mnuContextTreeViewProperties.Name = "mnuContextTreeViewProperties";
this.mnuContextTreeViewProperties.ShortcutKeyDisplayString = "Alt+Enter";
this.mnuContextTreeViewProperties.Size = new System.Drawing.Size(189, 22);
this.mnuContextTreeViewProperties.Text = "P&roperties...";
//
// lv
//
@ -72,6 +189,18 @@
this.lv.TabIndex = 0;
this.lv.UseCompatibleStateImageBehavior = false;
//
// imlSmallIcons
//
this.imlSmallIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imlSmallIcons.ImageSize = new System.Drawing.Size(16, 16);
this.imlSmallIcons.TransparentColor = System.Drawing.Color.Transparent;
//
// imlLargeIcons
//
this.imlLargeIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.imlLargeIcons.ImageSize = new System.Drawing.Size(32, 32);
this.imlLargeIcons.TransparentColor = System.Drawing.Color.Transparent;
//
// StoryEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -82,6 +211,7 @@
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.ResumeLayout(false);
this.mnuContextTreeView.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -91,5 +221,21 @@
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TreeView tv;
private System.Windows.Forms.ListView lv;
private System.Windows.Forms.ImageList imlSmallIcons;
private System.Windows.Forms.ImageList imlLargeIcons;
private AwesomeControls.CommandBars.CBContextMenu mnuContextTreeView;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewAdd;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewAddNewItem;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewAddExistingItem;
private System.Windows.Forms.ToolStripSeparator mnuContextTreeViewSep1;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewProperties;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewCut;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewCopy;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewPaste;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewDelete;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewRename;
private System.Windows.Forms.ToolStripSeparator mnuContextTreeViewSep3;
private System.Windows.Forms.ToolStripMenuItem mnuContextTreeViewExclude;
private System.Windows.Forms.ToolStripSeparator mnuContextTreeViewSep2;
}
}

View File

@ -14,6 +14,7 @@ namespace UniversalEditor.Editors
public StoryEditor()
{
InitializeComponent();
IconMethods.PopulateSystemIcons(ref imlSmallIcons);
}
protected override void OnObjectModelChanged(EventArgs e)
@ -24,23 +25,30 @@ namespace UniversalEditor.Editors
tv.Nodes.Clear();
TreeNode tnUniverse = tv.Nodes.Add("tnUniverse", "Universe", "generic-folder-closed");
TreeNode tnCharacters = tnUniverse.Nodes.Add("tnCharacters", "Characters", "generic-folder-closed");
foreach (Character chara in story.Characters)
#region Universe
{
TreeNode tn = new TreeNode();
tn.Text = chara.Name;
tn.ImageKey = "character";
tnCharacters.Nodes.Add(tn);
TreeNode tnUniverse = tv.Nodes.Add("tnUniverse", "Universe", "generic-folder-closed");
TreeNode tnCharacters = tnUniverse.Nodes.Add("tnCharacters", "Characters", "generic-folder-closed");
foreach (Character chara in story.Characters)
{
TreeNode tn = new TreeNode();
tn.Text = chara.Name.ToString();
tn.ImageKey = "character";
tnCharacters.Nodes.Add(tn);
}
tnUniverse.Nodes.Add("tnDevices", "Devices", "generic-folder-closed");
tnUniverse.Nodes.Add("tnLocations", "Locations", "generic-folder-closed");
tnUniverse.Nodes.Add("tnOrganizations", "Organizations", "generic-folder-closed");
tnUniverse.Nodes.Add("tnVehicles", "Vehicles", "generic-folder-closed");
}
tnUniverse.Nodes.Add("tnDevices", "Devices", "generic-folder-closed");
tnUniverse.Nodes.Add("tnLocations", "Locations", "generic-folder-closed");
tnUniverse.Nodes.Add("tnOrganizations", "Organizations", "generic-folder-closed");
tnUniverse.Nodes.Add("tnVehicles", "Vehicles", "generic-folder-closed");
tv.Nodes.Add("tnBooks", "Books", "generic-folder-closed");
#endregion
#region Books
{
tv.Nodes.Add("tnBooks", "Books", "generic-folder-closed");
}
#endregion
tv.ExpandAll();
}
@ -49,5 +57,22 @@ namespace UniversalEditor.Editors
{
}
private void mnuContextTreeView_Opening(object sender, CancelEventArgs e)
{
if (tv.SelectedNode.Tag is Chapter)
{
}
}
private void tv_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
TreeNode tn = tv.HitTest(e.Location).Node;
if (tn != null) tv.SelectedNode = tn;
}
}
}
}

View File

@ -117,4 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="mnuContextTreeView.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>256, 8</value>
</metadata>
<metadata name="imlSmallIcons.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>15, 8</value>
</metadata>
<metadata name="imlLargeIcons.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>135, 8</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>38</value>
</metadata>
</root>

View File

@ -0,0 +1,250 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
internal static class IconMethods
{
public enum IconSize
{
Large,
Small
}
private static class Internal
{
#region Old ExtractAssociatedIcon
public static HandleRef NullHandleRef = default(HandleRef);
[DllImport("shell32.dll", EntryPoint = "ExtractAssociatedIcon", CharSet = CharSet.Auto)]
public static extern IntPtr IntExtractAssociatedIcon(HandleRef hInst, StringBuilder iconPath, ref int index);
public static IntPtr ExtractAssociatedIcon(HandleRef hInst, StringBuilder iconPath, ref int index)
{
return IntExtractAssociatedIcon(hInst, iconPath, ref index);
}
#endregion
#region New ExtractIconEx
[DllImport("shell32.dll", EntryPoint = "ExtractIconEx")]
public static extern uint ExtractIconEx(string lpszFile, int nIconIndex, IntPtr[] phiconLarge, IntPtr[] phiconSmall, uint nIcons);
#endregion
}
#region Old ExtractAssociatedIcon
private static Icon __ExtractAssociatedIcon(string filePath, int index)
{
Uri uri = null;
if ((filePath == null))
{
throw new ArgumentException("Argument cannot be null.", "filePath");
}
try
{
uri = new Uri(filePath);
}
catch (UriFormatException)
{
filePath = Path.GetFullPath(filePath);
uri = new Uri(filePath);
}
//If uri.IsUnc Then
// Throw New ArgumentException("File path cannot be a UNC path.", "filePath")
//End If
if (uri.IsFile | uri.IsUnc)
{
if (!File.Exists(filePath))
{
throw new FileNotFoundException(filePath);
}
System.Text.StringBuilder iconPath = new System.Text.StringBuilder(260);
iconPath.Append(filePath);
IntPtr handle = Internal.ExtractAssociatedIcon(Internal.NullHandleRef, iconPath, ref index);
if ((handle != IntPtr.Zero))
{
return Icon.FromHandle(handle);
}
}
return null;
}
#endregion
#region New ExtractIconEx
private static Icon __EIEExtractAssociatedIcon(string filePath, int index, IconSize size)
{
IntPtr[] phiconLarge = new IntPtr[] { IntPtr.Zero };
IntPtr[] phiconSmall = new IntPtr[] { IntPtr.Zero };
Internal.ExtractIconEx(filePath, index, phiconLarge, phiconSmall, 1);
switch (size)
{
case IconSize.Large:
try
{
return Icon.FromHandle(phiconLarge[0]);
}
catch (ArgumentException)
{
return null;
}
case IconSize.Small:
try
{
return Icon.FromHandle(phiconSmall[0]);
}
catch (ArgumentException)
{
return null;
}
}
return null;
}
#endregion
public static Icon ExtractFileTypeIcon(string filePath)
{
string ext = System.IO.Path.GetExtension(filePath);
string iconPath = String.Empty;
int iconIndex = 0;
switch (System.Environment.OSVersion.Platform)
{
case PlatformID.MacOSX:
{
break;
}
case PlatformID.Unix:
{
break;
}
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
{
// TODO: Implement something that uses along the lines of MIME info
// specification
/*
http://standards.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/msword">
<comment>MS Word Files</comment>
<glob pattern="*.doc"/>
</mime-type>
</mime-info>
*/
Microsoft.Win32.RegistryKey rkExt = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
string className = rkExt.GetValue(String.Empty, String.Empty).ToString();
Microsoft.Win32.RegistryKey rkClass = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(className);
if (rkClass != null)
{
Microsoft.Win32.RegistryKey rkDefaultIcon = rkClass.OpenSubKey("DefaultIcon");
if (rkDefaultIcon != null)
{
string defaultIconPath = rkDefaultIcon.GetValue(String.Empty, String.Empty).ToString();
int splitIndex = defaultIconPath.LastIndexOf(',');
string defaultIconFileName = defaultIconPath.Substring(0, splitIndex);
string defaultIconIndex = defaultIconPath.Substring(splitIndex + 1);
Int32.TryParse(defaultIconIndex, out iconIndex);
if (defaultIconFileName.StartsWith("\""))
{
defaultIconFileName = defaultIconFileName.Substring(1);
}
if (defaultIconFileName.EndsWith("\""))
{
defaultIconFileName = defaultIconFileName.Substring(0, defaultIconFileName.Length - 1);
}
iconPath = defaultIconFileName;
}
}
break;
}
}
Icon icon = ExtractAssociatedIcon(iconPath, iconIndex);
return icon;
}
public static Icon ExtractAssociatedIcon(string filePath, int index = 0)
{
return ExtractAssociatedIcon(filePath, index, IconSize.Large);
}
public static Icon ExtractAssociatedIcon(string filePath, int index, IconSize size)
{
Icon icon = null;
switch (System.Environment.OSVersion.Platform)
{
case PlatformID.MacOSX:
// TODO: Mac OS X support?
break;
case PlatformID.Unix:
break;
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
icon = __EIEExtractAssociatedIcon(filePath, index, size);
break;
case PlatformID.Xbox:
break;
}
return icon;
}
public static void PopulateSystemIcons(ref System.Windows.Forms.ImageList iml)
{
switch (Environment.OSVersion.Platform)
{
case PlatformID.MacOSX:
break;
case PlatformID.Unix:
break;
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
{
if (iml.ImageSize.Width == 16 && iml.ImageSize.Height == 16)
{
Icon iconFile = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 0, IconSize.Small);
iml.Images.Add("generic-file", iconFile);
Icon iconDocument = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 1, IconSize.Small);
iml.Images.Add("generic-document", iconDocument);
Icon iconApplication = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 2, IconSize.Small);
iml.Images.Add("generic-application", iconApplication);
Icon iconFolderClosed = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 3, IconSize.Small);
iml.Images.Add("generic-folder-closed", iconFolderClosed);
Icon iconFolderOpen = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 4, IconSize.Small);
iml.Images.Add("generic-folder-open", iconFolderOpen);
}
else
{
Icon iconFile = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 0, IconSize.Large);
iml.Images.Add("generic-file", iconFile);
Icon iconDocument = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 1, IconSize.Large);
iml.Images.Add("generic-document", iconDocument);
Icon iconApplication = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 2, IconSize.Large);
iml.Images.Add("generic-application", iconApplication);
Icon iconFolderClosed = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 3, IconSize.Large);
iml.Images.Add("generic-folder-closed", iconFolderClosed);
Icon iconFolderOpen = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 4, IconSize.Large);
iml.Images.Add("generic-folder-open", iconFolderOpen);
}
return;
}
}
// throw new PlatformNotSupportedException();
}
}

View File

@ -31,8 +31,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AwesomeControls, Version=1.0.5375.17542, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\AwesomeControls\bin\Debug\AwesomeControls.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
@ -43,6 +48,7 @@
<Compile Include="Editors\StoryEditor.Designer.cs">
<DependentUpon>StoryEditor.cs</DependentUpon>
</Compile>
<Compile Include="IconMethods.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
public class Author : ICloneable
{
public class AuthorCollection
: System.Collections.ObjectModel.Collection<Author>
{
}
private PersonalName mvarName = null;
public PersonalName Name { get { return mvarName; } set { mvarName = value; } }
public object Clone()
{
Author clone = new Author();
if (mvarName != null)
{
clone.Name = (mvarName.Clone() as PersonalName);
}
return clone;
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
public class Book
public class Book : ICloneable
{
public class BookCollection
: System.Collections.ObjectModel.Collection<Book>
@ -13,7 +13,28 @@ namespace UniversalEditor.ObjectModels.StoryWriter.Story
}
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
private Author.AuthorCollection mvarAuthors = new Author.AuthorCollection();
public Author.AuthorCollection Authors { get { return mvarAuthors; } }
private Chapter.ChapterCollection mvarChapters = new Chapter.ChapterCollection();
public Chapter.ChapterCollection Chapters { get { return mvarChapters; } }
public object Clone()
{
Book clone = new Book();
clone.Title = (mvarTitle.Clone() as string);
foreach (Author author in mvarAuthors)
{
clone.Authors.Add(author);
}
foreach (Chapter chapter in mvarChapters)
{
clone.Chapters.Add(chapter.Clone() as Chapter);
}
return clone;
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
public class Chapter
public class Chapter : ICloneable
{
public class ChapterCollection
@ -13,5 +13,25 @@ namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
}
private Guid mvarID = Guid.Empty;
public Guid ID { get { return mvarID; } set { mvarID = value; } }
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
private Section.SectionCollection mvarSections = new Section.SectionCollection();
public Section.SectionCollection Sections { get { return mvarSections; } }
public object Clone()
{
Chapter clone = new Chapter();
clone.Title = (mvarTitle.Clone() as string);
foreach (Section section in mvarSections)
{
clone.Sections.Add(section.Clone() as Section);
}
return clone;
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
public class Character
public class Character : ICloneable
{
public class CharacterCollection
: System.Collections.ObjectModel.Collection<Character>
@ -13,60 +13,21 @@ namespace UniversalEditor.ObjectModels.StoryWriter.Story
}
private string mvarGivenName = String.Empty;
public string GivenName { get { return mvarGivenName; } set { mvarGivenName = value; } }
private string mvarMiddleName = String.Empty;
public string MiddleName { get { return mvarMiddleName; } set { mvarMiddleName = value; } }
private string mvarFamilyName = String.Empty;
public string FamilyName { get { return mvarFamilyName; } set { mvarFamilyName = value; } }
private PersonalName mvarName = null;
public PersonalName Name { get { return mvarName; } set { mvarName = value; } }
private Gender mvarGender = null;
public Gender Gender { get { return mvarGender; } set { mvarGender = value; } }
public string Name
public object Clone()
{
get
Character clone = new Character();
if (mvarName != null)
{
StringBuilder sb = new StringBuilder();
sb.Append(mvarGivenName);
if (!String.IsNullOrEmpty(mvarMiddleName))
{
sb.Append(" ");
sb.Append(mvarMiddleName);
}
if (!String.IsNullOrEmpty(mvarFamilyName))
{
sb.Append(" ");
sb.Append(mvarFamilyName);
}
return sb.ToString();
}
set
{
mvarGivenName = String.Empty;
mvarMiddleName = String.Empty;
mvarFamilyName = String.Empty;
string[] values = value.Split(new char[] { ' ' }, 3);
if (values.Length > 0)
{
mvarGivenName = values[0];
if (values.Length > 1)
{
if (values.Length > 2)
{
mvarMiddleName = values[1];
mvarFamilyName = values[2];
}
else
{
mvarFamilyName = values[1];
}
}
}
clone.Name = (mvarName.Clone() as PersonalName);
}
clone.Gender = mvarGender;
return clone;
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
public abstract class ContentItem
{
protected abstract string RenderContent();
}
}

View File

@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
public class PersonalName : ICloneable
{
private string mvarGivenName = String.Empty;
public string GivenName { get { return mvarGivenName; } set { mvarGivenName = value; } }
private System.Collections.Specialized.StringCollection mvarMiddleNames = new System.Collections.Specialized.StringCollection();
public System.Collections.Specialized.StringCollection MiddleNames { get { return mvarMiddleNames; } }
private string mvarFamilyName = String.Empty;
public string FamilyName { get { return mvarFamilyName; } set { mvarFamilyName = value; } }
private string mvarNickname = String.Empty;
public string Nickname { get { return mvarNickname; } set { mvarNickname = value; } }
public PersonalName()
{
}
public PersonalName(string fullName)
{
Name = fullName;
}
public PersonalName(string givenName, string familyName) : this(givenName, String.Empty, familyName)
{
}
public PersonalName(string givenName, string middleName, string familyName)
{
mvarGivenName = givenName;
string[] mn = middleName.Split(new char[] { ' ' });
foreach (string m in mn)
{
if (!String.IsNullOrEmpty(m)) mvarMiddleNames.Add(m);
}
mvarFamilyName = familyName;
}
public string Name
{
get
{
StringBuilder sb = new StringBuilder();
sb.Append(mvarGivenName);
foreach (string s in mvarMiddleNames)
{
sb.Append(" ");
sb.Append(s);
}
if (!String.IsNullOrEmpty(mvarFamilyName))
{
sb.Append(" ");
sb.Append(mvarFamilyName);
}
return sb.ToString();
}
set
{
string[] values = value.Split(new char[] { ' ' });
StringBuilder sb = new StringBuilder();
if (values.Length > 0)
{
sb.Append(values[0]);
if (values.Length > 2)
{
for (int i = 1; i < values.Length - 1; i++)
{
mvarMiddleNames.Add(values[i]);
}
}
if (values.Length > 1)
{
sb.Append(" ");
sb.Append(values[values.Length - 1]);
}
}
}
}
public object Clone()
{
PersonalName clone = new PersonalName();
clone.GivenName = (mvarGivenName.Clone() as string);
foreach (string s in mvarMiddleNames)
{
clone.MiddleNames.Add(s.Clone() as string);
}
clone.FamilyName = (mvarFamilyName.Clone() as string);
return clone;
}
public override string ToString()
{
return Name;
}
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
public class PersonalNameReference : ContentItem
{
private PersonalName mvarValue = null;
public PersonalName Value { get { return mvarValue; } }
private string mvarFormat = "{GivenName}";
public string Format { get { return mvarFormat; } set { mvarFormat = value; } }
protected override string RenderContent()
{
if (mvarValue == null) throw new NullReferenceException("Value cannot be null");
return FormatString(mvarFormat, mvarValue);
}
private static string FormatString(string format, PersonalName value)
{
string retval = format;
retval = retval.Replace("{GivenName}", value.GivenName);
retval = retval.Replace("{FamilyName}", value.FamilyName);
for (int i = 0; i < value.MiddleNames.Count; i++)
{
retval = retval.Replace("{MiddleName:" + i.ToString() + "}", value.MiddleNames[i]);
}
retval = retval.Replace("{Nickname}", value.Nickname);
return retval;
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
/// <summary>
/// Represents a section or a scene in a <see cref="Chapter" />.
/// </summary>
public class Section : ICloneable
{
public class SectionCollection
: System.Collections.ObjectModel.Collection<Section>
{
}
private Guid mvarID = Guid.Empty;
public Guid ID { get { return mvarID; } set { mvarID = value; } }
private string mvarTitle = String.Empty;
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
public object Clone()
{
Section clone = new Section();
clone.Title = (mvarTitle.Clone() as string);
return clone;
}
}
}

View File

@ -4,11 +4,19 @@ using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
public class StoryObjectModel
public class StoryObjectModel : ObjectModel
{
private Universe mvarUniverse = new Universe();
/// <summary>
/// The <see cref="Universe" /> this story is set in. A Universe is a collection of characters and
/// other entities referenced in a story.
/// </summary>
public Universe Universe { get { return mvarUniverse; } }
private Character.CharacterCollection mvarCharacters = new Character.CharacterCollection();
/// <summary>
/// All the characters available to draw from within this story.
/// Characters introduced for this story only. Characters that can be used across stories should
/// be added to a <see cref="Universe" />.
/// </summary>
public Character.CharacterCollection Characters { get { return mvarCharacters; } }
@ -17,5 +25,24 @@ namespace UniversalEditor.ObjectModels.StoryWriter.Story
/// The books collected in this story.
/// </summary>
public Book.BookCollection Books { get { return mvarBooks; } }
public override void Clear()
{
mvarCharacters.Clear();
mvarBooks.Clear();
}
public override void CopyTo(ObjectModel where)
{
StoryObjectModel clone = (where as StoryObjectModel);
foreach (Character chara in mvarCharacters)
{
clone.Characters.Add(chara.Clone() as Character);
}
foreach (Book book in mvarBooks)
{
clone.Books.Add(book.Clone() as Book);
}
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.ObjectModels.StoryWriter.Story
{
/// <summary>
/// Represents a universe, a collection of related elements in a particular story.
/// </summary>
public class Universe
{
private Character.CharacterCollection mvarCharacters = new Character.CharacterCollection();
public Character.CharacterCollection Characters { get { return mvarCharacters; } }
}
}

View File

@ -36,11 +36,17 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DataFormats\StoryWriter\Story\StoryXML\StoryXMLDataFormat.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\Author.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\Book.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\Chapter.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\Character.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\ContentItem.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\Gender.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\PersonalName.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\PersonalNameReference.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\Section.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\StoryObjectModel.cs" />
<Compile Include="ObjectModels\StoryWriter\Story\Universe.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>