source: trunk/Forms/FormAcronym.pas

Last change on this file was 227, checked in by chronos, 44 hours ago
  • Modified: Do not reference global Core object if possible.
File size: 3.3 KB
Line 
1unit FormAcronym;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
7 StdCtrls, ActnList, Acronym, FormEx;
8
9type
10
11 { TFormAcronym }
12
13 TFormAcronym = class(TFormEx)
14 ACategoryAdd: TAction;
15 ACategoryRemove: TAction;
16 ActionList1: TActionList;
17 Button1: TButton;
18 Button2: TButton;
19 ButtonOk: TButton;
20 ButtonCancel: TButton;
21 EditAcronym: TEdit;
22 EditMeaning: TEdit;
23 Label1: TLabel;
24 Label2: TLabel;
25 Label3: TLabel;
26 Label4: TLabel;
27 Label5: TLabel;
28 ListBoxCategories: TListBox;
29 ListBoxImportSources: TListBox;
30 MemoDescription: TMemo;
31 MenuItem1: TMenuItem;
32 MenuItem2: TMenuItem;
33 PopupMenuCategory: TPopupMenu;
34 ScrollBox1: TScrollBox;
35 procedure ACategoryAddExecute(Sender: TObject);
36 procedure ACategoryRemoveExecute(Sender: TObject);
37 procedure EditMeaningKeyPress(Sender: TObject; var Key: char);
38 procedure FormShow(Sender: TObject);
39 procedure ListBoxCategoriesSelectionChange(Sender: TObject; User: boolean);
40 private
41 procedure UpdateInterface;
42 public
43 AcronymDb: TAcronymDb;
44 procedure Load(Entry: TAcronymEntry);
45 procedure Save(Entry: TAcronymEntry);
46 end;
47
48
49implementation
50
51{$R *.lfm}
52
53uses
54 FormCategorySelect;
55
56{ TFormAcronym }
57
58procedure TFormAcronym.ACategoryAddExecute(Sender: TObject);
59var
60 I: Integer;
61 FormCategorySelect: TFormCategorySelect;
62begin
63 FormCategorySelect := TFormCategorySelect.Create(Self);
64 try
65 FormCategorySelect.AcronymDb := AcronymDb;
66 FormCategorySelect.Load(ListBoxCategories.Items);
67 if FormCategorySelect.ShowModal = mrOk then begin
68 for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
69 if FormCategorySelect.ListBox1.Selected[I] then begin
70 ListBoxCategories.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
71 end;
72 end;
73 finally
74 FreeAndNil(FormCategorySelect);
75 end;
76end;
77
78procedure TFormAcronym.ACategoryRemoveExecute(Sender: TObject);
79var
80 I: Integer;
81begin
82 if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
83 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
84 for I := ListBoxCategories.Items.Count - 1 downto 0 do
85 if ListBoxCategories.Selected[I] then
86 ListBoxCategories.Items.Delete(I);
87 UpdateInterface;
88 end;
89end;
90
91procedure TFormAcronym.EditMeaningKeyPress(Sender: TObject; var Key: char);
92begin
93 if Ord(Key) = 13 then ButtonOk.Click;
94 if Ord(Key) = 27 then ButtonCancel.Click;
95end;
96
97procedure TFormAcronym.FormShow(Sender: TObject);
98begin
99 UpdateInterface;
100end;
101
102procedure TFormAcronym.ListBoxCategoriesSelectionChange(Sender: TObject; User: boolean);
103begin
104 UpdateInterface;
105end;
106
107procedure TFormAcronym.UpdateInterface;
108begin
109 ACategoryRemove.Enabled := ListBoxCategories.ItemIndex <> -1;
110end;
111
112procedure TFormAcronym.Load(Entry: TAcronymEntry);
113begin
114 EditAcronym.Text := Entry.Name;
115 EditMeaning.Text := Entry.Meaning;
116 MemoDescription.Text := Entry.Description;
117 ListBoxCategories.Items.Assign(Entry.Categories);
118 ListBoxImportSources.Items.Assign(Entry.Sources);
119end;
120
121procedure TFormAcronym.Save(Entry: TAcronymEntry);
122begin
123 Entry.Name := EditAcronym.Text;
124 Entry.Meaning := EditMeaning.Text;
125 Entry.Description := MemoDescription.Text;
126 Entry.Categories.Assign(ListBoxCategories.Items);
127end;
128
129end.
130
Note: See TracBrowser for help on using the repository browser.