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