Add preference option to restrict number of application instances to 1. If the executable is open and called a second time, it's brought to foreground. Plus, if a filename was passed, a new tab is opened. Should fix a part of what is described in issue #1332.

This commit is contained in:
Ansgar Becker
2010-01-24 00:14:23 +00:00
parent f7ed772b29
commit 5d7b25d7e9
6 changed files with 215 additions and 12 deletions

View File

@ -5,6 +5,7 @@ uses
Forms,
SysUtils,
Dialogs,
Windows,
main in '..\..\source\main.pas' {MainForm},
about in '..\..\source\about.pas' {AboutBox},
connections in '..\..\source\connections.pas' {connform},
@ -40,14 +41,26 @@ uses
{$R ..\..\res\version.RES}
{$R ..\..\res\manifest.RES}
var
DoStop, prefAllowMultipleInstances: Boolean;
begin
debug('perf: All modules loaded.');
Application.Initialize;
Application.Title := APPNAME;
Application.UpdateFormatSettings := False;
Application.CreateForm(TMainForm, MainForm);
Application.OnMessage := Mainform.OnMessageHandler;
debug('perf: Main created.');
MainForm.Startup;
Application.Run;
prefAllowMultipleInstances := GetRegValue(REGNAME_MULTI_INSTANCES, DEFAULT_MULTI_INSTANCES);
SecondInstMsgId := RegisterWindowMessage(APPNAME);
DoStop := False;
if not prefAllowMultipleInstances then
DoStop := CheckForSecondInstance;
if DoStop then
Application.Terminate
else begin
Application.Initialize;
Application.Title := APPNAME;
Application.UpdateFormatSettings := False;
Application.CreateForm(TMainForm, MainForm);
Application.OnMessage := Mainform.OnMessageHandler;
debug('perf: Main created.');
MainForm.Startup;
Application.Run;
end;
end.