From: Lars Op den Kamp Date: Tue, 12 Mar 2013 23:12:32 +0000 (+0100) Subject: CecTray: don't use lazy loading for the main controller, but pass the instance. bugzi... X-Git-Tag: upstream/2.2.0~1^2~4^2~31 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=97401db10c2303a67f4f2d2f1756aa078d473d65;p=deb_libcec.git CecTray: don't use lazy loading for the main controller, but pass the instance. bugzid: 2082 --- diff --git a/src/LibCecTray/Program.cs b/src/LibCecTray/Program.cs index 32dc7af..3ab9cf7 100644 --- a/src/LibCecTray/Program.cs +++ b/src/LibCecTray/Program.cs @@ -42,7 +42,15 @@ namespace LibCECTray private static CECTray _instance; public static CECTray Instance { - get { return _instance ?? (_instance = new CECTray()); } + get + { + if (_instance == null) + { + _instance = new CECTray(); + _instance.Initialise(); + } + return _instance; + } } [STAThread] diff --git a/src/LibCecTray/controller/applications/ApplicationController.cs b/src/LibCecTray/controller/applications/ApplicationController.cs index ae9a226..3c7b83f 100644 --- a/src/LibCecTray/controller/applications/ApplicationController.cs +++ b/src/LibCecTray/controller/applications/ApplicationController.cs @@ -49,9 +49,9 @@ namespace LibCECTray.controller.applications /// class ApplicationController { - public ApplicationController(CECSettings settings, string uiName, string processName, string filename, string workingDirectory) + public ApplicationController(CECController controller, string uiName, string processName, string filename, string workingDirectory) { - Settings = settings; + Controller = controller; UiName = uiName; ProcessName = processName; ApplicationFilename = filename; @@ -60,13 +60,13 @@ namespace LibCECTray.controller.applications IsInternal = false; } - public static ApplicationController FromString(CECSettings settings, string serialisedConfig) + public static ApplicationController FromString(CECController controller, CECSettings settings, string serialisedConfig) { var splitString = serialisedConfig.Split(';'); if (splitString.Length != 4) throw new InvalidDataException("incorrect number of parameters"); - return new ApplicationController(settings, splitString[0], splitString[1], splitString[2], splitString[3]); + return new ApplicationController(controller, splitString[0], splitString[1], splitString[2], splitString[3]); } public string AsString() @@ -383,7 +383,10 @@ namespace LibCECTray.controller.applications get { return _buttonConfig ?? (_buttonConfig = new CecButtonConfig(this)); } } - public CECSettings Settings; + public CECSettings Settings + { + get { return Controller.Settings; } + } protected DataGridView CecButtonGridView; public virtual ApplicationAction DefaultValue(CecKeypress key) @@ -407,6 +410,8 @@ namespace LibCECTray.controller.applications private bool _applicationRunning; + protected readonly CECController Controller; + #endregion } } diff --git a/src/LibCecTray/controller/applications/Applications.cs b/src/LibCecTray/controller/applications/Applications.cs index 2835f1c..3f3a359 100644 --- a/src/LibCecTray/controller/applications/Applications.cs +++ b/src/LibCecTray/controller/applications/Applications.cs @@ -74,7 +74,7 @@ namespace LibCECTray.controller.applications { if (item.Length > 0) { - var app = ApplicationController.FromString(_controller.Settings, item); + var app = ApplicationController.FromString(_controller, _controller.Settings, item); if (app != null) _controllers.Add(app.ProcessName, app); } @@ -100,9 +100,9 @@ namespace LibCECTray.controller.applications get { var defaultValues = new Dictionary(); - WMCController wmcController = new WMCController(_controller.Settings); + WMCController wmcController = new WMCController(_controller); defaultValues.Add(wmcController.ProcessName, wmcController); - XBMCController xbmcController = new XBMCController(_controller.Settings); + XBMCController xbmcController = new XBMCController(_controller); defaultValues.Add(xbmcController.ProcessName, xbmcController); return defaultValues; diff --git a/src/LibCecTray/controller/applications/ConfigureApplication.cs b/src/LibCecTray/controller/applications/ConfigureApplication.cs index 2e58977..ad06820 100644 --- a/src/LibCecTray/controller/applications/ConfigureApplication.cs +++ b/src/LibCecTray/controller/applications/ConfigureApplication.cs @@ -132,7 +132,7 @@ namespace LibCECTray.controller.applications } else if (_cecController != null) { - ApplicationController newController = new ApplicationController(_settings, tbUiName.Text, tbProcessName.Text, tbFilename.Text, tbWorkingDir.Text); + ApplicationController newController = new ApplicationController(_cecController, tbUiName.Text, tbProcessName.Text, tbFilename.Text, tbWorkingDir.Text); if (_cecController.RegisterApplication(newController)) newController.Settings.Persist(); } @@ -145,8 +145,8 @@ namespace LibCECTray.controller.applications Dispose(); } - private ApplicationController _controller; - private CECController _cecController; - private CECSettings _settings; + private readonly ApplicationController _controller; + private readonly CECController _cecController; + private readonly CECSettings _settings; } } diff --git a/src/LibCecTray/controller/applications/internal/WMCController.cs b/src/LibCecTray/controller/applications/internal/WMCController.cs index 17d7cc7..201fcda 100644 --- a/src/LibCecTray/controller/applications/internal/WMCController.cs +++ b/src/LibCecTray/controller/applications/internal/WMCController.cs @@ -39,8 +39,8 @@ namespace LibCECTray.controller.applications.@internal { internal class WMCController : ApplicationController { - public WMCController(CECSettings settings) : - base(settings, + public WMCController(CECController controller) : + base(controller, Resources.application_windows_media_center, "ehshell", "ehshell.exe", diff --git a/src/LibCecTray/controller/applications/internal/XBMCController.cs b/src/LibCecTray/controller/applications/internal/XBMCController.cs index 075178c..b4801e2 100644 --- a/src/LibCecTray/controller/applications/internal/XBMCController.cs +++ b/src/LibCecTray/controller/applications/internal/XBMCController.cs @@ -44,8 +44,8 @@ namespace LibCECTray.controller.applications.@internal { internal class XBMCController : ApplicationController { - public XBMCController(CECSettings settings) : - base(settings, + public XBMCController(CECController controller) : + base(controller, Resources.application_xbmc, "XBMC", "XBMC.exe", diff --git a/src/LibCecTray/ui/CECTray.Designer.cs b/src/LibCecTray/ui/CECTray.Designer.cs index 34db412..b153957 100644 --- a/src/LibCecTray/ui/CECTray.Designer.cs +++ b/src/LibCecTray/ui/CECTray.Designer.cs @@ -742,7 +742,6 @@ this.MaximizeBox = false; this.Name = "CECTray"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Load += new System.EventHandler(this.CECTrayLoad); this.Resize += new System.EventHandler(this.CECTrayResize); this.trayIconMenu.ResumeLayout(false); this.LogOutput.ResumeLayout(false); diff --git a/src/LibCecTray/ui/CECTray.cs b/src/LibCecTray/ui/CECTray.cs index 6703e5f..7c08eec 100644 --- a/src/LibCecTray/ui/CECTray.cs +++ b/src/LibCecTray/ui/CECTray.cs @@ -78,7 +78,7 @@ namespace LibCECTray.ui set { base.Text = value; } } - private void CECTrayLoad(object sender, EventArgs e) + public void Initialise() { Controller.Initialise(); } @@ -484,7 +484,10 @@ namespace LibCECTray.ui private CECController _controller; public CECController Controller { - get { return _controller ?? (_controller = new CECController(this)); } + get + { + return _controller ?? (_controller = new CECController(this)); + } } public Control.ControlCollection TabControls {