From: Lars Op den Kamp Date: Sat, 6 Oct 2012 18:56:41 +0000 (+0200) Subject: fixed duplicate entry and entry for 'unknown' in the button config list X-Git-Tag: upstream/2.2.0~1^2~17^2^2~23 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=324a4cb1d256252a4cd506e90e158828e160b0ed;p=deb_libcec.git fixed duplicate entry and entry for 'unknown' in the button config list --- diff --git a/src/LibCecTray/controller/applications/ApplicationController.cs b/src/LibCecTray/controller/applications/ApplicationController.cs index 310f30f..4d23071 100644 --- a/src/LibCecTray/controller/applications/ApplicationController.cs +++ b/src/LibCecTray/controller/applications/ApplicationController.cs @@ -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; diff --git a/src/LibCecTray/controller/applications/CecButtonConfig.cs b/src/LibCecTray/controller/applications/CecButtonConfig.cs index 63aba6c..35300bd 100644 --- a/src/LibCecTray/controller/applications/CecButtonConfig.cs +++ b/src/LibCecTray/controller/applications/CecButtonConfig.cs @@ -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()