source: tags/1.0.0/Forms/UFormImportSources.pas

Last change on this file was 33, checked in by chronos, 8 years ago
  • Added: Now import sources have categories which are merged to new imported acronym meanings.
File size: 5.0 KB
Line 
1unit UFormImportSources;
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 { 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
44var
45 FormImportSources: TFormImportSources;
46
47implementation
48
49{$R *.lfm}
50
51uses
52 UFormMain, UFormImportSource;
53
54resourcestring
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
62procedure TFormImportSources.ListView1Data(Sender: TObject; Item: TListItem);
63begin
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;
73end;
74
75procedure TFormImportSources.ListView1DblClick(Sender: TObject);
76begin
77 AModify.Execute;
78end;
79
80procedure TFormImportSources.ListView1SelectItem(Sender: TObject;
81 Item: TListItem; Selected: Boolean);
82begin
83 UpdateInterface;
84end;
85
86procedure TFormImportSources.UpdateList;
87begin
88 ListView1.Items.Count := ImportSources.Count;
89 ListView1.Refresh;
90 UpdateInterface;
91end;
92
93procedure TFormImportSources.UpdateInterface;
94begin
95 ARemove.Enabled := Assigned(ListView1.Selected);
96 AModify.Enabled := Assigned(ListView1.Selected);
97end;
98
99procedure TFormImportSources.FormShow(Sender: TObject);
100begin
101 UpdateList;
102end;
103
104procedure TFormImportSources.AAddExecute(Sender: TObject);
105var
106 NewImportSource: TImportSource;
107begin
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;
121end;
122
123procedure TFormImportSources.AModifyExecute(Sender: TObject);
124var
125 NewImportSource: TImportSource;
126begin
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;
147end;
148
149procedure TFormImportSources.AProcessExecute(Sender: TObject);
150begin
151 if Assigned(ListView1.Selected) then begin
152 TImportSource(ListView1.Selected.Data).Process;
153 ShowMessage(Format(SAddedCount, [TImportSource(ListView1.Selected.Data).ItemCount]));
154 end;
155end;
156
157procedure TFormImportSources.ARemoveExecute(Sender: TObject);
158var
159 I: Integer;
160begin
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;
170end;
171
172end.
173
Note: See TracBrowser for help on using the repository browser.