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

78 lines
2.3 KiB
C#
Raw Normal View History

2014-07-23 20:27:14 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterEditor.Business;
using RainmeterEditor.UI.Dialogs;
using RainmeterEditor.Model.Events;
using RainmeterEditor.Model;
2014-07-24 20:41:17 +00:00
using System.Windows;
2014-07-25 08:09:10 +00:00
using System.Windows.Input;
using System.Windows.Media.Imaging;
2014-07-23 20:27:14 +00:00
namespace RainmeterEditor.UI.Controller
{
public class DocumentController
{
2014-07-25 08:09:10 +00:00
#region Commands
public Command DocumentCreateCommand { get; private set; }
#endregion
2014-07-23 20:27:14 +00:00
public event EventHandler<DocumentOpenedEventArgs> DocumentOpened
{
add
{
DocumentManager.Instance.DocumentOpened += value;
}
remove
{
DocumentManager.Instance.DocumentOpened -= value;
}
}
public event EventHandler DocumentClosed;
2014-07-25 08:09:10 +00:00
public Window OwnerWindow { get; set; }
2014-07-23 20:27:14 +00:00
public DocumentController()
{
2014-07-25 08:09:10 +00:00
DocumentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow())
{
DisplayText = Resources.Strings.DocumentCreateCommand_DisplayText,
Tooltip = Resources.Strings.DocumentCreateCommand_ToolTip,
Icon = new BitmapImage(new Uri("/Resources/Icons/page_white_star_16.png", UriKind.RelativeOrAbsolute)),
Shortcut = new KeyGesture(Key.N, ModifierKeys.Control)
};
2014-07-23 20:27:14 +00:00
}
2014-07-25 08:09:10 +00:00
public void CreateWindow(DocumentFormat defaultFormat = null, string defaultPath = "")
2014-07-23 20:27:14 +00:00
{
// Show dialog
2014-07-24 20:41:17 +00:00
var dialog = new CreateDocumentDialog()
{
2014-07-25 08:09:10 +00:00
Owner = OwnerWindow,
2014-07-24 20:41:17 +00:00
SelectedFormat = defaultFormat,
SelectedPath = defaultPath
};
2014-07-23 20:27:14 +00:00
bool? res = dialog.ShowDialog();
if (!res.HasValue || !res.Value)
return;
var format = dialog.SelectedFormat;
var path = dialog.SelectedPath;
// Call manager
DocumentManager.Instance.Create(format, path);
}
2014-07-24 20:41:17 +00:00
public void Create(DocumentFormat format, string path)
{
// Call manager
DocumentManager.Instance.Create(format, path);
}
2014-07-25 08:09:10 +00:00
2014-07-23 20:27:14 +00:00
}
}