Implemented Accessor References
This commit is contained in:
parent
09869448a9
commit
3dfea8a0cc
@ -8,8 +8,13 @@ using System.Diagnostics;
|
||||
namespace UniversalEditor
|
||||
{
|
||||
[DebuggerNonUserCode()]
|
||||
public abstract class Accessor
|
||||
public abstract class Accessor : References<AccessorReference>
|
||||
{
|
||||
public virtual AccessorReference MakeReference()
|
||||
{
|
||||
return new AccessorReference(this.GetType());
|
||||
}
|
||||
|
||||
public Accessor()
|
||||
{
|
||||
mvarReader = new Reader(this);
|
||||
|
||||
78
CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs
Normal file
78
CSharp/Libraries/UniversalEditor.Core/AccessorReference.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor
|
||||
{
|
||||
public class AccessorReference : ReferencedBy<Accessor>
|
||||
{
|
||||
public AccessorReference(Type type)
|
||||
{
|
||||
if (!type.IsSubclassOf(typeof(Accessor)))
|
||||
{
|
||||
throw new InvalidCastException("Cannot create an accessor reference to a non-Accessor type");
|
||||
}
|
||||
else if (type.IsAbstract)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot create an accessor reference to an abstract type");
|
||||
}
|
||||
|
||||
mvarAccessorType = type;
|
||||
mvarAccessorTypeName = mvarAccessorType.FullName;
|
||||
}
|
||||
|
||||
private Type mvarAccessorType = null;
|
||||
public Type AccessorType { get { return mvarAccessorType; } set { mvarAccessorType = value; } }
|
||||
|
||||
private string mvarAccessorTypeName = null;
|
||||
public string AccessorTypeName { get { return mvarAccessorTypeName; } set { mvarAccessorTypeName = value; } }
|
||||
|
||||
private string mvarTitle = String.Empty;
|
||||
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
|
||||
|
||||
public bool ShouldFilterObject(string filter)
|
||||
{
|
||||
return mvarTitle.ToLower().Contains(filter.ToLower());
|
||||
}
|
||||
public string[] GetDetails()
|
||||
{
|
||||
return new string[] { mvarTitle };
|
||||
}
|
||||
|
||||
private bool mvarVisible = true;
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="Accessor" /> is visible in a selection list. Setting this
|
||||
/// property to false can be useful for accessors that are intended for use in code, but should
|
||||
/// not be exposed to UniversalEditor user interface components, such as the document properties
|
||||
/// dialog.
|
||||
/// </summary>
|
||||
public bool Visible { get { return mvarVisible; } set { mvarVisible = value; } }
|
||||
|
||||
private CustomOption.CustomOptionCollection mvarExportOptions = new CustomOption.CustomOptionCollection();
|
||||
/// <summary>
|
||||
/// A collection of <see cref="CustomOption" />s that are applied to the <see cref="Accessor" />
|
||||
/// when it is being used to save or export a file.
|
||||
/// </summary>
|
||||
public CustomOption.CustomOptionCollection ExportOptions { get { return mvarExportOptions; } }
|
||||
|
||||
private CustomOption.CustomOptionCollection mvarImportOptions = new CustomOption.CustomOptionCollection();/// <summary>
|
||||
/// A collection of <see cref="CustomOption" />s that are applied to the <see cref="Accessor" />
|
||||
/// when it is being used to open or import a file.
|
||||
/// </summary>
|
||||
public CustomOption.CustomOptionCollection ImportOptions { get { return mvarImportOptions; } }
|
||||
|
||||
public Accessor Create()
|
||||
{
|
||||
if (mvarAccessorType == null && mvarAccessorTypeName != null)
|
||||
{
|
||||
mvarAccessorType = Type.GetType(mvarAccessorTypeName);
|
||||
}
|
||||
if (mvarAccessorType != null)
|
||||
{
|
||||
return (mvarAccessorType.Assembly.CreateInstance(mvarAccessorType.FullName) as Accessor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,25 @@ namespace UniversalEditor.Accessors
|
||||
{
|
||||
public class FileAccessor : Accessor
|
||||
{
|
||||
private static AccessorReference _ar = null;
|
||||
public override AccessorReference MakeReference()
|
||||
{
|
||||
if (_ar == null)
|
||||
{
|
||||
_ar = base.MakeReference();
|
||||
_ar.Title = "Local file";
|
||||
|
||||
_ar.ImportOptions.Add(new CustomOptionFile("FileName", "&File name:"));
|
||||
_ar.ImportOptions.Add(new CustomOptionBoolean("ForceOverwrite", "Force &overwrite if file exists", false, false));
|
||||
_ar.ImportOptions.Add(new CustomOptionBoolean("AllowWrite", "Open file for &writing", false, false));
|
||||
|
||||
_ar.ExportOptions.Add(new CustomOptionFile("FileName", "&File name:"));
|
||||
_ar.ExportOptions.Add(new CustomOptionBoolean("ForceOverwrite", "Force &overwrite if file exists", true, true));
|
||||
_ar.ExportOptions.Add(new CustomOptionBoolean("AllowWrite", "Open file for &writing", true, false));
|
||||
}
|
||||
return _ar;
|
||||
}
|
||||
|
||||
protected override long GetPosition()
|
||||
{
|
||||
return mvarFileStream.Position;
|
||||
@ -50,7 +69,11 @@ namespace UniversalEditor.Accessors
|
||||
public bool ForceOverwrite { get { return mvarForceOverwrite; } set { mvarForceOverwrite = value; } }
|
||||
|
||||
private string mvarFileName = String.Empty;
|
||||
public string FileName { get { return mvarFileName; } set { mvarFileName = value; } }
|
||||
|
||||
public FileAccessor()
|
||||
{
|
||||
}
|
||||
public FileAccessor(string FileName, bool AllowWrite = false, bool ForceOverwrite = false, bool AutoOpen = false)
|
||||
{
|
||||
mvarFileName = FileName;
|
||||
@ -63,8 +86,6 @@ namespace UniversalEditor.Accessors
|
||||
}
|
||||
}
|
||||
|
||||
public string FileName { get { return mvarFileName; } set { mvarFileName = value; } }
|
||||
|
||||
public void Open(string FileName)
|
||||
{
|
||||
mvarFileName = FileName;
|
||||
|
||||
@ -8,6 +8,17 @@ namespace UniversalEditor.Accessors
|
||||
{
|
||||
public class MemoryAccessor : Accessor
|
||||
{
|
||||
private static AccessorReference _ar = null;
|
||||
public override AccessorReference MakeReference()
|
||||
{
|
||||
if (_ar == null)
|
||||
{
|
||||
_ar = base.MakeReference();
|
||||
_ar.Visible = false;
|
||||
}
|
||||
return _ar;
|
||||
}
|
||||
|
||||
private byte[] _data = new byte[0];
|
||||
|
||||
private long ptr = 0;
|
||||
|
||||
@ -9,6 +9,17 @@ namespace UniversalEditor.Accessors
|
||||
{
|
||||
public class StreamAccessor : Accessor
|
||||
{
|
||||
private static AccessorReference _ar = null;
|
||||
public override AccessorReference MakeReference()
|
||||
{
|
||||
if (_ar == null)
|
||||
{
|
||||
_ar = base.MakeReference();
|
||||
_ar.Visible = false;
|
||||
}
|
||||
return _ar;
|
||||
}
|
||||
|
||||
private System.IO.Stream mvarBaseStream = null;
|
||||
public System.IO.Stream BaseStream { get { return mvarBaseStream; } }
|
||||
|
||||
|
||||
@ -7,6 +7,17 @@ namespace UniversalEditor.Accessors
|
||||
{
|
||||
public class StringAccessor : Accessor
|
||||
{
|
||||
private static AccessorReference _ar = null;
|
||||
public override AccessorReference MakeReference()
|
||||
{
|
||||
if (_ar == null)
|
||||
{
|
||||
_ar = base.MakeReference();
|
||||
_ar.Visible = false;
|
||||
}
|
||||
return _ar;
|
||||
}
|
||||
|
||||
private char[] _data = new char[0];
|
||||
|
||||
private long ptr = 0;
|
||||
|
||||
@ -55,6 +55,7 @@ namespace UniversalEditor.Common
|
||||
}
|
||||
|
||||
#region Initializing Object Models
|
||||
List<AccessorReference> listAccessors = new List<AccessorReference>();
|
||||
List<ObjectModelReference> listObjectModels = new List<ObjectModelReference>();
|
||||
List<DataFormatReference> listDataFormats = new List<DataFormatReference>();
|
||||
List<DocumentTemplate> listDocumentTemplates = new List<DocumentTemplate>();
|
||||
@ -82,6 +83,21 @@ namespace UniversalEditor.Common
|
||||
|
||||
listObjectModels.Add(omr);
|
||||
}
|
||||
else if (mvarAvailableAccessors == null && (type.IsSubclassOf(typeof(Accessor)) && !type.IsAbstract))
|
||||
{
|
||||
try
|
||||
{
|
||||
Accessor a = (type.Assembly.CreateInstance(type.FullName) as Accessor);
|
||||
AccessorReference ar = a.MakeReference();
|
||||
if (ar != null)
|
||||
{
|
||||
listAccessors.Add(ar);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (mvarAvailableDataFormats == null && (type.IsSubclassOf(typeof(DataFormat)) && !type.IsAbstract))
|
||||
{
|
||||
try
|
||||
@ -133,6 +149,7 @@ namespace UniversalEditor.Common
|
||||
|
||||
if (mvarAvailableDocumentTemplates == null) mvarAvailableDocumentTemplates = listDocumentTemplates.ToArray();
|
||||
if (mvarAvailableProjectTemplates == null) mvarAvailableProjectTemplates = listProjectTemplates.ToArray();
|
||||
if (mvarAvailableAccessors == null) mvarAvailableAccessors = listAccessors.ToArray();
|
||||
}
|
||||
|
||||
private static int _DataFormatReferenceComparer(DataFormatReference dfr1, DataFormatReference dfr2)
|
||||
@ -1101,6 +1118,14 @@ namespace UniversalEditor.Common
|
||||
return list.ToArray();
|
||||
}
|
||||
#endregion
|
||||
#region Accessors
|
||||
private static AccessorReference[] mvarAvailableAccessors = null;
|
||||
public static AccessorReference[] GetAvailableAccessors()
|
||||
{
|
||||
if (mvarAvailableAccessors == null) Initialize();
|
||||
return mvarAvailableAccessors;
|
||||
}
|
||||
#endregion
|
||||
#region Data Formats
|
||||
private static DataFormatReference[] mvarAvailableDataFormats = null;
|
||||
public static DataFormatReference[] GetAvailableDataFormats()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user