From bd7fde99af3df59c5ec96184b2649b4308250b24 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 10 Sep 2019 19:11:41 +0200 Subject: fixup Fix some warnings --- .../conversation_selector_row.vala | 6 +----- main/src/ui/global_search.vala | 22 +++++++++++----------- main/src/ui/unified_window_controller.vala | 12 ++---------- main/src/ui/util/helper.vala | 8 ++++++++ 4 files changed, 22 insertions(+), 26 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 46f6c1a8..6ffefc94 100644 --- a/main/src/ui/conversation_selector/conversation_selector_row.vala +++ b/main/src/ui/conversation_selector/conversation_selector_row.vala @@ -136,11 +136,7 @@ public class ConversationSelectorRow : ListBoxRow { nick_label.label = last_message.direction == Message.DIRECTION_SENT ? _("Me") + ": " : ""; } - try { - message_label.label = Markup.escape_text((/\s+/).replace_literal(last_message.body, -1, 0, " ")); - } catch (RegexError e) { - assert_not_reached(); - } + message_label.label = Util.summarize_whitespaces_to_space(last_message.body); break; case FileItem.TYPE: FileItem file_item = last_content_item as FileItem; diff --git a/main/src/ui/global_search.vala b/main/src/ui/global_search.vala index db7dbc0f..74e96999 100644 --- a/main/src/ui/global_search.vala +++ b/main/src/ui/global_search.vala @@ -205,8 +205,8 @@ public class GlobalSearch : Overlay { regex_str += ")"; // Color the keywords - int elongated_by = 0; try { + int elongated_by = 0; Regex highlight_regex = new Regex(regex_str); MatchInfo match_info; string markup_text_bak = markup_text.down(); @@ -218,19 +218,19 @@ public class GlobalSearch : Overlay { elongated_by += "".length + "".length; } markup_text_bak += ""; // We need markup_text_bak to live until here because url_regex.match does not copy the string - - label.label = markup_text; - grid.attach(label, 1, 1, 1, 1); - - Button button = new Button() { relief=ReliefStyle.NONE, visible=true }; - button.clicked.connect(() => { - selected_item(item); - }); - button.add(grid); - return button; } catch (RegexError e) { assert_not_reached(); } + + label.label = markup_text; + grid.attach(label, 1, 1, 1, 1); + + Button button = new Button() { relief=ReliefStyle.NONE, visible=true }; + button.clicked.connect(() => { + selected_item(item); + }); + button.add(grid); + return button; } private Grid get_context_message_widget(MessageItem item) { diff --git a/main/src/ui/unified_window_controller.vala b/main/src/ui/unified_window_controller.vala index 21725574..2fd8eb0d 100644 --- a/main/src/ui/unified_window_controller.vala +++ b/main/src/ui/unified_window_controller.vala @@ -153,19 +153,11 @@ public class UnifiedWindowController : Object { private void update_conversation_topic(string? subtitle = null) { if (subtitle != null) { - try { - conversation_topic = (/\s+/).replace_literal(subtitle, -1, 0, " "); - } catch (RegexError e) { - assert_not_reached(); - } + conversation_topic = Util.summarize_whitespaces_to_space(subtitle); } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account); if (subject != null) { - try { - conversation_topic = (/\s+/).replace_literal(subject, -1, 0, " "); - } catch (RegexError e) { - assert_not_reached(); - } + conversation_topic = Util.summarize_whitespaces_to_space(subject); } else { conversation_topic = null; } diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index c3353fb6..4e5fbb41 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -272,6 +272,14 @@ public int get_only_emoji_count(string markup_text) { return emoji_no; } +public string summarize_whitespaces_to_space(string s) { + try { + return (/\s+/).replace_literal(s, -1, 0, " "); + } catch (RegexError e) { + assert_not_reached(); + } +} + public bool use_csd() { return (GLib.Application.get_default() as Application).use_csd(); } -- cgit v1.2.3-70-g09d2