source: tags/1.4.0/Forms/UFormExport.pas

Last change on this file was 102, checked in by chronos, 8 years ago
  • Added: Main form hide action to tray icon popup menu.
File size: 3.9 KB
Line 
1unit UFormExport;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 UJobProgressView;
10
11type
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
34var
35 FormExport: TFormExport;
36
37implementation
38
39{$R *.lfm}
40
41uses
42 UCore, UAcronym;
43
44resourcestring
45 SExportedAcronyms = 'Exported %d acronyms';
46 SExporting = 'Exporting';
47
48{ TFormExport }
49
50procedure TFormExport.ButtonSaveToFileClick(Sender: TObject);
51begin
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;
58end;
59
60procedure TFormExport.FormCreate(Sender: TObject);
61begin
62 Core.CoolTranslator1.TranslateComponentRecursive(Self);
63end;
64
65procedure TFormExport.JobExportCSV(Job: TJob);
66var
67 I: Integer;
68 J: Integer;
69begin
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;
83end;
84
85procedure TFormExport.JobExportMediaWiki(Job: TJob);
86var
87 I: Integer;
88 J: Integer;
89begin
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;
104end;
105
106procedure TFormExport.JobExportMediaWikiTable(Job: TJob);
107var
108 I: Integer;
109 J: Integer;
110begin
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;
128end;
129
130procedure TFormExport.ButtonProcessClick(Sender: TObject);
131begin
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]));
141end;
142
143end.
144
Note: See TracBrowser for help on using the repository browser.