Skip to content

Commit d838df1

Browse files
committed
feat(developer): add editor of Package Description and Examples
1 parent bf1d5b0 commit d838df1

File tree

8 files changed

+726
-43
lines changed

8 files changed

+726
-43
lines changed

common/windows/delphi/packages/PackageInfo.pas

Lines changed: 187 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface
4141
System.Generics.Collections,
4242
System.IniFiles,
4343
System.JSON,
44+
System.StrUtils,
4445
System.Sysutils,
4546
Winapi.Windows,
4647
Xml.XMLDoc,
@@ -55,17 +56,33 @@ function GetJsonValueString(o: TJSONObject; const n: string): string;
5556
function GetJsonValueBool(o: TJSONObject; const n: string): Boolean;
5657

5758
type
58-
TPackageInfoEntryType = (pietName, pietVersion, pietCopyright, pietAuthor, pietWebsite, pietOther);
59+
TPackageInfoEntryType = (
60+
pietName,
61+
pietVersion,
62+
pietCopyright,
63+
pietAuthor,
64+
pietWebsite,
65+
pietDescription,
66+
pietOther
67+
);
5968

6069
const
6170
PackageInfo_Name = 'Name';
6271
PackageInfo_Version = 'Version';
6372
PackageInfo_Copyright = 'Copyright';
6473
PackageInfo_Author = 'Author';
6574
PackageInfo_Website = 'Website';
66-
67-
PackageInfoEntryTypeNames: array[TPackageInfoEntryType] of WideString =
68-
(PackageInfo_Name, PackageInfo_Version, PackageInfo_Copyright, PackageInfo_Author, PackageInfo_Website, '');
75+
PackageInfo_Description = 'Description';
76+
77+
PackageInfoEntryTypeNames: array[TPackageInfoEntryType] of string = (
78+
PackageInfo_Name,
79+
PackageInfo_Version,
80+
PackageInfo_Copyright,
81+
PackageInfo_Author,
82+
PackageInfo_Website,
83+
PackageInfo_Description,
84+
''
85+
);
6986

7087
type
7188
EPackageInfo = class(Exception);
@@ -282,6 +299,8 @@ TPackageKeyboard = class;
282299
TPackageKeyboardList = class;
283300
TPackageKeyboardLanguage = class;
284301
TPackageKeyboardLanguageList = class;
302+
TPackageKeyboardExample = class;
303+
TPackageKeyboardExampleList = class;
285304

286305
TPackageKeyboard = class(TPackageBaseObject)
287306
private
@@ -291,6 +310,7 @@ TPackageKeyboard = class(TPackageBaseObject)
291310
FRTL: Boolean;
292311
FDisplayFont: TPackageContentFile;
293312
FLanguages: TPackageKeyboardLanguageList;
313+
FExamples: TPackageKeyboardExampleList;
294314
FVersion: string;
295315
FMinKeymanVersion: string;
296316
procedure SetDisplayFont(const Value: TPackageContentFile);
@@ -308,6 +328,7 @@ TPackageKeyboard = class(TPackageBaseObject)
308328
property RTL: Boolean read FRTL write FRTL;
309329
property Version: string read FVersion write FVersion;
310330
property Languages: TPackageKeyboardLanguageList read FLanguages;
331+
property Examples: TPackageKeyboardExampleList read FExamples;
311332
property OSKFont: TPackageContentFile read FOSKFont write SetOSKFont;
312333
property DisplayFont: TPackageContentFile read FDisplayFont write SetDisplayFont;
313334
// The following properties are used only in memory and never streamed in or out
@@ -341,6 +362,23 @@ TPackageKeyboardLanguageList = class(TPackageObjectList<TPackageKeyboardLangua
341362
function IndexOfID(const id: string): Integer;
342363
end;
343364

365+
TPackageKeyboardExample = class(TPackageBaseObject)
366+
ID: string;
367+
Keys: string;
368+
Text: string;
369+
Note: string;
370+
end;
371+
372+
TPackageKeyboardExampleList = class(TPackageObjectList<TPackageKeyboardExample>)
373+
public
374+
procedure LoadJSON(ARoot: TJSONObject); virtual;
375+
procedure SaveJSON(ARoot: TJSONObject); virtual;
376+
procedure LoadXML(ARoot: IXMLNode); virtual;
377+
procedure SaveXML(ARoot: IXMLNode); virtual;
378+
function ContainsID(const id: string): Boolean;
379+
function IndexOfID(const id: string; from: Integer = 0): Integer;
380+
end;
381+
344382
TPackageLexicalModel = class(TPackageBaseObject)
345383
private
346384
FName: string;
@@ -450,11 +488,18 @@ implementation
450488
SXML_PackageKeyboard_OSKFont = 'OSKFont';
451489
SXML_PackageKeyboard_DisplayFont = 'DisplayFont';
452490
SXML_PackageKeyboard_Languages = 'Languages';
491+
SXML_PackageKeyboard_Examples = 'Examples';
453492

454493
SXML_PackageKeyboard_Language = 'Language';
455494
SXML_PackageKeyboard_Language_ID = 'ID';
456495
SXML_PackageKeyboard_Language_Name = 'Name';
457496

497+
SXML_PackageKeyboard_Example = 'Example';
498+
SXML_PackageKeyboard_Example_ID = 'ID';
499+
SXML_PackageKeyboard_Example_Keys = 'Keys';
500+
SXML_PackageKeyboard_Example_Text = 'Text';
501+
SXML_PackageKeyboard_Example_Note = 'Note';
502+
458503
SXML_PackageLexicalModels = 'LexicalModels';
459504
SXML_PackageLexicalModel = 'LexicalModel';
460505
SXML_PackageLexicalModel_Name = 'Name';
@@ -493,14 +538,22 @@ implementation
493538
SJSON_Info__Description = 'description';
494539
SJSON_Info__URL = 'url';
495540

496-
SJSON_Info_Website = 'website';
497-
SJSON_Info_Version = 'version';
498541
SJSON_Info_Name = 'name';
542+
SJSON_Info_Version = 'version';
499543
SJSON_Info_Copyright = 'copyright';
500544
SJSON_Info_Author = 'author';
501-
502-
SJSON_PackageInfoEntryTypeNames: array[TPackageInfoEntryType] of string =
503-
(SJSON_Info_Name, SJSON_Info_Version, SJSON_Info_Copyright, SJSON_Info_Author, SJSON_Info_Website, '');
545+
SJSON_Info_Website = 'website';
546+
SJSON_Info_Description = 'description';
547+
548+
SJSON_PackageInfoEntryTypeNames: array[TPackageInfoEntryType] of string = (
549+
SJSON_Info_Name,
550+
SJSON_Info_Version,
551+
SJSON_Info_Copyright,
552+
SJSON_Info_Author,
553+
SJSON_Info_Website,
554+
SJSON_Info_Description,
555+
''
556+
);
504557

505558
SJSON_Files = 'files';
506559
SJSON_Files_Name = 'name';
@@ -519,6 +572,12 @@ implementation
519572
SJSON_Keyboard_Language_ID = 'id';
520573
SJSON_Keyboard_Language_Name = 'name';
521574

575+
SJSON_Keyboard_Examples = 'examples';
576+
SJSON_Keyboard_Example_ID = 'id';
577+
SJSON_Keyboard_Example_Keys = 'keys';
578+
SJSON_Keyboard_Example_Text = 'text';
579+
SJSON_Keyboard_Example_Note = 'note';
580+
522581
SJSON_LexicalModels = 'lexicalModels';
523582
SJSON_LexicalModel_Name = 'name';
524583
SJSON_LexicalModel_ID = 'id';
@@ -527,7 +586,7 @@ implementation
527586

528587
function XmlVarToStr(v: OleVariant): string;
529588
begin
530-
Result := Trim(VarToStr(v));
589+
Result := ReplaceStr(ReplaceStr(Trim(VarToStr(v)), #$D#$A, #$A), #$A, #$D#$A);
531590
end;
532591

533592
{-------------------------------------------------------------------------------
@@ -1822,6 +1881,7 @@ procedure TPackageKeyboard.Assign(Source: TPackageKeyboard);
18221881
var
18231882
i: Integer;
18241883
FLanguage: TPackageKeyboardLanguage;
1884+
FExample: TPackageKeyboardExample;
18251885
begin
18261886
FName := Source.Name;
18271887
FID := Source.ID;
@@ -1842,6 +1902,16 @@ procedure TPackageKeyboard.Assign(Source: TPackageKeyboard);
18421902
FLanguage.Name := Source.Languages[i].Name;
18431903
FLanguages.Add(FLanguage);
18441904
end;
1905+
FExamples.Clear;
1906+
for i := 0 to Source.Examples.Count - 1 do
1907+
begin
1908+
FExample := TPackageKeyboardExample.Create(Package);
1909+
FExample.ID := Source.Examples[i].ID;
1910+
FExample.Keys := Source.Examples[i].Keys;
1911+
FExample.Text := Source.Examples[i].Text;
1912+
FExample.Note := Source.Examples[i].Note;
1913+
FExamples.Add(FExample);
1914+
end;
18451915
end;
18461916

18471917
procedure TPackageKeyboard.SetDisplayFont(const Value: TPackageContentFile);
@@ -1861,11 +1931,13 @@ constructor TPackageKeyboard.Create(APackage: TPackage);
18611931
begin
18621932
inherited Create(APackage);
18631933
FLanguages := TPackageKeyboardLanguageList.Create(APackage);
1934+
FExamples := TPackageKeyboardExampleList.Create(APackage);
18641935
end;
18651936

18661937
destructor TPackageKeyboard.Destroy;
18671938
begin
18681939
FreeAndNil(FLanguages);
1940+
FreeAndNil(FExamples);
18691941
inherited Destroy;
18701942
end;
18711943

@@ -1990,6 +2062,7 @@ procedure TPackageKeyboardList.LoadJSON(ARoot: TJSONObject);
19902062
keyboard.OSKFont := Package.Files.FromFileNameEx(GetJsonValueString(AKeyboard, SJSON_Keyboard_OSKFont));
19912063
keyboard.DisplayFont := Package.Files.FromFileNameEx(GetJsonValueString(AKeyboard, SJSON_Keyboard_DisplayFont));
19922064
keyboard.Languages.LoadJSON(AKeyboard);
2065+
keyboard.Examples.LoadJSON(AKeyboard);
19932066
Add(keyboard);
19942067
end;
19952068
end;
@@ -2016,6 +2089,7 @@ procedure TPackageKeyboardList.LoadXML(ARoot: IXMLNode);
20162089
keyboard.DisplayFont := Package.Files.FromFileNameEx(XmlVarToStr(AKeyboard.ChildValues[SXML_PackageKeyboard_DisplayFont]));
20172090

20182091
keyboard.Languages.LoadXML(AKeyboard);
2092+
keyboard.Examples.LoadXML(AKeyboard);
20192093
Add(keyboard);
20202094
end;
20212095
end;
@@ -2071,6 +2145,7 @@ procedure TPackageKeyboardList.SaveJSON(ARoot: TJSONObject);
20712145
AKeyboard.AddPair(SJSON_Keyboard_DisplayFont, Items[i].DisplayFont.RelativeFileName);
20722146

20732147
Items[i].Languages.SaveJSON(AKeyboard);
2148+
Items[i].Examples.SaveJSON(AKeyboard);
20742149
end;
20752150
end;
20762151

@@ -2095,6 +2170,7 @@ procedure TPackageKeyboardList.SaveXML(ARoot: IXMLNode);
20952170
AKeyboard.ChildNodes[SXML_PackageKeyboard_DisplayFont].NodeValue := Items[i].DisplayFont.RelativeFileName;
20962171

20972172
Items[i].Languages.SaveXML(AKeyboard);
2173+
Items[i].Examples.SaveXML(AKeyboard);
20982174
end;
20992175
end;
21002176

@@ -2353,5 +2429,106 @@ procedure TPackageKeyboardLanguageList.SaveXML(ARoot: IXMLNode);
23532429
end;
23542430
end;
23552431

2432+
{ TPackageKeyboardExampleList }
2433+
2434+
function TPackageKeyboardExampleList.ContainsID(const id: string): Boolean;
2435+
begin
2436+
Result := IndexOfID(id) >= 0;
2437+
end;
2438+
2439+
function TPackageKeyboardExampleList.IndexOfID(const id: string;
2440+
from: Integer): Integer;
2441+
var
2442+
i: Integer;
2443+
begin
2444+
for i := from to Count - 1 do
2445+
if SameText(Items[i].ID, id) then
2446+
Exit(i);
2447+
Result := -1;
2448+
end;
2449+
2450+
procedure TPackageKeyboardExampleList.LoadJSON(ARoot: TJSONObject);
2451+
var
2452+
j: Integer;
2453+
AExample: TJSONObject;
2454+
FExample: TPackageKeyboardExample;
2455+
AExamples: TJSONArray;
2456+
begin
2457+
AExamples := ARoot.Values[SJSON_Keyboard_Examples] as TJSONArray;
2458+
if not Assigned(AExamples) then
2459+
Exit;
2460+
2461+
for j := 0 to AExamples.Count - 1 do
2462+
begin
2463+
AExample := AExamples.Items[j] as TJSONObject;
2464+
2465+
FExample := TPackageKeyboardExample.Create(Package);
2466+
FExample.ID := GetJsonValueString(AExample, SJSON_Keyboard_Example_ID);
2467+
FExample.Keys := GetJsonValueString(AExample, SJSON_Keyboard_Example_Keys);
2468+
FExample.Text := GetJsonValueString(AExample, SJSON_Keyboard_Example_Text);
2469+
FExample.Note := GetJsonValueString(AExample, SJSON_Keyboard_Example_Note);
2470+
Self.Add(FExample);
2471+
end;
2472+
end;
2473+
2474+
procedure TPackageKeyboardExampleList.LoadXML(ARoot: IXMLNode);
2475+
var
2476+
j: Integer;
2477+
AExamples, AExample: IXMLNode;
2478+
FExample: TPackageKeyboardExample;
2479+
begin
2480+
AExamples := ARoot.ChildNodes[SXML_PackageKeyboard_Examples];
2481+
if not Assigned(AExamples) then
2482+
Exit;
2483+
2484+
for j := 0 to AExamples.ChildNodes.Count - 1 do
2485+
begin
2486+
AExample := AExamples.ChildNodes[j];
2487+
2488+
FExample := TPackageKeyboardExample.Create(Package);
2489+
FExample.ID := VarToStr(AExample.Attributes[SXML_PackageKeyboard_Example_ID]);
2490+
FExample.Keys := VarToStr(AExample.Attributes[SXML_PackageKeyboard_Example_Keys]);
2491+
FExample.Text := VarToStr(AExample.Attributes[SXML_PackageKeyboard_Example_Text]);
2492+
FExample.Note := VarToStr(AExample.Attributes[SXML_PackageKeyboard_Example_Note]);
2493+
Self.Add(FExample);
2494+
end;
2495+
end;
2496+
2497+
procedure TPackageKeyboardExampleList.SaveJSON(ARoot: TJSONObject);
2498+
var
2499+
AExamples: TJSONArray;
2500+
j: Integer;
2501+
AExample: TJSONObject;
2502+
begin
2503+
AExamples := TJSONArray.Create;
2504+
ARoot.AddPair(SJSON_Keyboard_Examples, AExamples);
2505+
for j := 0 to Count - 1 do
2506+
begin
2507+
AExample := TJSONObject.Create;
2508+
AExamples.Add(AExample);
2509+
AExample.AddPair(SJSON_Keyboard_Example_ID, Items[j].ID);
2510+
AExample.AddPair(SJSON_Keyboard_Example_Keys, Items[j].Keys);
2511+
AExample.AddPair(SJSON_Keyboard_Example_Text, Items[j].Text);
2512+
AExample.AddPair(SJSON_Keyboard_Example_Note, Items[j].Note);
2513+
end;
2514+
end;
2515+
2516+
procedure TPackageKeyboardExampleList.SaveXML(ARoot: IXMLNode);
2517+
var
2518+
AExamples: IXMLNode;
2519+
j: Integer;
2520+
AExample: IXMLNode;
2521+
begin
2522+
AExamples := ARoot.AddChild(SXML_PackageKeyboard_Examples);
2523+
for j := 0 to Count - 1 do
2524+
begin
2525+
AExample := AExamples.AddChild(SXML_PackageKeyboard_Example);
2526+
AExample.Attributes[SXML_PackageKeyboard_Example_ID] := Items[j].ID;
2527+
AExample.Attributes[SXML_PackageKeyboard_Example_Keys] := Items[j].Keys;
2528+
AExample.Attributes[SXML_PackageKeyboard_Example_Text] := Items[j].Text;
2529+
AExample.Attributes[SXML_PackageKeyboard_Example_Note] := Items[j].Note;
2530+
end;
2531+
end;
2532+
23562533
end.
23572534

0 commit comments

Comments
 (0)