Nice Exception Dialog
This commit is contained in:
40
EstusShots.Gtk/Dialogs/ErrorDialog.cs
Normal file
40
EstusShots.Gtk/Dialogs/ErrorDialog.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using EstusShots.Shared.Models;
|
||||
using Gtk;
|
||||
using UI = Gtk.Builder.ObjectAttribute;
|
||||
|
||||
namespace EstusShots.Gtk.Dialogs
|
||||
{
|
||||
public class ErrorHandler
|
||||
{
|
||||
[UI] private readonly Dialog ShowErrorDialog = null;
|
||||
[UI] private readonly Label ErrorShortTextLabel = null;
|
||||
[UI] private readonly Label ErrorDetailTextLabel = null;
|
||||
[UI] private readonly TextView StackTraceTextView = null;
|
||||
[UI] private readonly Button ErrorDialogCloseButton = null;
|
||||
|
||||
public void ShowFor(Window window, OperationResult error)
|
||||
{
|
||||
ShowErrorDialog.TransientFor = window;
|
||||
ErrorDialogCloseButton.Clicked += (sender, args) => { ShowErrorDialog.Dispose();};
|
||||
ErrorShortTextLabel.Text = error.ShortMessage;
|
||||
ErrorDetailTextLabel.Visible = error.DetailedMessage != null;
|
||||
ErrorDetailTextLabel.Text = error.DetailedMessage;
|
||||
StackTraceTextView.Visible = error.StackTrace != null;
|
||||
var buff = new TextBuffer(new TextTagTable()) {Text = error.StackTrace};
|
||||
StackTraceTextView.Buffer = buff;
|
||||
ShowErrorDialog.Show();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorDialog
|
||||
{
|
||||
public static Window MainWindow;
|
||||
public static void Show(OperationResult error)
|
||||
{
|
||||
var handler = new ErrorHandler();
|
||||
var builder = new Builder("MainWindow.glade");
|
||||
builder.Autoconnect(handler);
|
||||
handler.ShowFor(MainWindow, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,8 +43,8 @@ namespace EstusShots.Gtk.Dialogs
|
||||
|
||||
SavePlayerButton.Clicked += SavePlayerButtonOnClicked;
|
||||
|
||||
PlayerEditorDialog.Parent = parent;
|
||||
PlayerEditorDialog.TransientFor = parent;
|
||||
PlayerEditorDialog.Show();
|
||||
|
||||
ReadFromModel();
|
||||
}
|
||||
@@ -55,6 +55,7 @@ namespace EstusShots.Gtk.Dialogs
|
||||
{
|
||||
ReadToModel();
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs(true, _player));
|
||||
PlayerEditorDialog.Dispose();
|
||||
}
|
||||
|
||||
// Private Methods
|
||||
|
||||
Reference in New Issue
Block a user