[smuxi: 153/179] Engine: allow enabling emojis on-demand via MessageBuilderSettings.set_Emojis()
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi: 153/179] Engine: allow enabling emojis on-demand via MessageBuilderSettings.set_Emojis()
- Date: Sat, 4 Nov 2017 05:50:33 +0000 (UTC)
commit 48de7754213d2ae59ae3233a95b30fc046b0e796
Author: Mirco Bauer <meebey meebey net>
Date: Sat Jun 3 09:53:40 2017 +0800
Engine: allow enabling emojis on-demand via MessageBuilderSettings.set_Emojis()
The old implementation only allowed to enable emojijs when the global setting
did so. Setting MessageBuilderSettings.Emojis to true after ApplyConfig() was
called had no effect as the property was just a flag. Now the Emojis property is
actually injecting the needed message pattern or removing it from the active
list of patterns.
src/Engine/Config/MessageBuilderSettings.cs | 35 +++++++++++++++++++-------
1 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/src/Engine/Config/MessageBuilderSettings.cs b/src/Engine/Config/MessageBuilderSettings.cs
index 05590d4..06e6b44 100644
--- a/src/Engine/Config/MessageBuilderSettings.cs
+++ b/src/Engine/Config/MessageBuilderSettings.cs
@@ -27,6 +27,7 @@ namespace Smuxi.Engine
public class MessageBuilderSettings
{
static List<MessagePatternModel> BuiltinPatterns { get; set; }
+ static MessagePatternModel EmojiMessagePattern { get; set; }
public List<MessagePatternModel> UserPatterns { get; set; }
public List<MessagePatternModel> Patterns { get; set; }
public bool NickColors { get; set; }
@@ -34,10 +35,29 @@ namespace Smuxi.Engine
public bool StripColors { get; set; }
public TextColor HighlightColor { get; set; }
public List<string> HighlightWords { get; set; }
- public bool Emojis { get; set; }
+
+ public bool Emojis {
+ get {
+ return Patterns.Contains(EmojiMessagePattern);
+ }
+ set {
+ if (value && !Emojis) {
+ Patterns.Add(EmojiMessagePattern);
+ }
+ if (!value) {
+ Patterns.Remove(EmojiMessagePattern);
+ }
+ }
+ }
static MessageBuilderSettings()
{
+ var emojiRegex = new Regex(@":(\w+):", RegexOptions.Compiled);
+ EmojiMessagePattern = new MessagePatternModel(emojiRegex) {
+ MessagePartType = typeof(ImageMessagePartModel),
+ LinkFormat = "smuxi-emoji://{1}"
+ };
+
BuiltinPatterns = new List<MessagePatternModel>();
InitBuiltinSmartLinks();
}
@@ -387,7 +407,6 @@ namespace Smuxi.Engine
HighlightWords = new List<string>(
(string[]) userConfig["Interface/Chat/HighlightWords"]
);
- Emojis = (bool) userConfig["Interface/Chat/Emojis"];
var patternController = new MessagePatternListController(userConfig);
var userPatterns = patternController.GetList();
@@ -400,16 +419,12 @@ namespace Smuxi.Engine
// of MessageBuilderSettings is created via the static initializer.
patterns.AddRange(builtinPatterns);
patterns.AddRange(userPatterns);
- if (Emojis) {
- // Emoji
- var regex = new Regex(@":(\w+):", RegexOptions.Compiled);
- patterns.Add(new MessagePatternModel(regex) {
- MessagePartType = typeof(ImageMessagePartModel),
- LinkFormat = "smuxi-emoji://{1}",
- });
- }
Patterns = patterns;
UserPatterns = userPatterns;
+
+ // The Patterns property has to be initialized before we set the
+ // Emojis property as it will modify the existing Patterns collection
+ Emojis = (bool) userConfig["Interface/Chat/Emojis"];
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]