| 1 | unit FormImportSource;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
|---|
| 7 | ActnList, Menus, ExtCtrls, Acronym, LCLIntf, FormEx;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 |
|
|---|
| 11 | { TFormImportSource }
|
|---|
| 12 |
|
|---|
| 13 | TFormImportSource = class(TFormEx)
|
|---|
| 14 | ACategoryAdd: TAction;
|
|---|
| 15 | ACategoryRemove: TAction;
|
|---|
| 16 | ActionList1: TActionList;
|
|---|
| 17 | Button1: TButton;
|
|---|
| 18 | Button2: TButton;
|
|---|
| 19 | ButtonOk: TButton;
|
|---|
| 20 | ButtonCancel: TButton;
|
|---|
| 21 | ButtonOpenURL: TButton;
|
|---|
| 22 | ButtonShowFormat: TButton;
|
|---|
| 23 | CheckBoxEnabled: TCheckBox;
|
|---|
| 24 | ComboBox1: TComboBox;
|
|---|
| 25 | EditName: TEdit;
|
|---|
| 26 | EditPassword: TEdit;
|
|---|
| 27 | EditURL: TEdit;
|
|---|
| 28 | EditUserName: TEdit;
|
|---|
| 29 | Label1: TLabel;
|
|---|
| 30 | Label2: TLabel;
|
|---|
| 31 | Label3: TLabel;
|
|---|
| 32 | Label4: TLabel;
|
|---|
| 33 | Label5: TLabel;
|
|---|
| 34 | Label6: TLabel;
|
|---|
| 35 | ListBox1: TListBox;
|
|---|
| 36 | MenuItem1: TMenuItem;
|
|---|
| 37 | MenuItem2: TMenuItem;
|
|---|
| 38 | PopupMenuCategory: TPopupMenu;
|
|---|
| 39 | ScrollBox1: TScrollBox;
|
|---|
| 40 | procedure ACategoryAddExecute(Sender: TObject);
|
|---|
| 41 | procedure ACategoryRemoveExecute(Sender: TObject);
|
|---|
| 42 | procedure ButtonOpenURLClick(Sender: TObject);
|
|---|
| 43 | procedure ButtonShowFormatClick(Sender: TObject);
|
|---|
| 44 | procedure FormShow(Sender: TObject);
|
|---|
| 45 | public
|
|---|
| 46 | AcronymDb: TAcronymDb;
|
|---|
| 47 | procedure UpdateInterface;
|
|---|
| 48 | procedure Load(ImportSource: TImportSource);
|
|---|
| 49 | procedure Save(ImportSource: TImportSource);
|
|---|
| 50 | end;
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | implementation
|
|---|
| 54 |
|
|---|
| 55 | {$R *.lfm}
|
|---|
| 56 |
|
|---|
| 57 | uses
|
|---|
| 58 | FormImportFormat, FormCategorySelect;
|
|---|
| 59 |
|
|---|
| 60 | { TFormImportSource }
|
|---|
| 61 |
|
|---|
| 62 | procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
|
|---|
| 63 | var
|
|---|
| 64 | NewImportFormat: TImportFormat;
|
|---|
| 65 | FormImportFormat: TFormImportFormat;
|
|---|
| 66 | begin
|
|---|
| 67 | if ComboBox1.ItemIndex <> -1 then begin
|
|---|
| 68 | NewImportFormat := TImportFormat.Create;
|
|---|
| 69 | NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
|
|---|
| 70 | FormImportFormat := TFormImportFormat.Create(Self);
|
|---|
| 71 | try
|
|---|
| 72 | FormImportFormat.Load(NewImportFormat);
|
|---|
| 73 | if FormImportFormat.ShowModal = mrOk then begin
|
|---|
| 74 | FormImportFormat.Save(NewImportFormat);
|
|---|
| 75 | TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
|
|---|
| 76 | AcronymDb.Modified := True;
|
|---|
| 77 | ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
|
|---|
| 78 | end;
|
|---|
| 79 | if Assigned(NewImportFormat) then NewImportFormat.Free;
|
|---|
| 80 | finally
|
|---|
| 81 | FreeAndNil(FormImportFormat);
|
|---|
| 82 | end;
|
|---|
| 83 | end;
|
|---|
| 84 | end;
|
|---|
| 85 |
|
|---|
| 86 | procedure TFormImportSource.FormShow(Sender: TObject);
|
|---|
| 87 | begin
|
|---|
| 88 | UpdateInterface;
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | procedure TFormImportSource.UpdateInterface;
|
|---|
| 92 | begin
|
|---|
| 93 | ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
|
|---|
| 97 | var
|
|---|
| 98 | I: Integer;
|
|---|
| 99 | FormCategorySelect: TFormCategorySelect;
|
|---|
| 100 | begin
|
|---|
| 101 | FormCategorySelect := TFormCategorySelect.Create(Self);
|
|---|
| 102 | try
|
|---|
| 103 | FormCategorySelect.AcronymDb := AcronymDb;
|
|---|
| 104 | FormCategorySelect.Load(ListBox1.Items);
|
|---|
| 105 | if FormCategorySelect.ShowModal = mrOk then begin
|
|---|
| 106 | for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
|
|---|
| 107 | if FormCategorySelect.ListBox1.Selected[I] then begin
|
|---|
| 108 | ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
|
|---|
| 109 | end;
|
|---|
| 110 | end;
|
|---|
| 111 | finally
|
|---|
| 112 | FreeAndNil(FormCategorySelect);
|
|---|
| 113 | end;
|
|---|
| 114 | end;
|
|---|
| 115 |
|
|---|
| 116 | procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
|
|---|
| 117 | var
|
|---|
| 118 | I: Integer;
|
|---|
| 119 | begin
|
|---|
| 120 | if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
|
|---|
| 121 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
|---|
| 122 | for I := ListBox1.Items.Count - 1 downto 0 do
|
|---|
| 123 | if ListBox1.Selected[I] then
|
|---|
| 124 | ListBox1.Items.Delete(I);
|
|---|
| 125 | UpdateInterface;
|
|---|
| 126 | end;
|
|---|
| 127 | end;
|
|---|
| 128 |
|
|---|
| 129 | procedure TFormImportSource.ButtonOpenURLClick(Sender: TObject);
|
|---|
| 130 | begin
|
|---|
| 131 | OpenURL(EditURL.Text);
|
|---|
| 132 | end;
|
|---|
| 133 |
|
|---|
| 134 | procedure TFormImportSource.Load(ImportSource: TImportSource);
|
|---|
| 135 | var
|
|---|
| 136 | I: Integer;
|
|---|
| 137 | begin
|
|---|
| 138 | EditName.Text := ImportSource.Name;
|
|---|
| 139 | EditURL.Text := ImportSource.URL;
|
|---|
| 140 | while ComboBox1.Items.Count > AcronymDb.ImportFormats.Count do
|
|---|
| 141 | ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
|
|---|
| 142 | while ComboBox1.Items.Count < AcronymDb.ImportFormats.Count do
|
|---|
| 143 | ComboBox1.Items.Add('');
|
|---|
| 144 | for I := 0 to AcronymDb.ImportFormats.Count - 1 do begin
|
|---|
| 145 | ComboBox1.Items[I] := TImportFormat(AcronymDb.ImportFormats[I]).Name;
|
|---|
| 146 | ComboBox1.Items.Objects[I] := AcronymDb.ImportFormats[I];
|
|---|
| 147 | end;
|
|---|
| 148 | ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
|
|---|
| 149 | if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
|
|---|
| 150 | ComboBox1.ItemIndex := 0;
|
|---|
| 151 | CheckBoxEnabled.Checked := ImportSource.Enabled;
|
|---|
| 152 | ImportSource.Categories.AssignToStrings(ListBox1.Items);
|
|---|
| 153 | EditUserName.Text := ImportSource.UserName;
|
|---|
| 154 | EditPassword.Text := ImportSource.Password;
|
|---|
| 155 | end;
|
|---|
| 156 |
|
|---|
| 157 | procedure TFormImportSource.Save(ImportSource: TImportSource);
|
|---|
| 158 | begin
|
|---|
| 159 | ImportSource.Name := EditName.Text;
|
|---|
| 160 | ImportSource.URL := EditURL.Text;
|
|---|
| 161 | ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
|
|---|
| 162 | ImportSource.Enabled := CheckBoxEnabled.Checked;
|
|---|
| 163 | ImportSource.Categories.AssignFromStrings(ListBox1.Items);
|
|---|
| 164 | ImportSource.UserName := EditUserName.Text;
|
|---|
| 165 | ImportSource.Password := EditPassword.Text;
|
|---|
| 166 | end;
|
|---|
| 167 |
|
|---|
| 168 | end.
|
|---|
| 169 |
|
|---|