2014-07-26 07:12:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
using RainmeterStudio.Business;
|
2014-08-12 13:33:13 +00:00
|
|
|
|
using RainmeterStudio.Core.Documents;
|
2014-08-14 07:06:20 +00:00
|
|
|
|
using RainmeterStudio.UI.Controller;
|
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-07-29 20:35:59 +00:00
|
|
|
|
public DocumentTemplate SelectedTemplate
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-07-26 10:49:11 +00:00
|
|
|
|
return listFormats.SelectedItem as DocumentTemplate;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
listFormats.SelectedItem = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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-14 07:06:20 +00:00
|
|
|
|
PopulateCategories();
|
|
|
|
|
RepopulateFormats();
|
2014-07-26 07:12:56 +00:00
|
|
|
|
Validate();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-14 07:06:20 +00:00
|
|
|
|
private void PopulateCategories()
|
|
|
|
|
{
|
|
|
|
|
listCategories.ItemsSource = _documentController.DocumentTemplates
|
|
|
|
|
.Select(template => template.Category)
|
|
|
|
|
.Where(cat => cat != null)
|
|
|
|
|
.Distinct()
|
|
|
|
|
.Concat(new[] { "All" });
|
|
|
|
|
|
|
|
|
|
listCategories.SelectedIndex = listCategories.Items.Count - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RepopulateFormats()
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
2014-08-14 07:06:20 +00:00
|
|
|
|
if (Object.Equals(listCategories.SelectedItem, "All"))
|
|
|
|
|
listFormats.ItemsSource = _documentController.DocumentTemplates;
|
2014-07-29 16:42:52 +00:00
|
|
|
|
|
2014-08-14 07:06:20 +00:00
|
|
|
|
else
|
|
|
|
|
listFormats.ItemsSource = _documentController.DocumentTemplates.Where(x => Object.Equals(x.Category, listCategories.SelectedItem));
|
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;
|
|
|
|
|
res &= !String.IsNullOrWhiteSpace(textPath.Text);
|
|
|
|
|
res &= (listFormats.SelectedItem != null);
|
|
|
|
|
|
|
|
|
|
buttonCreate.IsEnabled = res;
|
|
|
|
|
}
|
2014-08-14 07:06:20 +00:00
|
|
|
|
|
|
|
|
|
private void listCategories_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RepopulateFormats();
|
|
|
|
|
}
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|