better dialogues, working rename and delete buttons

This commit is contained in:
Lynne Megido 2020-09-04 18:06:45 +10:00
parent 32ff00d8be
commit 1917225f39
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90

View File

@ -268,12 +268,16 @@ namespace Buypeeb {
}
// 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!") {
Dialog ed = new Dialog(title, null, Gtk.DialogFlags.DestroyWithParent, "Cancel", ResponseType.Cancel, "OK", ResponseType.Ok);
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);
ed.DefaultResponse = ResponseType.Ok;
ed.KeepAbove = true;
Label edLabel = new Label(message);
Entry edEntry = new Entry();
if (!String.IsNullOrWhiteSpace(prefill)) {
edEntry.Text = prefill;
}
edEntry.ActivatesDefault = true;
ed.ContentArea.PackStart(edLabel, true, true, 2);
@ -281,6 +285,12 @@ namespace Buypeeb {
ed.ContentArea.PackStart(edEntry, true, true, 10);
edEntry.Show();
ed.ContentArea.MarginBottom = 5;
ed.ContentArea.MarginTop = 5;
ed.ContentArea.MarginStart = 5;
ed.ContentArea.MarginEnd = 5;
ed.ActionArea.MarginBottom = 5; // TODO: apparently actionarea is obsolete
ResponseType accepted = (ResponseType)ed.Run();
string response = edEntry.Text;
ed.Dispose();
@ -299,6 +309,7 @@ namespace Buypeeb {
private void ButtonAddClicked(object sender, EventArgs a) {
// Console.WriteLine("ButtonAddClicked");
AddItemDialogue aid = new AddItemDialogue();
aid.Title = "Buypeeb";
ResponseType accepted = (ResponseType)aid.Run();
string url = aid.GetURL();
string name = aid.GetName();
@ -333,7 +344,15 @@ namespace Buypeeb {
}
private void ButtonQuitClicked(object sender, EventArgs a) {
MessageDialog md = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.OkCancel, "Are you sure you want to quit?");
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;
ResponseType response = (ResponseType)md.Run();
md.Dispose();
if (response == ResponseType.Ok) {
@ -355,11 +374,32 @@ namespace Buypeeb {
}
private void ButtonSelectedRemoveClicked(object sender, EventArgs a) {
Console.WriteLine("ButtonSelectedRemoveClicked");
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;
ResponseType response = (ResponseType)md.Run();
md.Dispose();
if (response == ResponseType.Ok) {
this.settings.watchlist.Remove(item.id);
this.RenderList();
}
}
private void ButtonSelectedRenameClicked(object sender, EventArgs a) {
Console.WriteLine("ButtonSelectedRenameClicked");
var item = this.SelectedItem;
(bool accepted, string response) = this.EntryDialogue("Rename item", $"Enter a new name for the item \"{item.name}\".", item.name);
if (accepted) {
item.name = response;
this.UpdateSelectionView();
}
}
private void ButtonSelectedUpdateClicked(object sender, EventArgs args) {