|
@@ -141,19 +141,22 @@ public partial class MessageWindow : Window, INotifyPropertyChanged
|
|
|
OnPropertyChanged(nameof(RightButtons));
|
|
|
}
|
|
|
|
|
|
- public void AddButton(MessageWindowButton button)
|
|
|
+ public MessageWindow AddButton(MessageWindowButton button)
|
|
|
{
|
|
|
Buttons.Add(button);
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
- public void AddOKButton(string content = "OK")
|
|
|
+ public MessageWindow AddOKButton(string content = "OK")
|
|
|
{
|
|
|
Buttons.Add(new MessageWindowButton(content, OKButton_Click, MessageWindowButtonPosition.Right));
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
- public void AddCancelButton(string content = "Cancel")
|
|
|
+ public MessageWindow AddCancelButton(string content = "Cancel")
|
|
|
{
|
|
|
Buttons.Add(new MessageWindowButton(content, CancelButton_Click, MessageWindowButtonPosition.Right));
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
private void CancelButton_Click(MessageWindow window, MessageWindowButton button)
|
|
@@ -179,44 +182,54 @@ public partial class MessageWindow : Window, INotifyPropertyChanged
|
|
|
|
|
|
public static readonly BitmapImage _warning = InABox.Wpf.Resources.warning.AsBitmapImage();
|
|
|
|
|
|
+ public static MessageWindow New()
|
|
|
+ {
|
|
|
+ return new MessageWindow();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageWindow NewMessage(string message, string title, ImageSource? image = null)
|
|
|
+ {
|
|
|
+ return new MessageWindow()
|
|
|
+ .Title(title)
|
|
|
+ .Message(message)
|
|
|
+ .Image(image)
|
|
|
+ .AddOKButton();
|
|
|
+ }
|
|
|
public static void ShowMessage(string message, string title, ImageSource? image = null)
|
|
|
{
|
|
|
- var window = new MessageWindow
|
|
|
- {
|
|
|
- Message = message,
|
|
|
- Title = title,
|
|
|
- Image = image
|
|
|
- };
|
|
|
- window.AddOKButton();
|
|
|
- window.ShowDialog();
|
|
|
+ NewMessage(message, title, image).Display();
|
|
|
}
|
|
|
|
|
|
+ public static MessageWindow NewOKCancel(string message, string title, ImageSource? image = null)
|
|
|
+ {
|
|
|
+ return new MessageWindow()
|
|
|
+ .Title(title)
|
|
|
+ .Message(message)
|
|
|
+ .Image(image)
|
|
|
+ .AddOKButton()
|
|
|
+ .AddCancelButton();
|
|
|
+ }
|
|
|
public static bool ShowOKCancel(string message, string title, ImageSource? image = null)
|
|
|
{
|
|
|
- var window = new MessageWindow
|
|
|
- {
|
|
|
- Message = message,
|
|
|
- Title = title,
|
|
|
- Image = image
|
|
|
- };
|
|
|
- window.AddOKButton();
|
|
|
- window.AddCancelButton();
|
|
|
- window.ShowDialog();
|
|
|
- return window.Result == MessageWindowResult.OK;
|
|
|
+ return NewOKCancel(message, title, image)
|
|
|
+ .Display()
|
|
|
+ .Result == MessageWindowResult.OK;
|
|
|
}
|
|
|
|
|
|
+ public static MessageWindow NewYesNo(string message, string title, ImageSource? image = null)
|
|
|
+ {
|
|
|
+ return new MessageWindow()
|
|
|
+ .Title(title)
|
|
|
+ .Message(message)
|
|
|
+ .Image(image)
|
|
|
+ .AddOKButton("Yes")
|
|
|
+ .AddCancelButton("No");
|
|
|
+ }
|
|
|
public static bool ShowYesNo(string message, string title, ImageSource? image = null)
|
|
|
{
|
|
|
- var window = new MessageWindow
|
|
|
- {
|
|
|
- Message = message,
|
|
|
- Title = title,
|
|
|
- Image = image
|
|
|
- };
|
|
|
- window.AddOKButton("Yes");
|
|
|
- window.AddCancelButton("No");
|
|
|
- window.ShowDialog();
|
|
|
- return window.Result == MessageWindowResult.OK;
|
|
|
+ return NewYesNo(message, title, image)
|
|
|
+ .Display()
|
|
|
+ .Result == MessageWindowResult.OK;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -226,22 +239,19 @@ public partial class MessageWindow : Window, INotifyPropertyChanged
|
|
|
/// <param name="exception"></param>
|
|
|
/// <param name="title"></param>
|
|
|
/// <param name="shouldLog">If <see langword="true"/>, also logs the exception.</param>
|
|
|
- public static void ShowError(string? message, Exception exception, string title = "Error", bool shouldLog = true, ImageSource? image = null)
|
|
|
+ public static MessageWindow NewError(string? message, Exception exception, string title = "Error", bool shouldLog = true, ImageSource? image = null)
|
|
|
{
|
|
|
if (shouldLog)
|
|
|
{
|
|
|
CoreUtils.LogException(ClientFactory.UserID, exception);
|
|
|
}
|
|
|
|
|
|
- var window = new MessageWindow
|
|
|
- {
|
|
|
- Message = message ?? exception.Message,
|
|
|
- Title = title,
|
|
|
- Details = CoreUtils.FormatException(exception),
|
|
|
- Image = image ?? _warning
|
|
|
- };
|
|
|
-
|
|
|
- window.AddButton(new MessageWindowButton("Show Logs", ShowLogs_Click, MessageWindowButtonPosition.Left));
|
|
|
+ var window = new MessageWindow()
|
|
|
+ .Message(message ?? exception.Message)
|
|
|
+ .Title(title)
|
|
|
+ .Details(CoreUtils.FormatException(exception))
|
|
|
+ .Image(image ?? _warning)
|
|
|
+ .AddButton(new MessageWindowButton("Show Logs", ShowLogs_Click, MessageWindowButtonPosition.Left));
|
|
|
|
|
|
var showDetailsButton = new MessageWindowButton("Show Details", (win, button) =>
|
|
|
{
|
|
@@ -250,10 +260,14 @@ public partial class MessageWindow : Window, INotifyPropertyChanged
|
|
|
? "Hide Details"
|
|
|
: "Show Details";
|
|
|
}, MessageWindowButtonPosition.Left);
|
|
|
- window.AddButton(showDetailsButton);
|
|
|
|
|
|
- window.AddOKButton();
|
|
|
- window.ShowDialog();
|
|
|
+ return window.AddButton(showDetailsButton)
|
|
|
+ .AddOKButton();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void ShowError(string? message, Exception exception, string title = "Error", bool shouldLog = true, ImageSource? image = null)
|
|
|
+ {
|
|
|
+ NewError(message, exception, title, shouldLog, image).Display();
|
|
|
}
|
|
|
|
|
|
private static void ShowLogs_Click(MessageWindow window, MessageWindowButton button)
|
|
@@ -265,6 +279,45 @@ public partial class MessageWindow : Window, INotifyPropertyChanged
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
+public static class MessageWindowBuilder
|
|
|
+{
|
|
|
+ public static MessageWindow Title(this MessageWindow window, string title)
|
|
|
+ {
|
|
|
+ window.Title = title;
|
|
|
+ return window;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageWindow Message(this MessageWindow window, string message)
|
|
|
+ {
|
|
|
+ window.Message = message;
|
|
|
+ return window;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageWindow Image(this MessageWindow window, ImageSource? image)
|
|
|
+ {
|
|
|
+ window.Image = image;
|
|
|
+ return window;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageWindow Icon(this MessageWindow window, ImageSource image)
|
|
|
+ {
|
|
|
+ window.Icon = image;
|
|
|
+ return window;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageWindow Details(this MessageWindow window, string details)
|
|
|
+ {
|
|
|
+ window.Details = details;
|
|
|
+ return window;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MessageWindow Display(this MessageWindow window)
|
|
|
+ {
|
|
|
+ window.ShowDialog();
|
|
|
+ return window;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
public class MessageWindowConsole : Console.Console
|
|
|
{
|
|
|
public string FileName { get; set; }
|