2018-04-28 18:27:10 +02:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
public class Tootle.RichLabel : Gtk.Label {
|
|
|
|
|
|
|
|
public weak Mention[]? mentions;
|
|
|
|
|
|
|
|
public RichLabel (string text, bool override_links = true) {
|
|
|
|
label = text;
|
|
|
|
set_use_markup (true);
|
|
|
|
|
|
|
|
if (override_links)
|
|
|
|
activate_link.connect (open_link);
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:57:31 +02:00
|
|
|
public void wrap_words () {
|
|
|
|
halign = Gtk.Align.START;
|
|
|
|
single_line_mode = false;
|
|
|
|
set_line_wrap (true);
|
|
|
|
wrap_mode = Pango.WrapMode.WORD_CHAR;
|
|
|
|
justify = Gtk.Justification.LEFT;
|
|
|
|
xalign = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-28 18:27:10 +02:00
|
|
|
public bool open_link (string url){
|
|
|
|
if (mentions != null){
|
2018-05-04 22:57:31 +02:00
|
|
|
foreach (Mention mention in mentions) {
|
2018-04-28 18:27:10 +02:00
|
|
|
if (url == mention.url){
|
|
|
|
AccountView.open_from_id (mention.id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 16:43:10 +02:00
|
|
|
if ("/tags/" in url){
|
|
|
|
var encoded = url.split("/tags/")[1];
|
|
|
|
var hashtag = Soup.URI.decode (encoded);
|
|
|
|
var feed = new HomeView ("tag/" + hashtag);
|
|
|
|
Tootle.window.open_view (feed);
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-28 18:27:10 +02:00
|
|
|
|
|
|
|
if ("/@" in url){
|
|
|
|
var profile = url.split("/@")[1];
|
2018-04-28 18:41:35 +02:00
|
|
|
AccountView.open_from_name (profile);
|
2018-04-28 18:27:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-04 22:57:31 +02:00
|
|
|
Tootle.Utils.open_url (url);
|
2018-04-28 18:27:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|