source: trunk/Forms/UFormImportSource.pas

Last change on this file was 207, checked in by chronos, 3 years ago
  • Modified: Updated Common package.
  • Modified: CoolTranslator package merged into Common package.
  • Fixed: Build with Lazarus 2.0.12
File size: 5.5 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 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
57var
58 FormImportSource: TFormImportSource;
59
60implementation
61
62{$R *.lfm}
63
64uses
65 UCore, UFormImportFormat, UFormCategorySelect;
66
67{ TFormImportSource }
68
69procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
70var
71 NewImportFormat: TImportFormat;
72begin
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;
90end;
91
92procedure TFormImportSource.FormClose(Sender: TObject;
93 var CloseAction: TCloseAction);
94begin
95 Core.PersistentForm1.Save(Self);
96end;
97
98procedure TFormImportSource.FormCreate(Sender: TObject);
99begin
100 Core.Translator.TranslateComponentRecursive(Self);
101 Core.ThemeManager.UseTheme(Self);
102end;
103
104procedure TFormImportSource.FormShow(Sender: TObject);
105begin
106 Core.PersistentForm1.Load(Self);
107 UpdateInterface;
108end;
109
110procedure TFormImportSource.UpdateInterface;
111begin
112 ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
113end;
114
115procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
116var
117 I: Integer;
118begin
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;
131end;
132
133procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
134var
135 I: Integer;
136begin
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;
144end;
145
146procedure TFormImportSource.ButtonOpenURLClick(Sender: TObject);
147begin
148 OpenURL(EditURL.Text);
149end;
150
151procedure TFormImportSource.Load(ImportSource: TImportSource);
152var
153 I: Integer;
154begin
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;
172end;
173
174procedure TFormImportSource.Save(ImportSource: TImportSource);
175begin
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;
183end;
184
185end.
186
Note: See TracBrowser for help on using the repository browser.