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 FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
47 | procedure FormCreate(Sender: TObject);
|
---|
48 | procedure FormShow(Sender: TObject);
|
---|
49 | private
|
---|
50 | { private declarations }
|
---|
51 | public
|
---|
52 | procedure UpdateInterface;
|
---|
53 | procedure Load(ImportSource: TImportSource);
|
---|
54 | procedure Save(ImportSource: TImportSource);
|
---|
55 | end;
|
---|
56 |
|
---|
57 | var
|
---|
58 | FormImportSource: TFormImportSource;
|
---|
59 |
|
---|
60 | implementation
|
---|
61 |
|
---|
62 | {$R *.lfm}
|
---|
63 |
|
---|
64 | uses
|
---|
65 | UCore, UFormImportFormat, UFormCategorySelect;
|
---|
66 |
|
---|
67 | { TFormImportSource }
|
---|
68 |
|
---|
69 | procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
|
---|
70 | var
|
---|
71 | NewImportFormat: TImportFormat;
|
---|
72 | begin
|
---|
73 | if ComboBox1.ItemIndex <> -1 then begin
|
---|
74 | NewImportFormat := TImportFormat.Create;
|
---|
75 | NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
|
---|
76 | FormImportFormat := TFormImportFormat.Create(Self);
|
---|
77 | try
|
---|
78 | FormImportFormat.Load(NewImportFormat);
|
---|
79 | if FormImportFormat.ShowModal = mrOk then begin
|
---|
80 | FormImportFormat.Save(NewImportFormat);
|
---|
81 | TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
|
---|
82 | Core.AcronymDb.Modified := True;
|
---|
83 | ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
|
---|
84 | end;
|
---|
85 | if Assigned(NewImportFormat) then NewImportFormat.Free;
|
---|
86 | finally
|
---|
87 | FreeAndNil(FormImportFormat);
|
---|
88 | end;
|
---|
89 | end;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TFormImportSource.FormClose(Sender: TObject;
|
---|
93 | var CloseAction: TCloseAction);
|
---|
94 | begin
|
---|
95 | Core.PersistentForm1.Save(Self);
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormImportSource.FormCreate(Sender: TObject);
|
---|
99 | begin
|
---|
100 | Core.CoolTranslator1.TranslateComponentRecursive(Self);
|
---|
101 | Core.ThemeManager.UseTheme(Self);
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TFormImportSource.FormShow(Sender: TObject);
|
---|
105 | begin
|
---|
106 | Core.PersistentForm1.Load(Self);
|
---|
107 | UpdateInterface;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | procedure TFormImportSource.UpdateInterface;
|
---|
111 | begin
|
---|
112 | ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
|
---|
116 | var
|
---|
117 | I: Integer;
|
---|
118 | begin
|
---|
119 | FormCategorySelect := TFormCategorySelect.Create(Self);
|
---|
120 | try
|
---|
121 | FormCategorySelect.Load(ListBox1.Items);
|
---|
122 | if FormCategorySelect.ShowModal = mrOk then begin
|
---|
123 | for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
|
---|
124 | if FormCategorySelect.ListBox1.Selected[I] then begin
|
---|
125 | ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
|
---|
126 | end;
|
---|
127 | end;
|
---|
128 | finally
|
---|
129 | FreeAndNil(FormCategorySelect);
|
---|
130 | end;
|
---|
131 | end;
|
---|
132 |
|
---|
133 | procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
|
---|
134 | var
|
---|
135 | I: Integer;
|
---|
136 | begin
|
---|
137 | if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
|
---|
138 | TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
|
---|
139 | for I := ListBox1.Items.Count - 1 downto 0 do
|
---|
140 | if ListBox1.Selected[I] then
|
---|
141 | ListBox1.Items.Delete(I);
|
---|
142 | UpdateInterface;
|
---|
143 | end;
|
---|
144 | end;
|
---|
145 |
|
---|
146 | procedure TFormImportSource.ButtonOpenURLClick(Sender: TObject);
|
---|
147 | begin
|
---|
148 | OpenURL(EditURL.Text);
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TFormImportSource.Load(ImportSource: TImportSource);
|
---|
152 | var
|
---|
153 | I: Integer;
|
---|
154 | begin
|
---|
155 | EditName.Text := ImportSource.Name;
|
---|
156 | EditURL.Text := ImportSource.URL;
|
---|
157 | while ComboBox1.Items.Count > Core.AcronymDb.ImportFormats.Count do
|
---|
158 | ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
|
---|
159 | while ComboBox1.Items.Count < Core.AcronymDb.ImportFormats.Count do
|
---|
160 | ComboBox1.Items.Add('');
|
---|
161 | for I := 0 to Core.AcronymDb.ImportFormats.Count - 1 do begin
|
---|
162 | ComboBox1.Items[I] := TImportFormat(Core.AcronymDb.ImportFormats[I]).Name;
|
---|
163 | ComboBox1.Items.Objects[I] := Core.AcronymDb.ImportFormats[I];
|
---|
164 | end;
|
---|
165 | ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
|
---|
166 | if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
|
---|
167 | ComboBox1.ItemIndex := 0;
|
---|
168 | CheckBoxEnabled.Checked := ImportSource.Enabled;
|
---|
169 | ImportSource.Categories.AssignToStrings(ListBox1.Items);
|
---|
170 | EditUserName.Text := ImportSource.UserName;
|
---|
171 | EditPassword.Text := ImportSource.Password;
|
---|
172 | end;
|
---|
173 |
|
---|
174 | procedure TFormImportSource.Save(ImportSource: TImportSource);
|
---|
175 | begin
|
---|
176 | ImportSource.Name := EditName.Text;
|
---|
177 | ImportSource.URL := EditURL.Text;
|
---|
178 | ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
|
---|
179 | ImportSource.Enabled := CheckBoxEnabled.Checked;
|
---|
180 | ImportSource.Categories.AssignFromStrings(ListBox1.Items);
|
---|
181 | ImportSource.UserName := EditUserName.Text;
|
---|
182 | ImportSource.Password := EditPassword.Text;
|
---|
183 | end;
|
---|
184 |
|
---|
185 | end.
|
---|
186 |
|
---|