From e662bc4712d042de5f0fe340cf79dff904434b68 Mon Sep 17 00:00:00 2001 From: bleakgrey Date: Wed, 31 Oct 2018 15:05:36 +0300 Subject: [PATCH] Close #101 --- src/API/Notification.vala | 2 +- src/Dialogs/WatchlistDialog.vala | 127 +++++++++++++++---------------- src/Watchlist.vala | 2 +- 3 files changed, 65 insertions(+), 66 deletions(-) diff --git a/src/API/Notification.vala b/src/API/Notification.vala index ed149bd..ce08f0e 100644 --- a/src/API/Notification.vala +++ b/src/API/Notification.vala @@ -61,7 +61,7 @@ public class Tootle.Notification { public Soup.Message? dismiss () { if (type == NotificationType.WATCHLIST) { - if (accounts.formal.cached_notifications.remove (this)); + if (accounts.formal.cached_notifications.remove (this)) accounts.save (); return null; } diff --git a/src/Dialogs/WatchlistDialog.vala b/src/Dialogs/WatchlistDialog.vala index 55f781e..f4d251e 100644 --- a/src/Dialogs/WatchlistDialog.vala +++ b/src/Dialogs/WatchlistDialog.vala @@ -1,17 +1,17 @@ using Gtk; -using Tootle; +using Gee; public class Tootle.WatchlistDialog : Gtk.Dialog { private static WatchlistDialog dialog; - private HeaderBar header; private StackSwitcher switcher; private Gtk.MenuButton button_add; + private Button button_remove; private Stack stack; private ListStack users; private ListStack hashtags; - + private ActionBar actionbar; private Popover popover; private Grid popover_grid; private Entry popover_entry; @@ -22,39 +22,20 @@ public class Tootle.WatchlistDialog : Gtk.Dialog { private class ModelItem : GLib.Object { public string name; - public bool is_hashtag; - public ModelItem (string name, bool is_hashtag) { + public ModelItem (string name) { this.name = name; - this.is_hashtag = is_hashtag; } } private class ModelView : ListBoxRow { - private Box box; - private Button button_remove; - private Label label; - private bool is_hashtag; - + public Label label; public ModelView (ModelItem item) { - is_hashtag = item.is_hashtag; - box = new Box (Orientation.HORIZONTAL, 0); - box.margin = 6; label = new Label (item.name); - label.vexpand = true; - label.valign = Align.CENTER; + label.margin = 6; + label.halign = Align.START; label.justify = Justification.LEFT; - button_remove = new Button.from_icon_name ("list-remove-symbolic", IconSize.BUTTON); - button_remove.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); - button_remove.clicked.connect (() => { - watchlist.remove (label.label, is_hashtag); - watchlist.save (); - destroy (); - }); - - box.pack_start (label, false, false, 0); - box.pack_end (button_remove, false, false, 0); - add (box); + add (label); show_all (); } } @@ -88,29 +69,20 @@ public class Tootle.WatchlistDialog : Gtk.Dialog { private class ListStack : ScrolledWindow { public Model model; public ListBox list; - private bool is_hashtags; - public void update () { - if (is_hashtags) - watchlist.hashtags.@foreach (item => { - model.append (new ModelItem (item, true)); - return true; - }); - else - watchlist.users.@foreach (item => { - model.append (new ModelItem (item, false)); - return true; - }); - + public void update (ArrayList array) { + array.@foreach (item => { + model.append (new ModelItem (item)); + return true; + }); list.bind_model (model, create_row); } - public ListStack (bool is_hashtags) { - this.is_hashtags = is_hashtags; + public ListStack (ArrayList array) { model = new Model (); list = new ListBox (); add (list); - update (); + update (array); } } @@ -120,24 +92,26 @@ public class Tootle.WatchlistDialog : Gtk.Dialog { } public WatchlistDialog () { - deletable = true; + border_width = 6; + deletable = false; resizable = false; transient_for = window; + title = _("Watchlist"); - var content = get_content_area (); + users = new ListStack (watchlist.users); + hashtags = new ListStack (watchlist.hashtags); stack = new Stack (); stack.transition_type = StackTransitionType.SLIDE_LEFT_RIGHT; stack.hexpand = true; stack.vexpand = true; - - users = new ListStack (false); - hashtags = new ListStack (true); - stack.add_titled (users, "users", _("Users")); stack.add_titled (hashtags, "hashtags", _("Hashtags")); - stack.set_size_request (350, 400); - content.pack_start (stack, true, true, 0); + + switcher = new StackSwitcher (); + switcher.stack = stack; + switcher.halign = Align.CENTER; + switcher.margin_bottom = 12; popover_entry = new Entry (); popover_entry.hexpand = true; @@ -161,25 +135,52 @@ public class Tootle.WatchlistDialog : Gtk.Dialog { button_add = new MenuButton (); button_add.image = new Image.from_icon_name ("list-add-symbolic", IconSize.BUTTON); - button_add.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); button_add.popover = popover; button_add.clicked.connect (() => set_tip ()); - switcher = new StackSwitcher (); - switcher.stack = stack; - switcher.halign = Align.CENTER; + button_remove = new Button (); + button_remove.image = new Image.from_icon_name ("list-remove-symbolic", IconSize.BUTTON); + button_remove.clicked.connect (on_remove); - header = new HeaderBar (); - header.show_close_button = true; - header.pack_start (button_add); - header.set_custom_title (switcher); - set_titlebar (header); + actionbar = new ActionBar (); + actionbar.add (button_add); + actionbar.add (button_remove); + var grid = new Grid (); + grid.attach (stack, 0, 1); + grid.attach (actionbar, 0, 2); + + var frame = new Frame (null); + frame.margin_bottom = 6; + frame.add (grid); + frame.set_size_request (350, 350); + + var content = get_content_area (); + content.pack_start (switcher, true, true, 0); + content.pack_start (frame, true, true, 0); + + add_button (_("_Close"), ResponseType.DELETE_EVENT); show_all (); + response.connect (on_response); destroy.connect (() => dialog = null); } + private void on_response (int i) { + destroy (); + } + + private void on_remove () { + var is_hashtag = stack.visible_child_name == "hashtags"; + ListStack stack = is_hashtag ? hashtags : users; + stack.list.get_selected_rows ().@foreach (_row => { + var row = _row as ModelView; + watchlist.remove (row.label.label, is_hashtag); + watchlist.save (); + row.destroy (); + }); + } + private void submit () { if (popover_entry.text_length < 1) return; @@ -193,10 +194,8 @@ public class Tootle.WatchlistDialog : Gtk.Dialog { watchlist.save (); button_add.active = false; - if (is_hashtag) - hashtags.list.insert (create_row (new ModelItem (entity, true)), 0); - else - users.list.insert (create_row (new ModelItem (entity, false)), 0); + var stack = is_hashtag ? hashtags : users; + stack.list.insert (create_row (new ModelItem (entity)), 0); } public static void open () { diff --git a/src/Watchlist.vala b/src/Watchlist.vala index 0ca8b22..4aa95c6 100644 --- a/src/Watchlist.vala +++ b/src/Watchlist.vala @@ -108,7 +108,7 @@ public class Tootle.Watchlist : Object { public void remove (string entity, bool is_hashtag) { if (entity == "") return; - + if (is_hashtag) { var i = hashtags.index_of (entity); var notificator = notificators.@get(i);