move splash screen functionality into MBS.Framework.UserInterface proper

This commit is contained in:
Michael Becker 2020-01-14 13:39:36 -05:00
parent c113b3e029
commit f60ba5c8cd
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
4 changed files with 22 additions and 192 deletions

View File

@ -32,35 +32,6 @@ namespace UniversalEditor.UserInterface
public class Engine
{
private static Engine _TheEngine = new Engine();
private SplashScreenWindow splasher = null;
private System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
private void ShowSplashScreen()
{
sw.Reset();
sw.Start();
// if (LocalConfiguration.SplashScreen.Enabled)
// {
splasher = new SplashScreenWindow();
splasher.Show();
// }
}
protected internal void HideSplashScreen()
{
while (splasher == null)
{
System.Threading.Thread.Sleep(500);
}
splasher.Hide();
splasher = null;
AfterInitializationInternal();
AfterInitialization();
sw.Stop();
Console.WriteLine("stopwatch: went from rip to ready in {0}", sw.Elapsed);
}
#region implemented abstract members of Engine
protected void ShowCrashDialog (Exception ex)
@ -234,8 +205,28 @@ namespace UniversalEditor.UserInterface
}
#endregion
Engine.CurrentEngine.UpdateSplashScreenStatus("Loading object models...");
UniversalEditor.Common.Reflection.GetAvailableObjectModels();
Engine.CurrentEngine.UpdateSplashScreenStatus("Loading data formats...");
UniversalEditor.Common.Reflection.GetAvailableDataFormats();
// Initialize Recent File Manager
Engine.CurrentEngine.RecentFileManager.DataFileName = Application.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "RecentItems.xml";
Engine.CurrentEngine.RecentFileManager.Load();
// Initialize Bookmarks Manager
Engine.CurrentEngine.BookmarksManager.DataFileName = Application.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Bookmarks.xml";
Engine.CurrentEngine.BookmarksManager.Load();
// Initialize Session Manager
Engine.CurrentEngine.SessionManager.DataFileName = Application.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Sessions.xml";
Engine.CurrentEngine.SessionManager.Load();
// load editors into memory so we don't wait 10-15 seconds before opening a file
Common.Reflection.GetAvailableEditors();
AfterInitialization();
}
@ -259,52 +250,8 @@ namespace UniversalEditor.UserInterface
{
}
private void t_threadStart()
{
Application.DoEvents();
// less do this
Application.ShortName = "mbs-editor";
// Application.Title = "Universal Editor";
Engine.CurrentEngine.UpdateSplashScreenStatus("Loading object models...");
UniversalEditor.Common.Reflection.GetAvailableObjectModels();
Engine.CurrentEngine.UpdateSplashScreenStatus("Loading data formats...");
UniversalEditor.Common.Reflection.GetAvailableDataFormats();
// Initialize Recent File Manager
Engine.CurrentEngine.RecentFileManager.DataFileName = Application.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "RecentItems.xml";
Engine.CurrentEngine.RecentFileManager.Load();
// Initialize Bookmarks Manager
Engine.CurrentEngine.BookmarksManager.DataFileName = Application.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Bookmarks.xml";
Engine.CurrentEngine.BookmarksManager.Load();
// Initialize Session Manager
Engine.CurrentEngine.SessionManager.DataFileName = Application.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Sessions.xml";
Engine.CurrentEngine.SessionManager.Load();
Engine.CurrentEngine.HideSplashScreen();
}
void Application_Activated(object sender, ApplicationActivatedEventArgs e)
{
if (e.FirstRun)
{
ShowSplashScreen();
System.Threading.Thread t = new System.Threading.Thread(t_threadStart);
t.Start();
while (splasher != null)
{
Application.DoEvents();
System.Threading.Thread.Sleep(500);
}
}
Document[] docs = new Document[e.CommandLine.FileNames.Count];
if (e.CommandLine.FileNames.Count > 0)
{
@ -443,11 +390,7 @@ namespace UniversalEditor.UserInterface
return new Engine[] { _TheEngine };
}
protected virtual void AfterInitialization()
{
}
private void AfterInitializationInternal()
private void AfterInitialization()
{
// Initialize all the commands that are common to UniversalEditor
#region File
@ -1051,31 +994,6 @@ namespace UniversalEditor.UserInterface
protected internal virtual void UpdateSplashScreenStatus(string message, int progressValue = -1, int progressMinimum = 0, int progressMaximum = 100)
{
// most of this is relic from when we had to workaround WinForms
// threading issues; these threading issues should be
// automagically handled by the UWT WinForms engine
/*
if (LocalConfiguration.SplashScreen.Enabled)
{
int spins = 0, maxspins = 30;
if (splasher == null) return;
while (splasher == null)
{
System.Threading.Thread.Sleep(500);
if (spins == maxspins) return;
spins++;
}
splasher.InvokeUpdateStatus(message);
}
*/
if (splasher == null)
splasher = new SplashScreenWindow();
if (!splasher.IsDisposed) {
splasher.SetStatus (message, progressValue, progressMinimum, progressMaximum);
}
}
private void Initialize()

View File

@ -17,7 +17,7 @@ namespace UniversalEditor.UserInterface
public static string ApplicationShortName { get; set; } = "mbs-editor";
public static string CompanyName { get; set; } = "Mike Becker's Software";
public static SplashScreenSettings SplashScreen { get; } = new SplashScreenSettings();
public static MBS.Framework.UserInterface.SplashScreenSettings SplashScreen { get; } = new MBS.Framework.UserInterface.SplashScreenSettings();
public static StartPageSettings StartPage { get; } = new StartPageSettings();
public static ColorSchemeSettings ColorScheme { get; } = new ColorSchemeSettings();

View File

@ -1,87 +0,0 @@
//
// SplashScreenWindow.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2019
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using MBS.Framework.Drawing;
using MBS.Framework.UserInterface;
using MBS.Framework.UserInterface.Controls;
using MBS.Framework.UserInterface.Drawing;
using MBS.Framework.UserInterface.Layouts;
namespace UniversalEditor.UserInterface
{
public class SplashScreenWindow : Window
{
public SplashScreenWindow()
{
this.Decorated = false;
this.Layout = new BoxLayout(Orientation.Vertical);
this.StartPosition = WindowStartPosition.Center;
PictureFrame image = new PictureFrame();
if (System.IO.File.Exists("splash.bmp"))
{
image.Image = Image.FromFile("splash.bmp");
}
else
{
image.Image = Image.FromName("universal-editor", 300);
this.Size = new Dimension2D(300, 300);
}
Label lbl = new Label("Universal Editor");
lbl.Attributes.Add("scale", 1.4);
this.Controls.Add(image, new BoxLayout.Constraints(true, true));
// this.Controls.Add(lbl, new BoxLayout.Constraints(true, true));
}
protected override void OnRealize(EventArgs e)
{
base.OnRealize(e);
OnShown(e);
}
private static bool created = false;
protected override void OnMapped(EventArgs e)
{
base.OnMapped(e);
if (created) return;
created = true;
}
public void SetStatus(string message, int progressValue, int progressMinimum, int progressMaximum)
{
}
}
public class SplashScreenSettings
{
public bool Enabled { get; set; }
public string ImageFileName { get; set; }
public string SoundFileName { get; set; }
// private Image mvarImage = null;
// public Image Image { get { return mvarImage; } set { mvarImage = value; } }
public System.IO.MemoryStream Sound { get; set; }
}
}

View File

@ -81,7 +81,6 @@
<Compile Include="WindowState.cs" />
<Compile Include="StockCommandType.cs" />
<Compile Include="MainWindow.cs" />
<Compile Include="SplashScreenWindow.cs" />
<Compile Include="Panels\ErrorListPanel.cs" />
<Compile Include="Panel.cs" />
<Compile Include="MenuBar.cs" />