source: tags/1.3.0/Forms/UFormExport.pas

Last change on this file was 90, checked in by chronos, 8 years ago
  • Added: Acronym export action in menu Tools - Export. Supported formats are CSV and MediaWiki list/table.
File size: 3.2 KB
Line 
1unit UFormExport;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
9
10type
11
12 { TFormExport }
13
14 TFormExport = class(TForm)
15 ButtonProcess: TButton;
16 ButtonSaveToFile: TButton;
17 ComboBoxDataFormat: TComboBox;
18 Memo1: TMemo;
19 SaveDialog1: TSaveDialog;
20 procedure ButtonProcessClick(Sender: TObject);
21 procedure ButtonSaveToFileClick(Sender: TObject);
22 private
23 procedure ExportCSV;
24 procedure ExportMediaWiki;
25 procedure ExportMediaWikiTable;
26 public
27 { public declarations }
28 end;
29
30var
31 FormExport: TFormExport;
32
33implementation
34
35{$R *.lfm}
36
37uses
38 UCore, UAcronym;
39
40resourcestring
41 SExpotedAcronyms = 'Exported %d acronyms';
42
43{ TFormExport }
44
45procedure TFormExport.ButtonSaveToFileClick(Sender: TObject);
46begin
47 if ComboBoxDataFormat.ItemIndex = 0 then SaveDialog1.DefaultExt := '.csv';
48 if ComboBoxDataFormat.ItemIndex = 1 then SaveDialog1.DefaultExt := '.txt';
49 if ComboBoxDataFormat.ItemIndex = 2 then SaveDialog1.DefaultExt := '.txt';
50 if SaveDialog1.Execute then begin
51 Memo1.Lines.SaveToFile(SaveDialog1.FileName);
52 end;
53end;
54
55procedure TFormExport.ExportCSV;
56var
57 I: Integer;
58 J: Integer;
59 ItemCount: Integer;
60begin
61 Memo1.Lines.Clear;
62 Memo1.Lines.BeginUpdate;
63 ItemCount := 0;
64 for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
65 with TAcronym(Core.AcronymDb.Acronyms[I]) do
66 for J := 0 to Meanings.Count - 1 do
67 with TAcronymMeaning(Meanings[J]) do begin
68 Memo1.Lines.Add('"' + Acronym.Name + '","' + Name + '","' + Description + '","' + Categories.GetString + '"');
69 Inc(ItemCount);
70 end;
71 Memo1.Lines.EndUpdate;
72 ShowMessage(Format(SExpotedAcronyms, [ItemCount]));
73end;
74
75procedure TFormExport.ExportMediaWiki;
76var
77 I: Integer;
78 J: Integer;
79 ItemCount: Integer;
80begin
81 Memo1.Lines.Clear;
82 Memo1.Lines.BeginUpdate;
83 ItemCount := 0;
84 for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
85 with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
86 Memo1.Lines.Add('; ' + Name);
87 for J := 0 to Meanings.Count - 1 do
88 with TAcronymMeaning(Meanings[J]) do begin
89 Memo1.Lines.Add(': ' + Name);
90 Inc(ItemCount);
91 end;
92 end;
93 Memo1.Lines.EndUpdate;
94 ShowMessage(Format(SExpotedAcronyms, [ItemCount]));
95end;
96
97procedure TFormExport.ExportMediaWikiTable;
98var
99 I: Integer;
100 J: Integer;
101 ItemCount: Integer;
102begin
103 Memo1.Lines.Clear;
104 Memo1.Lines.BeginUpdate;
105 ItemCount := 0;
106 Memo1.Lines.Add('{| class="wikitable sortable"');
107 Memo1.Lines.Add('! Name !! Meaning !! Description !! Categories');
108 for I := 0 to Core.AcronymDb.Acronyms.Count - 1 do
109 with TAcronym(Core.AcronymDb.Acronyms[I]) do begin
110 for J := 0 to Meanings.Count - 1 do
111 with TAcronymMeaning(Meanings[J]) do begin
112 Memo1.Lines.Add('|-');
113 Memo1.Lines.Add('| ' + Acronym.Name + ' || ' + Name + ' || ' + Description + ' || ' + Categories.GetString);
114 Inc(ItemCount);
115 end;
116 end;
117 Memo1.Lines.Add('|}');
118 Memo1.Lines.EndUpdate;
119 ShowMessage(Format(SExpotedAcronyms, [ItemCount]));
120end;
121
122procedure TFormExport.ButtonProcessClick(Sender: TObject);
123begin
124 if ComboBoxDataFormat.ItemIndex = 0 then ExportCSV;
125 if ComboBoxDataFormat.ItemIndex = 1 then ExportMediaWiki;
126 if ComboBoxDataFormat.ItemIndex = 2 then ExportMediaWikiTable;
127end;
128
129end.
130
Note: See TracBrowser for help on using the repository browser.