Break out ConversationMessage link popover into seperate UI file

This reduces the number of widgets to be parsed and constructed when
showing a conversation, improving loading perf a bit for large
conversations.

See #230
This commit is contained in:
Michael Gratton 2019-11-27 11:09:09 +11:00 committed by Michael James Gratton
parent e4a5b85698
commit e99bf29bd5
4 changed files with 181 additions and 166 deletions

View file

@ -292,13 +292,6 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
[GtkChild]
private Gtk.ProgressBar body_progress;
[GtkChild]
private Gtk.Popover link_popover;
[GtkChild]
private Gtk.Label good_link_label;
[GtkChild]
private Gtk.Label bad_link_label;
[GtkChild]
private Gtk.InfoBar remote_images_infobar;
@ -1309,23 +1302,42 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
string anchor_label = Soup.URI.decode(anchor_href);
Gtk.Builder builder = new Gtk.Builder.from_resource(
"/org/gnome/Geary/conversation-message-link-popover.ui"
);
var link_popover = builder.get_object("link_popover") as Gtk.Popover;
var good_link = builder.get_object("good_link_label") as Gtk.Label;
var bad_link = builder.get_object("bad_link_label") as Gtk.Label;
// Escape text and especially URLs since we got them from the
// HREF, and Gtk.Label.set_markup is a strict parser.
good_link_label.set_markup(
var main = get_toplevel() as Application.MainWindow;
good_link.set_markup(
Markup.printf_escaped("<a href=\"%s\">%s</a>", text_href, text_label)
);
bad_link_label.set_markup(
good_link.activate_link.connect((label, uri) => {
link_popover.popdown();
main.application.show_uri.begin(uri);
return Gdk.EVENT_STOP;
}
);
bad_link.set_markup(
Markup.printf_escaped("<a href=\"%s\">%s</a>", anchor_href, anchor_label)
);
bad_link.activate_link.connect((label, uri) => {
link_popover.popdown();
main.application.show_uri.begin(uri);
return Gdk.EVENT_STOP;
}
);
link_popover.set_relative_to(this.web_view);
link_popover.set_pointing_to(location);
link_popover.show();
}
[GtkCallback]
private bool on_link_popover_activated() {
this.link_popover.hide();
return Gdk.EVENT_PROPAGATE;
link_popover.closed.connect_after(() => { link_popover.destroy(); });
link_popover.popup();
}
private void on_selection_changed(bool has_selection) {

View file

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.14"/>
<object class="GtkPopover" id="link_popover">
<property name="can_focus">False</property>
<property name="position">bottom</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="margin_right">12</property>
<property name="vexpand">True</property>
<property name="icon_name">dialog-warning-symbolic</property>
<property name="icon_size">3</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="height">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="bad_link_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">12</property>
<property name="label">&lt;a href="http://badlink.com"&gt;http://badlink.com&lt;/a&gt;</property>
<property name="use_markup">True</property>
<property name="ellipsize">middle</property>
<property name="max_width_chars">60</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">But actually goes to:</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="good_link_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">12</property>
<property name="margin_bottom">6</property>
<property name="label">&lt;a href="http://goodlink.com"&gt;http://goodlink.com&lt;/a&gt;</property>
<property name="use_markup">True</property>
<property name="ellipsize">middle</property>
<property name="max_width_chars">60</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_top">12</property>
<property name="label" translatable="yes">The link appears to go to:</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Deceptive link found</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">The email sender may be leading you to the wrong web site.</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_top">12</property>
<property name="label" translatable="yes">If unsure, contact the sender and ask before continuing.</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<style>
<class name="tooltip"/>
</style>
</object>
</interface>

View file

@ -639,154 +639,4 @@
<class name="geary-message"/>
</style>
</template>
<object class="GtkPopover" id="link_popover">
<property name="can_focus">False</property>
<property name="relative_to">body_container</property>
<property name="position">bottom</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="margin_right">12</property>
<property name="vexpand">True</property>
<property name="icon_name">dialog-warning-symbolic</property>
<property name="icon_size">3</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="height">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="bad_link_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">12</property>
<property name="label">&lt;a href="http://badlink.com"&gt;http://badlink.com&lt;/a&gt;</property>
<property name="use_markup">True</property>
<property name="ellipsize">middle</property>
<property name="max_width_chars">60</property>
<signal name="activate-link" handler="on_link_popover_activated" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">But actually goes to:</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="good_link_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">12</property>
<property name="margin_bottom">6</property>
<property name="label">&lt;a href="http://goodlink.com"&gt;http://goodlink.com&lt;/a&gt;</property>
<property name="use_markup">True</property>
<property name="ellipsize">middle</property>
<property name="max_width_chars">60</property>
<signal name="activate-link" handler="on_link_popover_activated" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_top">12</property>
<property name="label" translatable="yes">The link appears to go to:</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Deceptive link found</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">The email sender may be leading you to the wrong web site.</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_top">12</property>
<property name="label" translatable="yes">If unsure, contact the sender and ask before continuing.</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<style>
<class name="tooltip"/>
</style>
</object>
</interface>

View file

@ -29,6 +29,7 @@
<file compressed="true" preprocess="xml-stripblanks">conversation-email.ui</file>
<file compressed="true" preprocess="xml-stripblanks">conversation-email-menus.ui</file>
<file compressed="true" preprocess="xml-stripblanks">conversation-message.ui</file>
<file compressed="true" preprocess="xml-stripblanks">conversation-message-link-popover.ui</file>
<file compressed="true" preprocess="xml-stripblanks">conversation-message-menus.ui</file>
<file compressed="true" preprocess="xml-stripblanks">conversation-viewer.ui</file>
<file compressed="true">conversation-web-view.css</file>