-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcustforms.pp
More file actions
193 lines (152 loc) · 4.65 KB
/
Copy pathcustforms.pp
File metadata and controls
193 lines (152 loc) · 4.65 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
unit custforms;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms;
Type
{ TCustomFormDescr }
TCustomFormDescr = Class
private
FAuthor: String;
FCaption: String;
FCategory: String;
FDescription: String;
FFormClass: TFormClass;
FLazPackage: String;
FUnitName: String;
public
Constructor Create(AFormClass : TFormClass; const APackage: string);
Constructor Create(AFormClass : TFormClass; Const ACaption,ADescription,AUnit,APackage : String);
Property FormClass : TFormClass Read FFormClass Write FFormClass;
Property Caption : String Read FCaption Write FCaption;
Property Description : String Read FDescription Write FDescription;
Property UnitName : String Read FUnitName Write FUnitName;
Property Category : String Read FCategory Write FCategory;
Property Author : String Read FAuthor Write FAuthor;
Property LazPackage : String Read FLazPackage Write FLazPackage;
end;
Procedure RegisterCustomForm(Descr : TCustomFormDescr);
Procedure RegisterCustomForm(AFormClass : TFormClass; const APackage: string);
Procedure RegisterCustomForm(AFormClass : TFormClass; Const AUnitName, APackage : String);
Procedure Register;
implementation
uses ProjectIntf,NewItemIntf,contnrs;
Const
SAppFrameWork = 'Custom forms';
SInstanceOf = 'Create a new instance of %s';
{ TCustomFormDescr }
constructor TCustomFormDescr.Create(AFormClass: TFormClass;
const APackage: string);
Var
N,U : String;
begin
N:=AFormClass.ClassName;
U:=N;
If (Upcase(U[1])='T') then
Delete(U,1,1);
Create(AFormClass,N,Format(SInstanceOf,[N]),U,APackage);
end;
constructor TCustomFormDescr.Create(AFormClass: TFormClass;
const ACaption, ADescription, AUnit, APackage: String);
begin
FFormClass:=AFormClass;
FCaption:=ACaption;
FDescription:=ADescription;
FUnitName:=AUnit;
FCategory:=SAppFrameWork;
FLazPackage:=APackage;
end;
// Registration code.
Type
{ TCustomFormFileDescriptor }
TCustomFormFileDescriptor = Class(TFileDescPascalUnitWithResource)
private
FFormDescr: TCustomFormDescr;
Public
Constructor Create(ADescr : TCustomFormDescr);
Property FormDescr : TCustomFormDescr Read FFormDescr;
Function GetLocalizedName : String; override;
Function GetLocalizedDescription : String; override;
Function GetInterfaceUsesSection : String; override;
end;
{ TCustomFormFileDescriptor }
constructor TCustomFormFileDescriptor.Create(ADescr: TCustomFormDescr);
begin
Inherited Create;
FFormDescr:=ADescr;
ResourceClass:=FFormDescr.FFormClass;
Name:=FFormDescr.Caption;
RequiredPackages:=ADescr.LazPackage;
//Writeln('TCustomFormFileDescriptor.Create RequiredPackages=',RequiredPackages);
end;
function TCustomFormFileDescriptor.GetLocalizedName: String;
begin
Result:=FFormDescr.Caption;
end;
function TCustomFormFileDescriptor.GetLocalizedDescription: String;
begin
Result:=FFormDescr.Description;
If (FFormDescr.Author<>'') then
Result:=Result+LineEnding+'By '+FFormDescr.Author;
end;
function TCustomFormFileDescriptor.GetInterfaceUsesSection: String;
begin
Result:=inherited GetInterfaceUsesSection;
Result:=Result+',Forms,'+FFormDescr.UnitName;
end;
Var
CustomFormList : TObjectList;
Procedure RegisterCustomForm(Descr : TCustomFormDescr);
begin
CustomFormList.Add(Descr);
end;
Procedure RegisterCustomForm(AFormClass : TFormClass; const APackage: string);
begin
RegisterCustomForm(TCustomFormDescr.Create(AFormClass,APackage));
end;
Procedure RegisterCustomForm(AFormClass : TFormClass; Const AUnitName, APackage : String);
Var
D : TCustomFormDescr;
begin
D:=TCustomFormDescr.Create(AFormClass,APackage);
D.UnitName:=AUnitName;
RegisterCustomForm(D);
end;
Procedure Register;
Var
L : TStringList;
I : Integer;
D : TCustomFormDescr;
begin
L:=TStringList.Create;
Try
L.Sorted:=True;
L.Duplicates:=dupIgnore;
For I:=0 to CustomFormList.Count-1 do
L.Add(TCustomFormDescr(CustomFormList[i]).Category);
For I:=0 to L.Count-1 do
begin
RegisterNewItemCategory(TNewIDEItemCategory.Create(L[i]));
end;
Finally
L.Free;
end;
For I:=0 to CustomFormList.Count-1 do
begin
D:=TCustomFormDescr(CustomFormList[i]);
RegisterProjectFileDescriptor(TCustomFormFileDescriptor.Create(D),D.Category);
end;
end;
Procedure InitCustomForms;
begin
CustomFormList:=TObjectList.Create;
end;
Procedure DoneCustomForms;
begin
FreeAndNil(CustomFormList);
end;
Initialization
InitCustomForms;
Finalization
DoneCustomForms;
end.