From 275436b7796cde8a7cae695914aad4e72a6edd05 Mon Sep 17 00:00:00 2001 From: bleakgrey Date: Wed, 24 Oct 2018 12:29:36 +0300 Subject: [PATCH] Indicate pinned posts --- src/API/Status.vala | 8 ++++---- src/Views/AbstractView.vala | 37 +++++++++++++++++++---------------- src/Views/AccountView.vala | 6 ++++-- src/Views/TimelineView.vala | 2 +- src/Widgets/StatusWidget.vala | 7 +++++++ 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/API/Status.vala b/src/API/Status.vala index 0761257..b499ad4 100644 --- a/src/API/Status.vala +++ b/src/API/Status.vala @@ -153,17 +153,17 @@ public class Tootle.Status { public void set_pinned (bool pin = true){ var action = pin ? "pin" : "unpin"; - var msg = new Soup.Message("POST", "%s/api/v1/statuses/%lld/%s".printf (Tootle.accounts.formal.instance, id, action)); + var msg = new Soup.Message("POST", "%s/api/v1/statuses/%lld/%s".printf (accounts.formal.instance, id, action)); msg.priority = Soup.MessagePriority.HIGH; msg.finished.connect (() => { pinned = pin; updated (); if (pin) - Tootle.app.toast (_("Pinned!")); + app.toast (_("Pinned on Profile")); else - Tootle.app.toast (_("Unpinned")); + app.toast (_("Unpinned from Profile")); }); - Tootle.network.queue (msg); + network.queue (msg); } public void poof (){ diff --git a/src/Views/AbstractView.vala b/src/Views/AbstractView.vala index 9e03cf4..9502c1e 100644 --- a/src/Views/AbstractView.vala +++ b/src/Views/AbstractView.vala @@ -1,24 +1,29 @@ using Gtk; -public abstract class Tootle.AbstractView : Gtk.ScrolledWindow { +public abstract class Tootle.AbstractView : ScrolledWindow { public int stack_pos = -1; - public Gtk.Image? image; - public Gtk.Box view; - protected Gtk.Box? empty; + public Image? image; + public Box view; + protected Grid grid; + protected Box? empty; construct { - view = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - view.valign = Gtk.Align.START; - hscrollbar_policy = Gtk.PolicyType.NEVER; - add (view); + view = new Box (Orientation.VERTICAL, 0); + view.valign = Align.START; + + grid = new Grid (); + grid.hexpand = true; + grid.vexpand = true; + grid.attach (view, 0, 2); + + hscrollbar_policy = PolicyType.NEVER; + add (grid); edge_reached.connect(pos => { - if (pos == Gtk.PositionType.BOTTOM) + if (pos == PositionType.BOTTOM) bottom_reached (); }); - - pre_construct (); } public AbstractView () { @@ -35,11 +40,8 @@ public abstract class Tootle.AbstractView : Gtk.ScrolledWindow { public virtual void clear (){ view.forall (widget => widget.destroy ()); - pre_construct (); } - public virtual void pre_construct () {} - public virtual void bottom_reached (){} public virtual bool is_empty () { @@ -52,14 +54,15 @@ public abstract class Tootle.AbstractView : Gtk.ScrolledWindow { if (!is_empty ()) return false; - empty = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + empty = new Box (Orientation.VERTICAL, 0); empty.margin = 64; var image = new Image.from_resource ("/com/github/bleakgrey/tootle/empty_state"); - var text = new Gtk.Label (_("Nothing to see here")); + var text = new Label (_("Nothing to see here")); text.get_style_context ().add_class ("h2"); text.opacity = 0.5; + empty.hexpand = true; empty.vexpand = true; - empty.valign = Gtk.Align.FILL; + empty.valign = Align.FILL; empty.pack_start (image, false, false, 0); empty.pack_start (text, false, false, 12); empty.show_all (); diff --git a/src/Views/AccountView.vala b/src/Views/AccountView.vala index 512ff02..642dfef 100644 --- a/src/Views/AccountView.vala +++ b/src/Views/AccountView.vala @@ -26,7 +26,8 @@ public class Tootle.AccountView : TimelineView { Gtk.MenuItem menu_report; Gtk.MenuButton button_menu; - public override void pre_construct () { + //public override void pre_construct () { + construct { header = new Gtk.Grid (); header_info = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); header_info.margin = 12; @@ -104,7 +105,8 @@ public class Tootle.AccountView : TimelineView { button_follow.hide (); header.attach (actions, 0, 0, 2, 2); - view.pack_start (header, false, false, 0); + grid.attach (header, 0, 1); + //view.pack_start (header, false, false, 0); } public AccountView (Account acc) { diff --git a/src/Views/TimelineView.vala b/src/Views/TimelineView.vala index 5a02c70..7c50368 100644 --- a/src/Views/TimelineView.vala +++ b/src/Views/TimelineView.vala @@ -63,7 +63,7 @@ public class Tootle.TimelineView : AbstractView { view.pack_start(separator, false, false, 0); view.pack_start(widget, false, false, 0); - if (first) { + if (first || status.pinned) { view.reorder_child (widget, 0); view.reorder_child (separator, 0); } diff --git a/src/Widgets/StatusWidget.vala b/src/Widgets/StatusWidget.vala index ec40000..793c40f 100644 --- a/src/Widgets/StatusWidget.vala +++ b/src/Widgets/StatusWidget.vala @@ -23,6 +23,7 @@ public class Tootle.StatusWidget : Gtk.EventBox { public Gtk.Box counters; public Gtk.Label reblogs; public Gtk.Label favorites; + private Image pin_indicator; public ImageToggleButton reblog; public ImageToggleButton favorite; public ImageToggleButton reply; @@ -55,6 +56,10 @@ public class Tootle.StatusWidget : Gtk.EventBox { title_box.pack_end (title_date, false, false, 0); title_box.show_all (); + pin_indicator = new Image.from_icon_name ("view-pin-symbolic", IconSize.MENU); + pin_indicator.opacity = 0.5; + title_box.pack_end (pin_indicator, false, false, 0); + content_label = new RichLabel (""); content_label.wrap_words (); @@ -203,6 +208,7 @@ public class Tootle.StatusWidget : Gtk.EventBox { title_acct.label = "@" + formal.account.acct; content_label.label = formal.content; content_label.mentions = formal.mentions; + pin_indicator.visible = status.pinned; var datetime = parse_date_iso8601 (formal.created_at); title_date.label = Granite.DateTime.get_relative_datetime (datetime); @@ -272,6 +278,7 @@ public class Tootle.StatusWidget : Gtk.EventBox { var is_muted = status.muted; var is_pinned = status.pinned; + var item_muting = new Gtk.MenuItem.with_label (is_muted ? _("Unmute Conversation") : _("Mute Conversation")); item_muting.activate.connect (() => status.set_muted (!is_muted)); var item_pin = new Gtk.MenuItem.with_label (is_pinned ? _("Unpin from Profile") : _("Pin on Profile"));