using System; using System.Linq; using System.Windows; using System.Windows.Controls; 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 SelectedPath { get { return textPath.Text; } set { textPath.Text = value; } } /// /// Creates a new instance of CreateDocumentDialog /// public CreateDocumentDialog(DocumentController docCtrl) { InitializeComponent(); _documentController = docCtrl; PopulateFormats(); Validate(); } private void PopulateFormats() { listTemplates.ItemsSource = _documentController.DocumentTemplates; } 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 &= !String.IsNullOrWhiteSpace(textPath.Text); res &= !textPath.Text.Intersect(System.IO.Path.GetInvalidFileNameChars()).Any(); res &= (listTemplates.SelectedItem != null); buttonCreate.IsEnabled = res; } private void listFormats_SelectionChanged(object sender, SelectionChangedEventArgs e) { Validate(); } } }