diff options
author | fiaxh <git@mx.ax.lt> | 2018-09-18 21:28:56 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2018-09-21 21:53:48 +0200 |
commit | 85d194e349858b3cbbb4dd2a8ca007428378c56c (patch) | |
tree | 4ec16ce60c26c2f57b245f2a0280c61b5db1c828 /main/src/ui/util | |
parent | 9575b192e4d22d9f5422fae1b02ddf81db1ecf68 (diff) | |
download | dino-85d194e349858b3cbbb4dd2a8ca007428378c56c.tar.gz dino-85d194e349858b3cbbb4dd2a8ca007428378c56c.zip |
Use Label instead of TextView for message display
Diffstat (limited to 'main/src/ui/util')
-rw-r--r-- | main/src/ui/util/helper.vala | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 4e9e942d..06715ad6 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -138,13 +138,39 @@ public static bool is_24h_format() { return settings_format == "24h" || p_format == " "; } -// Workaround GTK TextView issues -public static void force_alloc_width(Widget widget, int width) { - Allocation alloc = Allocation(); - widget.get_preferred_width(out alloc.width, null); - widget.get_preferred_height(out alloc.height, null); - alloc.width = width; - widget.size_allocate(alloc); +public static string make_word_bold_markup(string s, string word) { + string ret = s; + int elongated_by = 0; + Regex highlight_regex = new Regex("\\b" + Regex.escape_string(word.down()) + "\\b"); + MatchInfo match_info; + string markup_text_bak = s.down(); + highlight_regex.match(markup_text_bak, 0, out match_info); + for (; match_info.matches(); match_info.next()) { + int start, end; + match_info.fetch_pos(0, out start, out end); + ret = ret[0:start+elongated_by] + "<b>" + ret[start+elongated_by:end+elongated_by] + "</b>" + ret[end+elongated_by:ret.length]; + elongated_by += 7; + } + markup_text_bak += ""; // We need markup_text_bak to live until here because url_regex.match does not copy the string + return ret; +} + +public static string make_link_markup(string s) { + string ret = s; + Regex url_regex = new Regex("""(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))"""); + int elongated_by = 0; + MatchInfo match_info; + string markup_text_bak = ret.down(); + url_regex.match(markup_text_bak, 0, out match_info); + for (; match_info.matches(); match_info.next()) { + int start, end; + match_info.fetch_pos(0, out start, out end); + string link = ret[start+elongated_by:end+elongated_by]; + ret = ret[0:start+elongated_by] + "<a href=\"" + link + "\">" + link + "</a>" + ret[end+elongated_by:ret.length]; + elongated_by += 15 + link.length; + } + markup_text_bak += ""; // We need markup_text_bak to live until here because url_regex.match does not copy the string + return ret; } } |