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