-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigObjectSelect.pas
More file actions
157 lines (134 loc) · 3.86 KB
/
ConfigObjectSelect.pas
File metadata and controls
157 lines (134 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
unit ConfigObjectSelect;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
Vcl.ComCtrls, System.ImageList, Vcl.ImgList, ConfigTypes, ConfigRegistry;
type
TfrmConfigObjectSelect = class(TForm)
pnlBottom: TPanel;
btnOK: TButton;
btnCancel: TButton;
lvObjectTypes: TListView;
edtName: TLabeledEdit;
mmoDescription: TMemo;
lblDescription: TLabel;
ilIcons: TImageList;
procedure FormCreate(Sender: TObject);
procedure lvObjectTypesSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
procedure edtNameChange(Sender: TObject);
procedure lvObjectTypesDblClick(Sender: TObject);
private
FRegistry: TConfigObjectRegistry;
FSelectedType: string;
FObjectName: string;
procedure LoadObjectTypes;
procedure UpdateControls;
public
// 鍒濆鍖?
procedure Initialize(ARegistry: TConfigObjectRegistry);
// 鑾峰彇閫夋嫨鐨勭被鍨?
property SelectedType: string read FSelectedType;
property ObjectName: string read FObjectName;
end;
var
frmConfigObjectSelect: TfrmConfigObjectSelect;
implementation
{$R *.dfm}
procedure TfrmConfigObjectSelect.FormCreate(Sender: TObject);
begin
FSelectedType := '';
FObjectName := '';
UpdateControls;
end;
procedure TfrmConfigObjectSelect.Initialize(ARegistry: TConfigObjectRegistry);
begin
FRegistry := ARegistry;
LoadObjectTypes;
end;
procedure TfrmConfigObjectSelect.LoadObjectTypes;
var
TypeId: string;
Meta: TConfigObjectMeta;
Item: TListItem;
Types: TArray<string>;
ImageIndex: Integer;
begin
// 娓呯┖鍒楄〃
lvObjectTypes.Items.Clear;
if not Assigned(FRegistry) then
Exit;
// 鑾峰彇鎵€鏈夋敞鍐岀殑绫诲瀷
Types := FRegistry.GetAllConfigTypes;
// 娣诲姞鍒板垪琛ㄤ腑
for TypeId in Types do
begin
Meta := FRegistry.GetConfigMeta(TypeId);
if not Assigned(Meta) then
Continue;
// 鏍规嵁閰嶇疆绫诲瀷閫夋嫨涓嶅悓鐨勫浘鏍?
case Meta.ConfigType of
etFont: ImageIndex := 0;
etDatabase: ImageIndex := 1;
etBackGround: ImageIndex := 2;
etImage, etImageOnBG: ImageIndex := 3;
etTextOnBG: ImageIndex := 4;
etDrawerOnBG: ImageIndex := 5;
etSubtitle: ImageIndex := 6;
etPage: ImageIndex := 7;
etVideoClip: ImageIndex := 8;
etAIAPI: ImageIndex := 9;
else ImageIndex := 10;
end;
// 鍒涘缓鍒楄〃椤?
Item := lvObjectTypes.Items.Add;
Item.Caption := Meta.Name;
Item.SubItems.Add(Meta.Description);
Item.Data := Pointer(TypeId);
Item.ImageIndex := ImageIndex;
end;
end;
procedure TfrmConfigObjectSelect.lvObjectTypesSelectItem(Sender: TObject;
Item: TListItem; Selected: Boolean);
var
TypeId: string;
Meta: TConfigObjectMeta;
begin
if Selected and Assigned(Item) then
begin
// 鑾峰彇閫夋嫨鐨勭被鍨?
TypeId := string(Item.Data);
FSelectedType := TypeId;
// 鏄剧ず绫诲瀷鎻忚堪
if Assigned(FRegistry) then
begin
Meta := FRegistry.GetConfigMeta(TypeId);
if Assigned(Meta) then
mmoDescription.Lines.Text := Meta.Description
else
mmoDescription.Lines.Text := '娌℃湁鍙敤鐨勬弿杩?;
end;
end
else
begin
FSelectedType := '';
mmoDescription.Lines.Text := '';
end;
UpdateControls;
end;
procedure TfrmConfigObjectSelect.lvObjectTypesDblClick(Sender: TObject);
begin
if (FSelectedType <> '') and (edtName.Text <> '') then
ModalResult := mrOk;
end;
procedure TfrmConfigObjectSelect.edtNameChange(Sender: TObject);
begin
FObjectName := edtName.Text;
UpdateControls;
end;
procedure TfrmConfigObjectSelect.UpdateControls;
begin
btnOK.Enabled := (FSelectedType <> '') and (FObjectName <> '');
end;
end.