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