Make player and drink editor use the editor base class
This commit is contained in:
@@ -18,47 +18,33 @@ namespace EstusShots.Gtk.Dialogs
|
||||
}
|
||||
public delegate void DialogClosedEventHandler<T>(object o, DialogClosedEventArgs<T> args) where T: class, new();
|
||||
|
||||
// TODO remove non-generic version
|
||||
public class DialogClosedEventArgs : EventArgs
|
||||
{
|
||||
public bool Ok { get; }
|
||||
public object Model { get; }
|
||||
|
||||
public DialogClosedEventArgs(bool ok, object model)
|
||||
{
|
||||
Ok = ok;
|
||||
Model = model;
|
||||
}
|
||||
}
|
||||
public delegate void DialogClosedEventHandler(object o, DialogClosedEventArgs args);
|
||||
|
||||
public abstract class DialogBase<T> where T: class, new()
|
||||
public abstract class DialogBase<T> : Dialog where T: class, new()
|
||||
{
|
||||
protected readonly Builder Builder;
|
||||
protected T EditObject { get; set; }
|
||||
|
||||
[UI] private readonly Dialog _editorDialog = null;
|
||||
[UI] private readonly Button _saveButton = null;
|
||||
[UI] private readonly Button _cancelButton = null;
|
||||
|
||||
public event DialogClosedEventHandler<T> OnDialogClosed;
|
||||
public event DialogClosedEventHandler<T> DialogClosed;
|
||||
|
||||
protected DialogBase(Window parent, Builder builder)
|
||||
protected DialogBase(Window parent, Builder builder) : base(builder.GetObject("_editorDialog").Handle)
|
||||
{
|
||||
builder.Autoconnect(this);
|
||||
|
||||
Builder = builder;
|
||||
Builder.Autoconnect(this);
|
||||
_saveButton.Clicked += OnSaveButtonClicked;
|
||||
_cancelButton.Clicked += (sender, args) =>
|
||||
{
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(false, new T()));
|
||||
_editorDialog.Dispose();
|
||||
DialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(false, new T()));
|
||||
Dispose();
|
||||
};
|
||||
_editorDialog.TransientFor = parent;
|
||||
TransientFor = parent;
|
||||
}
|
||||
|
||||
public void Show()
|
||||
public new void Show()
|
||||
{
|
||||
LoadFromModel();
|
||||
_editorDialog.Show();
|
||||
base.Show();
|
||||
}
|
||||
|
||||
private void OnSaveButtonClicked(object sender, EventArgs e)
|
||||
@@ -66,8 +52,8 @@ namespace EstusShots.Gtk.Dialogs
|
||||
try
|
||||
{
|
||||
LoadToModel();
|
||||
OnDialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(true, EditObject));
|
||||
_editorDialog.Dispose();
|
||||
DialogClosed?.Invoke(this, new DialogClosedEventArgs<T>(true, EditObject));
|
||||
Dispose();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user