[smuxi/experiments/configurable_message_patterns: 3/6] Engine: implemented /config remove command action



commit 259c105b6fba785ece065b0537066560782c1850
Author: Mirco Bauer <meebey meebey net>
Date:   Sun Feb 16 18:29:28 2014 +0100

    Engine: implemented /config remove command action

 src/Engine/Session.cs |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/Engine/Session.cs b/src/Engine/Session.cs
index 325bea8..d640992 100644
--- a/src/Engine/Session.cs
+++ b/src/Engine/Session.cs
@@ -782,6 +782,40 @@ namespace Smuxi.Engine
                         );
                     }
                     break;
+                case "remove": {
+                    if (cd.DataArray.Length < 3) {
+                        _NotEnoughParameters(cd);
+                        return;
+                    }
+                    var removeParam = cd.DataArray[2];
+                    if (!removeParam.StartsWith("MessagePatterns/")) {
+                        builder.AppendErrorText(
+                            _("Invalid config remove key: '{0}'. Valid remove " +
+                              "keys: MessagePatterns/{ID}."),
+                            removeParam
+                        );
+                        AddMessageToFrontend(cd, builder.ToMessage());
+                        return;
+                    }
+                    var id = removeParam.Split('/')[1];
+                    var parsedId = Int32.Parse(id);
+                    var patternController = new MessagePatternListController(_UserConfig);
+                    var pattern = patternController.Get(parsedId);
+                    if (pattern == null) {
+                        builder.AppendErrorText(
+                            _("Message pattern with ID: '{0}' does not exist."),
+                            id
+                        );
+                    } else {
+                        patternController.Remove(parsedId);
+                        MessageBuilderSettings.ApplyConfig(UserConfig);
+                        builder.AppendText(
+                            _("Message pattern with ID: '{0}' removed."),
+                            id
+                        );
+                    }
+                    break;
+                }
                 default:
                     builder.AppendErrorText(
                         _("Invalid parameter for config; use load, save, get or set.")


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]