From 11020ed0c493d3fef1a726e0506664d46546931a Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Fri, 4 Sep 2020 19:10:55 +1000 Subject: [PATCH] dont repeat urself --- MainWindow.cs | 34 ++++++++++++++++++---------------- ui/add.glade | 9 +++++---- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/MainWindow.cs b/MainWindow.cs index bc8f1cb..1b09475 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -267,6 +267,22 @@ namespace Buypeeb { } } + private MessageDialog OkCancelDialogue(string message) { + var md = new MessageDialog( + parent_window: this, + flags: DialogFlags.DestroyWithParent | DialogFlags.Modal, + type: MessageType.Question, + bt: ButtonsType.OkCancel, + format: message + ); + md.KeepAbove = true; + md.Resizable = false; + md.FocusOnMap = true; + md.Title = "buypeeb"; + + return md; + } + // show a simple entry dialogue that allows the user to enter text and either cancel or submit it private (Boolean accepted, string response) EntryDialogue(string title = "Buypeeb", string message = "Hi there!", string prefill = null) { Dialog ed = new Dialog(title, null, DialogFlags.DestroyWithParent | DialogFlags.Modal, "Cancel", ResponseType.Cancel, "OK", ResponseType.Ok); @@ -344,14 +360,7 @@ namespace Buypeeb { } private void ButtonQuitClicked(object sender, EventArgs a) { - MessageDialog md = new MessageDialog( - parent_window: this, - flags: DialogFlags.DestroyWithParent | DialogFlags.Modal, - type: MessageType.Question, - bt: ButtonsType.OkCancel, - format: "Are you sure you want to quit?" - ); - md.KeepAbove = true; + var md = this.OkCancelDialogue("Are you sure you want to quit?"); ResponseType response = (ResponseType)md.Run(); md.Dispose(); @@ -376,14 +385,7 @@ namespace Buypeeb { private void ButtonSelectedRemoveClicked(object sender, EventArgs a) { var item = this.SelectedItem; - MessageDialog md = new MessageDialog( - parent_window: this, - flags: DialogFlags.DestroyWithParent | DialogFlags.Modal, - type: MessageType.Question, - bt: ButtonsType.OkCancel, - format: $"Are you sure you want to remove the item \"{item.name}\"?" // TODO: this looks bad being all on one line - ); - md.KeepAbove = true; + var md = this.OkCancelDialogue($"Are you sure you want to remove the item \"{item.name}\"?"); // TODO: this looks bad being all on one line ResponseType response = (ResponseType)md.Run(); md.Dispose(); diff --git a/ui/add.glade b/ui/add.glade index c941f29..e8f8d66 100644 --- a/ui/add.glade +++ b/ui/add.glade @@ -1,5 +1,5 @@ - + @@ -8,8 +8,12 @@ True center-on-parent 320 + True dialog center + + + False @@ -150,8 +154,5 @@ ButtonAddCancel ButtonAddOK - - -