spiegel-keyman/developer/src/tike/project/Keyman.Developer.UI.Project.ProjectUI.pas
Marc Durdin 39b7c882a3 feat(developer): Multi-process model for projects 🦕
This is a bit of an omnibus commit, apologies for that. This commit
moves Keyman Developer to a proper multi-process model, where editing
files from multiple projects is handled much more cleanly, with each
project loaded in a separate process.

Files that are edited outside of a project structure are loaded into a
'temporary project' in a single process, which provides a pathway for
existing users who may have legacy files outside the normal Keyman
Developer project model.

There are several components to this:

1. Inter-process communication (Multiprocess, CopyDataHelper units and
   multiprocess test project). These modules establish a method of
   enumerating running Keyman Developer instances (with EnumWindow),
   recording relevant metadata for each instance (by thread id) in the
   registry (registry used because it manages contention without
   additional effort from us), and communicating between processes with
   WM_COPYDATA.
2. Command-line parsing (TikeCommandLine). Determines project ownership
   (ProjectOwningFile) for each filename passed on the command-line, and
   passes these over to existing instances of Keyman Developer that have
   that project loaded, or starts new instances as needed.
3. Temporary project management. Mostly in ProjectUI.

Also, moved GlobalProjectStateWnd management out of ProjectFile.pas and
into Project.pas, alongside other global project variables.

A follow-up will add functionality to determine if a file opened within
the Keyman Developer UI should open in the same instance or in a
separate instance (see TfrmKeymanDeveloper.OpenFileInProject). This will
use the same methodology as TikeCommandLine does now, so may involve
further refactoring.

This commit establishes the idea of 'keyman.kpj' as a future default
filename for Keyman Developer projects, but does not enable it, in
ProjectOwningFile. It is planned to introduce this fixed filename in
version 18.0 (see #10113).
2023-12-01 11:48:09 +07:00

105 lines
2.5 KiB
ObjectPascal

(*
Name: Keyman.Developer.UI.Project.ProjectUI
Copyright: Copyright (C) SIL International.
Documentation:
Description:
Create Date: 4 May 2015
Modified Date: 4 May 2015
Authors: mcdurdin
Related Files:
Dependencies:
Bugs:
Todo:
Notes:
History: 04 May 2015 - mcdurdin - I4687 - V9.0 - Split project UI actions into separate classes
*)
unit Keyman.Developer.UI.Project.ProjectUI; // I4687
interface
uses
Keyman.Developer.System.Project.ProjectFile,
Keyman.Developer.UI.Project.ProjectFileUI;
function GetGlobalProjectUI: TProjectUI;
function LoadGlobalProjectUI(pt: TProjectType; AFilename: string): TProjectUI;
procedure FreeGlobalProjectUI;
function IsGlobalProjectUIReady: Boolean;
function CreateTempGlobalProjectUI(pt: TProjectType): TProjectUI;
implementation
uses
System.SysUtils,
Winapi.Windows,
Keyman.Developer.System.TikeMultiProcess,
Keyman.Developer.System.Project.Project,
utildir;
function GetGlobalProjectUI: TProjectUI;
begin
Result := FGlobalProject as TProjectUI;
end;
function IsGlobalProjectUIReady: Boolean;
begin
Result := Assigned(FGlobalProject);
end;
procedure FreeGlobalProjectUI;
begin
FreeAndNil(FGlobalProject);
TikeMultiProcess.CloseProject;
end;
function CreateTempGlobalProjectUI(pt: TProjectType): TProjectUI;
var
kpj: TProject;
AFilename: string;
begin
Assert(not Assigned(FGlobalProject));
AFileName := KGetTempFileName('.kpj');
System.SysUtils.DeleteFile(AFileName);
kpj := TProject.Create(pt, AFilename, False);
try
kpj.Options.Version := pv10;
kpj.Options.BuildPath := ''; //'$SOURCEPATH';
kpj.Options.WarnDeprecatedCode := True;
kpj.Options.CompilerWarningsAsErrors := True;
kpj.Options.CheckFilenameConventions := False;
kpj.Options.SkipMetadataFiles := True;
kpj.Save;
finally
kpj.Free;
end;
Result := TProjectUI.Create(pt, AFilename, True);
Result.IsTemporary := True;
FGlobalProject := Result;
TikeMultiProcess.OpenProject(
'', // We use the empty string to designate a temp project (* is no project)
FGlobalProject.GetTargetFilename(FGlobalProject.Options.SourcePath,
'', '')
);
end;
function LoadGlobalProjectUI(pt: TProjectType; AFilename: string): TProjectUI;
begin
Assert(not Assigned(FGlobalProject));
Result := TProjectUI.Create(pt, AFilename, True); // I4687
FGlobalProject := Result;
TikeMultiProcess.OpenProject(
FGlobalProject.FileName,
FGlobalProject.GetTargetFilename(FGlobalProject.Options.SourcePath,
'', '')
);
end;
end.