From a9bff793bd8f8802f914e8cdf1164a2c55720dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 14 Feb 2019 13:30:03 -0800 Subject: [PATCH 1/3] MessageListItem: Parse message_info.from into a linkbutton --- src/MessageList/MessageListItem.vala | 44 +++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/MessageList/MessageListItem.vala b/src/MessageList/MessageListItem.vala index 33d875970..4cff8a1f4 100644 --- a/src/MessageList/MessageListItem.vala +++ b/src/MessageList/MessageListItem.vala @@ -88,9 +88,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { subject_label.valign = Gtk.Align.START; subject_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - var from_val_label = new Gtk.Label (message_info.from); - from_val_label.wrap = true; - from_val_label.xalign = 0; + var from_individualitem = new IndividualItem (message_info.from); var to_val_label = new Gtk.Label (message_info.to); to_val_label.wrap = true; @@ -106,7 +104,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { fields_grid.attach (from_label, 0, 0, 1, 1); fields_grid.attach (to_label, 0, 1, 1, 1); fields_grid.attach (subject_label, 0, 3, 1, 1); - fields_grid.attach (from_val_label, 1, 0, 1, 1); + fields_grid.attach (from_individualitem, 1, 0); fields_grid.attach (to_val_label, 1, 1, 1, 1); fields_grid.attach (subject_val_label, 1, 3, 1, 1); @@ -125,9 +123,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { fields_grid.attach (cc_val_label, 1, 2, 1, 1); } - var small_from_label = new Gtk.Label (message_info.from); - from_val_label.ellipsize = Pango.EllipsizeMode.END; - from_val_label.xalign = 0; + var small_from_label = new IndividualItem (message_info.from); var small_fields_grid = new Gtk.Grid (); small_fields_grid.attach (small_from_label, 0, 0, 1, 1); @@ -462,4 +458,38 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { public string get_message_body_html () { return web_view.get_body_html (); } + + private class IndividualItem : Gtk.Button { + public string message_info_from { get; construct; } + + public IndividualItem (string message_info_from) { + Object (message_info_from: message_info_from); + } + + construct { + string[] parsed_from = message_info_from.replace (">", "").split ("<"); + + var display_name_label = new Gtk.Label (parsed_from[0]); + display_name_label.wrap = true; + display_name_label.tooltip_text = parsed_from[1]; + + halign = Gtk.Align.START; + add (display_name_label); + + var style_context = get_style_context (); + style_context.add_class (Gtk.STYLE_CLASS_FLAT); + style_context.add_class ("link"); + + /* Connecting to clicked () doesn't allow us to prevent the event from propagating to header_event_box */ + button_release_event.connect (() => { + try { + AppInfo.launch_default_for_uri ("mailto:" + parsed_from[1], null); + } catch (Error e) { + warning ("Failed to open mailto link: %s", e.message); + } + + return Gdk.EVENT_STOP; + }); + } + } } From 1614094595b46111f1f0e5d11f6cdc6a9b8ab527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 14 Feb 2019 13:32:57 -0800 Subject: [PATCH 2/3] keep left align when we wrap --- src/MessageList/MessageListItem.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MessageList/MessageListItem.vala b/src/MessageList/MessageListItem.vala index 4cff8a1f4..8ccf81468 100644 --- a/src/MessageList/MessageListItem.vala +++ b/src/MessageList/MessageListItem.vala @@ -472,6 +472,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { var display_name_label = new Gtk.Label (parsed_from[0]); display_name_label.wrap = true; display_name_label.tooltip_text = parsed_from[1]; + display_name_label.xalign = 0; halign = Gtk.Align.START; add (display_name_label); From 39b1e0e712b5f6c68188c7175a573d95550eb1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 14 Feb 2019 20:17:39 -0800 Subject: [PATCH 3/3] Move from parsing out of individual widget --- src/MessageList/MessageListItem.vala | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/MessageList/MessageListItem.vala b/src/MessageList/MessageListItem.vala index 8ccf81468..ca3188b9e 100644 --- a/src/MessageList/MessageListItem.vala +++ b/src/MessageList/MessageListItem.vala @@ -70,6 +70,8 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { style_context = get_style_context (); style_context.add_class ("card"); + string[] parsed_from = message_info.from.replace (">", "").split ("<"); + var avatar = new Granite.Widgets.Avatar.with_default_icon (48); avatar.valign = Gtk.Align.START; @@ -88,7 +90,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { subject_label.valign = Gtk.Align.START; subject_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - var from_individualitem = new IndividualItem (message_info.from); + var from_individualitem = new IndividualItem (parsed_from[0], parsed_from [1]); var to_val_label = new Gtk.Label (message_info.to); to_val_label.wrap = true; @@ -123,7 +125,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { fields_grid.attach (cc_val_label, 1, 2, 1, 1); } - var small_from_label = new IndividualItem (message_info.from); + var small_from_label = new IndividualItem (parsed_from[0], parsed_from [1]); var small_fields_grid = new Gtk.Grid (); small_fields_grid.attach (small_from_label, 0, 0, 1, 1); @@ -460,18 +462,20 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { } private class IndividualItem : Gtk.Button { - public string message_info_from { get; construct; } - - public IndividualItem (string message_info_from) { - Object (message_info_from: message_info_from); + public string display_name { get; construct; } + public string email_address { get; construct; } + + public IndividualItem (string display_name, string email_address) { + Object ( + display_name: display_name, + email_address: email_address + ); } construct { - string[] parsed_from = message_info_from.replace (">", "").split ("<"); - - var display_name_label = new Gtk.Label (parsed_from[0]); + var display_name_label = new Gtk.Label (display_name); display_name_label.wrap = true; - display_name_label.tooltip_text = parsed_from[1]; + display_name_label.tooltip_text = email_address; display_name_label.xalign = 0; halign = Gtk.Align.START; @@ -484,7 +488,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { /* Connecting to clicked () doesn't allow us to prevent the event from propagating to header_event_box */ button_release_event.connect (() => { try { - AppInfo.launch_default_for_uri ("mailto:" + parsed_from[1], null); + AppInfo.launch_default_for_uri ("mailto:" + email_address, null); } catch (Error e) { warning ("Failed to open mailto link: %s", e.message); }