CecTray: don't use lazy loading for the main controller, but pass the instance. bugzi...
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 12 Mar 2013 23:12:32 +0000 (00:12 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 12 Mar 2013 23:47:56 +0000 (00:47 +0100)
src/LibCecTray/Program.cs
src/LibCecTray/controller/applications/ApplicationController.cs
src/LibCecTray/controller/applications/Applications.cs
src/LibCecTray/controller/applications/ConfigureApplication.cs
src/LibCecTray/controller/applications/internal/WMCController.cs
src/LibCecTray/controller/applications/internal/XBMCController.cs
src/LibCecTray/ui/CECTray.Designer.cs
src/LibCecTray/ui/CECTray.cs

index 32dc7af2b8675f7207703931933d17fe2183ef89..3ab9cf7317e7d5f6a9827768d720ecf4c5f1bdf1 100644 (file)
@@ -42,7 +42,15 @@ namespace LibCECTray
     private static CECTray _instance;
     public static CECTray Instance
     {
     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]
     }
 
     [STAThread]
index ae9a226f26cfba18f7bc84b94ee68404d08ff710..3c7b83f1a0657054993c9862d6168e77c6987248 100644 (file)
@@ -49,9 +49,9 @@ namespace LibCECTray.controller.applications
   /// </summary>
   class ApplicationController
   {
   /// </summary>
   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;
       UiName = uiName;
       ProcessName = processName;
       ApplicationFilename = filename;
@@ -60,13 +60,13 @@ namespace LibCECTray.controller.applications
       IsInternal = false;
     }
 
       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");
 
     {
       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()
     }
 
     public string AsString()
@@ -383,7 +383,10 @@ namespace LibCECTray.controller.applications
       get { return _buttonConfig ?? (_buttonConfig = new CecButtonConfig(this)); }
     }
 
       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)
     protected DataGridView CecButtonGridView;
 
     public virtual ApplicationAction DefaultValue(CecKeypress key)
@@ -407,6 +410,8 @@ namespace LibCECTray.controller.applications
 
     private bool _applicationRunning;
 
 
     private bool _applicationRunning;
 
+    protected readonly CECController Controller;
+
     #endregion
   }
 }
     #endregion
   }
 }
index 2835f1c16baa11b54c0ca9f53a822519efda5ff1..3f3a359b136d877d3ac2ea0f11e9a4ffefdc0fbb 100644 (file)
@@ -74,7 +74,7 @@ namespace LibCECTray.controller.applications
           {
             if (item.Length > 0)
             {
           {
             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);
             }
               if (app != null)
                 _controllers.Add(app.ProcessName, app);
             }
@@ -100,9 +100,9 @@ namespace LibCECTray.controller.applications
       get
       {
         var defaultValues = new Dictionary<string, ApplicationController>();
       get
       {
         var defaultValues = new Dictionary<string, ApplicationController>();
-        WMCController wmcController = new WMCController(_controller.Settings);
+        WMCController wmcController = new WMCController(_controller);
         defaultValues.Add(wmcController.ProcessName, wmcController);
         defaultValues.Add(wmcController.ProcessName, wmcController);
-        XBMCController xbmcController = new XBMCController(_controller.Settings);
+        XBMCController xbmcController = new XBMCController(_controller);
         defaultValues.Add(xbmcController.ProcessName, xbmcController);
 
         return defaultValues;
         defaultValues.Add(xbmcController.ProcessName, xbmcController);
 
         return defaultValues;
index 2e5897709dca21958797e3aa5491bd0163e371d8..ad0682057b0c7b38bbd9cc01f015d96514b5dc55 100644 (file)
@@ -132,7 +132,7 @@ namespace LibCECTray.controller.applications
       }
       else if (_cecController != null)
       {
       }
       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();
       }
         if (_cecController.RegisterApplication(newController))
           newController.Settings.Persist();
       }
@@ -145,8 +145,8 @@ namespace LibCECTray.controller.applications
       Dispose();
     }
 
       Dispose();
     }
 
-    private ApplicationController _controller;
-    private CECController _cecController;
-    private CECSettings _settings;
+    private readonly ApplicationController _controller;
+    private readonly CECController _cecController;
+    private readonly CECSettings _settings;
   }
 }
   }
 }
index 17d7cc73297f814a22afef6b5c7073a68e7c494e..201fcda0705d993625835adbee4c217e819dfc12 100644 (file)
@@ -39,8 +39,8 @@ namespace LibCECTray.controller.applications.@internal
 {
   internal class WMCController : ApplicationController
   {
 {
   internal class WMCController : ApplicationController
   {
-    public WMCController(CECSettings settings) :
-      base(settings,
+    public WMCController(CECController controller) :
+      base(controller,
            Resources.application_windows_media_center,
            "ehshell",
            "ehshell.exe",
            Resources.application_windows_media_center,
            "ehshell",
            "ehshell.exe",
index 075178c3c47f69db8a692eb4f01154444dacedf0..b4801e2e62a40252f3aef5e7060639e3c6aa81e7 100644 (file)
@@ -44,8 +44,8 @@ namespace LibCECTray.controller.applications.@internal
 {
        internal class XBMCController : ApplicationController
        {
 {
        internal class XBMCController : ApplicationController
        {
-    public XBMCController(CECSettings settings) :
-      base(settings,
+    public XBMCController(CECController controller) :
+      base(controller,
            Resources.application_xbmc,
            "XBMC",
            "XBMC.exe",
            Resources.application_xbmc,
            "XBMC",
            "XBMC.exe",
index 34db4123f4213faec88e1e68c6d5429f3d43881e..b153957fa27c8145417154ad9a2a030ad94ebdba 100644 (file)
       this.MaximizeBox = false;
       this.Name = "CECTray";
       this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
       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);
       this.Resize += new System.EventHandler(this.CECTrayResize);
       this.trayIconMenu.ResumeLayout(false);
       this.LogOutput.ResumeLayout(false);
index 6703e5f8d76e6a9a22c825678bf7b7ccb0a4fcd8..7c08eec2304f4fa8b5749cbbeeb72d9f389c380f 100644 (file)
@@ -78,7 +78,7 @@ namespace LibCECTray.ui
       set { base.Text = value; }
     }
 
       set { base.Text = value; }
     }
 
-    private void CECTrayLoad(object sender, EventArgs e)
+    public void Initialise()
     {
       Controller.Initialise();
     }
     {
       Controller.Initialise();
     }
@@ -484,7 +484,10 @@ namespace LibCECTray.ui
     private CECController _controller;
     public CECController Controller
     {
     private CECController _controller;
     public CECController Controller
     {
-      get { return _controller ?? (_controller = new CECController(this)); }
+      get
+      {
+        return _controller ?? (_controller = new CECController(this));
+      }
     }
     public Control.ControlCollection TabControls
     {
     }
     public Control.ControlCollection TabControls
     {