1 | unit UFormCategories;
|
---|
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 | { TFormCategories }
|
---|
14 |
|
---|
15 | TFormCategories = class(TForm)
|
---|
16 | AAdd: TAction;
|
---|
17 | ASelectAll: TAction;
|
---|
18 | ARemove: TAction;
|
---|
19 | AModify: TAction;
|
---|
20 | ActionList1: TActionList;
|
---|
21 | ListViewCategories: TListView;
|
---|
22 | MenuItem1: TMenuItem;
|
---|
23 | MenuItem2: TMenuItem;
|
---|
24 | MenuItem3: TMenuItem;
|
---|
25 | MenuItem4: TMenuItem;
|
---|
26 | PopupMenuCategory: TPopupMenu;
|
---|
27 | ToolBar1: TToolBar;
|
---|
28 | ToolButton1: TToolButton;
|
---|
29 | ToolButton2: TToolButton;
|
---|
30 | ToolButton3: TToolButton;
|
---|
31 | procedure AAddExecute(Sender: TObject);
|
---|
32 | procedure AModifyExecute(Sender: TObject);
|
---|
33 | procedure ARemoveExecute(Sender: TObject);
|
---|
34 | procedure ASelectAllExecute(Sender: TObject);
|
---|
35 | procedure FormCreate(Sender: TObject);
|
---|
36 | procedure FormShow(Sender: TObject);
|
---|
37 | procedure ListViewCategoriesData(Sender: TObject; Item: TListItem);
|
---|
38 | procedure ListViewCategoriesDblClick(Sender: TObject);
|
---|
39 | procedure ListViewCategoriesKeyPress(Sender: TObject; var Key: char);
|
---|
40 | procedure ListViewCategoriesSelectItem(Sender: TObject; Item: TListItem;
|
---|
41 | Selected: Boolean);
|
---|
42 | private
|
---|
43 | { private declarations }
|
---|
44 | public
|
---|
45 | Categories: TAcronymCategories;
|
---|
46 | procedure UpdateList;
|
---|
47 | procedure UpdateInterface;
|
---|
48 | end;
|
---|
49 |
|
---|
50 | var
|
---|
51 | FormCategories: TFormCategories;
|
---|
52 |
|
---|
53 | implementation
|
---|
54 |
|
---|
55 | {$R *.lfm}
|
---|
56 |
|
---|
57 | uses
|
---|
58 | UCore;
|
---|
59 |
|
---|
60 | resourcestring
|
---|
61 | SCategory = 'Category';
|
---|
62 | SCategoryQuery = 'Enter name of category';
|
---|
63 | SRemoveCategory = 'Remove categories';
|
---|
64 | SRemoveCategoryQuery = 'Do you really want to remove selected categories?';
|
---|
65 | SCategoryAlreadyExists = 'Category %s already exists!';
|
---|
66 |
|
---|
67 | { TFormCategories }
|
---|
68 |
|
---|
69 | procedure TFormCategories.FormShow(Sender: TObject);
|
---|
70 | begin
|
---|
71 | UpdateList;
|
---|
72 | Core.ScaleDPI1.ScaleControl(ToolBar1, Core.ScaleDPI1.DesignDPI);
|
---|
73 | end;
|
---|
74 |
|
---|
75 | procedure TFormCategories.AAddExecute(Sender: TObject);
|
---|
76 | var
|
---|
77 | S: string;
|
---|
78 | begin
|
---|
79 | S := InputBox(SCategory, SCategoryQuery, '');
|
---|
80 | if S <> '' then begin
|
---|
81 | if not Assigned(Core.AcronymDb.Categories.SearchByName(S)) then begin;
|
---|
82 | TAcronymCategory(Core.AcronymDb.Categories[Core.AcronymDb.Categories.Add(TAcronymCategory.Create)]).Name := S;
|
---|
83 | Core.AcronymDb.Modified := True;
|
---|
84 | UpdateList;
|
---|
85 | end else ShowMessage(Format(SCategoryAlreadyExists, [S]));
|
---|
86 | end;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | procedure TFormCategories.AModifyExecute(Sender: TObject);
|
---|
90 | var
|
---|
91 | S: string;
|
---|
92 | begin
|
---|
93 | if Assigned(ListViewCategories.Selected) then begin
|
---|
94 | S := InputBox(SCategory, SCategoryQuery, ListViewCategories.Selected.Caption);
|
---|
95 | if S <> ListViewCategories.Selected.Caption then begin
|
---|
96 | if not Assigned(Core.AcronymDb.Categories.SearchByName(S)) then begin;
|
---|
97 | TAcronymCategory(ListViewCategories.Selected.Data).Name := S;
|
---|
98 | Core.AcronymDb.Modified := True;
|
---|
99 | UpdateList;
|
---|
100 | end else ShowMessage(Format(SCategoryAlreadyExists, [S]));
|
---|
101 | end;
|
---|
102 | end;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TFormCategories.ARemoveExecute(Sender: TObject);
|
---|
106 | var
|
---|
107 | I: Integer;
|
---|
108 | begin
|
---|
109 | if Assigned(ListViewCategories.Selected) then begin
|
---|
110 | if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
|
---|
111 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
112 | for I := ListViewCategories.Items.Count - 1 downto 0 do
|
---|
113 | if ListViewCategories.Items[I].Selected then
|
---|
114 | Categories.Remove(ListViewCategories.Items[I].Data);
|
---|
115 | UpdateList;
|
---|
116 | end;
|
---|
117 | end;
|
---|
118 | end;
|
---|
119 |
|
---|
120 | procedure TFormCategories.ASelectAllExecute(Sender: TObject);
|
---|
121 | var
|
---|
122 | I: Integer;
|
---|
123 | begin
|
---|
124 | for I := 0 to ListViewCategories.Items.Count - 1 do
|
---|
125 | ListViewCategories.Items[I].Selected := True;
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure TFormCategories.FormCreate(Sender: TObject);
|
---|
129 | var
|
---|
130 | I: Integer;
|
---|
131 | begin
|
---|
132 | Core.CoolTranslator1.TranslateComponentRecursive(Self);
|
---|
133 | for I := 0 to ToolBar1.ButtonCount - 1 do
|
---|
134 | ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
|
---|
135 | end;
|
---|
136 |
|
---|
137 | procedure TFormCategories.ListViewCategoriesData(Sender: TObject; Item: TListItem);
|
---|
138 | begin
|
---|
139 | if Item.Index < Core.AcronymDb.Categories.Count then
|
---|
140 | with TAcronymCategory(Core.AcronymDb.Categories[Item.Index]) do begin
|
---|
141 | Item.Caption := Name;
|
---|
142 | Item.Data := Core.AcronymDb.Categories[Item.Index];
|
---|
143 | Item.SubItems.Add(IntToStr(AcronymMeanings.Count));
|
---|
144 | end;
|
---|
145 | end;
|
---|
146 |
|
---|
147 | procedure TFormCategories.ListViewCategoriesDblClick(Sender: TObject);
|
---|
148 | begin
|
---|
149 | AModify.Execute;
|
---|
150 | end;
|
---|
151 |
|
---|
152 | procedure TFormCategories.ListViewCategoriesKeyPress(Sender: TObject;
|
---|
153 | var Key: char);
|
---|
154 | begin
|
---|
155 | if Key = #27 then Close;
|
---|
156 | end;
|
---|
157 |
|
---|
158 | procedure TFormCategories.ListViewCategoriesSelectItem(Sender: TObject; Item: TListItem;
|
---|
159 | Selected: Boolean);
|
---|
160 | begin
|
---|
161 | UpdateInterface;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | procedure TFormCategories.UpdateList;
|
---|
165 | begin
|
---|
166 | ListViewCategories.Items.Count := Core.AcronymDb.Categories.Count;
|
---|
167 | ListViewCategories.Refresh;
|
---|
168 | UpdateInterface;
|
---|
169 | end;
|
---|
170 |
|
---|
171 | procedure TFormCategories.UpdateInterface;
|
---|
172 | begin
|
---|
173 | ARemove.Enabled := Assigned(ListViewCategories.Selected);
|
---|
174 | AModify.Enabled := Assigned(ListViewCategories.Selected);
|
---|
175 | end;
|
---|
176 |
|
---|
177 | end.
|
---|
178 |
|
---|