source: tags/1.0.1/Forms/UFormImportFormats.pas

Last change on this file was 22, checked in by chronos, 8 years ago
  • Added: Now import formats can be specified using new edit windows.
  • Added: Import source can now be downloaded and processed including download from https URLs.
File size: 4.5 KB
Line 
1unit UFormImportFormats;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 ActnList, Menus, UAcronym;
10
11type
12
13 { TFormImportFormats }
14
15 TFormImportFormats = class(TForm)
16 AAdd: TAction;
17 ActionList1: TActionList;
18 AModify: TAction;
19 ARemove: TAction;
20 ListView1: TListView;
21 MenuItem1: TMenuItem;
22 MenuItem2: TMenuItem;
23 MenuItem3: TMenuItem;
24 PopupMenuImportSource: TPopupMenu;
25 procedure AAddExecute(Sender: TObject);
26 procedure AModifyExecute(Sender: TObject);
27 procedure ARemoveExecute(Sender: TObject);
28 procedure FormShow(Sender: TObject);
29 procedure ListView1Data(Sender: TObject; Item: TListItem);
30 procedure ListView1DblClick(Sender: TObject);
31 procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
32 Selected: Boolean);
33 private
34 { private declarations }
35 public
36 ImportFormats: TImportFormats;
37 procedure UpdateList;
38 procedure UpdateInterface;
39 end;
40
41var
42 FormImportFormats: TFormImportFormats;
43
44implementation
45
46{$R *.lfm}
47
48uses
49 UFormMain, UFormImportFormat;
50
51resourcestring
52 SRemoveImportFormat = 'Remove import formats';
53 SRemoveImportFormatQuery = 'Do you really want to remove selected import formats?';
54 SImportFormatAlreadyExists = 'Import format %s already exists!';
55
56
57{ TFormImportFormats }
58
59procedure TFormImportFormats.ListView1Data(Sender: TObject; Item: TListItem);
60begin
61 if Item.Index < ImportFormats.Count then
62 with TImportFormat(ImportFormats[Item.Index]) do begin
63 Item.Caption := Name;
64 Item.Data := ImportFormats[Item.Index];
65 end;
66end;
67
68procedure TFormImportFormats.ListView1DblClick(Sender: TObject);
69begin
70 AModify.Execute;
71end;
72
73procedure TFormImportFormats.ListView1SelectItem(Sender: TObject;
74 Item: TListItem; Selected: Boolean);
75begin
76 UpdateInterface;
77end;
78
79procedure TFormImportFormats.UpdateList;
80begin
81 ListView1.Items.Count := ImportFormats.Count;
82 ListView1.Refresh;
83 UpdateInterface;
84end;
85
86procedure TFormImportFormats.UpdateInterface;
87begin
88 ARemove.Enabled := Assigned(ListView1.Selected);
89 AModify.Enabled := Assigned(ListView1.Selected);
90end;
91
92procedure TFormImportFormats.FormShow(Sender: TObject);
93begin
94 UpdateList;
95end;
96
97procedure TFormImportFormats.AAddExecute(Sender: TObject);
98var
99 NewImportFormat: TImportFormat;
100begin
101 NewImportFormat := TImportFormat.Create;
102 NewImportFormat.Formats := ImportFormats;
103 FormImportFormat.Load(NewImportFormat);
104 if FormImportFormat.ShowModal = mrOk then begin
105 FormImportFormat.Save(NewImportFormat);
106 if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
107 ImportFormats.Add(NewImportFormat);
108 NewImportFormat := nil;
109 FormMain.AcronymDb.Modified := True;
110 UpdateList;
111 end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
112 end;
113 if Assigned(NewImportFormat) then NewImportFormat.Free;
114end;
115
116procedure TFormImportFormats.AModifyExecute(Sender: TObject);
117var
118 NewImportFormat: TImportFormat;
119begin
120 if Assigned(ListView1.Selected) then begin
121 NewImportFormat := TImportFormat.Create;
122 NewImportFormat.Assign(ListView1.Selected.Data);
123 FormImportFormat.Load(NewImportFormat);
124 if FormImportFormat.ShowModal = mrOk then begin
125 FormImportFormat.Save(NewImportFormat);
126 if (NewImportFormat.Name <> TImportFormat(ListView1.Selected.Data).Name) then begin
127 if not Assigned(ImportFormats.SearchByName(NewImportFormat.Name)) then begin;
128 TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
129 FormMain.AcronymDb.Modified := True;
130 UpdateList;
131 end else ShowMessage(Format(SImportFormatAlreadyExists, [NewImportFormat.Name]));
132 end else begin
133 TImportFormat(ListView1.Selected.Data).Assign(NewImportFormat);
134 FormMain.AcronymDb.Modified := True;
135 UpdateList;
136 end;
137 end;
138 if Assigned(NewImportFormat) then NewImportFormat.Free;
139 end;
140end;
141
142procedure TFormImportFormats.ARemoveExecute(Sender: TObject);
143var
144 I: Integer;
145begin
146 if Assigned(ListView1.Selected) then begin
147 if MessageDlg(SRemoveImportFormat, SRemoveImportFormatQuery,
148 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
149 for I := ListView1.Items.Count - 1 downto 0 do
150 if ListView1.Items[I].Selected then
151 ImportFormats.Remove(ListView1.Items[I].Data);
152 UpdateList;
153 end;
154 end;
155end;
156
157end.
158
Note: See TracBrowser for help on using the repository browser.