source: tags/1.1.0/Forms/UFormCategories.pas

Last change on this file was 51, checked in by chronos, 8 years ago
  • Added: Bottom action toolbar to windows with lists.
File size: 4.1 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 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
45var
46 FormCategories: TFormCategories;
47
48implementation
49
50{$R *.lfm}
51
52uses
53 UFormMain;
54
55resourcestring
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
64procedure TFormCategories.FormShow(Sender: TObject);
65begin
66 UpdateList;
67end;
68
69procedure TFormCategories.AAddExecute(Sender: TObject);
70var
71 S: string;
72begin
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;
81end;
82
83procedure TFormCategories.AModifyExecute(Sender: TObject);
84var
85 S: string;
86begin
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;
97end;
98
99procedure TFormCategories.ARemoveExecute(Sender: TObject);
100var
101 I: Integer;
102begin
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;
112end;
113
114procedure TFormCategories.FormCreate(Sender: TObject);
115var
116 I: Integer;
117begin
118 for I := 0 to ToolBar1.ButtonCount - 1 do
119 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
120end;
121
122procedure TFormCategories.ListViewCategoriesData(Sender: TObject; Item: TListItem);
123begin
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;
130end;
131
132procedure TFormCategories.ListViewCategoriesSelectItem(Sender: TObject; Item: TListItem;
133 Selected: Boolean);
134begin
135 UpdateInterface;
136end;
137
138procedure TFormCategories.UpdateList;
139begin
140 ListViewCategories.Items.Count := FormMain.AcronymDb.Categories.Count;
141 ListViewCategories.Refresh;
142 UpdateInterface;
143end;
144
145procedure TFormCategories.UpdateInterface;
146begin
147 ARemove.Enabled := Assigned(ListViewCategories.Selected);
148 AModify.Enabled := Assigned(ListViewCategories.Selected);
149end;
150
151end.
152
Note: See TracBrowser for help on using the repository browser.