Skip to content

Commit

Permalink
fix(developer): prevent opening .kpj in multiple processes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mcdurdin committed Dec 5, 2023
1 parent ff5a366 commit 4641684
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
5 changes: 2 additions & 3 deletions developer/src/tike/actions/dmActionsMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -576,16 +576,15 @@ procedure TmodActionsMain.actProjectCloseUpdate(Sender: TObject);

procedure TmodActionsMain.actProjectNewExecute(Sender: TObject);
begin
// TODO: new process
if not frmKeymanDeveloper.BeforeOpenProject then
Exit;
ShowNewProjectForm(frmKeymanDeveloper);
end;

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);
Expand Down
18 changes: 15 additions & 3 deletions developer/src/tike/main/UfrmMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>);

Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,7 @@ initialization
RegisterProjectFileType('.html', TOpenableProjectFile); // I1769
RegisterProjectFileType('.xml', TOpenableProjectFile); // I1769
RegisterProjectFileType('.js', TOpenableProjectFile);
RegisterProjectFileType('.kpj', TOpenableProjectFile);
RegisterProjectFileType('.user', TOpenableProjectFile);
end.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4641684

Please sign in to comment.