source: tags/1.0.0/Forms/UFormImportSource.pas

Last change on this file was 33, checked in by chronos, 8 years ago
  • Added: Now import sources have categories which are merged to new imported acronym meanings.
File size: 4.3 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;
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 CheckBoxEnabled: TCheckBox;
26 ComboBox1: TComboBox;
27 EditName: TEdit;
28 EditURL: TEdit;
29 Label1: TLabel;
30 Label2: TLabel;
31 Label3: TLabel;
32 Label4: TLabel;
33 ListBox1: TListBox;
34 MenuItem1: TMenuItem;
35 MenuItem2: TMenuItem;
36 PopupMenuCategory: TPopupMenu;
37 procedure ACategoryAddExecute(Sender: TObject);
38 procedure ACategoryRemoveExecute(Sender: TObject);
39 procedure ButtonShowFormatClick(Sender: TObject);
40 procedure FormShow(Sender: TObject);
41 private
42 { private declarations }
43 public
44 procedure UpdateInterface;
45 procedure Load(ImportSource: TImportSource);
46 procedure Save(ImportSource: TImportSource);
47 end;
48
49var
50 FormImportSource: TFormImportSource;
51
52implementation
53
54{$R *.lfm}
55
56uses
57 UFormMain, UFormImportFormat, UFormCategorySelect;
58
59{ TFormImportSource }
60
61procedure TFormImportSource.ButtonShowFormatClick(Sender: TObject);
62var
63 NewImportFormat: TImportFormat;
64begin
65 if ComboBox1.ItemIndex <> -1 then begin
66 NewImportFormat := TImportFormat.Create;
67 NewImportFormat.Assign(TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]));
68 FormImportFormat.Load(NewImportFormat);
69 if FormImportFormat.ShowModal = mrOk then begin
70 FormImportFormat.Save(NewImportFormat);
71 TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]).Assign(NewImportFormat);
72 FormMain.AcronymDb.Modified := True;
73 ComboBox1.Items.Strings[ComboBox1.ItemIndex] := NewImportFormat.Name;
74 end;
75 if Assigned(NewImportFormat) then NewImportFormat.Free;
76 end;
77end;
78
79procedure TFormImportSource.FormShow(Sender: TObject);
80begin
81 UpdateInterface;
82end;
83
84procedure TFormImportSource.UpdateInterface;
85begin
86 ACategoryRemove.Enabled := ListBox1.ItemIndex <> -1;
87end;
88
89procedure TFormImportSource.ACategoryAddExecute(Sender: TObject);
90var
91 I: Integer;
92begin
93 FormCategorySelect.Load(ListBox1.Items);
94 if FormCategorySelect.ShowModal = mrOk then begin
95 for I := 0 to FormCategorySelect.ListBox1.Count - 1 do
96 if FormCategorySelect.ListBox1.Selected[I] then begin
97 ListBox1.Items.AddObject(FormCategorySelect.ListBox1.Items[I], FormCategorySelect.ListBox1.Items.Objects[I]);
98 end;
99 end;
100end;
101
102procedure TFormImportSource.ACategoryRemoveExecute(Sender: TObject);
103var
104 I: Integer;
105begin
106 if MessageDlg(SRemoveCategory, SRemoveCategoryQuery,
107 TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
108 for I := ListBox1.Items.Count - 1 downto 0 do
109 if ListBox1.Selected[I] then
110 ListBox1.Items.Delete(I);
111 UpdateInterface;
112 end;
113end;
114
115procedure TFormImportSource.Load(ImportSource: TImportSource);
116var
117 I: Integer;
118begin
119 EditName.Text := ImportSource.Name;
120 EditURL.Text := ImportSource.URL;
121 while ComboBox1.Items.Count > FormMain.AcronymDb.ImportFormats.Count do
122 ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
123 while ComboBox1.Items.Count < FormMain.AcronymDb.ImportFormats.Count do
124 ComboBox1.Items.Add('');
125 for I := 0 to FormMain.AcronymDb.ImportFormats.Count - 1 do begin
126 ComboBox1.Items[I] := TImportFormat(FormMain.AcronymDb.ImportFormats[I]).Name;
127 ComboBox1.Items.Objects[I] := FormMain.AcronymDb.ImportFormats[I];
128 end;
129 ComboBox1.ItemIndex := ComboBox1.Items.IndexOfObject(ImportSource.Format);
130 if (ComboBox1.ItemIndex = -1) and (ComboBox1.Items.Count > 0) then
131 ComboBox1.ItemIndex := 0;
132 CheckBoxEnabled.Checked := ImportSource.Enabled;
133 ImportSource.Categories.AssignToStrings(ListBox1.Items);
134end;
135
136procedure TFormImportSource.Save(ImportSource: TImportSource);
137begin
138 ImportSource.Name := EditName.Text;
139 ImportSource.URL := EditURL.Text;
140 ImportSource.Format := TImportFormat(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);
141 ImportSource.Enabled := CheckBoxEnabled.Checked;
142 ImportSource.Categories.AssignFromStrings(ListBox1.Items);
143end;
144
145end.
146
Note: See TracBrowser for help on using the repository browser.