source: trunk/Forms/FormImportSource.pas

Last change on this file was 227, checked in by chronos, 44 hours ago
  • Modified: Do not reference global Core object if possible.
File size: 4.9 KB
Line 
1unit FormImportSource;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
7 ActnList, Menus, ExtCtrls, Acronym, LCLIntf, FormEx;
8
9type
10
11 { TFormImportSource }
12
13 TFormImportSource = class(TFormEx)
14 ACategoryAdd: TAction;
15 ACategoryRemove: TAction;
16 ActionList1: TActionList;
17 Button1: TButton;
18 Button2: TButton;
19 ButtonOk: TButton;
20 ButtonCancel: TButton;
21 ButtonOpenURL: TButton;
22 ButtonShowFormat: TButton;
23 CheckBoxEnabled: TCheckBox;
24 ComboBox1: TComboBox;
25 EditName: TEdit;
26 EditPassword: TEdit;
27 EditURL: TEdit;
28 EditUserName: TEdit;
29 Label1: TLabel;
30 Label2: TLabel;
31 Label3: TLabel;
32 Label4: TLabel;
33 Label5: TLabel;
34 Label6: TLabel;
35 ListBox1: TListBox;
36 MenuItem1: TMenuItem;
37 MenuItem2: TMenuItem;
38 PopupMenuCategory: TPopupMenu;
39 ScrollBox1: TScrollBox;
40 procedure ACategoryAddExecute(Sender: TObject);
41 procedure ACategoryRemoveExecute(Sender: TObject);
42 procedure ButtonOpenURLClick(Sender: TObject);
43 procedure ButtonShowFormatClick(Sender: TObject);
44 procedure FormShow(Sender: TObject);
45 public
46 AcronymDb: TAcronymDb;
47 procedure UpdateInterface;
48 procedure Load(ImportSource: TImportSource);
49 procedure Save(ImportSource: TImportSource);
50 end;
51
52
53implementation
54
55{$R *.lfm}
56
57uses
58 FormImportFormat, FormCategorySelect;
59
60{ TFormImportSource }
61
62procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
63var
64 NewImportFormat: TImportFormat;
65 FormImportFormat: TFormImportFormat;
66begin
67 if ComboBox1.ItemIndex <> -1 then begin
68 NewImportFormat := TImportFormat.Create;
69 NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
70 FormImportFormat := TFormImportFormat.Create(Self);
71 try
72 FormImportFormat.Load(NewImportFormat);
73 if FormImportFormat.ShowModal = mrOk then begin
74 FormImportFormat.Save(NewImportFormat);
75 TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
76 AcronymDb.Modified := True;
77 ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
78 end;
79 if Assigned(NewImportFormat) then NewImportFormat.Free;
80 finally
81 FreeAndNil(FormImportFormat);
82 end;
83 end;
84end;
85
86procedure TFormImportSource.FormShow(Sender: TObject);
87begin
88 UpdateInterface;
89end;
90
91procedure TFormImportSource.UpdateInterface;
92begin
93 ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
94end;
95
96procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
97var
98 I: Integer;
99 FormCategorySelect: TFormCategorySelect;
100begin
101 FormCategorySelect := TFormCategorySelect.Create(Self);
102 try
103 FormCategorySelect.AcronymDb := AcronymDb;
104 FormCategorySelect.Load(ListBox1.Items);
105 if FormCategorySelect.ShowModal = mrOk then begin
106 for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
107 if FormCategorySelect.ListBox1.Selected[I] then begin
108 ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
109 end;
110 end;
111 finally
112 FreeAndNil(FormCategorySelect);
113 end;
114end;
115
116procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
117var
118 I: Integer;
119begin
120 if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
121 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
122 for I := ListBox1.Items.Count - 1 downto 0 do
123 if ListBox1.Selected[I] then
124 ListBox1.Items.Delete(I);
125 UpdateInterface;
126 end;
127end;
128
129procedure TFormImportSource.ButtonOpenURLClick(Sender: TObject);
130begin
131 OpenURL(EditURL.Text);
132end;
133
134procedure TFormImportSource.Load(ImportSource: TImportSource);
135var
136 I: Integer;
137begin
138 EditName.Text := ImportSource.Name;
139 EditURL.Text := ImportSource.URL;
140 while ComboBox1.Items.Count > AcronymDb.ImportFormats.Count do
141 ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
142 while ComboBox1.Items.Count < AcronymDb.ImportFormats.Count do
143 ComboBox1.Items.Add('');
144 for I := 0 to AcronymDb.ImportFormats.Count - 1 do begin
145 ComboBox1.Items[I] := TImportFormat(AcronymDb.ImportFormats[I]).Name;
146 ComboBox1.Items.Objects[I] := AcronymDb.ImportFormats[I];
147 end;
148 ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
149 if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
150 ComboBox1.ItemIndex := 0;
151 CheckBoxEnabled.Checked := ImportSource.Enabled;
152 ImportSource.Categories.AssignToStrings(ListBox1.Items);
153 EditUserName.Text := ImportSource.UserName;
154 EditPassword.Text := ImportSource.Password;
155end;
156
157procedure TFormImportSource.Save(ImportSource: TImportSource);
158begin
159 ImportSource.Name := EditName.Text;
160 ImportSource.URL := EditURL.Text;
161 ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
162 ImportSource.Enabled := CheckBoxEnabled.Checked;
163 ImportSource.Categories.AssignFromStrings(ListBox1.Items);
164 ImportSource.UserName := EditUserName.Text;
165 ImportSource.Password := EditPassword.Text;
166end;
167
168end.
169
Note: See TracBrowser for help on using the repository browser.