fixed duplicate entry and entry for 'unknown' in the button config list
authorLars Op den Kamp <lars@opdenkamp.eu>
Sat, 6 Oct 2012 18:56:41 +0000 (20:56 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sat, 6 Oct 2012 18:56:41 +0000 (20:56 +0200)
src/LibCecTray/controller/applications/ApplicationController.cs
src/LibCecTray/controller/applications/CecButtonConfig.cs

index 310f30f8ef05e12f25dbf04ecb3ae320912fb895..4d23071946db8ecfff2e61d5fc32c9a4e5240581 100644 (file)
@@ -353,18 +353,7 @@ namespace LibCECTray.controller.applications
     private CecButtonConfig _buttonConfig;
     public CecButtonConfig ButtonConfig
     {
-      get
-      {
-        if (_buttonConfig == null)
-        {
-          _buttonConfig = new CecButtonConfig(this);
-          foreach (CecUserControlCode key in Enum.GetValues(typeof(CecUserControlCode)))
-            _buttonConfig.Add(new CecButtonConfigItem(this, (new CecKeypress { Keycode = key })));
-
-          _buttonConfig.Load();
-        }
-        return _buttonConfig;
-      }
+      get { return _buttonConfig ?? (_buttonConfig = new CecButtonConfig(this)); }
     }
 
     public CECSettings Settings;
index 63aba6c84616971c5206bf1142d7eccd59059294..35300bd7688adc6150ca875c0f4c1c1abb9f8da0 100644 (file)
@@ -33,6 +33,7 @@
 using System.Collections.Generic;
 using CecSharp;
 using LibCECTray.settings;
+using System;
 
 namespace LibCECTray.controller.applications
 {
@@ -269,6 +270,27 @@ namespace LibCECTray.controller.applications
     public CecButtonConfig(ApplicationController controller)
     {
       _controller = controller;
+
+      foreach (CecUserControlCode key in Enum.GetValues(typeof(CecUserControlCode)))
+        AddConfigItem(new CecButtonConfigItem(controller, (new CecKeypress { Keycode = key })));
+
+      Load();
+    }
+
+    private void AddConfigItem(CecButtonConfigItem item)
+    {
+      if (!HasItem(item) && item.Key.Keycode != CecUserControlCode.Unknown)
+        Add(item);
+    }
+
+    public bool HasItem(CecButtonConfigItem item)
+    {
+      foreach (var entry in  this)
+      {
+        if (item.Key.Keycode == entry.Key.Keycode)
+          return true;
+      }
+      return false;
     }
 
     public void Load()