using System;
using System.Collections.Generic;
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.Core.Model;
namespace RainmeterStudio.UI.Dialogs
{
///
/// Interaction logic for CloseUnsavedDialog.xaml
///
public partial class CloseUnsavedDialog : Window
{
///
/// Displays the dialog and returns the result
///
/// List of unsaved documents
/// Dialog result
public static bool? ShowDialog(IEnumerable unsavedDocuments)
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
return dialog.ShowDialog();
}
///
/// Displays the dialog and returns the result
///
/// Owner window
/// List of unsaved documents
/// Dialog result
public static bool? ShowDialog(Window owner, IEnumerable unsavedDocuments)
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
dialog.Owner = owner;
return dialog.ShowDialog();
}
///
/// Displays the dialog and returns the result
///
/// Owner window
/// List of unsaved documents
/// Dialog result
public static bool? ShowDialog(Window owner, params IDocument[] unsavedDocuments)
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
dialog.Owner = owner;
return dialog.ShowDialog();
}
///
/// Initializes the dialog
///
/// List of unsaved documents
public CloseUnsavedDialog(IEnumerable unsavedDocuments)
{
InitializeComponent();
textFiles.Inlines.AddRange(unsavedDocuments.SelectMany(GetInlines));
}
private IEnumerable GetInlines(IDocument doc)
{
var folder = System.IO.Path.GetDirectoryName(doc.Reference.StoragePath);
yield return new Run(folder)
{
Foreground = Brushes.DarkGray
};
yield return new Run(doc.Reference.Name)
{
FontWeight = FontWeights.Bold
};
}
private void buttonSave_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
private void buttonDoNotSave_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = null;
Close();
}
}
}