From 1917225f39906907b7b3734cd5f490ef584c32e6 Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Fri, 4 Sep 2020 18:06:45 +1000 Subject: [PATCH] better dialogues, working rename and delete buttons --- MainWindow.cs | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/MainWindow.cs b/MainWindow.cs index 6bd0e14..bc8f1cb 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -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) {