From 1d123c7e66d963fd8cc8cc4250b5813a62676f56 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Mon, 6 Feb 2023 20:23:54 +0100 Subject: Fix label attributes updated with delay --- .../conversation_selector_row.vala | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'main/src') diff --git a/main/src/ui/conversation_selector/conversation_selector_row.vala b/main/src/ui/conversation_selector/conversation_selector_row.vala index 8355b104..e71176aa 100644 --- a/main/src/ui/conversation_selector/conversation_selector_row.vala +++ b/main/src/ui/conversation_selector/conversation_selector_row.vala @@ -182,7 +182,7 @@ public class ConversationSelectorRow : ListBoxRow { nick_label.label += ": "; } - message_label.attributes.filter((attr) => attr.equal(attr_style_new(Pango.Style.ITALIC))); + change_label_attribute(message_label, attr_style_new(Pango.Style.NORMAL)); message_label.label = Util.summarize_whitespaces_to_space(body); break; @@ -198,7 +198,7 @@ public class ConversationSelectorRow : ListBoxRow { } bool file_is_image = transfer.mime_type != null && transfer.mime_type.has_prefix("image"); - message_label.attributes.insert(attr_style_new(Pango.Style.ITALIC)); + change_label_attribute(message_label, attr_style_new(Pango.Style.ITALIC)); if (transfer.direction == Message.DIRECTION_SENT) { message_label.label = (file_is_image ? _("Image sent") : _("File sent") ); } else { @@ -210,7 +210,7 @@ public class ConversationSelectorRow : ListBoxRow { Call call = call_item.call; nick_label.label = call.direction == Call.DIRECTION_OUTGOING ? _("Me") + ": " : ""; - message_label.attributes.insert(attr_style_new(Pango.Style.ITALIC)); + change_label_attribute(message_label, attr_style_new(Pango.Style.ITALIC)); message_label.label = call.direction == Call.DIRECTION_OUTGOING ? _("Outgoing call") : _("Incoming call"); break; } @@ -219,6 +219,12 @@ public class ConversationSelectorRow : ListBoxRow { } } + private static void change_label_attribute(Label label, owned Attribute attribute) { + AttrList copy = label.attributes.copy(); + copy.change((owned) attribute); + label.attributes = copy; + } + protected void update_read(bool force_update = false) { int current_num_unread = stream_interactor.get_module(ChatInteraction.IDENTITY).get_num_unread(conversation); if (num_unread == current_num_unread && !force_update) return; @@ -227,10 +233,10 @@ public class ConversationSelectorRow : ListBoxRow { if (num_unread == 0) { unread_count_label.visible = false; - name_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD))); - time_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD))); - nick_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD))); - message_label.attributes.filter((attr) => attr.equal(attr_weight_new(Weight.BOLD))); + change_label_attribute(name_label, attr_weight_new(Weight.NORMAL)); + change_label_attribute(time_label, attr_weight_new(Weight.NORMAL)); + change_label_attribute(nick_label, attr_weight_new(Weight.NORMAL)); + change_label_attribute(message_label, attr_weight_new(Weight.NORMAL)); } else { unread_count_label.label = num_unread.to_string(); unread_count_label.visible = true; @@ -243,16 +249,11 @@ public class ConversationSelectorRow : ListBoxRow { unread_count_label.remove_css_class("unread-count-notify"); } - name_label.attributes.insert(attr_weight_new(Weight.BOLD)); - time_label.attributes.insert(attr_weight_new(Weight.BOLD)); - nick_label.attributes.insert(attr_weight_new(Weight.BOLD)); - message_label.attributes.insert(attr_weight_new(Weight.BOLD)); + change_label_attribute(name_label, attr_weight_new(Weight.BOLD)); + change_label_attribute(time_label, attr_weight_new(Weight.BOLD)); + change_label_attribute(nick_label, attr_weight_new(Weight.BOLD)); + change_label_attribute(message_label, attr_weight_new(Weight.BOLD)); } - - name_label.label = name_label.label; // TODO initializes redrawing, which would otherwise not happen. nicer? - time_label.label = time_label.label; - nick_label.label = nick_label.label; - message_label.label = message_label.label; } public override void state_flags_changed(StateFlags flags) { -- cgit v1.2.3-70-g09d2