From 89467c900a843dd8f57a3e2ab2960022dc1572cc Mon Sep 17 00:00:00 2001 From: alcexhim Date: Wed, 25 Jun 2014 16:03:27 -0400 Subject: [PATCH] Moved much of Windows Forms specific code to Engine proper --- .../LocalConfiguration.cs | 2 +- .../WindowsFormsEngine.cs | 80 ++++++++-------- .../UniversalEditor.UserInterface/Engine.cs | 92 ++++++++++++++----- 3 files changed, 109 insertions(+), 65 deletions(-) diff --git a/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/LocalConfiguration.cs b/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/LocalConfiguration.cs index 6394a870..8b20d938 100644 --- a/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/LocalConfiguration.cs +++ b/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/LocalConfiguration.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using UniversalEditor.ObjectModels.Markup; using UniversalEditor.DataFormats.Markup.XML; -using System.Drawing; using UniversalEditor.Accessors; namespace UniversalEditor.UserInterface.WindowsForms diff --git a/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/WindowsFormsEngine.cs b/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/WindowsFormsEngine.cs index ba42a502..7aa8f0bc 100644 --- a/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/WindowsFormsEngine.cs +++ b/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/WindowsFormsEngine.cs @@ -133,8 +133,38 @@ namespace UniversalEditor.UserInterface.WindowsForms } } - [STAThreadAttribute()] - protected override void MainLoop() + protected override void ShowSplashScreen() + { + if (LocalConfiguration.SplashScreen.Enabled) + { + splasher = new SplashScreenWindow(); + splasher.ShowDialog(); + } + } + protected override void HideSplashScreen() + { + if (LocalConfiguration.SplashScreen.Enabled) + { + while (splasher == null) + { + System.Threading.Thread.Sleep(500); + } + splasher.InvokeClose(); + } + } + protected override void UpdateSplashScreenStatus(string message, int progressValue = -1, int progressMinimum = 0, int progressMaximum = 100) + { + if (LocalConfiguration.SplashScreen.Enabled) + { + while (splasher == null) + { + System.Threading.Thread.Sleep(500); + } + splasher.InvokeUpdateStatus(message); + } + } + + protected override void BeforeInitialization() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -147,6 +177,13 @@ namespace UniversalEditor.UserInterface.WindowsForms AwesomeControls.Theming.Theme.CurrentTheme = theme; Glue.ApplicationInformation.ApplicationID = new Guid("{b359fe9a-080a-43fc-ae38-00ba7ac1703e}"); + + base.BeforeInitialization(); + } + + [STAThreadAttribute()] + protected override void MainLoop() + { switch (System.Environment.OSVersion.Platform) { case PlatformID.MacOSX: @@ -166,15 +203,6 @@ namespace UniversalEditor.UserInterface.WindowsForms } } - System.Threading.Thread threadLoader = new System.Threading.Thread(threadLoader_ThreadStart); - threadLoader.Start(); - - if (LocalConfiguration.SplashScreen.Enabled) - { - splasher = new SplashScreenWindow(); - splasher.ShowDialog(); - } - Glue.ApplicationEventEventArgs e = new Glue.ApplicationEventEventArgs(Glue.Common.Constants.EventNames.ApplicationStart); Glue.Common.Methods.SendApplicationEvent(e); if (e.CancelApplication) return; @@ -187,14 +215,8 @@ namespace UniversalEditor.UserInterface.WindowsForms row1.Items.Add("textEditor", "Text Editor"); PieMenuManager.Groups.Add(row1); - OpenWindow(SelectedFileNames.ToArray()); - Application.Run(); - SessionManager.Save(); - BookmarksManager.Save(); - RecentFileManager.Save(); - Glue.Common.Methods.SendApplicationEvent(new Glue.ApplicationEventEventArgs(Glue.Common.Constants.EventNames.ApplicationStop)); } @@ -353,30 +375,6 @@ namespace UniversalEditor.UserInterface.WindowsForms } #endif - private static void threadLoader_ThreadStart() - { - /* - if (Configuration.SplashScreen.Enabled) - { - while (splasher == null) System.Threading.Thread.Sleep(500); - } - */ - - // if (Configuration.SplashScreen.Enabled) splasher.InvokeUpdateStatus("Loading object models..."); - UniversalEditor.Common.Reflection.GetAvailableObjectModels(); - - // if (Configuration.SplashScreen.Enabled) splasher.InvokeUpdateStatus("Loading data formats..."); - UniversalEditor.Common.Reflection.GetAvailableDataFormats(); - - if (LocalConfiguration.SplashScreen.Enabled) - { - while (splasher == null) - { - System.Threading.Thread.Sleep(500); - } - splasher.InvokeClose(); - } - } protected override IHostApplicationWindow OpenWindowInternal(params string[] FileNames) { diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs index a84bd1ea..1e87d732 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -512,10 +512,71 @@ namespace UniversalEditor.UserInterface private static Engine mvarCurrentEngine = null; public static Engine CurrentEngine { get { return mvarCurrentEngine; } } + protected virtual void ShowSplashScreen() + { + } + protected virtual void HideSplashScreen() + { + } + protected virtual void UpdateSplashScreenStatus(string message, int progressValue = -1, int progressMinimum = 0, int progressMaximum = 100) + { + } + + private void Initialize() + { + System.Threading.Thread threadLoader = new System.Threading.Thread(threadLoader_ThreadStart); + threadLoader.Start(); + + ShowSplashScreen(); + } + protected virtual void InitializeInternal() + { + UpdateSplashScreenStatus("Loading object models..."); + UniversalEditor.Common.Reflection.GetAvailableObjectModels(); + + UpdateSplashScreenStatus("Loading data formats..."); + UniversalEditor.Common.Reflection.GetAvailableDataFormats(); + + // Initialize the XML files + InitializeXMLConfiguration(); + + // Initialize Recent File Manager + mvarRecentFileManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "RecentItems.xml"; + mvarRecentFileManager.Load(); + + // Initialize Bookmarks Manager + mvarBookmarksManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Bookmarks.xml"; + mvarBookmarksManager.Load(); + + // Initialize Session Manager + mvarSessionManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Sessions.xml"; + mvarSessionManager.Load(); + } + private void threadLoader_ThreadStart() + { + /* + if (Configuration.SplashScreen.Enabled) + { + while (splasher == null) System.Threading.Thread.Sleep(500); + } + */ + + InitializeInternal(); + HideSplashScreen(); + } + public void StartApplication() { Engine.mvarCurrentEngine = this; + string INSTANCEID = GetType().FullName + "$2d429aa3371c421fb63b42525e51a50c$92751853175891031214292357218181357901238$"; + if (Configuration.GetValue("SingleInstanceUniquePerDirectory", true)) + { + // The single instance should be unique per directory + INSTANCEID += System.Reflection.Assembly.GetEntryAssembly().Location; + } + if (!SingleInstanceManager.CreateSingleInstance(INSTANCEID, new EventHandler(SingleInstanceManager_Callback))) return; + string[] args1 = Environment.GetCommandLineArgs(); string[] args = new string[args1.Length - 1]; Array.Copy(args1, 1, args, 0, args.Length); @@ -533,36 +594,21 @@ namespace UniversalEditor.UserInterface BeforeInitialization(); - // Initialize the XML files - InitializeXMLConfiguration(); - // Initialize the branding for the selected application InitializeBranding(); - - // Initialize Recent File Manager - mvarRecentFileManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "RecentItems.xml"; - mvarRecentFileManager.Load(); - - // Initialize Bookmarks Manager - mvarBookmarksManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Bookmarks.xml"; - mvarBookmarksManager.Load(); - - // Initialize Session Manager - mvarSessionManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Sessions.xml"; - mvarSessionManager.Load(); - - string INSTANCEID = GetType().FullName + "$2d429aa3371c421fb63b42525e51a50c$92751853175891031214292357218181357901238$"; - if (Configuration.GetValue("SingleInstanceUniquePerDirectory", true)) - { - // The single instance should be unique per directory - INSTANCEID += System.Reflection.Assembly.GetEntryAssembly().Location; - } - if (!SingleInstanceManager.CreateSingleInstance(INSTANCEID, new EventHandler(SingleInstanceManager_Callback))) return; + + Initialize(); AfterInitializationInternal(); AfterInitialization(); + OpenWindow(SelectedFileNames.ToArray()); + MainLoop(); + + SessionManager.Save(); + BookmarksManager.Save(); + RecentFileManager.Save(); } } }