source: tags/1.4.0/Forms/UFormImportSource.pas

Last change on this file was 123, checked in by chronos, 7 years ago
  • Added: Remember width of list view columns after closing the application.
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.CoolTranslator1.TranslateComponentRecursive(Self);
101end;
102
103procedure TFormImportSource.FormShow(Sender: TObject);
104begin
105 Core.PersistentForm1.Load(Self);
106 UpdateInterface;
107end;
108
109procedure TFormImportSource.UpdateInterface;
110begin
111 ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
112end;
113
114procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
115var
116 I: Integer;
117begin
118 FormCategorySelect := TFormCategorySelect.Create(Self);
119 try
120 FormCategorySelect.Load(ListBox1.Items);
121 if FormCategorySelect.ShowModal = mrOk then begin
122 for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
123 if FormCategorySelect.ListBox1.Selected[I] then begin
124 ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
125 end;
126 end;
127 finally
128 FreeAndNil(FormCategorySelect);
129 end;
130end;
131
132procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
133var
134 I: Integer;
135begin
136 if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
137 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
138 for I := ListBox1.Items.Count - 1 downto 0 do
139 if ListBox1.Selected[I] then
140 ListBox1.Items.Delete(I);
141 UpdateInterface;
142 end;
143end;
144
145procedure TFormImportSource.ButtonOpenURLClick(Sender: TObject);
146begin
147 OpenURL(EditURL.Text);
148end;
149
150procedure TFormImportSource.Load(ImportSource: TImportSource);
151var
152 I: Integer;
153begin
154 EditName.Text := ImportSource.Name;
155 EditURL.Text := ImportSource.URL;
156 while ComboBox1.Items.Count > Core.AcronymDb.ImportFormats.Count do
157 ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
158 while ComboBox1.Items.Count < Core.AcronymDb.ImportFormats.Count do
159 ComboBox1.Items.Add('');
160 for I := 0 to Core.AcronymDb.ImportFormats.Count - 1 do begin
161 ComboBox1.Items[I] := TImportFormat(Core.AcronymDb.ImportFormats[I]).Name;
162 ComboBox1.Items.Objects[I] := Core.AcronymDb.ImportFormats[I];
163 end;
164 ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
165 if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
166 ComboBox1.ItemIndex := 0;
167 CheckBoxEnabled.Checked := ImportSource.Enabled;
168 ImportSource.Categories.AssignToStrings(ListBox1.Items);
169 EditUserName.Text := ImportSource.UserName;
170 EditPassword.Text := ImportSource.Password;
171end;
172
173procedure TFormImportSource.Save(ImportSource: TImportSource);
174begin
175 ImportSource.Name := EditName.Text;
176 ImportSource.URL := EditURL.Text;
177 ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
178 ImportSource.Enabled := CheckBoxEnabled.Checked;
179 ImportSource.Categories.AssignFromStrings(ListBox1.Items);
180 ImportSource.UserName := EditUserName.Text;
181 ImportSource.Password := EditPassword.Text;
182end;
183
184end.
185
Note: See TracBrowser for help on using the repository browser.