source: tags/1.0.0/Forms/UFormCategories.pas

Last change on this file was 20, checked in by chronos, 8 years ago
File size: 3.8 KB
Line 
1unit UFormCategories;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 StdCtrls, ActnList, Menus, UAcronym;
10
11type
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
43var
44 FormCategories: TFormCategories;
45
46implementation
47
48{$R *.lfm}
49
50uses
51 UFormMain;
52
53resourcestring
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
62procedure TFormCategories.FormShow(Sender: TObject);
63begin
64 UpdateList;
65end;
66
67procedure TFormCategories.AAddExecute(Sender: TObject);
68var
69 S: string;
70begin
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;
79end;
80
81procedure TFormCategories.AModifyExecute(Sender: TObject);
82var
83 S: string;
84begin
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;
95end;
96
97procedure TFormCategories.ARemoveExecute(Sender: TObject);
98var
99 I: Integer;
100begin
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;
110end;
111
112procedure TFormCategories.ListViewCategoriesData(Sender: TObject; Item: TListItem);
113begin
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;
120end;
121
122procedure TFormCategories.ListViewCategoriesSelectItem(Sender: TObject; Item: TListItem;
123 Selected: Boolean);
124begin
125 UpdateInterface;
126end;
127
128procedure TFormCategories.UpdateList;
129begin
130 ListViewCategories.Items.Count := FormMain.AcronymDb.Categories.Count;
131 ListViewCategories.Refresh;
132 UpdateInterface;
133end;
134
135procedure TFormCategories.UpdateInterface;
136begin
137 ARemove.Enabled := Assigned(ListViewCategories.Selected);
138 AModify.Enabled := Assigned(ListViewCategories.Selected);
139end;
140
141end.
142
Note: See TracBrowser for help on using the repository browser.