| 1 | unit FormAcronym;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
|
|---|
| 7 | StdCtrls, ActnList, Acronym, FormEx;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 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 |
|
|---|
| 49 | implementation
|
|---|
| 50 |
|
|---|
| 51 | {$R *.lfm}
|
|---|
| 52 |
|
|---|
| 53 | uses
|
|---|
| 54 | FormCategorySelect;
|
|---|
| 55 |
|
|---|
| 56 | { TFormAcronym }
|
|---|
| 57 |
|
|---|
| 58 | procedure TFormAcronym.ACategoryAddExecute(Sender: TObject);
|
|---|
| 59 | var
|
|---|
| 60 | I: Integer;
|
|---|
| 61 | FormCategorySelect: TFormCategorySelect;
|
|---|
| 62 | begin
|
|---|
| 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;
|
|---|
| 76 | end;
|
|---|
| 77 |
|
|---|
| 78 | procedure TFormAcronym.ACategoryRemoveExecute(Sender: TObject);
|
|---|
| 79 | var
|
|---|
| 80 | I: Integer;
|
|---|
| 81 | begin
|
|---|
| 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;
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | procedure TFormAcronym.EditMeaningKeyPress(Sender: TObject; var Key: char);
|
|---|
| 92 | begin
|
|---|
| 93 | if Ord(Key) = 13 then ButtonOk.Click;
|
|---|
| 94 | if Ord(Key) = 27 then ButtonCancel.Click;
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TFormAcronym.FormShow(Sender: TObject);
|
|---|
| 98 | begin
|
|---|
| 99 | UpdateInterface;
|
|---|
| 100 | end;
|
|---|
| 101 |
|
|---|
| 102 | procedure TFormAcronym.ListBoxCategoriesSelectionChange(Sender: TObject; User: boolean);
|
|---|
| 103 | begin
|
|---|
| 104 | UpdateInterface;
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | procedure TFormAcronym.UpdateInterface;
|
|---|
| 108 | begin
|
|---|
| 109 | ACategoryRemove.Enabled := ListBoxCategories.ItemIndex <> -1;
|
|---|
| 110 | end;
|
|---|
| 111 |
|
|---|
| 112 | procedure TFormAcronym.Load(Entry: TAcronymEntry);
|
|---|
| 113 | begin
|
|---|
| 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);
|
|---|
| 119 | end;
|
|---|
| 120 |
|
|---|
| 121 | procedure TFormAcronym.Save(Entry: TAcronymEntry);
|
|---|
| 122 | begin
|
|---|
| 123 | Entry.Name := EditAcronym.Text;
|
|---|
| 124 | Entry.Meaning := EditMeaning.Text;
|
|---|
| 125 | Entry.Description := MemoDescription.Text;
|
|---|
| 126 | Entry.Categories.Assign(ListBoxCategories.Items);
|
|---|
| 127 | end;
|
|---|
| 128 |
|
|---|
| 129 | end.
|
|---|
| 130 |
|
|---|