Skip to content

Commit

Permalink
feat(developer): Actions to support LdmlKeyboardEditor
Browse files Browse the repository at this point in the history
Adds actions to support LdmlKeyboardEditor, and refactors and
reorganizes the existing actions along the way to make them clearer.

Compile, Install, and Uninstall supported at this time
  • Loading branch information
mcdurdin committed Nov 8, 2023
1 parent 7c937e7 commit a923537
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 45 deletions.
7 changes: 6 additions & 1 deletion developer/src/tike/actions/dmActionsKeyboardEditor.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ object modActionsKeyboardEditor: TmodActionsKeyboardEditor
Width = 408
object actionsKeyboardEditor: TActionList
Images = frmKeymanDeveloper.lstImages
OnUpdate = actionsKeyboardEditorUpdate
Left = 60
Top = 24
object actKeyboardCompile: TAction
Expand All @@ -27,32 +26,38 @@ object modActionsKeyboardEditor: TmodActionsKeyboardEditor
ImageIndex = 41
ShortCut = 16504
OnExecute = actKeyboardInstallExecute
OnUpdate = actKeyboardInstallUpdate
end
object actKeyboardUninstall: TAction
Category = 'Keyboard'
Caption = '&Uninstall...'
ImageIndex = 42
OnExecute = actKeyboardUninstallExecute
OnUpdate = actKeyboardUninstallUpdate
end
object actKeyboardTest: TAction
Category = 'Keyboard'
Caption = '&Test Keyboard'
OnExecute = actKeyboardTestExecute
OnUpdate = actKeyboardTestUpdate
end
object actKeyboardTestKeymanWeb: TAction
Category = 'Keyboard'
Caption = 'Test &Keyboard on web'
OnExecute = actKeyboardTestKeymanWebExecute
OnUpdate = actKeyboardTestKeymanWebUpdate
end
object actKeyboardFontHelper: TAction
Category = 'Keyboard'
Caption = 'Font &Helper...'
OnExecute = actKeyboardFontHelperExecute
OnUpdate = actKeyboardFontHelperUpdate
end
object actKeyboardFonts: TAction
Category = 'Keyboard'
Caption = '&Fonts...'
OnExecute = actKeyboardFontsExecute
OnUpdate = actKeyboardFontsUpdate
end
end
end
142 changes: 103 additions & 39 deletions developer/src/tike/actions/dmActionsKeyboardEditor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ TmodActionsKeyboardEditor = class(TDataModule)
actKeyboardFontHelper: TAction;
actKeyboardFonts: TAction;
procedure actKeyboardCompileExecute(Sender: TObject);
procedure actionsKeyboardEditorUpdate(Action: TBasicAction;
var Handled: Boolean);
procedure actKeyboardIncludeDebugInformationExecute(Sender: TObject);
procedure actKeyboardInstallExecute(Sender: TObject);
procedure actKeyboardUninstallExecute(Sender: TObject);
Expand All @@ -72,6 +70,12 @@ TmodActionsKeyboardEditor = class(TDataModule)
procedure actKeyboardFontHelperExecute(Sender: TObject);
procedure actKeyboardFontsExecute(Sender: TObject);
procedure actKeyboardCompileUpdate(Sender: TObject);
procedure actKeyboardInstallUpdate(Sender: TObject);
procedure actKeyboardUninstallUpdate(Sender: TObject);
procedure actKeyboardTestUpdate(Sender: TObject);
procedure actKeyboardTestKeymanWebUpdate(Sender: TObject);
procedure actKeyboardFontHelperUpdate(Sender: TObject);
procedure actKeyboardFontsUpdate(Sender: TObject);
end;

var
Expand Down Expand Up @@ -129,33 +133,57 @@ function ActivePackageEditor: TfrmPackageEditor;

function ActiveLdmlKeyboardProjectFile: TxmlLdmlProjectFile;
begin
Result := ActiveLdmlKeyboardEditor.ProjectFile as TxmlLdmlProjectFile;
if ActiveLdmlKeyboardEditor = nil
then Result := nil
else Result := ActiveLdmlKeyboardEditor.ProjectFile as TxmlLdmlProjectFile;
end;

function ActiveKmnKeyboardProjectFile: TkmnProjectFile;
begin
Result := ActiveKmnKeyboardEditor.ProjectFile as TkmnProjectFile;
if ActiveKmnKeyboardEditor = nil
then Result := nil
else Result := ActiveKmnKeyboardEditor.ProjectFile as TkmnProjectFile;
end;

function ActivePackageProjectFile: TkpsProjectFile;
begin
Result := ActivePackageEditor.ProjectFile as TkpsProjectFile;
if ActivePackageEditor = nil
then Result := nil
else Result := ActivePackageEditor.ProjectFile as TkpsProjectFile;
end;

procedure TmodActionsKeyboardEditor.actionsKeyboardEditorUpdate(Action: TBasicAction; var Handled: Boolean);
function ActiveProjectFileUI: TProjectFileUI;
begin
with Action as TAction do
begin
if not Assigned(Action.OnUpdate) then
begin
Enabled := ActiveKmnKeyboardEditor <> nil;
if not Enabled then Handled := True;
end;
end;
if ActiveKmnKeyboardProjectFile <> nil then
Result := ActiveKmnKeyboardProjectFile.UI as TProjectFileUI
else if ActiveLdmlKeyboardProjectFile <> nil then
Result := ActiveLdmlKeyboardProjectFile.UI as TProjectFileUI
else if ActivePackageProjectFile <> nil then
Result := ActivePackageProjectFile.UI as TProjectFileUI
else
Result := nil;
end;

{ ---- Keyboard Menu ---- }

procedure TmodActionsKeyboardEditor.actKeyboardCompileUpdate(Sender: TObject);
begin
// TODO: Split Keyboard menu and package editor functions
actKeyboardCompile.Enabled :=
(ActiveKmnKeyboardEditor <> nil) or
(ActiveLdmlKeyboardEditor <> nil) or
(ActivePackageEditor <> nil) or
((frmKeymanDeveloper.ActiveChild is TfrmProject) and (FGlobalProject <> nil));

if actKeyboardCompile.Enabled
then actKeyboardCompile.ShortCut := Vcl.Menus.Shortcut(VK_F7, [])
else actKeyboardCompile.ShortCut := scNone;

// This is a little side-effecty
frmKeymanDeveloper.mnuKeyboard.Visible := True;
frmKeymanDeveloper.mnuDebug.Visible := ActiveKmnKeyboardEditor <> nil;
end;

procedure TmodActionsKeyboardEditor.actKeyboardCompileExecute(Sender: TObject); // I4504
var
DebugReset: Boolean;
Expand All @@ -169,63 +197,76 @@ procedure TmodActionsKeyboardEditor.actKeyboardCompileExecute(Sender: TObject);
if not ActiveKmnKeyboardEditor.PrepareForBuild(DebugReset) then
Exit;

if (ActiveKmnKeyboardProjectFile.UI as TProjectFileUI).DoAction(pfaCompile, False) and DebugReset then // I4686
if ActiveProjectFileUI.DoAction(pfaCompile, False) and DebugReset then // I4686
ActiveKmnKeyboardEditor.StartDebugging;
end
else if ActiveLdmlKeyboardEditor <> nil then
begin
ActiveProjectFileUI.DoAction(pfaCompile, False);
end
else if ActivePackageEditor <> nil then
begin
(ActivePackageProjectFile.UI as TProjectFileUI).DoAction(pfaCompile, False);
ActiveProjectFileUI.DoAction(pfaCompile, False);
end
else if frmKeymanDeveloper.ActiveChild is TfrmProject then
begin
(frmKeymanDeveloper.ActiveChild as TfrmProject).CompileAll;
end;
end;

procedure TmodActionsKeyboardEditor.actKeyboardCompileUpdate(Sender: TObject);
begin
// TODO: Split Keyboard menu and package editor functions
actKeyboardCompile.Enabled :=
(ActiveKmnKeyboardEditor <> nil) or
(ActivePackageEditor <> nil) or
((frmKeymanDeveloper.ActiveChild is TfrmProject) and (FGlobalProject <> nil));
//------------------------------------------------------------------------------

if actKeyboardCompile.Enabled
then actKeyboardCompile.ShortCut := Vcl.Menus.Shortcut(VK_F7, [])
else actKeyboardCompile.ShortCut := scNone;

frmKeymanDeveloper.mnuKeyboard.Visible := True;
frmKeymanDeveloper.mnuDebug.Visible := ActiveKmnKeyboardEditor <> nil;
procedure TmodActionsKeyboardEditor.actKeyboardFontHelperUpdate(
Sender: TObject);
begin
actKeyboardFontHelper.Enabled := (ActiveKmnKeyboardProjectFile <> nil);
end;

procedure TmodActionsKeyboardEditor.actKeyboardFontHelperExecute(
Sender: TObject);
begin
(ActiveKmnKeyboardProjectFile.UI as TProjectFileUI).DoAction(pfaFontHelper, False) // I4687
ActiveProjectFileUI.DoAction(pfaFontHelper, False) // I4687
end;

procedure TmodActionsKeyboardEditor.actKeyboardFontsExecute(Sender: TObject); // I4057
//------------------------------------------------------------------------------

procedure TmodActionsKeyboardEditor.actKeyboardFontsUpdate(Sender: TObject);
begin
(ActiveKmnKeyboardProjectFile.UI as TProjectFileUI).DoAction(pfaFontDialog, False); // I4687
actKeyboardFonts.Enabled := (ActiveKmnKeyboardProjectFile <> nil);
end;

procedure TmodActionsKeyboardEditor.actKeyboardIncludeDebugInformationExecute(Sender: TObject);
procedure TmodActionsKeyboardEditor.actKeyboardFontsExecute(Sender: TObject); // I4057
begin
(ActiveKmnKeyboardProjectFile.UI as TkmnProjectFileUI).Debug := not (ActiveKmnKeyboardProjectFile.UI as TkmnProjectFileUI).Debug; // I4687
ActiveProjectFileUI.DoAction(pfaFontDialog, False); // I4687
end;

//------------------------------------------------------------------------------

procedure TmodActionsKeyboardEditor.actKeyboardIncludeDebugInformationUpdate(
Sender: TObject);
begin
actKeyboardIncludeDebugInformation.Enabled := ActiveKmnKeyboardEditor <> nil;
if (ActiveKmnKeyboardEditor <> nil) and (ActiveKmnKeyboardProjectFile <> nil)
then actKeyboardIncludeDebugInformation.Checked := (ActiveKmnKeyboardProjectFile.UI as TkmnProjectFileUI).Debug // I4687
then actKeyboardIncludeDebugInformation.Checked := (ActiveProjectFileUI as TkmnProjectFileUI).Debug // I4687
else actKeyboardIncludeDebugInformation.Checked := False;
end;

procedure TmodActionsKeyboardEditor.actKeyboardIncludeDebugInformationExecute(Sender: TObject);
begin
(ActiveProjectFileUI as TkmnProjectFileUI).Debug := not (ActiveProjectFileUI as TkmnProjectFileUI).Debug; // I4687
end;

//------------------------------------------------------------------------------

procedure TmodActionsKeyboardEditor.actKeyboardInstallUpdate(Sender: TObject);
begin
actKeyboardInstall.Enabled := ActiveProjectFileUI <> nil;
end;

procedure TmodActionsKeyboardEditor.actKeyboardInstallExecute(Sender: TObject);
begin
try
(ActiveKmnKeyboardProjectFile.UI as TProjectFileUI).DoAction(pfaInstall, False); // I4687
//WideShowMessage('Keyboard installed successfully.');
ActiveProjectFileUI.DoAction(pfaInstall, False); // I4687
except
on E:EOleException do // I654
begin
Expand All @@ -234,22 +275,45 @@ procedure TmodActionsKeyboardEditor.actKeyboardInstallExecute(Sender: TObject);
end;
end;

//------------------------------------------------------------------------------

procedure TmodActionsKeyboardEditor.actKeyboardTestUpdate(Sender: TObject);
begin
actKeyboardTest.Enabled := (ActiveKmnKeyboardEditor <> nil);
// TODO: test xml keyboards in editor
end;

procedure TmodActionsKeyboardEditor.actKeyboardTestExecute(Sender: TObject);
begin
ActiveKmnKeyboardEditor.DebugForm.UIStatus := duiTest;
ActiveKmnKeyboardEditor.StartDebugging(True);
end;

//------------------------------------------------------------------------------

procedure TmodActionsKeyboardEditor.actKeyboardTestKeymanWebUpdate(
Sender: TObject);
begin
actKeyboardTestKeymanWeb.Enabled := (ActiveKmnKeyboardEditor <> nil);
end;

procedure TmodActionsKeyboardEditor.actKeyboardTestKeymanWebExecute(
Sender: TObject);
begin
(ActiveKmnKeyboardProjectFile.UI as TProjectFileUI).DoAction(pfaTestKeymanWeb, False); // I4687
ActiveProjectFileUI.DoAction(pfaTestKeymanWeb, False); // I4687
end;

//------------------------------------------------------------------------------

procedure TmodActionsKeyboardEditor.actKeyboardUninstallUpdate(Sender: TObject);
begin
actKeyboardUninstall.Enabled := ActiveProjectFileUI <> nil;
end;

procedure TmodActionsKeyboardEditor.actKeyboardUninstallExecute(Sender: TObject);
begin
try
if (ActiveKmnKeyboardProjectFile.UI as TProjectFileUI).DoAction(pfaUninstall, False)
if ActiveProjectFileUI.DoAction(pfaUninstall, False)
then ShowMessage('Keyboard uninstalled successfully.')
else ShowMessage('Failed to uninstall keyboard.');
except
Expand Down
8 changes: 6 additions & 2 deletions developer/src/tike/main/UfrmMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,10 @@ implementation
Keyman.Developer.System.Project.ProjectFileType,
Keyman.Developer.System.Project.WelcomeRenderer,
Keyman.Developer.System.Project.ProjectLog,
Keyman.Developer.System.Project.XmlLdmlProjectFile,
Keyman.Developer.UI.Project.ProjectFileUI,
Keyman.Developer.UI.Project.ProjectUI,
Keyman.Developer.UI.UfrmLdmlKeyboardEditor,
Keyman.Developer.UI.UfrmWordlistEditor,
Keyman.Developer.UI.UfrmModelEditor,
TextFileFormat,
Expand Down Expand Up @@ -1092,10 +1094,10 @@ procedure TfrmKeymanDeveloper.cbDebugSystemKeyboard_DropDown(Sender: TObject);
}
if cbDebugSystemKeyboard.Items.Count < 2 then
begin
//modActionsDebugger.SelectedSystemKeyboard;
//modActionsKeyboardEditor.SelectedSystemKeyboard;
FillSystemKeyboardList(cbDebugSystemKeyboard.Items);
end;
//modActionsDebugger.SetupDebugSystemKeyboard(cbDebugSystemKeyboard.Strings);
//modActionsKeyboardEditor.SetupDebugSystemKeyboard(cbDebugSystemKeyboard.Strings);
end;

{-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1226,6 +1228,8 @@ function TfrmKeymanDeveloper.OpenFile(FFileName: string; FCloseNewFile: Boolean)
else if ext = '.kvks' then Result := OpenKVKEditor(FFileName)
else if ext = '.bmp' then Result := OpenEditor(FFileName, TfrmBitmapEditor)
else if ext = '.tsv' then Result := OpenTSVEditor(FFileName)
else if (ext = '.xml') and TxmlLdmlProjectFile.IsFileTypeSupported(FFileName) then
Result := OpenEditor(FFileName, TfrmLdmlKeyboardEditor)
else if FileHasModelTsExt(FFileName) then Result := OpenModelEditor(FFileName)
else Result := OpenEditor(FFileName, TfrmEditor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ implementation

Keyman.Developer.UI.UfrmMessageDlgWithSave,
UfrmMain,
UfrmEditor,
Keyman.Developer.UI.UfrmLdmlKeyboardEditor,
UfrmMDIEditor,
UKeymanTargets,
UmodWebHttpServer,
Expand Down Expand Up @@ -236,9 +236,9 @@ function TxmlLdmlProjectFileUI.UninstallKeyboard: Boolean;

function TxmlLdmlProjectFileUI.DebugKeyboard(FSilent: Boolean): Boolean;
var
editor: TfrmEditor;
editor: TfrmLdmlKeyboardEditor;
begin
editor := frmKeymanDeveloper.OpenEditor(ProjectFile.FileName, TfrmEditor) as TfrmEditor;
editor := frmKeymanDeveloper.OpenEditor(ProjectFile.FileName, TfrmLdmlKeyboardEditor) as TfrmLdmlKeyboardEditor;
// editor.StartDebugging;
Result := True;
end;
Expand Down

0 comments on commit a923537

Please sign in to comment.