1 | unit UFormCategories;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
|
---|
9 | StdCtrls, ActnList, Menus, UAcronym;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormCategories }
|
---|
14 |
|
---|
15 | TFormCategories = class(TForm)
|
---|
16 | AAdd: TAction;
|
---|
17 | ARemove: TAction;
|
---|
18 | AModify: TAction;
|
---|
19 | ActionList1: TActionList;
|
---|
20 | Button1: TButton;
|
---|
21 | Button2: TButton;
|
---|
22 | Button3: TButton;
|
---|
23 | ListViewCategories: TListView;
|
---|
24 | MenuItem1: TMenuItem;
|
---|
25 | MenuItem2: TMenuItem;
|
---|
26 | MenuItem3: TMenuItem;
|
---|
27 | PopupMenuCategory: TPopupMenu;
|
---|
28 | procedure AAddExecute(Sender: TObject);
|
---|
29 | procedure AModifyExecute(Sender: TObject);
|
---|
30 | procedure ARemoveExecute(Sender: TObject);
|
---|
31 | procedure FormShow(Sender: TObject);
|
---|
32 | procedure ListViewCategoriesData(Sender: TObject; Item: TListItem);
|
---|
33 | procedure ListViewCategoriesSelectItem(Sender: TObject; Item: TListItem;
|
---|
34 | Selected: Boolean);
|
---|
35 | private
|
---|
36 | { private declarations }
|
---|
37 | public
|
---|
38 | Categories: TAcronymCategories;
|
---|
39 | procedure UpdateList;
|
---|
40 | procedure UpdateInterface;
|
---|
41 | end;
|
---|
42 |
|
---|
43 | var
|
---|
44 | FormCategories: TFormCategories;
|
---|
45 |
|
---|
46 | implementation
|
---|
47 |
|
---|
48 | {$R *.lfm}
|
---|
49 |
|
---|
50 | uses
|
---|
51 | UFormMain;
|
---|
52 |
|
---|
53 | resourcestring
|
---|
54 | SCategory = 'Category';
|
---|
55 | SCategoryQuery = 'Enter name of category';
|
---|
56 | SRemoveCategory = 'Remove categories';
|
---|
57 | SRemoveCategoryQuery = 'Do you really want to remove selected categories?';
|
---|
58 | SCategoryAlreadyExists = 'Category %s already exists!';
|
---|
59 |
|
---|
60 | { TFormCategories }
|
---|
61 |
|
---|
62 | procedure TFormCategories.FormShow(Sender: TObject);
|
---|
63 | begin
|
---|
64 | UpdateList;
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure TFormCategories.AAddExecute(Sender: TObject);
|
---|
68 | var
|
---|
69 | S: string;
|
---|
70 | begin
|
---|
71 | S := InputBox(SCategory, SCategoryQuery, '');
|
---|
72 | if S <> '' then begin
|
---|
73 | if not Assigned(FormMain.AcronymDb.Categories.SearchByName(S)) then begin;
|
---|
74 | TAcronymCategory(FormMain.AcronymDb.Categories[FormMain.AcronymDb.Categories.Add(TAcronymCategory.Create)]).Name := S;
|
---|
75 | FormMain.AcronymDb.Modified := True;
|
---|
76 | UpdateList;
|
---|
77 | end else ShowMessage(Format(SCategoryAlreadyExists, [S]));
|
---|
78 | end;
|
---|
79 | end;
|
---|
80 |
|
---|
81 | procedure TFormCategories.AModifyExecute(Sender: TObject);
|
---|
82 | var
|
---|
83 | S: string;
|
---|
84 | begin
|
---|
85 | if Assigned(ListViewCategories.Selected) then begin
|
---|
86 | S := InputBox(SCategory, SCategoryQuery, ListViewCategories.Selected.Caption);
|
---|
87 | if S <> ListViewCategories.Selected.Caption then begin
|
---|
88 | if not Assigned(FormMain.AcronymDb.Categories.SearchByName(S)) then begin;
|
---|
89 | TAcronymCategory(ListViewCategories.Selected.Data).Name := S;
|
---|
90 | FormMain.AcronymDb.Modified := True;
|
---|
91 | UpdateList;
|
---|
92 | end else ShowMessage(Format(SCategoryAlreadyExists, [S]));
|
---|
93 | end;
|
---|
94 | end;
|
---|
95 | end;
|
---|
96 |
|
---|
97 | procedure TFormCategories.ARemoveExecute(Sender: TObject);
|
---|
98 | var
|
---|
99 | I: Integer;
|
---|
100 | begin
|
---|
101 | if Assigned(ListViewCategories.Selected) then begin
|
---|
102 | if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
|
---|
103 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
104 | for I := ListViewCategories.Items.Count - 1 downto 0 do
|
---|
105 | if ListViewCategories.Items[I].Selected then
|
---|
106 | Categories.Remove(ListViewCategories.Items[I].Data);
|
---|
107 | UpdateList;
|
---|
108 | end;
|
---|
109 | end;
|
---|
110 | end;
|
---|
111 |
|
---|
112 | procedure TFormCategories.ListViewCategoriesData(Sender: TObject; Item: TListItem);
|
---|
113 | begin
|
---|
114 | if Item.Index < FormMain.AcronymDb.Categories.Count then
|
---|
115 | with TAcronymCategory(FormMain.AcronymDb.Categories[Item.Index]) do begin
|
---|
116 | Item.Caption := Name;
|
---|
117 | Item.Data := FormMain.AcronymDb.Categories[Item.Index];
|
---|
118 | Item.SubItems.Add(IntToStr(AcronymMeanings.Count));
|
---|
119 | end;
|
---|
120 | end;
|
---|
121 |
|
---|
122 | procedure TFormCategories.ListViewCategoriesSelectItem(Sender: TObject; Item: TListItem;
|
---|
123 | Selected: Boolean);
|
---|
124 | begin
|
---|
125 | UpdateInterface;
|
---|
126 | end;
|
---|
127 |
|
---|
128 | procedure TFormCategories.UpdateList;
|
---|
129 | begin
|
---|
130 | ListViewCategories.Items.Count := FormMain.AcronymDb.Categories.Count;
|
---|
131 | ListViewCategories.Refresh;
|
---|
132 | UpdateInterface;
|
---|
133 | end;
|
---|
134 |
|
---|
135 | procedure TFormCategories.UpdateInterface;
|
---|
136 | begin
|
---|
137 | ARemove.Enabled := Assigned(ListViewCategories.Selected);
|
---|
138 | AModify.Enabled := Assigned(ListViewCategories.Selected);
|
---|
139 | end;
|
---|
140 |
|
---|
141 | end.
|
---|
142 |
|
---|