source: tags/1.3.0/Forms/UFormCategories.pas

Last change on this file was 89, checked in by chronos, 8 years ago
  • Added: Show from which imports acronym meanings comes from.

This would easy correcting wrong acronyms directly in source.

  • Modified: References to categories stored more efficiently in XML project file.
File size: 4.4 KB
Line 
1unit UFormCategories;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
9 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 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
47var
48 FormCategories: TFormCategories;
49
50implementation
51
52{$R *.lfm}
53
54uses
55 UCore;
56
57resourcestring
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
66procedure TFormCategories.FormShow(Sender: TObject);
67begin
68 UpdateList;
69end;
70
71procedure TFormCategories.AAddExecute(Sender: TObject);
72var
73 S: string;
74begin
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;
83end;
84
85procedure TFormCategories.AModifyExecute(Sender: TObject);
86var
87 S: string;
88begin
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;
99end;
100
101procedure TFormCategories.ARemoveExecute(Sender: TObject);
102var
103 I: Integer;
104begin
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;
114end;
115
116procedure TFormCategories.FormCreate(Sender: TObject);
117var
118 I: Integer;
119begin
120 for I := 0 to ToolBar1.ButtonCount - 1 do
121 ToolBar1.Buttons[I].Hint := ToolBar1.Buttons[I].Caption;
122end;
123
124procedure TFormCategories.ListViewCategoriesData(Sender: TObject; Item: TListItem);
125begin
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;
132end;
133
134procedure TFormCategories.ListViewCategoriesDblClick(Sender: TObject);
135begin
136 AModify.Execute;
137end;
138
139procedure TFormCategories.ListViewCategoriesKeyPress(Sender: TObject;
140 var Key: char);
141begin
142 if Key = #27 then Close;
143end;
144
145procedure TFormCategories.ListViewCategoriesSelectItem(Sender: TObject; Item: TListItem;
146 Selected: Boolean);
147begin
148 UpdateInterface;
149end;
150
151procedure TFormCategories.UpdateList;
152begin
153 ListViewCategories.Items.Count := Core.AcronymDb.Categories.Count;
154 ListViewCategories.Refresh;
155 UpdateInterface;
156end;
157
158procedure TFormCategories.UpdateInterface;
159begin
160 ARemove.Enabled := Assigned(ListViewCategories.Selected);
161 AModify.Enabled := Assigned(ListViewCategories.Selected);
162end;
163
164end.
165
Note: See TracBrowser for help on using the repository browser.