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 FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
24 | procedure FormCreate(Sender: TObject);
|
---|
25 | procedure FormShow(Sender: TObject);
|
---|
26 | private
|
---|
27 | ItemCount: Integer;
|
---|
28 | Content: string;
|
---|
29 | procedure JobExportCSV(Job: TJob);
|
---|
30 | procedure JobExportMediaWiki(Job: TJob);
|
---|
31 | procedure JobExportMediaWikiTable(Job: TJob);
|
---|
32 | public
|
---|
33 | { public declarations }
|
---|
34 | end;
|
---|
35 |
|
---|
36 | var
|
---|
37 | FormExport: TFormExport;
|
---|
38 |
|
---|
39 | implementation
|
---|
40 |
|
---|
41 | {$R *.lfm}
|
---|
42 |
|
---|
43 | uses
|
---|
44 | UCore, UAcronym;
|
---|
45 |
|
---|
46 | resourcestring
|
---|
47 | SExportedAcronyms = 'Exported %d acronyms';
|
---|
48 | SExporting = 'Exporting';
|
---|
49 |
|
---|
50 | { TFormExport }
|
---|
51 |
|
---|
52 | procedure TFormExport.ButtonSaveToFileClick(Sender: TObject);
|
---|
53 | begin
|
---|
54 | if ComboBoxDataFormat.ItemIndex = 0 then SaveDialog1.DefaultExt := '.csv';
|
---|
55 | if ComboBoxDataFormat.ItemIndex = 1 then SaveDialog1.DefaultExt := '.txt';
|
---|
56 | if ComboBoxDataFormat.ItemIndex = 2 then SaveDialog1.DefaultExt := '.txt';
|
---|
57 | if SaveDialog1.Execute then begin
|
---|
58 | Memo1.Lines.SaveToFile(SaveDialog1.FileName);
|
---|
59 | end;
|
---|
60 | end;
|
---|
61 |
|
---|
62 | procedure TFormExport.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
63 | begin
|
---|
64 | Core.PersistentForm1.Save(Self);
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure TFormExport.FormCreate(Sender: TObject);
|
---|
68 | begin
|
---|
69 | Core.Translator.TranslateComponentRecursive(Self);
|
---|
70 | Core.ThemeManager.UseTheme(Self);
|
---|
71 | end;
|
---|
72 |
|
---|
73 | procedure TFormExport.FormShow(Sender: TObject);
|
---|
74 | begin
|
---|
75 | Core.PersistentForm1.Load(Self);
|
---|
76 | end;
|
---|
77 |
|
---|
78 | procedure TFormExport.JobExportCSV(Job: TJob);
|
---|
79 | var
|
---|
80 | I: Integer;
|
---|
81 | J: Integer;
|
---|
82 | begin
|
---|
83 | Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
|
---|
84 | ItemCount := 0;
|
---|
85 | Content := '';
|
---|
86 | for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
|
---|
87 | with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
|
---|
88 | for J := 0 to Meanings.Count - 1 do
|
---|
89 | with TAcronymMeaning(Meanings[J]) do begin
|
---|
90 | Content := Content + '"' + Acronym.Name + '","' + Name + '","' + Description + '","' + Categories.GetString + '"' + LineEnding;
|
---|
91 | Inc(ItemCount);
|
---|
92 | end;
|
---|
93 | Job.Progress.Increment;
|
---|
94 | if Job.Terminate then Break;
|
---|
95 | end;
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormExport.JobExportMediaWiki(Job: TJob);
|
---|
99 | var
|
---|
100 | I: Integer;
|
---|
101 | J: Integer;
|
---|
102 | begin
|
---|
103 | Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
|
---|
104 | ItemCount := 0;
|
---|
105 | Content := '';
|
---|
106 | for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
|
---|
107 | with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
|
---|
108 | Content := Content + '; ' + Name + LineEnding;
|
---|
109 | for J := 0 to Meanings.Count - 1 do
|
---|
110 | with TAcronymMeaning(Meanings[J]) do begin
|
---|
111 | Content := Content + ': ' + Name + LineEnding;
|
---|
112 | Inc(ItemCount);
|
---|
113 | end;
|
---|
114 | Job.Progress.Increment;
|
---|
115 | if Job.Terminate then Break;
|
---|
116 | end;
|
---|
117 | end;
|
---|
118 |
|
---|
119 | procedure TFormExport.JobExportMediaWikiTable(Job: TJob);
|
---|
120 | var
|
---|
121 | I: Integer;
|
---|
122 | J: Integer;
|
---|
123 | begin
|
---|
124 | Job.Progress.Max := Core.AcronymDb.Acronyms.Count;
|
---|
125 | ItemCount := 0;
|
---|
126 | Content := '{| class="wikitable sortable"' + LineEnding +
|
---|
127 | '! Name !! Meaning !! Description !! Categories' + LineEnding;
|
---|
128 | for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
|
---|
129 | with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
|
---|
130 | for J := 0 to Meanings.Count - 1 do
|
---|
131 | with TAcronymMeaning(Meanings[J]) do begin
|
---|
132 | Content := Content + '|-' + LineEnding +
|
---|
133 | '| ' + Acronym.Name + LineEnding + '| ' + Name + LineEnding +
|
---|
134 | '| ' + Description + LineEnding + '| ' + Categories.GetString + LineEnding;
|
---|
135 | Inc(ItemCount);
|
---|
136 | end;
|
---|
137 | Job.Progress.Increment;
|
---|
138 | if Job.Terminate then Break;
|
---|
139 | end;
|
---|
140 | Content := Content + '|}' + LineEnding;
|
---|
141 | end;
|
---|
142 |
|
---|
143 | procedure TFormExport.ButtonProcessClick(Sender: TObject);
|
---|
144 | begin
|
---|
145 | if ComboBoxDataFormat.ItemIndex = 0 then
|
---|
146 | Core.JobProgressView1.AddJob(SExporting, JobExportCSV);
|
---|
147 | if ComboBoxDataFormat.ItemIndex = 1 then
|
---|
148 | Core.JobProgressView1.AddJob(SExporting, JobExportMediaWiki);
|
---|
149 | if ComboBoxDataFormat.ItemIndex = 2 then
|
---|
150 | Core.JobProgressView1.AddJob(SExporting, JobExportMediaWikiTable);
|
---|
151 | Core.JobProgressView1.Start;
|
---|
152 | Memo1.Lines.Text := Content;
|
---|
153 | ShowMessage(Format(SExportedAcronyms, [ItemCount]));
|
---|
154 | end;
|
---|
155 |
|
---|
156 | end.
|
---|
157 |
|
---|