From 46416845011e0a71cfa470e13d850564d343541b Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 5 Dec 2023 15:08:05 +0700 Subject: [PATCH] fix(developer): prevent opening .kpj in multiple processes Fixes #10003. Multiple small fixes required here: * Add .kpj as an editable file type * Ensure that when OpenFile returns nil (which it always will for a .kpj), that we don't crash * Ensure that projects open in a new process rather than replacing the current project session Adds a TODO for New Project -- this should be opened in a new process if we already have a project open in the current process. Will push this into a separate PR. --- developer/src/tike/actions/dmActionsMain.pas | 5 ++--- developer/src/tike/main/UfrmMain.pas | 18 +++++++++++++++--- ...n.Developer.System.Project.ProjectFiles.pas | 2 ++ ...man.Developer.UI.Project.ProjectFilesUI.pas | 7 +++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/developer/src/tike/actions/dmActionsMain.pas b/developer/src/tike/actions/dmActionsMain.pas index 06d1ecd7770..eff73c4d8ec 100644 --- a/developer/src/tike/actions/dmActionsMain.pas +++ b/developer/src/tike/actions/dmActionsMain.pas @@ -576,6 +576,7 @@ procedure TmodActionsMain.actProjectCloseUpdate(Sender: TObject); procedure TmodActionsMain.actProjectNewExecute(Sender: TObject); begin + // TODO: new process if not frmKeymanDeveloper.BeforeOpenProject then Exit; ShowNewProjectForm(frmKeymanDeveloper); @@ -583,9 +584,7 @@ procedure TmodActionsMain.actProjectNewExecute(Sender: TObject); procedure TmodActionsMain.actProjectOpenAccept(Sender: TObject); begin - if not frmKeymanDeveloper.BeforeOpenProject then - Exit; - OpenProject(actProjectOpen.Dialog.FileName); + frmKeymanDeveloper.OpenProject(actProjectOpen.Dialog.FileName); end; procedure TmodActionsMain.OpenProject(FileName: WideString); diff --git a/developer/src/tike/main/UfrmMain.pas b/developer/src/tike/main/UfrmMain.pas index 70720146a68..53fd7e378e7 100644 --- a/developer/src/tike/main/UfrmMain.pas +++ b/developer/src/tike/main/UfrmMain.pas @@ -444,6 +444,7 @@ TfrmKeymanDeveloper = class(TTikeForm, IUnicodeDataUIManager, IDragDrop) procedure RefreshOptions; function OpenEditor(FFileName: string; frmClass: TfrmTikeEditorClass): TfrmTikeEditor; + procedure OpenProject(const filename: string); function OpenFile(FFileName: string; FCloseNewFile: Boolean): TfrmTikeChild; procedure OpenFilesInProject(FFileNames: TArray); @@ -1563,11 +1564,22 @@ procedure TfrmKeymanDeveloper.mnuProjectClick(Sender: TObject); end; procedure TfrmKeymanDeveloper.mnuProjectRecentFileClick(Sender: TObject); +var + filename: string; begin - with Sender as TMenuItem do + filename := (Sender as TMenuItem).Hint; + OpenProject(filename); +end; + +procedure TfrmKeymanDeveloper.OpenProject(const filename: string); +begin + if IsGlobalProjectUIReady then + begin + OpenFilesInProject([filename]); + end + else if BeforeOpenProject then begin - if BeforeOpenProject then - modActionsMain.OpenProject(Hint); + modActionsMain.OpenProject(filename); end; end; diff --git a/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFiles.pas b/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFiles.pas index 2f79dccbe38..112fcee68f7 100644 --- a/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFiles.pas +++ b/developer/src/tike/project/Keyman.Developer.System.Project.ProjectFiles.pas @@ -70,5 +70,7 @@ initialization RegisterProjectFileType('.html', TOpenableProjectFile); // I1769 RegisterProjectFileType('.xml', TOpenableProjectFile); // I1769 RegisterProjectFileType('.js', TOpenableProjectFile); + RegisterProjectFileType('.kpj', TOpenableProjectFile); + RegisterProjectFileType('.user', TOpenableProjectFile); end. diff --git a/developer/src/tike/project/Keyman.Developer.UI.Project.ProjectFilesUI.pas b/developer/src/tike/project/Keyman.Developer.UI.Project.ProjectFilesUI.pas index 063b1106fa2..61c0321630d 100644 --- a/developer/src/tike/project/Keyman.Developer.UI.Project.ProjectFilesUI.pas +++ b/developer/src/tike/project/Keyman.Developer.UI.Project.ProjectFilesUI.pas @@ -146,8 +146,11 @@ function TOpenableProjectFileUI.GetProjectFile: TOpenableProjectFile; procedure TOpenableProjectFileUI.OpenFile; begin FMDIChild := frmKeymanDeveloper.OpenFile(ProjectFile.FileName, False); - FMDIChild.OnCloseFile := CloseFile; - FMDIChild.ProjectFile := ProjectFile; + if Assigned(FMDIChild) then + begin + FMDIChild.OnCloseFile := CloseFile; + FMDIChild.ProjectFile := ProjectFile; + end; end; function TOpenableProjectFileUI.WindowOpen: Boolean;