From c404f4ab65d5d119280f00773e60fda3478d359a Mon Sep 17 00:00:00 2001 From: bleakgrey Date: Wed, 18 Apr 2018 12:13:22 +0300 Subject: [PATCH] Add gtk separators --- data/Application.css | 7 ------- src/Views/HomeView.vala | 14 +++++++++++++- src/Views/NotificationsView.vala | 13 +++++++++++++ src/Widgets/NotificationWidget.vala | 26 ++++++++++++++++---------- src/Widgets/StatusWidget.vala | 14 ++++++++++---- 5 files changed, 52 insertions(+), 22 deletions(-) diff --git a/data/Application.css b/data/Application.css index b8f8fe3..9664d7e 100644 --- a/data/Application.css +++ b/data/Application.css @@ -15,13 +15,6 @@ background:none; } -.status{ - border-bottom: 1px solid #cecece; -} -.status:last-child{ - border-bottom:none; -} - .toot-text{ background: none; } diff --git a/src/Views/HomeView.vala b/src/Views/HomeView.vala index 4d51104..abc0d84 100644 --- a/src/Views/HomeView.vala +++ b/src/Views/HomeView.vala @@ -26,9 +26,9 @@ public class Tootle.HomeView : Tootle.AbstractView { base (true); this.timeline = timeline; this.pars = pars; - show_all(); + view.remove.connect (on_remove); AccountManager.instance.changed_current.connect(on_account_changed); // var s = new Status(1); @@ -45,11 +45,23 @@ public class Tootle.HomeView : Tootle.AbstractView { } public void prepend(Status status){ //TODO: clear all on account switch + var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); + separator.show (); + var widget = new StatusWidget(status); + widget.separator = separator; widget.rebind (status); + view.pack_start(separator, false, false, 0); view.pack_start(widget, false, false, 0); } + public virtual void on_remove (Widget widget){ + if (!(widget is StatusWidget)) + return; + + //debug ("removed"); + } + public virtual void on_account_changed (Account? account){ if(account == null) return; diff --git a/src/Views/NotificationsView.vala b/src/Views/NotificationsView.vala index 7385a29..be57787 100644 --- a/src/Views/NotificationsView.vala +++ b/src/Views/NotificationsView.vala @@ -23,6 +23,7 @@ public class Tootle.NotificationsView : Tootle.AbstractView { base (true); show_all(); + view.remove.connect (on_remove); AccountManager.instance.changed_current.connect(on_account_changed); } @@ -35,11 +36,23 @@ public class Tootle.NotificationsView : Tootle.AbstractView { } public void prepend(Notification notification){ + var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); + separator.show (); + var widget = new NotificationWidget(notification); + widget.separator = separator; + view.pack_start(separator, false, false, 0); view.pack_start(widget, false, false, 0); image.icon_name = "notification-new-symbolic"; } + public virtual void on_remove (Widget widget){ + if (!(widget is NotificationWidget)) + return; + + //debug ("removed"); + } + public virtual void on_account_changed (Account? account){ if(account == null) return; diff --git a/src/Widgets/NotificationWidget.vala b/src/Widgets/NotificationWidget.vala index 1e72240..840e839 100644 --- a/src/Widgets/NotificationWidget.vala +++ b/src/Widgets/NotificationWidget.vala @@ -5,9 +5,10 @@ public class Tootle.NotificationWidget : Gtk.Grid { public Notification notification; + public Gtk.Separator? separator; private Gtk.Image image; private Gtk.Label label; - private Gtk.Button dismiss; + private Gtk.Button dismiss_button; private StatusWidget? status_widget; construct { @@ -20,17 +21,17 @@ public class Tootle.NotificationWidget : Gtk.Grid { label.hexpand = true; label.halign = Gtk.Align.START; label.use_markup = true; - dismiss = new Gtk.Button.from_icon_name ("close-symbolic", Gtk.IconSize.SMALL_TOOLBAR); - dismiss.tooltip_text = _("Dismiss"); - dismiss.clicked.connect (() => { + dismiss_button = new Gtk.Button.from_icon_name ("close-symbolic", Gtk.IconSize.SMALL_TOOLBAR); + dismiss_button.tooltip_text = _("Dismiss"); + dismiss_button.clicked.connect (() => { var parent = this.get_parent () as Gtk.Box; parent.remove (this); - dismiss_notification (this.notification); + //dismiss (this.notification); }); - attach(image, 0, 0, 1, 1); - attach(label, 1, 0, 1, 1); - attach(dismiss, 2, 0, 1, 1); + attach(image, 1, 2); + attach(label, 2, 2); + attach(dismiss_button, 3, 2); show_all(); } @@ -43,11 +44,16 @@ public class Tootle.NotificationWidget : Gtk.Grid { if (notification.status != null){ status_widget = new StatusWidget (this.notification.status); status_widget.rebind (this.notification.status); - attach(status_widget, 0, 1, 3, 1); + attach(status_widget, 1, 3, 3, 1); } + + destroy.connect (() => { + if(separator != null) + separator.destroy (); + }); } - public static Soup.Message dismiss_notification (Notification notification){ + public static Soup.Message dismiss (Notification notification){ var url = Settings.instance.instance_url; url += "api/v1/notifications/dismiss"; url += "?id=" + notification.id.to_string (); diff --git a/src/Widgets/StatusWidget.vala b/src/Widgets/StatusWidget.vala index 97942b6..89baa84 100644 --- a/src/Widgets/StatusWidget.vala +++ b/src/Widgets/StatusWidget.vala @@ -5,6 +5,7 @@ public class Tootle.StatusWidget : Gtk.Grid { public Status status; + public Gtk.Separator? separator; public Granite.Widgets.Avatar avatar; Gtk.Label user; Gtk.Label content; @@ -59,16 +60,21 @@ public class Tootle.StatusWidget : Gtk.Grid { counters.add(favorites); counters.show_all (); - attach(avatar, 0, 0, 1, 3); - attach(user, 1, 1, 1, 1); - attach(content, 1, 2, 1, 1); - attach(counters, 1, 3, 1, 1); + attach(avatar, 1, 0, 1, 3); + attach(user, 2, 1, 1, 1); + attach(content, 2, 2, 1, 1); + attach(counters, 2, 3, 1, 1); show_all(); //TODO: display conversations } public StatusWidget (Status status) { this.status = status; get_style_context ().add_class ("status"); + + destroy.connect (() => { + if(separator != null) + separator.destroy (); + }); } public void rebind (Status status = this.status){