rainmeter-studio/RainmeterStudio/UI/Controller/DocumentController.cs

102 lines
3.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using RainmeterStudio.Business;
using RainmeterStudio.Core.Documents;
using RainmeterStudio.Core.Model.Events;
using RainmeterStudio.UI.Dialogs;
using RainmeterStudio.UI.ViewModel;
namespace RainmeterStudio.UI.Controller
{
public class DocumentController
{
2014-07-29 16:42:52 +00:00
#region Managers
2014-07-29 16:42:52 +00:00
/// <summary>
/// Gets or sets the document manager
/// </summary>
protected DocumentManager DocumentManager { get; private set; }
2014-07-26 10:49:11 +00:00
2014-07-29 16:42:52 +00:00
/// <summary>
/// Gets or sets the project manager
/// </summary>
protected ProjectManager ProjectManager { get; private set; }
#endregion
#region Commands
public Command DocumentCreateCommand { get; private set; }
#endregion
/// <summary>
/// Triggered when a document is opened
/// </summary>
public event EventHandler<DocumentOpenedEventArgs> DocumentOpened
{
add { DocumentManager.DocumentOpened += value; }
remove { DocumentManager.DocumentOpened -= value; }
}
/// <summary>
/// Triggered when a document is closed
/// </summary>
public event EventHandler<DocumentClosedEventArgs> DocumentClosed
{
add { DocumentManager.DocumentClosed += value; }
remove { DocumentManager.DocumentClosed -= value; }
}
public Window OwnerWindow { get; set; }
2014-07-29 16:42:52 +00:00
public DocumentController(DocumentManager documentManager, ProjectManager projectManager)
{
2014-07-29 16:42:52 +00:00
DocumentManager = documentManager;
ProjectManager = projectManager;
DocumentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow());
}
2014-07-26 10:49:11 +00:00
public void CreateWindow(DocumentTemplate defaultFormat = null, string defaultPath = "")
{
// Show dialog
var dialog = new CreateDocumentDialog(this)
{
Owner = OwnerWindow,
SelectedTemplate = defaultFormat,
SelectedPath = defaultPath
};
bool? res = dialog.ShowDialog();
if (!res.HasValue || !res.Value)
return;
var format = dialog.SelectedTemplate;
var path = dialog.SelectedPath;
// Call manager
2014-07-29 16:42:52 +00:00
DocumentManager.Create(format);
}
2014-07-29 16:42:52 +00:00
public void Create(DocumentTemplate format)
{
// Call manager
2014-07-29 16:42:52 +00:00
DocumentManager.Create(format);
}
/// <summary>
/// Gets a list of document templates view models
/// </summary>
public IEnumerable<DocumentTemplateViewModel> DocumentTemplates
{
get
{
return DocumentManager.DocumentTemplates.Select(t => new DocumentTemplateViewModel(t));
}
}
}
}