rainmeter-studio/RainmeterStudio/UI/Dialogs/CloseUnsavedDialog.xaml.cs

106 lines
3.5 KiB
C#
Raw Normal View History

2014-08-30 07:24:01 +00:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
2014-08-30 07:24:01 +00:00
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;
using RainmeterStudio.Core.Utils;
2014-08-30 07:24:01 +00:00
namespace RainmeterStudio.UI.Dialogs
{
public enum CloseUnsavedDialogResult
{
Unset,
Save,
DoNotSave,
Cancel
}
2014-08-30 07:24:01 +00:00
/// <summary>
/// Interaction logic for CloseUnsavedDialog.xaml
/// </summary>
public partial class CloseUnsavedDialog : Window
{
/// <summary>
/// Displays the dialog and returns the result
/// </summary>
/// <param name="unsavedDocuments">List of unsaved documents</param>
/// <returns>Dialog result</returns>
public static CloseUnsavedDialogResult ShowDialog(IEnumerable<IDocument> unsavedDocuments)
2014-08-30 07:24:01 +00:00
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
dialog.ShowDialog();
return dialog.SaveDialogResult;
2014-08-30 07:24:01 +00:00
}
/// <summary>
/// Displays the dialog and returns the result
/// </summary>
/// <param name="owner">Owner window</param>
/// <param name="unsavedDocuments">List of unsaved documents</param>
/// <returns>Dialog result</returns>
public static CloseUnsavedDialogResult ShowDialog(Window owner, IEnumerable<IDocument> unsavedDocuments)
2014-08-30 07:24:01 +00:00
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
dialog.ShowDialog();
return dialog.SaveDialogResult;
2014-08-30 07:24:01 +00:00
}
/// <summary>
/// Displays the dialog and returns the result
/// </summary>
/// <param name="owner">Owner window</param>
/// <param name="unsavedDocuments">List of unsaved documents</param>
/// <returns>Dialog result</returns>
public static CloseUnsavedDialogResult ShowDialog(Window owner, params IDocument[] unsavedDocuments)
2014-08-30 07:24:01 +00:00
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
dialog.ShowDialog();
return dialog.SaveDialogResult;
2014-08-30 07:24:01 +00:00
}
/// <summary>
/// Gets the 'close unsaved' dialog result
/// </summary>
public CloseUnsavedDialogResult SaveDialogResult { get; private set; }
2014-08-30 07:24:01 +00:00
/// <summary>
/// Initializes the dialog
/// </summary>
/// <param name="unsavedDocuments">List of unsaved documents</param>
public CloseUnsavedDialog(IEnumerable<IDocument> unsavedDocuments)
{
InitializeComponent();
SaveDialogResult = CloseUnsavedDialogResult.Unset;
unsavedDocuments.ForEach(d => listUnsavedDocuments.Items.Add(d));
2014-08-30 07:24:01 +00:00
}
private void buttonSave_Click(object sender, RoutedEventArgs e)
{
SaveDialogResult = CloseUnsavedDialogResult.Save;
2014-08-30 07:24:01 +00:00
Close();
}
private void buttonDoNotSave_Click(object sender, RoutedEventArgs e)
{
SaveDialogResult = CloseUnsavedDialogResult.DoNotSave;
2014-08-30 07:24:01 +00:00
Close();
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
SaveDialogResult = CloseUnsavedDialogResult.Cancel;
2014-08-30 07:24:01 +00:00
Close();
}
}
}