Reparent Status widget to ListBoxRow (#183)

This commit is contained in:
Bleak Grey 2020-07-05 10:42:00 +03:00
parent b0cb6d8a14
commit 13293738d5
7 changed files with 26 additions and 28 deletions

View File

@ -215,7 +215,7 @@
<child>
<object class="TootleWidgetsAvatar" id="avatar">
<property name="visible">True</property>
<property name="size">28</property>
<property name="size">25</property>
</object>
<packing>
<property name="pass_through">True</property>

View File

@ -22,9 +22,9 @@
<property name="can_focus">False</property>
<property name="icon_name">media-playlist-repeat-symbolic</property>
</object>
<template class="TootleWidgetsStatus" parent="GtkEventBox">
<template class="TootleWidgetsStatus" parent="GtkListBoxRow">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="activatable">True</property>
<child>
<object class="GtkGrid" id="grid">
<property name="visible">True</property>

View File

@ -39,9 +39,7 @@ public class Tootle.API.Account : Entity, Widgetizable {
public override Gtk.Widget to_widget () {
var status = new API.Status.from_account (this);
var w = new Widgets.Status (status);
w.button_press_event.connect (w.open);
return w;
return new Widgets.Status (status);
}
public Request get_relationship () {

View File

@ -73,10 +73,7 @@ public class Tootle.API.Status : Entity, Widgetizable {
}
public override Gtk.Widget to_widget () {
var w = new Widgets.Status (this);
w.button_press_event.connect (w.open);
return w;
return new Widgets.Status (this);
}
public bool is_owned (){

View File

@ -52,6 +52,7 @@ public class Tootle.Views.Base : Box {
});
content.remove.connect (() => on_content_changed ());
content_list.remove.connect (() => on_content_changed ());
content_list.row_activated.connect (on_content_item_activated);
notify["status-message"].connect (() => {
status_message_label.label = @"<span size='large'>$status_message</span>";
@ -112,4 +113,8 @@ public class Tootle.Views.Base : Box {
ctx.add_class ("padded");
}
public virtual void on_content_item_activated (ListBoxRow row) {
Signal.emit_by_name (row, "open");
}
}

View File

@ -30,14 +30,12 @@ public class Tootle.Views.Search : Views.Base {
void append_account (API.Account acc) {
var status = new API.Status.from_account (acc);
var w = new Widgets.Status (status);
w.button_press_event.connect (w.on_avatar_clicked);
content_list.insert (w, -1);
on_content_changed ();
}
void append_status (API.Status status) {
var w = new Widgets.Status (status);
w.button_press_event.connect (w.on_avatar_clicked);
content_list.insert (w, -1);
on_content_changed ();
}

View File

@ -2,7 +2,7 @@ using Gtk;
using Gdk;
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/widgets/status.ui")]
public class Tootle.Widgets.Status : EventBox {
public class Tootle.Widgets.Status : ListBoxRow {
public API.Status status { get; construct set; }
public API.NotificationType? kind { get; construct set; }
@ -82,6 +82,18 @@ public class Tootle.Widgets.Status : EventBox {
}
}
public virtual signal void open () {
if (status.id == "") {
var view = new Views.Profile (status.formal.account);
window.open_view (view);
}
else {
var formal = status.formal;
var view = new Views.ExpandedStatus (formal);
window.open_view (view);
}
}
construct {
content.activate_link.connect (on_toggle_spoiler);
notify["kind"].connect (on_kind_changed);
@ -126,10 +138,7 @@ public class Tootle.Widgets.Status : EventBox {
content.single_line_mode = true;
content.lines = 2;
content.ellipsize = Pango.EllipsizeMode.END;
button_press_event.connect (on_avatar_clicked);
}
else {
button_press_event.connect (open);
button_release_event.connect (on_avatar_clicked);
}
if (!attachments.populate (status.formal.media_attachments) || status.id == "") {
@ -137,7 +146,7 @@ public class Tootle.Widgets.Status : EventBox {
}
menu_button.clicked.connect (open_menu);
avatar.button_press_event.connect (on_avatar_clicked);
avatar.button_release_event.connect (on_avatar_clicked);
}
public Status (API.Status status, API.NotificationType? _kind = null) {
@ -165,19 +174,10 @@ public class Tootle.Widgets.Status : EventBox {
}
public bool on_avatar_clicked (EventButton ev) {
if (ev.button == 1) {
if (ev.button == 1 && ev.type == EventType.BUTTON_RELEASE) {
var view = new Views.Profile (status.formal.account);
return window.open_view (view);
}
return true;
}
public bool open (EventButton ev) {
if (ev.button == 1) {
var formal = status.formal;
var view = new Views.ExpandedStatus (formal);
return window.open_view (view);
}
return false;
}