Added restart capability

This commit is contained in:
Michael Becker 2014-07-19 16:00:57 -04:00
parent fde225bf1d
commit e4f97c943d
5 changed files with 89 additions and 52 deletions

View File

@ -12,6 +12,7 @@
<Separator />
<CommandReference CommandID="FilePrint" />
<Separator />
<CommandReference CommandID="FileRestart" />
<CommandReference CommandID="FileExit" />
</Items>
</Command>
@ -79,6 +80,7 @@
<Command ID="FilePrint">
<Shortcut Modifiers="Control" Key="P" />
</Command>
<Command ID="FileRestart" />
<Command ID="FileExit">
<Shortcut Modifiers="Control" Key="Q" />
</Command>

View File

@ -72,7 +72,8 @@
<Command ID="FileCloseWindow" Title="_Window" />
<Command ID="FilePrint" Title="_Print..." />
<Command ID="FileRestart" Title="_Restart" />
<Command ID="FileExit" Title="E_xit" />
<!-- Edit -->

View File

@ -30,7 +30,8 @@
<Command ID="FileCloseWindow" Title="ウィンドウ(_W)" />
<Command ID="FilePrint" Title="印刷(_P)" />
<Command ID="FileRestart" Title="リスタート(_R)" />
<Command ID="FileExit" Title="出口(_X)" />
<!-- Edit -->

View File

@ -388,15 +388,20 @@ namespace UniversalEditor.UserInterface.WindowsForms
return mw;
}
public override void ExitApplication()
protected override void RestartApplicationInternal()
{
if (LocalConfiguration.ConfirmExit)
Application.Restart();
}
protected override bool BeforeStopApplication()
{
if (ConfigurationManager.GetValue<bool>(new string[] { "Application", "ConfirmExit" }, false))
{
if (MessageBox.Show("Are you sure you wish to quit " + LocalConfiguration.ApplicationName + "?", "Quit Application", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
{
return;
}
if (MessageBox.Show("Are you sure you wish to quit " + LocalConfiguration.ApplicationName + "?", "Quit Application", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) return false;
}
return base.BeforeStopApplication();
}
protected override void StopApplicationInternal()
{
Application.Exit();
}
}

View File

@ -124,9 +124,13 @@ namespace UniversalEditor.UserInterface
{
LastWindow.CloseFile();
});
AttachCommandEventHandler("FileRestart", delegate(object sender, EventArgs e)
{
RestartApplication();
});
AttachCommandEventHandler("FileExit", delegate(object sender, EventArgs e)
{
ExitApplication();
StopApplication();
});
#endregion
#region Edit
@ -251,10 +255,6 @@ namespace UniversalEditor.UserInterface
#endregion
}
public virtual void ExitApplication()
{
}
private IHostApplicationWindowCollection mvarWindows = new IHostApplicationWindowCollection();
public IHostApplicationWindowCollection Windows { get { return mvarWindows; } }
@ -897,51 +897,79 @@ namespace UniversalEditor.UserInterface
HideSplashScreen();
}
private bool mvarRunning = false;
public bool Running { get { return mvarRunning; } }
public void StartApplication()
{
Engine.mvarCurrentEngine = this;
mvarRunning = true;
string INSTANCEID = GetType().FullName + "$2d429aa3371c421fb63b42525e51a50c$92751853175891031214292357218181357901238$";
if (ConfigurationManager.GetValue<bool>("SingleInstanceUniquePerDirectory", true))
while (mvarRunning)
{
// The single instance should be unique per directory
INSTANCEID += System.Reflection.Assembly.GetEntryAssembly().Location;
string INSTANCEID = GetType().FullName + "$2d429aa3371c421fb63b42525e51a50c$92751853175891031214292357218181357901238$";
if (ConfigurationManager.GetValue<bool>("SingleInstanceUniquePerDirectory", true))
{
// The single instance should be unique per directory
INSTANCEID += System.Reflection.Assembly.GetEntryAssembly().Location;
}
if (!SingleInstanceManager.CreateSingleInstance(INSTANCEID, new EventHandler<SingleInstanceManager.InstanceCallbackEventArgs>(SingleInstanceManager_Callback))) return;
string[] args1 = Environment.GetCommandLineArgs();
string[] args = new string[args1.Length - 1];
Array.Copy(args1, 1, args, 0, args.Length);
System.Collections.ObjectModel.Collection<string> selectedFileNames = new System.Collections.ObjectModel.Collection<string>();
foreach (string commandLineArgument in args)
{
selectedFileNames.Add(commandLineArgument);
}
mvarSelectedFileNames = new System.Collections.ObjectModel.ReadOnlyCollection<string>(selectedFileNames);
// Set up the base path for the current application. Should this be able to be
// overridden with a switch (/basepath:...) ?
mvarBasePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
BeforeInitialization();
// Initialize the branding for the selected application
InitializeBranding();
Initialize();
AfterInitializationInternal();
AfterInitialization();
OpenWindow(SelectedFileNames.ToArray<string>());
MainLoop();
SessionManager.Save();
BookmarksManager.Save();
RecentFileManager.Save();
ConfigurationManager.Save();
}
if (!SingleInstanceManager.CreateSingleInstance(INSTANCEID, new EventHandler<SingleInstanceManager.InstanceCallbackEventArgs>(SingleInstanceManager_Callback))) return;
string[] args1 = Environment.GetCommandLineArgs();
string[] args = new string[args1.Length - 1];
Array.Copy(args1, 1, args, 0, args.Length);
System.Collections.ObjectModel.Collection<string> selectedFileNames = new System.Collections.ObjectModel.Collection<string>();
foreach (string commandLineArgument in args)
{
selectedFileNames.Add(commandLineArgument);
}
mvarSelectedFileNames = new System.Collections.ObjectModel.ReadOnlyCollection<string>(selectedFileNames);
// Set up the base path for the current application. Should this be able to be
// overridden with a switch (/basepath:...) ?
mvarBasePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
BeforeInitialization();
// Initialize the branding for the selected application
InitializeBranding();
Initialize();
AfterInitializationInternal();
AfterInitialization();
OpenWindow(SelectedFileNames.ToArray<string>());
MainLoop();
SessionManager.Save();
BookmarksManager.Save();
RecentFileManager.Save();
ConfigurationManager.Save();
}
public void RestartApplication()
{
RestartApplicationInternal();
}
public void StopApplication()
{
if (!BeforeStopApplication()) return;
StopApplicationInternal();
}
protected virtual void RestartApplicationInternal()
{
StopApplication();
StartApplication();
}
protected virtual bool BeforeStopApplication()
{
return true;
}
protected virtual void StopApplicationInternal()
{
}
}
}