Skip to content

Commit

Permalink
Merge pull request #10114 from keymanapp/feat/developer/multi-process…
Browse files Browse the repository at this point in the history
…-file-loading

feat(developer): Multi-process model for projects 🦕
  • Loading branch information
mcdurdin authored Dec 5, 2023
2 parents 86af296 + ff5a366 commit 56d5f37
Show file tree
Hide file tree
Showing 28 changed files with 2,524 additions and 171 deletions.
4 changes: 4 additions & 0 deletions common/windows/delphi/general/RegistryKeys.pas
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ interface
SRegKey_IDEVisualKeyboard_CU = SRegKey_IDE_CU + '\VisualKeyboard'; // CU
SRegKey_IDEToolbars_CU = SRegKey_IDE_CU + '\Toolbars'; // CU

SRegKey_IDEActiveProjects_CU = SRegKey_IDE_CU + '\Active Projects'; // CU
SRegValue_ActiveProject_Filename = 'project filename';
SRegValue_ActiveProject_SourcePath = 'source path';

SRegValue_CheckForUpdates = 'check for updates'; // CU
SRegValue_LastUpdateCheckTime = 'last update check time'; // CU

Expand Down
1 change: 1 addition & 0 deletions common/windows/delphi/general/UserMessages.pas
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface

WM_USER_Modified = WM_USER + 124;
WM_USER_UpdateCaption = WM_USER + 125; // I4918
WM_USER_OpenFiles = WM_USER + 126;

const
// SyntaxHighlight
Expand Down
8 changes: 8 additions & 0 deletions common/windows/delphi/general/utilfiletypes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ TKMFileTypeInfo = record
function GetFileTypeFromFileName(const FileName: string): TKMFileType;
function GetFileTypeFilter(ft: TKMFileType; var DefaultExt: string): string;

function IsProjectFile(const FileName: string): Boolean;

// TODO-LDML: do we need to extend this to support .xml?
function IsKeyboardFile(const FileName: string): Boolean;
function RemoveFileExtension(Filename, Extension: string): string;

Expand Down Expand Up @@ -164,6 +167,11 @@ function RemoveFileExtension(Filename, Extension: string): string;
else Result := Filename;
end;

function IsProjectFile(const FileName: string): Boolean;
begin
Result := SameText(ExtractFileExt(FileName), Ext_ProjectSource);
end;

{ TKeymanFileTypeInfo }

class function TKeymanFileTypeInfo.IsPackageOptionsFile(const Filename: string): Boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ procedure TKeyboardProjectTemplate.WriteKPJ;
var
kpj: TProject;
begin
kpj := TProject.Create(ptKeyboard, GetProjectFilename);
kpj := TProject.Create(ptKeyboard, GetProjectFilename, False);
try
kpj.Options.Version := pv20;
kpj.Options.BuildPath := '$PROJECTPATH\' + SFolder_Build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ procedure TModelProjectTemplate.WriteKPJ;
var
kpj: TProject;
begin
kpj := TProject.Create(ptLexicalModel, GetProjectFilename);
kpj := TProject.Create(ptLexicalModel, GetProjectFilename, False);
try
kpj.Options.BuildPath := '$PROJECTPATH\' + SFolder_Build;
kpj.Options.WarnDeprecatedCode := True;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
object frmMultiProcess: TfrmMultiProcess
Left = 0
Top = 0
Caption = 'frmMultiProcess'
ClientHeight = 333
ClientWidth = 608
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 240
Top = 11
Width = 31
Height = 13
Caption = 'Label1'
end
object Edit1: TEdit
Left = 296
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
OnChange = Edit1Change
end
object Button1: TButton
Left = 512
Top = 8
Width = 75
Height = 25
Caption = 'New Process'
TabOrder = 1
OnClick = Button1Click
end
object lbProcess: TListBox
Left = 8
Top = 8
Width = 209
Height = 289
ItemHeight = 13
TabOrder = 2
OnDblClick = lbProcessDblClick
end
object cmdFocus: TButton
Left = 8
Top = 300
Width = 75
Height = 25
Caption = 'Focus process'
TabOrder = 3
OnClick = cmdFocusClick
end
object tmrEnumerate: TTimer
Interval = 100
OnTimer = tmrEnumerateTimer
Left = 400
Top = 112
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
unit Keyman.MultiProcess.UI.UfrmMultiProcess;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Keyman.Developer.System.MultiProcess,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;

type
TfrmMultiProcess = class(TForm)
Edit1: TEdit;
Label1: TLabel;
tmrEnumerate: TTimer;
Button1: TButton;
lbProcess: TListBox;
cmdFocus: TButton;
procedure FormCreate(Sender: TObject);
procedure tmrEnumerateTimer(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure lbProcessDblClick(Sender: TObject);
procedure cmdFocusClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
function SelectedProcess: TMultiProcessInstance;
{ Private declarations }
public
{ Public declarations }
end;

var
frmMultiProcess: TfrmMultiProcess;

implementation

uses
utilexecute;

{$R *.dfm}

procedure TfrmMultiProcess.Button1Click(Sender: TObject);
begin
TUtilExecute.Execute('"'+ParamStr(0)+'"', ExtractFileDir(ParamStr(0)), SW_SHOWNORMAL);
end;

procedure TfrmMultiProcess.cmdFocusClick(Sender: TObject);
var
p: TMultiProcessInstance;
begin
p := SelectedProcess;
if Assigned(p) then
p.BringToFront;
end;

function TfrmMultiProcess.SelectedProcess: TMultiProcessInstance;
begin
if lbProcess.ItemIndex < 0 then
Result := nil
else
Result := TMultiProcessInstance(lbProcess.Items.Objects[lbProcess.ItemIndex]);
end;

procedure TfrmMultiProcess.Edit1Change(Sender: TObject);
begin
MultiProcessCoordinator.SetProcessIdentifier(Edit1.Text);
end;

procedure TfrmMultiProcess.FormCreate(Sender: TObject);
begin
Caption := 'MultiProcess Test Form - '+IntToStr(Handle)+'/'+IntToStr(GetCurrentThreadId);
end;

procedure TfrmMultiProcess.lbProcessDblClick(Sender: TObject);
begin
cmdFocusClick(cmdFocus);
end;

procedure TfrmMultiProcess.tmrEnumerateTimer(Sender: TObject);
var
p: TMultiProcessInstance;
LastTID: Cardinal;
begin
p := SelectedProcess;
if Assigned(p) then
begin
LastTID := p.ThreadId;
end
else
LastTID := 0;

lbProcess.Clear;
MultiProcessCoordinator.Enumerate;
for p in MultiProcessCoordinator.Processes do
begin
lbProcess.Items.AddObject(
p.Handle.ToString + '/' + p.ThreadId.ToString + ': '+p.Identifier,
p);
if p.ThreadId = LastTID then
lbProcess.ItemIndex := lbProcess.Items.Count - 1;
end;
end;

end.
18 changes: 18 additions & 0 deletions developer/src/test/manual/multiprocess/multiprocess.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
program multiprocess;

uses
Vcl.Forms,
Keyman.MultiProcess.UI.UfrmMultiProcess in 'Keyman.MultiProcess.UI.UfrmMultiProcess.pas' {frmMultiProcess},
Keyman.Developer.System.MultiProcess in '..\..\..\tike\main\Keyman.Developer.System.MultiProcess.pas',
utilexecute in '..\..\..\..\..\common\windows\delphi\general\utilexecute.pas',
Unicode in '..\..\..\..\..\common\windows\delphi\general\Unicode.pas';

{$R *.res}

begin
CreateMultiProcessCoordinator(TfrmMultiProcess.ClassName, 'Software\Keyman\Test\MultiProcess');
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TfrmMultiProcess, frmMultiProcess);
Application.Run;
end.
Loading

0 comments on commit 56d5f37

Please sign in to comment.