using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using RainmeterStudio.Core.Utils;
using RainmeterStudio.UI.Controller;
using RainmeterStudio.UI.ViewModel;
namespace RainmeterStudio.UI.Dialogs
{
///
/// Interaction logic for CreateDocumentDialog.xaml
///
public partial class CreateDocumentDialog : Window
{
private DocumentController _documentController;
///
/// Gets or sets the currently selected file format
///
public DocumentTemplateViewModel SelectedTemplate
{
get
{
return listTemplates.SelectedItem as DocumentTemplateViewModel;
}
set
{
listTemplates.SelectedItem = value;
}
}
///
/// Gets or sets the path
///
public string SelectedName
{
get
{
return textName.Text;
}
set
{
textName.Text = value;
}
}
///
/// Creates a new instance of CreateDocumentDialog
///
public CreateDocumentDialog(DocumentController docCtrl)
{
InitializeComponent();
_documentController = docCtrl;
listTemplates.ItemsSource = _documentController.DocumentTemplates.OrderBy(x => x.DisplayText);
Validate();
}
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;
res &= (listTemplates.SelectedItem != null);
res &= PathHelper.IsFileNameValid(SelectedName);
buttonCreate.IsEnabled = res;
}
private void listFormats_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Validate();
}
private void textName_TextChanged(object sender, TextChangedEventArgs e)
{
Validate();
}
}
}