source: tags/1.3.0/Forms/UFormImportSource.pas

Last change on this file was 89, checked in by chronos, 8 years ago
  • Added: Show from which imports acronym meanings comes from.

This would easy correcting wrong acronyms directly in source.

  • Modified: References to categories stored more efficiently in XML project file.
File size: 4.8 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 FormShow(Sender: TObject);
47 private
48 { private declarations }
49 public
50 procedure UpdateInterface;
51 procedure Load(ImportSource: TImportSource);
52 procedure Save(ImportSource: TImportSource);
53 end;
54
55var
56 FormImportSource: TFormImportSource;
57
58implementation
59
60{$R *.lfm}
61
62uses
63 UCore, UFormImportFormat, UFormCategorySelect;
64
65{ TFormImportSource }
66
67procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
68var
69 NewImportFormat: TImportFormat;
70begin
71 if ComboBox1.ItemIndex <> -1 then begin
72 NewImportFormat := TImportFormat.Create;
73 NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
74 FormImportFormat.Load(NewImportFormat);
75 if FormImportFormat.ShowModal = mrOk then begin
76 FormImportFormat.Save(NewImportFormat);
77 TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
78 Core.AcronymDb.Modified := True;
79 ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
80 end;
81 if Assigned(NewImportFormat) then NewImportFormat.Free;
82 end;
83end;
84
85procedure TFormImportSource.FormShow(Sender: TObject);
86begin
87 UpdateInterface;
88end;
89
90procedure TFormImportSource.UpdateInterface;
91begin
92 ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
93end;
94
95procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
96var
97 I: Integer;
98begin
99 FormCategorySelect.Load(ListBox1.Items);
100 if FormCategorySelect.ShowModal = mrOk then begin
101 for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
102 if FormCategorySelect.ListBox1.Selected[I] then begin
103 ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
104 end;
105 end;
106end;
107
108procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
109var
110 I: Integer;
111begin
112 if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
113 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
114 for I := ListBox1.Items.Count - 1 downto 0 do
115 if ListBox1.Selected[I] then
116 ListBox1.Items.Delete(I);
117 UpdateInterface;
118 end;
119end;
120
121procedure TFormImportSource.ButtonOpenURLClick(Sender: TObject);
122begin
123 OpenURL(EditURL.Text);
124end;
125
126procedure TFormImportSource.Load(ImportSource: TImportSource);
127var
128 I: Integer;
129begin
130 EditName.Text := ImportSource.Name;
131 EditURL.Text := ImportSource.URL;
132 while ComboBox1.Items.Count > Core.AcronymDb.ImportFormats.Count do
133 ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
134 while ComboBox1.Items.Count < Core.AcronymDb.ImportFormats.Count do
135 ComboBox1.Items.Add('');
136 for I := 0 to Core.AcronymDb.ImportFormats.Count - 1 do begin
137 ComboBox1.Items[I] := TImportFormat(Core.AcronymDb.ImportFormats[I]).Name;
138 ComboBox1.Items.Objects[I] := Core.AcronymDb.ImportFormats[I];
139 end;
140 ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
141 if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
142 ComboBox1.ItemIndex := 0;
143 CheckBoxEnabled.Checked := ImportSource.Enabled;
144 ImportSource.Categories.AssignToStrings(ListBox1.Items);
145 EditUserName.Text := ImportSource.UserName;
146 EditPassword.Text := ImportSource.Password;
147end;
148
149procedure TFormImportSource.Save(ImportSource: TImportSource);
150begin
151 ImportSource.Name := EditName.Text;
152 ImportSource.URL := EditURL.Text;
153 ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
154 ImportSource.Enabled := CheckBoxEnabled.Checked;
155 ImportSource.Categories.AssignFromStrings(ListBox1.Items);
156 ImportSource.UserName := EditUserName.Text;
157 ImportSource.Password := EditPassword.Text;
158end;
159
160end.
161
Note: See TracBrowser for help on using the repository browser.