using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using RainmeterStudio.Model;
using RainmeterStudio.UI.Controller;
namespace RainmeterStudio.Documents
{
///
/// Represents a document template
///
public class DocumentTemplate where T : IDocument
{
#region Private fields
private Func _createFunction;
#endregion
///
/// Gets the document template name
///
public string Name { get; private set; }
#region Icon property
private ImageSource _icon = null;
///
/// Gets or sets the template's icon
///
public virtual ImageSource Icon
{
get
{
if (_icon == null)
return IconProvider.GetIcon("Template_" + Name);
return _icon;
}
set
{
_icon = value;
}
}
#endregion
#region Display text property
private string _displayText = null;
///
/// Gets or sets the display text
///
public virtual string DisplayText
{
get
{
if (_displayText == null)
return Resources.Strings.ResourceManager.GetString("Template_" + Name + "_DisplayText");
return _displayText;
}
set
{
_displayText = value;
}
}
#endregion
#region Description property
private string _description = null;
///
/// Gets or sets the description
///
public virtual string Description
{
get
{
if (_description == null)
return Resources.Strings.ResourceManager.GetString("Template_" + Name + "_Description");
return _description;
}
set
{
_description = value;
}
}
#endregion
///
/// Gets or sets the default extension of this template
///
public string DefaultExtension { get; set; }
///
/// Gets or sets the category in which this template belongs
///
public virtual string Category { get; set; }
///
/// Initializes the document template
///
/// Name of document template
public DocumentTemplate(string name, string defaultExtension = null, string category = null, Func createDocument = null)
{
Name = name;
DefaultExtension = defaultExtension;
_createFunction = createDocument;
}
///
/// Creates a document of type T
///
///
public virtual T CreateDocument()
{
if (_createFunction != null)
return _createFunction();
return default(T);
}
}
}