dont repeat urself

This commit is contained in:
Lynne Megido 2020-09-04 19:10:55 +10:00
parent 1917225f39
commit 11020ed0c4
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
2 changed files with 23 additions and 20 deletions

View file

@ -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 // 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) { 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); 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) { private void ButtonQuitClicked(object sender, EventArgs a) {
MessageDialog md = new MessageDialog( var md = this.OkCancelDialogue("Are you sure you want to quit?");
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;
ResponseType response = (ResponseType)md.Run(); ResponseType response = (ResponseType)md.Run();
md.Dispose(); md.Dispose();
@ -376,14 +385,7 @@ namespace Buypeeb {
private void ButtonSelectedRemoveClicked(object sender, EventArgs a) { private void ButtonSelectedRemoveClicked(object sender, EventArgs a) {
var item = this.SelectedItem; var item = this.SelectedItem;
MessageDialog md = new MessageDialog( var md = this.OkCancelDialogue($"Are you sure you want to remove the item \"{item.name}\"?"); // TODO: this looks bad being all on one line
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;
ResponseType response = (ResponseType)md.Run(); ResponseType response = (ResponseType)md.Run();
md.Dispose(); md.Dispose();

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 --> <!-- Generated with glade 3.22.2 -->
<interface> <interface>
<requires lib="gtk+" version="3.22"/> <requires lib="gtk+" version="3.22"/>
<object class="GtkDialog" id="DialogueAdd"> <object class="GtkDialog" id="DialogueAdd">
@ -8,8 +8,12 @@
<property name="modal">True</property> <property name="modal">True</property>
<property name="window_position">center-on-parent</property> <property name="window_position">center-on-parent</property>
<property name="default_width">320</property> <property name="default_width">320</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<property name="gravity">center</property> <property name="gravity">center</property>
<child type="titlebar">
<placeholder/>
</child>
<child internal-child="vbox"> <child internal-child="vbox">
<object class="GtkBox"> <object class="GtkBox">
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -150,8 +154,5 @@
<action-widget response="-6">ButtonAddCancel</action-widget> <action-widget response="-6">ButtonAddCancel</action-widget>
<action-widget response="-5">ButtonAddOK</action-widget> <action-widget response="-5">ButtonAddOK</action-widget>
</action-widgets> </action-widgets>
<child type="titlebar">
<placeholder/>
</child>
</object> </object>
</interface> </interface>