1 | unit UFormExport;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
---|
9 | UJobProgressView;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormExport }
|
---|
14 |
|
---|
15 | TFormExport = class(TForm)
|
---|
16 | ButtonProcess: TButton;
|
---|
17 | ButtonSaveToFile: TButton;
|
---|
18 | ComboBoxDataFormat: TComboBox;
|
---|
19 | Memo1: TMemo;
|
---|
20 | SaveDialog1: TSaveDialog;
|
---|
21 | procedure ButtonProcessClick(Sender: TObject);
|
---|
22 | procedure ButtonSaveToFileClick(Sender: TObject);
|
---|
23 | procedure FormCreate(Sender: TObject);
|
---|
24 | private
|
---|
25 | ItemCount: Integer;
|
---|
26 | Content: string;
|
---|
27 | procedure JobExportCSV(Job: TJob);
|
---|
28 | procedure JobExportMediaWiki(Job: TJob);
|
---|
29 | procedure JobExportMediaWikiTable(Job: TJob);
|
---|
30 | public
|
---|
31 | { public declarations }
|
---|
32 | end;
|
---|
33 |
|
---|
34 | var
|
---|
35 | FormExport: TFormExport;
|
---|
36 |
|
---|
37 | implementation
|
---|
38 |
|
---|
39 | {$R *.lfm}
|
---|
40 |
|
---|
41 | uses
|
---|
42 | UCore, UAcronym;
|
---|
43 |
|
---|
44 | resourcestring
|
---|
45 | SExportedAcronyms = 'Exported %d acronyms';
|
---|
46 | SExporting = 'Exporting';
|
---|
47 |
|
---|
48 | { TFormExport }
|
---|
49 |
|
---|
50 | procedure TFormExport.ButtonSaveToFileClick(Sender: TObject);
|
---|
51 | begin
|
---|
52 | if ComboBoxDataFormat.ItemIndex = 0 then SaveDialog1.DefaultExt := '.csv';
|
---|
53 | if ComboBoxDataFormat.ItemIndex = 1 then SaveDialog1.DefaultExt := '.txt';
|
---|
54 | if ComboBoxDataFormat.ItemIndex = 2 then SaveDialog1.DefaultExt := '.txt';
|
---|
55 | if SaveDialog1.Execute then begin
|
---|
56 | Memo1.Lines.SaveToFile(SaveDialog1.FileName);
|
---|
57 | end;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | procedure TFormExport.FormCreate(Sender: TObject);
|
---|
61 | begin
|
---|
62 | Core.CoolTranslator1.TranslateComponentRecursive(Self);
|
---|
63 | end;
|
---|
64 |
|
---|
65 | procedure TFormExport.JobExportCSV(Job: TJob);
|
---|
66 | var
|
---|
67 | I: Integer;
|
---|
68 | J: Integer;
|
---|
69 | begin
|
---|
70 | Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
|
---|
71 | ItemCount := 0;
|
---|
72 | Content := '';
|
---|
73 | for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
|
---|
74 | with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
|
---|
75 | for J := 0 to Meanings.Count - 1 do
|
---|
76 | with TAcronymMeaning(Meanings[J]) do begin
|
---|
77 | Content := Content + '"' + Acronym.Name + '","' + Name + '","' + Description + '","' + Categories.GetString + '"' + LineEnding;
|
---|
78 | Inc(ItemCount);
|
---|
79 | end;
|
---|
80 | Job.Progress.Increment;
|
---|
81 | if Job.Terminate then Break;
|
---|
82 | end;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | procedure TFormExport.JobExportMediaWiki(Job: TJob);
|
---|
86 | var
|
---|
87 | I: Integer;
|
---|
88 | J: Integer;
|
---|
89 | begin
|
---|
90 | Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
|
---|
91 | ItemCount := 0;
|
---|
92 | Content := '';
|
---|
93 | for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
|
---|
94 | with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
|
---|
95 | Content := Content + '; ' + Name + LineEnding;
|
---|
96 | for J := 0 to Meanings.Count - 1 do
|
---|
97 | with TAcronymMeaning(Meanings[J]) do begin
|
---|
98 | Content := Content + ': ' + Name + LineEnding;
|
---|
99 | Inc(ItemCount);
|
---|
100 | end;
|
---|
101 | Job.Progress.Increment;
|
---|
102 | if Job.Terminate then Break;
|
---|
103 | end;
|
---|
104 | end;
|
---|
105 |
|
---|
106 | procedure TFormExport.JobExportMediaWikiTable(Job: TJob);
|
---|
107 | var
|
---|
108 | I: Integer;
|
---|
109 | J: Integer;
|
---|
110 | begin
|
---|
111 | Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
|
---|
112 | ItemCount := 0;
|
---|
113 | Content := '{| class="wikitable sortable"' + LineEnding +
|
---|
114 | '! Name !! Meaning !! Description !! Categories' + LineEnding;
|
---|
115 | for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
|
---|
116 | with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
|
---|
117 | for J := 0 to Meanings.Count - 1 do
|
---|
118 | with TAcronymMeaning(Meanings[J]) do begin
|
---|
119 | Content := Content + '|-' + LineEnding +
|
---|
120 | '| ' + Acronym.Name + LineEnding + '| ' + Name + LineEnding +
|
---|
121 | '| ' + Description + LineEnding + '| ' + Categories.GetString + LineEnding;
|
---|
122 | Inc(ItemCount);
|
---|
123 | end;
|
---|
124 | Job.Progress.Increment;
|
---|
125 | if Job.Terminate then Break;
|
---|
126 | end;
|
---|
127 | Content := Content + '|}' + LineEnding;
|
---|
128 | end;
|
---|
129 |
|
---|
130 | procedure TFormExport.ButtonProcessClick(Sender: TObject);
|
---|
131 | begin
|
---|
132 | if ComboBoxDataFormat.ItemIndex = 0 then
|
---|
133 | Core.JobProgressView1.AddJob(SExporting, JobExportCSV);
|
---|
134 | if ComboBoxDataFormat.ItemIndex = 1 then
|
---|
135 | Core.JobProgressView1.AddJob(SExporting, JobExportMediaWiki);
|
---|
136 | if ComboBoxDataFormat.ItemIndex = 2 then
|
---|
137 | Core.JobProgressView1.AddJob(SExporting, JobExportMediaWikiTable);
|
---|
138 | Core.JobProgressView1.Start;
|
---|
139 | Memo1.Lines.Text := Content;
|
---|
140 | ShowMessage(Format(SExportedAcronyms, [ItemCount]));
|
---|
141 | end;
|
---|
142 |
|
---|
143 | end.
|
---|
144 |
|
---|