-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCtwHelper.pas
163 lines (137 loc) · 4.47 KB
/
CtwHelper.pas
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
unit CtwHelper;
interface
uses
ToolsAPI;
type
// base module creator class, with default implementations
TCtwBaseModuleCreator = class (TInterfacedObject, IOTAModuleCreator)
private
FTextSource: string;
FFormSource: string;
FFormName: string;
FSourceFileName: string;
public
property TextSource: string read FTextSource write FTextSource;
property FormSource: string read FFormSource write FFormSource;
property FormName: string read FFormName write FFormName;
property SourceFileName: string read FSourceFileName write FSourceFileName;
public
procedure FormCreated(const FormEditor: IOTAFormEditor);
function GetAncestorName: String;
function GetCreatorType: String;
function GetExisting: Boolean;
function GetFileSystem: String;
function GetFormName: String;
function GetImplFileName: String;
function GetIntfFileName: String;
function GetMainForm: Boolean;
function GetOwner: IOTAModule;
function GetShowForm: Boolean;
function GetShowSource: Boolean;
function GetUnnamed: Boolean;
function NewFormFile(const FormIdent: String;
const AncestorIdent: String): IOTAFile;
function NewImplSource(const ModuleIdent: String;
const FormIdent: String; const AncestorIdent: String): IOTAFile;
function NewIntfSource(const ModuleIdent: String;
const FormIdent: String; const AncestorIdent: String): IOTAFile;
end;
implementation
uses
IStreams, CtwManager;
{ TCtwBaseModuleCreator }
procedure TCtwBaseModuleCreator.FormCreated(
const FormEditor: IOTAFormEditor);
begin
CantoolsManager.ShowMessage('FormCreated')
// add more components to the form
// nothing to do by default
end;
function TCtwBaseModuleCreator.GetAncestorName: String;
begin
CantoolsManager.ShowMessage('GetAncestorName');
Result := 'TForm';
end;
function TCtwBaseModuleCreator.GetCreatorType: String;
begin
CantoolsManager.ShowMessage('GetCreatorType');
Result := ''; // not a predefined one
end;
function TCtwBaseModuleCreator.GetExisting: Boolean;
begin
CantoolsManager.ShowMessage('GetExisting');
Result := FSourceFileName <> '';
end;
function TCtwBaseModuleCreator.GetFileSystem: String;
begin
CantoolsManager.ShowMessage('GetFileSystem');
Result := ''; // default
end;
function TCtwBaseModuleCreator.GetFormName: String;
begin
CantoolsManager.ShowMessage('GetFormName');
Result := FFormName;
end;
function TCtwBaseModuleCreator.GetImplFileName: String;
begin
CantoolsManager.ShowMessage('GetImplFileName');
Result := FSourceFileName;
end;
function TCtwBaseModuleCreator.GetIntfFileName: String;
begin
CantoolsManager.ShowMessage('GetIntfFileName');
Result := ''; // C++ header, if any!
end;
function TCtwBaseModuleCreator.GetMainForm: Boolean;
begin
CantoolsManager.ShowMessage('GetMainForm');
Result := False; // not the main form
end;
function TCtwBaseModuleCreator.GetOwner: IOTAModule;
begin
CantoolsManager.ShowMessage('GetOwner');
Result := ToolsAPI.GetActiveProject;
end;
function TCtwBaseModuleCreator.GetShowForm: Boolean;
begin
CantoolsManager.ShowMessage('GetShowForm');
Result := FFormSource <> ''; // form visible, if form code is there
end;
function TCtwBaseModuleCreator.GetShowSource: Boolean;
begin
CantoolsManager.ShowMessage('GetShowSource');
Result := True; // source visible in editor
end;
function TCtwBaseModuleCreator.GetUnnamed: Boolean;
begin
CantoolsManager.ShowMessage('GetUnnamed');
// unnamed if there is no file
Result := True; // FSourceFileName = ''; // new name when first saved
end;
function TCtwBaseModuleCreator.NewFormFile(const FormIdent,
AncestorIdent: String): IOTAFile;
begin
CantoolsManager.ShowMessage('NewFormFile');
// this is where you return the form source code
if FFormSource <> '' then
Result := TOTAFile.Create (FormSource)
else
Result := nil;
end;
function TCtwBaseModuleCreator.NewImplSource(const ModuleIdent, FormIdent,
AncestorIdent: String): IOTAFile;
begin
CantoolsManager.ShowMessage('NewImplSource');
// here you return the unit code
if FFormSource <> '' then
Result := TOTAFile.Create (TextSource)
else
Result := nil;
end;
function TCtwBaseModuleCreator.NewIntfSource(const ModuleIdent, FormIdent,
AncestorIdent: String): IOTAFile;
begin
CantoolsManager.ShowMessage('NewIntfSource');
Result := nil; // no interface in Delphi
end;
end.