using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterEditor.Model;
using RainmeterEditor.Model.Events;
namespace RainmeterEditor.Business
{
public class DocumentManager
{
#region Singleton instance
private static DocumentManager _instance = null;
///
/// Gets the instance of DocumentManager
///
public static DocumentManager Instance
{
get
{
if (_instance == null)
_instance = new DocumentManager();
return _instance;
}
}
#endregion
private DocumentManager()
{
}
List _factories = new List();
List _editors = new List();
public event EventHandler DocumentOpened;
///
/// Registers a document editor factory
///
/// Document editor factory
public void RegisterEditorFactory(IDocumentEditorFactory factory)
{
_factories.Add(factory);
}
///
/// Creates a new document in the specified path, with the specified format, and opens it
///
///
///
public void Create(DocumentFormat format, string path)
{
// Create document
var document = format.Factory.CreateDocument(format, path);
// Create editor
var editor = format.Factory.CreateEditor(document);
_editors.Add(editor);
// Trigger event
if (DocumentOpened != null)
DocumentOpened(this, new DocumentOpenedEventArgs(editor));
}
public IEnumerable DocumentFormats
{
get
{
foreach (var f in _factories)
foreach (var df in f.CreateDocumentFormats)
yield return df;
}
}
}
}