1 | unit UFormImportSources;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
9 | ActnList, Menus, UAcronym;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormImportSources }
|
---|
14 |
|
---|
15 | TFormImportSources = class(TForm)
|
---|
16 | AAdd: TAction;
|
---|
17 | AProcess: TAction;
|
---|
18 | ActionList1: TActionList;
|
---|
19 | AModify: TAction;
|
---|
20 | ARemove: TAction;
|
---|
21 | ListView1: TListView;
|
---|
22 | MenuItem1: TMenuItem;
|
---|
23 | MenuItem2: TMenuItem;
|
---|
24 | MenuItem3: TMenuItem;
|
---|
25 | MenuItem4: TMenuItem;
|
---|
26 | PopupMenuImportSource: TPopupMenu;
|
---|
27 | procedure AAddExecute(Sender: TObject);
|
---|
28 | procedure AModifyExecute(Sender: TObject);
|
---|
29 | procedure AProcessExecute(Sender: TObject);
|
---|
30 | procedure ARemoveExecute(Sender: TObject);
|
---|
31 | procedure FormShow(Sender: TObject);
|
---|
32 | procedure ListView1Data(Sender: TObject; Item: TListItem);
|
---|
33 | procedure ListView1DblClick(Sender: TObject);
|
---|
34 | procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
|
---|
35 | Selected: Boolean);
|
---|
36 | private
|
---|
37 | { private declarations }
|
---|
38 | public
|
---|
39 | ImportSources: TImportSources;
|
---|
40 | procedure UpdateList;
|
---|
41 | procedure UpdateInterface;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | var
|
---|
45 | FormImportSources: TFormImportSources;
|
---|
46 |
|
---|
47 | implementation
|
---|
48 |
|
---|
49 | {$R *.lfm}
|
---|
50 |
|
---|
51 | uses
|
---|
52 | UFormMain, UFormImportSource;
|
---|
53 |
|
---|
54 | resourcestring
|
---|
55 | SRemoveImportSource = 'Remove import sources';
|
---|
56 | SRemoveImportSourceQuery = 'Do you really want to remove selected import sources?';
|
---|
57 | SImportSourceAlreadyExists = 'Import source %s already exists!';
|
---|
58 |
|
---|
59 |
|
---|
60 | { TFormImportSources }
|
---|
61 |
|
---|
62 | procedure TFormImportSources.ListView1Data(Sender: TObject; Item: TListItem);
|
---|
63 | begin
|
---|
64 | if Item.Index < ImportSources.Count then
|
---|
65 | with TImportSource(ImportSources[Item.Index]) do begin
|
---|
66 | Item.Caption := Name;
|
---|
67 | Item.Data := ImportSources[Item.Index];
|
---|
68 | Item.SubItems.Add(URL);
|
---|
69 | Item.SubItems.Add(IntToStr(ItemCount));
|
---|
70 | Item.SubItems.Add(Categories.GetString);
|
---|
71 | Item.Checked := Enabled;
|
---|
72 | end;
|
---|
73 | end;
|
---|
74 |
|
---|
75 | procedure TFormImportSources.ListView1DblClick(Sender: TObject);
|
---|
76 | begin
|
---|
77 | AModify.Execute;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | procedure TFormImportSources.ListView1SelectItem(Sender: TObject;
|
---|
81 | Item: TListItem; Selected: Boolean);
|
---|
82 | begin
|
---|
83 | UpdateInterface;
|
---|
84 | end;
|
---|
85 |
|
---|
86 | procedure TFormImportSources.UpdateList;
|
---|
87 | begin
|
---|
88 | ListView1.Items.Count := ImportSources.Count;
|
---|
89 | ListView1.Refresh;
|
---|
90 | UpdateInterface;
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TFormImportSources.UpdateInterface;
|
---|
94 | begin
|
---|
95 | ARemove.Enabled := Assigned(ListView1.Selected);
|
---|
96 | AModify.Enabled := Assigned(ListView1.Selected);
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TFormImportSources.FormShow(Sender: TObject);
|
---|
100 | begin
|
---|
101 | UpdateList;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TFormImportSources.AAddExecute(Sender: TObject);
|
---|
105 | var
|
---|
106 | NewImportSource: TImportSource;
|
---|
107 | begin
|
---|
108 | NewImportSource := TImportSource.Create;
|
---|
109 | NewImportSource.Sources := ImportSources;
|
---|
110 | FormImportSource.Load(NewImportSource);
|
---|
111 | if FormImportSource.ShowModal = mrOk then begin
|
---|
112 | FormImportSource.Save(NewImportSource);
|
---|
113 | if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
|
---|
114 | ImportSources.Add(NewImportSource);
|
---|
115 | NewImportSource := nil;
|
---|
116 | FormMain.AcronymDb.Modified := True;
|
---|
117 | UpdateList;
|
---|
118 | end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
|
---|
119 | end;
|
---|
120 | if Assigned(NewImportSource) then NewImportSource.Free;
|
---|
121 | end;
|
---|
122 |
|
---|
123 | procedure TFormImportSources.AModifyExecute(Sender: TObject);
|
---|
124 | var
|
---|
125 | NewImportSource: TImportSource;
|
---|
126 | begin
|
---|
127 | if Assigned(ListView1.Selected) then begin
|
---|
128 | NewImportSource := TImportSource.Create;
|
---|
129 | NewImportSource.Assign(ListView1.Selected.Data);
|
---|
130 | FormImportSource.Load(NewImportSource);
|
---|
131 | if FormImportSource.ShowModal = mrOk then begin
|
---|
132 | FormImportSource.Save(NewImportSource);
|
---|
133 | if (NewImportSource.Name <> TImportSource(ListView1.Selected.Data).Name) then begin
|
---|
134 | if not Assigned(ImportSources.SearchByName(NewImportSource.Name)) then begin;
|
---|
135 | TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
|
---|
136 | FormMain.AcronymDb.Modified := True;
|
---|
137 | UpdateList;
|
---|
138 | end else ShowMessage(Format(SImportSourceAlreadyExists, [NewImportSource.Name]));
|
---|
139 | end else begin
|
---|
140 | TImportSource(ListView1.Selected.Data).Assign(NewImportSource);
|
---|
141 | FormMain.AcronymDb.Modified := True;
|
---|
142 | UpdateList;
|
---|
143 | end;
|
---|
144 | end;
|
---|
145 | if Assigned(NewImportSource) then NewImportSource.Free;
|
---|
146 | end;
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure TFormImportSources.AProcessExecute(Sender: TObject);
|
---|
150 | begin
|
---|
151 | if Assigned(ListView1.Selected) then begin
|
---|
152 | TImportSource(ListView1.Selected.Data).Process;
|
---|
153 | ShowMessage(Format(SAddedCount, [TImportSource(ListView1.Selected.Data).ItemCount]));
|
---|
154 | end;
|
---|
155 | end;
|
---|
156 |
|
---|
157 | procedure TFormImportSources.ARemoveExecute(Sender: TObject);
|
---|
158 | var
|
---|
159 | I: Integer;
|
---|
160 | begin
|
---|
161 | if Assigned(ListView1.Selected) then begin
|
---|
162 | if MessageDlg(SRemoveImportSource, SRemoveImportSourceQuery,
|
---|
163 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
164 | for I := ListView1.Items.Count - 1 downto 0 do
|
---|
165 | if ListView1.Items[I].Selected then
|
---|
166 | ImportSources.Remove(ListView1.Items[I].Data);
|
---|
167 | UpdateList;
|
---|
168 | end;
|
---|
169 | end;
|
---|
170 | end;
|
---|
171 |
|
---|
172 | end.
|
---|
173 |
|
---|