source: trunk/Forms/FormExport.pas

Last change on this file was 168, checked in by chronos, 17 months ago
File size: 4.6 KB
Line 
1unit FormExport;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComCtrls,
7 ExtCtrls, Table, LazFileUtils, FormEx;
8
9type
10
11 { TFormExport }
12
13 TFormExport = class(TFormEx)
14 ButtonBrowse: TButton;
15 ButtonCancel: TButton;
16 ButtonExport: TButton;
17 CheckBoxHumanReadableHeader: TCheckBox;
18 ComboBoxOutputFormat: TComboBox;
19 EditOutputFile: TEdit;
20 Label1: TLabel;
21 Label2: TLabel;
22 ListView1: TListView;
23 SaveDialog1: TSaveDialog;
24 ScrollBox1: TScrollBox;
25 TimerRedraw: TTimer;
26 procedure ButtonBrowseClick(Sender: TObject);
27 procedure ButtonExportClick(Sender: TObject);
28 procedure CheckBoxHumanReadableHeaderChange(Sender: TObject);
29 procedure ComboBoxOutputFormatChange(Sender: TObject);
30 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
31 procedure FormCreate(Sender: TObject);
32 procedure FormDestroy(Sender: TObject);
33 procedure FormShow(Sender: TObject);
34 procedure TimerRedrawTimer(Sender: TObject);
35 private
36 Table: TTable;
37 RedrawPending: Boolean;
38 procedure UpdateFileNameExt;
39 procedure LoadConfig;
40 procedure SaveConfig;
41 end;
42
43
44implementation
45
46{$R *.lfm}
47
48uses
49 Core, Common, RegistryEx, VCardFile, VCard;
50
51{ TFormExport }
52
53procedure TFormExport.FormClose(Sender: TObject; var CloseAction: TCloseAction);
54begin
55 SaveConfig;
56end;
57
58procedure TFormExport.ButtonExportClick(Sender: TObject);
59var
60 TableFormat: TTableFormat;
61begin
62 TableFormat := TTableFormat(ComboBoxOutputFormat.Items.Objects[ComboBoxOutputFormat.ItemIndex]);
63 TVCardFile(Core.Core.DataFile).VCard.ExportToFile(EditOutputFile.Text, TableFormat,
64 CheckBoxHumanReadableHeader.Checked);
65end;
66
67procedure TFormExport.CheckBoxHumanReadableHeaderChange(Sender: TObject);
68begin
69 RedrawPending := True;
70end;
71
72procedure TFormExport.ComboBoxOutputFormatChange(Sender: TObject);
73begin
74 UpdateFileNameExt;
75end;
76
77procedure TFormExport.ButtonBrowseClick(Sender: TObject);
78begin
79 SaveDialog1.DefaultExt := '';
80 SaveDialog1.InitialDir := ExtractFileDir(EditOutputFile.Text);
81 SaveDialog1.FileName := ExtractFileName(EditOutputFile.Text);
82 if SaveDialog1.Execute then begin
83 EditOutputFile.Text := SaveDialog1.FileName;
84 end;
85end;
86
87procedure TFormExport.FormCreate(Sender: TObject);
88var
89 TableFormat: TTableFormat;
90begin
91 ComboBoxOutputFormat.Items.BeginUpdate;
92 try
93 for TableFormat := Low(TTableFormat) to High(TTableFormat) do
94 if TableFormat <> tfListView then
95 ComboBoxOutputFormat.Items.AddObject(TableFormatText[TableFormat], TObject(TableFormat));
96 if (ComboBoxOutputFormat.ItemIndex = -1) and (ComboBoxOutputFormat.Items.Count > 0) then
97 ComboBoxOutputFormat.ItemIndex := 0;
98 finally
99 ComboBoxOutputFormat.Items.EndUpdate;
100 end;
101
102 Table := TTable.Create;
103 LoadConfig;
104 UpdateFileNameExt;
105end;
106
107procedure TFormExport.FormDestroy(Sender: TObject);
108begin
109 FreeAndNil(Table);
110end;
111
112procedure TFormExport.FormShow(Sender: TObject);
113begin
114 RedrawPending := True;
115end;
116
117procedure TFormExport.TimerRedrawTimer(Sender: TObject);
118begin
119 if RedrawPending then begin
120 TVCardFile(Core.Core.DataFile).VCard.ExportToTable(Table,
121 CheckBoxHumanReadableHeader.Checked);
122 Table.GetOutputListView(ListView1);
123 RedrawPending := False;
124 end;
125end;
126
127procedure TFormExport.UpdateFileNameExt;
128var
129 FileName: string;
130begin
131 FileName := EditOutputFile.Text;
132 EditOutputFile.Text := Copy(FileName, 1, Length(FileName) - Length(ExtractFileExt(FileName))) +
133 TableFormatExt[TTableFormat(ComboBoxOutputFormat.Items.Objects[ComboBoxOutputFormat.ItemIndex])];
134end;
135
136procedure TFormExport.LoadConfig;
137var
138 TableFormat: TTableFormat;
139begin
140 with TRegistryEx.Create do
141 try
142 CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
143 EditOutputFile.Text := ReadStringWithDefault('ExportFileName', 'Export.txt');
144 TableFormat := TTableFormat(ReadIntegerWithDefault('ExportTableFormat', Integer(tfCsv)));
145 CheckBoxHumanReadableHeader.Checked := ReadBoolWithDefault('ExportHumanReadableColumns', CheckBoxHumanReadableHeader.Checked);
146 ComboBoxOutputFormat.ItemIndex := ComboBoxOutputFormat.Items.IndexOfObject(TObject(TableFormat));
147 finally
148 Free;
149 end;
150end;
151
152procedure TFormExport.SaveConfig;
153begin
154 with TRegistryEx.Create do
155 try
156 CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
157 WriteString('ExportFileName', EditOutputFile.Text);
158 WriteInteger('ExportTableFormat', Integer(ComboBoxOutputFormat.Items.Objects[ComboBoxOutputFormat.ItemIndex]));
159 WriteBool('ExportHumanReadableColumns', CheckBoxHumanReadableHeader.Checked);
160 finally
161 Free;
162 end;
163end;
164
165end.
166
Note: See TracBrowser for help on using the repository browser.