Skip to content

Commit

Permalink
Merge pull request #9949 from keymanapp/feat/developer/tike-2.0-projects
Browse files Browse the repository at this point in the history
feat(developer): Support v2.0 projects in TIKE 🦕
  • Loading branch information
mcdurdin authored Nov 15, 2023
2 parents f70c1e8 + 4c5a910 commit a937f3c
Show file tree
Hide file tree
Showing 25 changed files with 722 additions and 362 deletions.
2 changes: 1 addition & 1 deletion common/windows/delphi/general/utilfiletypes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TKeymanFileTypeInfo = class
end;

type
TKeymanProjectType = (kptUnknown, kptBasic, kptBlank, kptImportWindowsKeyboard, kptBlankLexicalModel, kptWordlistLexicalModel);
TKeymanProjectType = (kptUnknown, kptBasic, kptImportWindowsKeyboard, kptWordlistLexicalModel);

implementation

Expand Down
25 changes: 11 additions & 14 deletions developer/src/tike/actions/dmActionsMain.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ object modActionsMain: TmodActionsMain
OnExecute = actViewCharacterIdentifierExecute
OnUpdate = actViewCharacterIdentifierUpdate
end
object actProjectOpenFolder: TBrowseForFolder
Category = 'Project'
Caption = 'Open Project Folder...'
DialogCaption = 'Open Project Folder'
BrowseOptions = []
BrowseOptionsEx = []
Hint = 'Open Project Folder|Opens an existing project folder'
ShortCut = 24655
UseFileDialog = True
OnAccept = actProjectOpenFolderAccept
end
object actFileOpen: TFileOpen
Category = 'File'
Caption = '&Open...'
Expand Down Expand Up @@ -248,22 +259,8 @@ object modActionsMain: TmodActionsMain
Dialog.Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist, ofEnableSizing]
Hint = 'Open Project|Opens an existing project'
ImageIndex = 28
ShortCut = 16463
OnAccept = actProjectOpenAccept
end
object actProjectSaveAs: TFileSaveAs
Category = 'Project'
Caption = 'Save Project &As...'
Dialog.DefaultExt = 'kpj'
Dialog.Filter = 'Keyman Developer Project Files (*.kpj)|*.kpj|All Files (*.*)|*.*'
Dialog.Options = [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist, ofEnableSizing]
Dialog.Title = 'Save Project As'
Dialog.OnCanClose = actProjectSaveAsSaveDialogCanClose
Hint = 'Save Project As|Saves the current project with a new name'
BeforeExecute = actProjectSaveAsBeforeExecute
OnAccept = actProjectSaveAsAccept
OnUpdate = actProjectSaveAsUpdate
end
object actProjectAddCurrentEditorFile: TAction
Category = 'Project'
Caption = '&Current Editor File'
Expand Down
63 changes: 19 additions & 44 deletions developer/src/tike/actions/dmActionsMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TmodActionsMain = class(TDataModule)
actViewStatusBar: TAction;
actProjectNew: TAction;
actProjectOpen: TFileOpen;
actProjectSaveAs: TFileSaveAs;
actProjectAddCurrentEditorFile: TAction;
actProjectAddFiles: TFileOpen;
actProjectSettings: TAction;
Expand Down Expand Up @@ -139,6 +138,7 @@ TmodActionsMain = class(TDataModule)
actToolsWebConfigure: TAction;
actToolsWebStartServer: TAction;
actToolsWebStopServer: TAction;
actProjectOpenFolder: TBrowseForFolder;
procedure actFileNewExecute(Sender: TObject);
procedure DataModuleCreate(Sender: TObject);
procedure actFileOpenAccept(Sender: TObject);
Expand Down Expand Up @@ -169,11 +169,9 @@ TmodActionsMain = class(TDataModule)
procedure actToolsOptionsExecute(Sender: TObject);
procedure actToolsVirtualKeyIdentifierExecute(Sender: TObject);
procedure actProjectNewExecute(Sender: TObject);
procedure actProjectSaveAsBeforeExecute(Sender: TObject);
procedure actProjectAddCurrentEditorFileExecute(Sender: TObject);
procedure actProjectSettingsExecute(Sender: TObject);
procedure actProjectOpenAccept(Sender: TObject);
procedure actProjectSaveAsAccept(Sender: TObject);
procedure actProjectAddFilesAccept(Sender: TObject);
procedure actProjectAddCurrentEditorFileUpdate(Sender: TObject);
procedure actHelpContentsExecute(Sender: TObject);
Expand Down Expand Up @@ -224,12 +222,9 @@ TmodActionsMain = class(TDataModule)
procedure actViewCharacterIdentifierExecute(Sender: TObject); // I4807
procedure actViewCharacterIdentifierUpdate(Sender: TObject);
procedure actFileSaveAsSaveDialogCanClose(Sender: TObject;
var CanClose: Boolean);
procedure actProjectSaveAsSaveDialogCanClose(Sender: TObject;
var CanClose: Boolean); // I4807
procedure actProjectCloseExecute(Sender: TObject);
procedure actProjectCloseUpdate(Sender: TObject);
procedure actProjectSaveAsUpdate(Sender: TObject);
procedure actProjectAddFilesUpdate(Sender: TObject);
procedure actProjectSettingsUpdate(Sender: TObject);
procedure actFileNewUpdate(Sender: TObject);
Expand All @@ -243,12 +238,12 @@ TmodActionsMain = class(TDataModule)
procedure actToolsWebStartServerUpdate(Sender: TObject);
procedure actToolsWebStopServerExecute(Sender: TObject);
procedure actToolsWebStopServerUpdate(Sender: TObject);
procedure actProjectOpenFolderAccept(Sender: TObject);
private
function CheckFilenameConventions(FileName: string): Boolean;
function SaveAndCloseAllFiles: Boolean;
procedure CloseProject;
public
procedure NewProject(pt: TProjectType);
procedure OpenProject(FileName: WideString);
end;

Expand Down Expand Up @@ -540,8 +535,12 @@ procedure TmodActionsMain.actProjectAddCurrentEditorFileExecute(

procedure TmodActionsMain.actProjectAddCurrentEditorFileUpdate(Sender: TObject);
begin
actProjectAddCurrentEditorFile.Visible :=
not IsGlobalProjectUIReady or
(FGlobalProject.Options.Version = pv10);
actProjectAddCurrentEditorFile.Enabled :=
IsGlobalProjectUIReady and
(FGlobalProject.Options.Version = pv10) and
Assigned(frmKeymanDeveloper.ActiveEditor) and
not frmKeymanDeveloper.ActiveEditor.Untitled and
(not Assigned(frmKeymanDeveloper.ActiveEditor.ProjectFile) or
Expand All @@ -561,7 +560,11 @@ procedure TmodActionsMain.actProjectAddFilesAccept(Sender: TObject);

procedure TmodActionsMain.actProjectAddFilesUpdate(Sender: TObject);
begin
actProjectAddFiles.Enabled := IsGlobalProjectUIReady;
actProjectAddFiles.Visible :=
not IsGlobalProjectUIReady or
(FGlobalProject.Options.Version = pv10);
actProjectAddFiles.Enabled := IsGlobalProjectUIReady and
(FGlobalProject.Options.Version = pv10);
end;

procedure TmodActionsMain.actProjectCloseExecute(Sender: TObject);
Expand All @@ -588,10 +591,17 @@ procedure TmodActionsMain.actProjectOpenAccept(Sender: TObject);
OpenProject(actProjectOpen.Dialog.FileName);
end;

procedure TmodActionsMain.actProjectOpenFolderAccept(Sender: TObject);
begin
if not frmKeymanDeveloper.BeforeOpenProject then
Exit;
OpenProject(actProjectOpenFolder.Folder);
end;

procedure TmodActionsMain.OpenProject(FileName: WideString);
begin
FileName := ExpandUNCFileName(FileName);
if (FileName <> '') and not FileExists(FileName) then
if (FileName <> '') and not FileExists(FileName) and not DirectoryExists(FileName) then
begin
ShowMessage('The project '+FileName+' does not exist.');
Exit;
Expand All @@ -608,18 +618,6 @@ procedure TmodActionsMain.OpenProject(FileName: WideString);
frmKeymanDeveloper.UpdateCaption;
end;

procedure TmodActionsMain.NewProject(pt: TProjectType);
begin
if IsGlobalProjectUIReady then
begin
if not SaveAndCloseAllFiles then Exit;
FreeGlobalProjectUI;
end;
NewGlobalProjectUI(pt);
frmKeymanDeveloper.ShowProject;
frmKeymanDeveloper.UpdateCaption;
end;

procedure TmodActionsMain.CloseProject;
begin
if IsGlobalProjectUIReady then
Expand All @@ -631,29 +629,6 @@ procedure TmodActionsMain.CloseProject;
frmKeymanDeveloper.UpdateCaption;
end;

procedure TmodActionsMain.actProjectSaveAsAccept(Sender: TObject);
begin
FGlobalProject.FileName := actProjectSaveAs.Dialog.FileName;
FGlobalProject.Save;
frmKeymanDeveloper.ProjectMRU.Add(FGlobalProject.FileName);
end;

procedure TmodActionsMain.actProjectSaveAsBeforeExecute(Sender: TObject);
begin
actProjectSaveAs.Dialog.FileName := FGlobalProject.FileName;
end;

procedure TmodActionsMain.actProjectSaveAsSaveDialogCanClose(Sender: TObject;
var CanClose: Boolean);
begin
CanClose := CheckFilenameConventions((Sender as TSaveDialog).FileName);
end;

procedure TmodActionsMain.actProjectSaveAsUpdate(Sender: TObject);
begin
actProjectSaveAs.Enabled := IsGlobalProjectUIReady;
end;

procedure TmodActionsMain.actProjectSettingsExecute(Sender: TObject);
begin
with TfrmProjectSettings.Create(Screen.ActiveForm) do // I4688
Expand Down
4 changes: 1 addition & 3 deletions developer/src/tike/dialogs/UfrmNew.pas
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ procedure TfrmNew.FormCreate(Sender: TObject);
i: Integer;
begin
inherited;
if FGlobalProject.Untitled
then FRootPath := FKeymanDeveloperOptions.DefaultProjectPath
else FRootPath := ExtractFilePath(FGlobalProject.FileName);
FRootPath := ExtractFilePath(FGlobalProject.FileName);

lvItems.Selected := lvItems.Items[0];
lvItems.ItemFocused := lvItems.Items[0];
Expand Down
6 changes: 3 additions & 3 deletions developer/src/tike/main/UfrmMain.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -2935,8 +2935,8 @@ inherited frmKeymanDeveloper: TfrmKeymanDeveloper
object OpenProject1: TMenuItem
Action = modActionsMain.actProjectOpen
end
object SaveProjectAs1: TMenuItem
Action = modActionsMain.actProjectSaveAs
object OpenProjectFolder1: TMenuItem
Action = modActionsMain.actProjectOpenFolder
end
object CloseProject1: TMenuItem
Action = modActionsMain.actProjectClose
Expand All @@ -2950,7 +2950,7 @@ inherited frmKeymanDeveloper: TfrmKeymanDeveloper
object N26: TMenuItem
Caption = '-'
end
object Addtoproject1: TMenuItem
object mnuProjectAddToProject: TMenuItem
Caption = 'A&dd to project'
object CurrentEditorFile1: TMenuItem
Action = modActionsMain.actProjectAddCurrentEditorFile
Expand Down
30 changes: 19 additions & 11 deletions developer/src/tike/main/UfrmMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,11 @@ TfrmKeymanDeveloper = class(TTikeForm, IUnicodeDataUIManager, IDragDrop)
CodeFont1: TMenuItem;
NewProject1: TMenuItem;
OpenProject1: TMenuItem;
SaveProjectAs1: TMenuItem;
N25: TMenuItem;
mnuProjectsRecent: TMenuItem;
N26: TMenuItem;
N27: TMenuItem;
Addtoproject1: TMenuItem;
mnuProjectAddToProject: TMenuItem;
CurrentEditorFile1: TMenuItem;
OtherFiles1: TMenuItem;
ProjectSettings1: TMenuItem;
Expand Down Expand Up @@ -285,6 +284,7 @@ TfrmKeymanDeveloper = class(TTikeForm, IUnicodeDataUIManager, IDragDrop)
Stopserver1: TMenuItem;
ToolButton13: TToolButton;
ToolButton16: TToolButton;
OpenProjectFolder1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure mnuFileClick(Sender: TObject);
Expand Down Expand Up @@ -549,10 +549,11 @@ procedure TfrmKeymanDeveloper.FormCreate(Sender: TObject);
RemoveOldestTikeTestFonts(False);

if (FActiveProject <> '') and not FileExists(FActiveProject) then
// TODO: we need to support folder-based projects here
FActiveProject := '';

if FActiveProject <> '' then
LoadGlobalProjectUI(ptUnknown, FActiveProject, True);
LoadGlobalProjectUI(ptUnknown, FActiveProject);

InitDock;

Expand Down Expand Up @@ -628,10 +629,7 @@ procedure TfrmKeymanDeveloper.DoCloseCleanup;
begin
if IsGlobalProjectUIReady then
begin
if FGlobalProject.Untitled
then FGlobalProject.PersistUntitledProject // I1010: Persist untitled project
else FGlobalProject.Save; // I4691

FGlobalProject.Save; // I4691
WriteString(SRegValue_ActiveProject, FGlobalProject.FileName);
end
else
Expand Down Expand Up @@ -1133,8 +1131,16 @@ function TfrmKeymanDeveloper.OpenFile(FFileName: string; FCloseNewFile: Boolean)
begin
if not IsGlobalProjectUIReady then
begin
// TODO: we need to open the parent folder as a project, if possible
// This can happen if we get a file opened via Explorer.
modActionsMain.NewProject(ptKeyboard);
ShowMessage('TODO -- open parent folder as project');
Exit(nil);
end;

if DirectoryExists(FFileName) then
begin
// This is an attempt to open a project folder?
// TODO
end;

Result := nil;
Expand Down Expand Up @@ -1400,6 +1406,9 @@ procedure TfrmKeymanDeveloper.mnuProjectClick(Sender: TObject);
end;

mnuProjectsRecent.Enabled := FProjectMRU.FileCount > 0;

mnuProjectAddToProject.Visible := not IsGlobalProjectUIReady or
(FGlobalProject.Options.Version = pv10);
end;

procedure TfrmKeymanDeveloper.mnuProjectRecentFileClick(Sender: TObject);
Expand Down Expand Up @@ -1494,9 +1503,8 @@ procedure TfrmKeymanDeveloper.UpdateCaption;
begin
if not IsGlobalProjectUIReady then
Caption := 'Keyman Developer'
else if FGlobalProject.Untitled
then Caption := '(Untitled project) - Keyman Developer'
else Caption := ChangeFileExt(ExtractFileName(FGlobalProject.FileName), '') + ' - Keyman Developer';
else
Caption := ChangeFileExt(ExtractFileName(FGlobalProject.FileName), '') + ' - Keyman Developer';
end;

procedure TfrmKeymanDeveloper.UpdateChildCaption(Window: TfrmTikeChild);
Expand Down
Loading

0 comments on commit a937f3c

Please sign in to comment.