source: trunk/Forms/UFormAcronym.pas

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