source: tags/1.3.1/Forms/UFormImportSource.pas

Last change on this file was 96, checked in by chronos, 8 years ago
  • Fixed: Dynamically created forms were not translated.
File size: 5.2 KB
Line 
1unit UFormImportSource;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 ActnList, Menus, ExtCtrls, UAcronym, LCLIntf;
10
11type
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 FormCreate(Sender: TObject);
47 procedure FormShow(Sender: TObject);
48 private
49 { private declarations }
50 public
51 procedure UpdateInterface;
52 procedure Load(ImportSource: TImportSource);
53 procedure Save(ImportSource: TImportSource);
54 end;
55
56var
57 FormImportSource: TFormImportSource;
58
59implementation
60
61{$R *.lfm}
62
63uses
64 UCore, UFormImportFormat, UFormCategorySelect;
65
66{ TFormImportSource }
67
68procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
69var
70 NewImportFormat: TImportFormat;
71begin
72 if ComboBox1.ItemIndex <> -1 then begin
73 NewImportFormat := TImportFormat.Create;
74 NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
75 FormImportFormat := TFormImportFormat.Create(Self);
76 try
77 FormImportFormat.Load(NewImportFormat);
78 if FormImportFormat.ShowModal = mrOk then begin
79 FormImportFormat.Save(NewImportFormat);
80 TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
81 Core.AcronymDb.Modified := True;
82 ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
83 end;
84 if Assigned(NewImportFormat) then NewImportFormat.Free;
85 finally
86 FreeAndNil(FormImportFormat);
87 end;
88 end;
89end;
90
91procedure TFormImportSource.FormCreate(Sender: TObject);
92begin
93 Core.CoolTranslator1.TranslateComponentRecursive(Self);
94end;
95
96procedure TFormImportSource.FormShow(Sender: TObject);
97begin
98 UpdateInterface;
99end;
100
101procedure TFormImportSource.UpdateInterface;
102begin
103 ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
104end;
105
106procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
107var
108 I: Integer;
109begin
110 FormCategorySelect := TFormCategorySelect.Create(Self);
111 try
112 FormCategorySelect.Load(ListBox1.Items);
113 if FormCategorySelect.ShowModal = mrOk then begin
114 for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
115 if FormCategorySelect.ListBox1.Selected[I] then begin
116 ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
117 end;
118 end;
119 finally
120 FreeAndNil(FormCategorySelect);
121 end;
122end;
123
124procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
125var
126 I: Integer;
127begin
128 if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
129 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
130 for I := ListBox1.Items.Count - 1 downto 0 do
131 if ListBox1.Selected[I] then
132 ListBox1.Items.Delete(I);
133 UpdateInterface;
134 end;
135end;
136
137procedure TFormImportSource.ButtonOpenURLClick(Sender: TObject);
138begin
139 OpenURL(EditURL.Text);
140end;
141
142procedure TFormImportSource.Load(ImportSource: TImportSource);
143var
144 I: Integer;
145begin
146 EditName.Text := ImportSource.Name;
147 EditURL.Text := ImportSource.URL;
148 while ComboBox1.Items.Count > Core.AcronymDb.ImportFormats.Count do
149 ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
150 while ComboBox1.Items.Count < Core.AcronymDb.ImportFormats.Count do
151 ComboBox1.Items.Add('');
152 for I := 0 to Core.AcronymDb.ImportFormats.Count - 1 do begin
153 ComboBox1.Items[I] := TImportFormat(Core.AcronymDb.ImportFormats[I]).Name;
154 ComboBox1.Items.Objects[I] := Core.AcronymDb.ImportFormats[I];
155 end;
156 ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
157 if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
158 ComboBox1.ItemIndex := 0;
159 CheckBoxEnabled.Checked := ImportSource.Enabled;
160 ImportSource.Categories.AssignToStrings(ListBox1.Items);
161 EditUserName.Text := ImportSource.UserName;
162 EditPassword.Text := ImportSource.Password;
163end;
164
165procedure TFormImportSource.Save(ImportSource: TImportSource);
166begin
167 ImportSource.Name := EditName.Text;
168 ImportSource.URL := EditURL.Text;
169 ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
170 ImportSource.Enabled := CheckBoxEnabled.Checked;
171 ImportSource.Categories.AssignFromStrings(ListBox1.Items);
172 ImportSource.UserName := EditUserName.Text;
173 ImportSource.Password := EditPassword.Text;
174end;
175
176end.
177
Note: See TracBrowser for help on using the repository browser.