From 0529bd6c93bc5e2c56a714b3fabd279c5b84ceb3 Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 1 Sep 2020 19:58:35 +1000 Subject: [PATCH] a working custom add dialogue! --- .gitignore | 2 +- AddItemDialogue.cs | 34 ++++++ MainWindow.cs | 22 +++- ui/add.glade | 157 +++++++++++++++++++++++++ ui.glade => ui/main.glade | 238 +++++++------------------------------- 5 files changed, 251 insertions(+), 202 deletions(-) create mode 100644 AddItemDialogue.cs create mode 100644 ui/add.glade rename ui.glade => ui/main.glade (84%) diff --git a/.gitignore b/.gitignore index efa2947..677b6ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ poop/ BuypeebApp.exe -ui.glade~ +*.glade~ bin/ obj/ out/ diff --git a/AddItemDialogue.cs b/AddItemDialogue.cs new file mode 100644 index 0000000..995e5a0 --- /dev/null +++ b/AddItemDialogue.cs @@ -0,0 +1,34 @@ +using System; +using Gtk; +using UI = Gtk.Builder.ObjectAttribute; + +namespace Buypeeb { + + class AddItemDialogue : Dialog { + private Entry EntryURL; + private Entry EntryName; + + public AddItemDialogue() : this(new Builder("add.glade")) { } + + private AddItemDialogue(Builder builder) : base(builder.GetObject("DialogueAdd").Handle) { + this.Title = "Add item"; + builder.Autoconnect(this); + this.EntryURL = (Entry)builder.GetObject("EntryAddURL"); + this.EntryName = (Entry)builder.GetObject("EntryAddName"); + DeleteEvent += Window_Shutdown; + } + + private void Window_Shutdown(object sender, DeleteEventArgs args) { + Application.Quit(); + } + + public string GetURL() { + return this.EntryURL.Text; + } + + public string GetName() { + return this.EntryName.Text; + } + + } +} diff --git a/MainWindow.cs b/MainWindow.cs index 8454779..ec868bb 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -17,8 +17,8 @@ along with this program. If not, see . */ using System; +using System.Text.RegularExpressions; using Gtk; -using UI = Gtk.Builder.ObjectAttribute; namespace Buypeeb { enum ItemColumns { @@ -33,7 +33,7 @@ namespace Buypeeb { private ListStore Items; - public MainWindow() : this(new Builder("ui.glade")) { } + public MainWindow() : this(new Builder("main.glade")) { } private MainWindow(Builder builder) : base(builder.GetObject("wndMain").Handle) { this.Title = "Buypeeb"; @@ -73,9 +73,21 @@ namespace Buypeeb { // button handlers private void ButtonAddClicked(object sender, EventArgs a) { - Console.WriteLine("ButtonAddClicked"); - var EntryResponse = EntryDialogue(); - Console.WriteLine(EntryResponse.response); + // Console.WriteLine("ButtonAddClicked"); + AddItemDialogue aid = new AddItemDialogue(); + ResponseType accepted = (ResponseType)aid.Run(); + string url = aid.GetURL(); + string name = aid.GetName(); + aid.Dispose(); + + // vry simpl url validation for simpol creachers + Regex rx = new Regex(@"^http.+yahoo.+"); + if (rx.IsMatch(url)) { + Console.WriteLine("{0} will be added", url); + } + else { + Console.WriteLine("{0} is an invalid url", url); + } } private void ButtonUpdateAllClicked(object sender, EventArgs a) { diff --git a/ui/add.glade b/ui/add.glade new file mode 100644 index 0000000..c941f29 --- /dev/null +++ b/ui/add.glade @@ -0,0 +1,157 @@ + + + + + + False + False + True + center-on-parent + 320 + dialog + center + + + False + 5 + 5 + vertical + 2 + + + False + 5 + end + + + Cancel + True + True + True + + + True + True + 0 + + + + + OK + True + True + True + True + True + + + True + True + 1 + + + + + False + False + 0 + + + + + True + False + 5 + 5 + vertical + + + True + False + 5 + Add item + + + + + + + False + True + 0 + + + + + True + False + start + Enter the URL of the item you want to add. + + + False + True + 1 + + + + + True + True + 5 + 10 + True + URL + url + + + False + True + 2 + + + + + True + False + start + You may also enter a custom name below. + + + False + True + 3 + + + + + True + True + 5 + True + Name (optional) + + + False + True + 4 + + + + + False + True + 1 + + + + + + ButtonAddCancel + ButtonAddOK + + + + + + diff --git a/ui.glade b/ui/main.glade similarity index 84% rename from ui.glade rename to ui/main.glade index 2ac317f..989f681 100644 --- a/ui.glade +++ b/ui/main.glade @@ -1,19 +1,19 @@ - + - + - + - + - + - + @@ -55,8 +55,8 @@ Add new True gtk-add - - + + False @@ -71,8 +71,8 @@ Update all True gtk-refresh - - + + False @@ -97,7 +97,7 @@ Undo True gtk-undo - + False @@ -112,7 +112,7 @@ Redo True gtk-redo - + False @@ -137,7 +137,7 @@ Clear ended True gtk-clear - + False @@ -152,7 +152,7 @@ Clear all True gtk-delete - + False @@ -177,7 +177,7 @@ Open True gtk-open - + False @@ -192,8 +192,8 @@ Save True gtk-save - - + + False @@ -208,7 +208,7 @@ Export as... True gtk-save-as - + False @@ -233,7 +233,7 @@ Help True gtk-help - + False @@ -248,7 +248,7 @@ Settings True gtk-preferences - + False @@ -263,8 +263,8 @@ Quit True gtk-quit - - + + False @@ -296,7 +296,7 @@ True - + @@ -308,7 +308,7 @@ True True - + 0 @@ -320,7 +320,7 @@ True Price (¥) - + 1 @@ -332,7 +332,7 @@ True Price (AUD) - + 2 @@ -345,7 +345,7 @@ Ending at True - + 3 @@ -385,8 +385,8 @@ 40 3 - - + + @@ -548,23 +548,6 @@ 1 - - - True - False - vertical - - - - - - - - - 1 - 0 - - True @@ -614,19 +597,22 @@ - + - + - + - + - + + + + @@ -661,7 +647,7 @@ True True True - + False @@ -675,7 +661,7 @@ True True True - + False @@ -696,7 +682,7 @@ True True Remove - + True @@ -718,7 +704,7 @@ True True Rename - + True @@ -843,147 +829,7 @@ - - - - - False - dialog - - - False - vertical - 2 - - - False - end - - - Cancel - True - True - True - - - True - True - 0 - - - - - OK - True - True - True - - - True - True - 1 - - - - - False - False - 0 - - - - - True - False - vertical - - - True - False - Add item - - - - - - - False - True - 0 - - - - - True - False - Enter the URL of the item you want to add. - - - False - True - 1 - - - - - True - True - URL - - - False - True - 2 - - - - - True - False - You can also enter a custom name to use instead of the default. - - - False - True - 3 - - - - - True - True - - - False - True - 4 - - - - - Favourite - True - True - False - True - - - False - True - 5 - - - - - False - True - 1 - - - - - - +