2014-07-26 07:12:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
2014-08-14 07:06:20 +00:00
|
|
|
|
using RainmeterStudio.UI.Controller;
|
2014-08-15 12:31:33 +00:00
|
|
|
|
using RainmeterStudio.UI.ViewModel;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
|
|
|
|
namespace RainmeterStudio.UI.Dialogs
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for CreateDocumentDialog.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class CreateDocumentDialog : Window
|
|
|
|
|
{
|
2014-08-14 07:06:20 +00:00
|
|
|
|
private DocumentController _documentController;
|
|
|
|
|
|
2014-07-26 07:12:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the currently selected file format
|
|
|
|
|
/// </summary>
|
2014-08-15 12:31:33 +00:00
|
|
|
|
public DocumentTemplateViewModel SelectedTemplate
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-08-15 12:31:33 +00:00
|
|
|
|
return listTemplates.SelectedItem as DocumentTemplateViewModel;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2014-08-15 12:31:33 +00:00
|
|
|
|
listTemplates.SelectedItem = value;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the path
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string SelectedPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return textPath.Text;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
textPath.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of CreateDocumentDialog
|
|
|
|
|
/// </summary>
|
2014-08-14 07:06:20 +00:00
|
|
|
|
public CreateDocumentDialog(DocumentController docCtrl)
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2014-08-14 07:06:20 +00:00
|
|
|
|
_documentController = docCtrl;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
2014-08-15 12:31:33 +00:00
|
|
|
|
PopulateFormats();
|
2014-07-26 07:12:56 +00:00
|
|
|
|
Validate();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-15 12:31:33 +00:00
|
|
|
|
private void PopulateFormats()
|
2014-08-14 07:06:20 +00:00
|
|
|
|
{
|
2014-08-15 12:31:33 +00:00
|
|
|
|
listTemplates.ItemsSource = _documentController.DocumentTemplates;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCreate_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = true;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCancel_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = false;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Validate()
|
|
|
|
|
{
|
|
|
|
|
bool res = true;
|
2014-08-15 12:31:33 +00:00
|
|
|
|
|
2014-07-26 07:12:56 +00:00
|
|
|
|
res &= !String.IsNullOrWhiteSpace(textPath.Text);
|
2014-08-15 12:31:33 +00:00
|
|
|
|
res &= !textPath.Text.Intersect(System.IO.Path.GetInvalidFileNameChars()).Any();
|
|
|
|
|
res &= (listTemplates.SelectedItem != null);
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
|
|
|
|
buttonCreate.IsEnabled = res;
|
|
|
|
|
}
|
2014-08-14 07:06:20 +00:00
|
|
|
|
|
2014-08-15 12:31:33 +00:00
|
|
|
|
private void listFormats_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
2014-08-14 07:06:20 +00:00
|
|
|
|
{
|
2014-08-15 12:31:33 +00:00
|
|
|
|
Validate();
|
2014-08-14 07:06:20 +00:00
|
|
|
|
}
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|