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, UAcronym, LCLIntf;
|
---|
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 | ButtonOpenURL: TButton;
|
---|
26 | CheckBoxEnabled: TCheckBox;
|
---|
27 | ComboBox1: TComboBox;
|
---|
28 | EditUserName: TEdit;
|
---|
29 | EditName: TEdit;
|
---|
30 | EditURL: TEdit;
|
---|
31 | EditPassword: TEdit;
|
---|
32 | Label1: TLabel;
|
---|
33 | Label2: TLabel;
|
---|
34 | Label3: TLabel;
|
---|
35 | Label4: TLabel;
|
---|
36 | Label5: TLabel;
|
---|
37 | Label6: TLabel;
|
---|
38 | ListBox1: TListBox;
|
---|
39 | MenuItem1: TMenuItem;
|
---|
40 | MenuItem2: TMenuItem;
|
---|
41 | PopupMenuCategory: TPopupMenu;
|
---|
42 | procedure ACategoryAddExecute(Sender: TObject);
|
---|
43 | procedure ACategoryRemoveExecute(Sender: TObject);
|
---|
44 | procedure ButtonOpenURLClick(Sender: TObject);
|
---|
45 | procedure ButtonShowFormatClick(Sender: TObject);
|
---|
46 | procedure FormShow(Sender: TObject);
|
---|
47 | private
|
---|
48 | { private declarations }
|
---|
49 | public
|
---|
50 | procedure UpdateInterface;
|
---|
51 | procedure Load(ImportSource: TImportSource);
|
---|
52 | procedure Save(ImportSource: TImportSource);
|
---|
53 | end;
|
---|
54 |
|
---|
55 | var
|
---|
56 | FormImportSource: TFormImportSource;
|
---|
57 |
|
---|
58 | implementation
|
---|
59 |
|
---|
60 | {$R *.lfm}
|
---|
61 |
|
---|
62 | uses
|
---|
63 | UCore, UFormImportFormat, UFormCategorySelect;
|
---|
64 |
|
---|
65 | { TFormImportSource }
|
---|
66 |
|
---|
67 | procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
|
---|
68 | var
|
---|
69 | NewImportFormat: TImportFormat;
|
---|
70 | begin
|
---|
71 | if ComboBox1.ItemIndex <> -1 then begin
|
---|
72 | NewImportFormat := TImportFormat.Create;
|
---|
73 | NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
|
---|
74 | FormImportFormat.Load(NewImportFormat);
|
---|
75 | if FormImportFormat.ShowModal = mrOk then begin
|
---|
76 | FormImportFormat.Save(NewImportFormat);
|
---|
77 | TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
|
---|
78 | Core.AcronymDb.Modified := True;
|
---|
79 | ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
|
---|
80 | end;
|
---|
81 | if Assigned(NewImportFormat) then NewImportFormat.Free;
|
---|
82 | end;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | procedure TFormImportSource.FormShow(Sender: TObject);
|
---|
86 | begin
|
---|
87 | UpdateInterface;
|
---|
88 | end;
|
---|
89 |
|
---|
90 | procedure TFormImportSource.UpdateInterface;
|
---|
91 | begin
|
---|
92 | ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
|
---|
93 | end;
|
---|
94 |
|
---|
95 | procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
|
---|
96 | var
|
---|
97 | I: Integer;
|
---|
98 | begin
|
---|
99 | FormCategorySelect.Load(ListBox1.Items);
|
---|
100 | if FormCategorySelect.ShowModal = mrOk then begin
|
---|
101 | for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
|
---|
102 | if FormCategorySelect.ListBox1.Selected[I] then begin
|
---|
103 | ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
|
---|
104 | end;
|
---|
105 | end;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
|
---|
109 | var
|
---|
110 | I: Integer;
|
---|
111 | begin
|
---|
112 | if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
|
---|
113 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
114 | for I := ListBox1.Items.Count - 1 downto 0 do
|
---|
115 | if ListBox1.Selected[I] then
|
---|
116 | ListBox1.Items.Delete(I);
|
---|
117 | UpdateInterface;
|
---|
118 | end;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TFormImportSource.ButtonOpenURLClick(Sender: TObject);
|
---|
122 | begin
|
---|
123 | OpenURL(EditURL.Text);
|
---|
124 | end;
|
---|
125 |
|
---|
126 | procedure TFormImportSource.Load(ImportSource: TImportSource);
|
---|
127 | var
|
---|
128 | I: Integer;
|
---|
129 | begin
|
---|
130 | EditName.Text := ImportSource.Name;
|
---|
131 | EditURL.Text := ImportSource.URL;
|
---|
132 | while ComboBox1.Items.Count > Core.AcronymDb.ImportFormats.Count do
|
---|
133 | ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
|
---|
134 | while ComboBox1.Items.Count < Core.AcronymDb.ImportFormats.Count do
|
---|
135 | ComboBox1.Items.Add('');
|
---|
136 | for I := 0 to Core.AcronymDb.ImportFormats.Count - 1 do begin
|
---|
137 | ComboBox1.Items[I] := TImportFormat(Core.AcronymDb.ImportFormats[I]).Name;
|
---|
138 | ComboBox1.Items.Objects[I] := Core.AcronymDb.ImportFormats[I];
|
---|
139 | end;
|
---|
140 | ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
|
---|
141 | if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
|
---|
142 | ComboBox1.ItemIndex := 0;
|
---|
143 | CheckBoxEnabled.Checked := ImportSource.Enabled;
|
---|
144 | ImportSource.Categories.AssignToStrings(ListBox1.Items);
|
---|
145 | EditUserName.Text := ImportSource.UserName;
|
---|
146 | EditPassword.Text := ImportSource.Password;
|
---|
147 | end;
|
---|
148 |
|
---|
149 | procedure TFormImportSource.Save(ImportSource: TImportSource);
|
---|
150 | begin
|
---|
151 | ImportSource.Name := EditName.Text;
|
---|
152 | ImportSource.URL := EditURL.Text;
|
---|
153 | ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
|
---|
154 | ImportSource.Enabled := CheckBoxEnabled.Checked;
|
---|
155 | ImportSource.Categories.AssignFromStrings(ListBox1.Items);
|
---|
156 | ImportSource.UserName := EditUserName.Text;
|
---|
157 | ImportSource.Password := EditPassword.Text;
|
---|
158 | end;
|
---|
159 |
|
---|
160 | end.
|
---|
161 |
|
---|