using System; using System.Collections.Generic; using System.Collections.ObjectModel; 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; namespace RainmeterStudio.UI.Dialogs { public enum CloseUnsavedDialogResult { Unset, Save, DoNotSave, Cancel } /// /// 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 CloseUnsavedDialogResult ShowDialog(IEnumerable unsavedDocuments) { var dialog = new CloseUnsavedDialog(unsavedDocuments); dialog.ShowDialog(); return dialog.SaveDialogResult; } /// /// Displays the dialog and returns the result /// /// Owner window /// List of unsaved documents /// Dialog result public static CloseUnsavedDialogResult ShowDialog(Window owner, IEnumerable unsavedDocuments) { var dialog = new CloseUnsavedDialog(unsavedDocuments); dialog.ShowDialog(); return dialog.SaveDialogResult; } /// /// Displays the dialog and returns the result /// /// Owner window /// List of unsaved documents /// Dialog result public static CloseUnsavedDialogResult ShowDialog(Window owner, params IDocument[] unsavedDocuments) { var dialog = new CloseUnsavedDialog(unsavedDocuments); dialog.ShowDialog(); return dialog.SaveDialogResult; } /// /// Gets the 'close unsaved' dialog result /// public CloseUnsavedDialogResult SaveDialogResult { get; private set; } /// /// Initializes the dialog /// /// List of unsaved documents public CloseUnsavedDialog(IEnumerable unsavedDocuments) { InitializeComponent(); SaveDialogResult = CloseUnsavedDialogResult.Unset; unsavedDocuments.ForEach(d => listUnsavedDocuments.Items.Add(d)); } private void buttonSave_Click(object sender, RoutedEventArgs e) { SaveDialogResult = CloseUnsavedDialogResult.Save; Close(); } private void buttonDoNotSave_Click(object sender, RoutedEventArgs e) { SaveDialogResult = CloseUnsavedDialogResult.DoNotSave; Close(); } private void buttonCancel_Click(object sender, RoutedEventArgs e) { SaveDialogResult = CloseUnsavedDialogResult.Cancel; Close(); } } }