Menu

[327ada]: / Source / NewFunctionFrm.pas  Maximize  Restore  History

Download this file

265 lines (226 with data), 7.9 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
{
This file is part of Dev-C++
Copyright (c) 2004 Bloodshed Software
Dev-C++ is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Dev-C++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dev-C++; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit NewFunctionFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, CppParser, CBUtils;
type
TNewFunctionForm = class(TForm)
lblReturnType: TLabel;
lblName: TLabel;
rgScope: TRadioGroup;
txtType: TEdit;
txtName: TEdit;
lblArguments: TLabel;
txtArguments: TEdit;
btnCreate: TButton;
btnCancel: TButton;
lblImplementIn: TLabel;
cmbClass: TComboBox;
chkToDo: TCheckBox;
grpAttr: TGroupBox;
chkStatic: TCheckBox;
chkVirtual: TCheckBox;
chkPure: TCheckBox;
chkInline: TCheckBox;
procedure txtTypeChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure btnCreateClick(Sender: TObject);
procedure chkStaticClick(Sender: TObject);
private
{ Private declarations }
procedure LoadText;
public
{ Public declarations }
end;
implementation
uses
System.UITypes, editor, main, MultiLangSupport, devcfg;
{$R *.dfm}
procedure TNewFunctionForm.txtTypeChange(Sender: TObject);
begin
btnCreate.Enabled := (txtType.Text <> '') and (txtName.Text <> '') and (cmbClass.ItemIndex <> -1);
end;
procedure TNewFunctionForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TNewFunctionForm.FormShow(Sender: TObject);
var
sl: TStringList;
begin
LoadText;
sl := TStringList.Create;
try
MainForm.CppParser.GetClassesList(sl);
cmbClass.Items.Assign(sl);
finally
sl.Free;
end;
cmbClass.ItemIndex := cmbClass.Items.IndexOf(PStatement(MainForm.ClassBrowser.Selected.Data)^._Command);
txtType.SetFocus;
end;
procedure TNewFunctionForm.btnCreateClick(Sender: TObject);
var
fName: String;
CppFname: String;
Line: integer;
e: TEditor;
AddScopeStr: boolean;
S: String;
VarScope: TStatementClassScope;
st: PStatement;
begin
// Check below shouldn't be needed
st := PStatement(cmbClass.Items.Objects[cmbClass.Items.IndexOf(cmbClass.Text)]);
if not Assigned(St) then begin
MessageDlg(Lang[ID_NEWVAR_MSG_NOCLASS], mtError, [mbOk], 0);
ModalResult := mrNone;
Exit;
end;
// We need a CPP file if we want to define it over there
MainForm.CppParser.GetSourcePair(st^._DefinitionFileName, CppFname, fName);
if not chkInline.Checked and not FileExists(CppFname) then begin
MessageDlg(Lang[ID_NEWVAR_MSG_NOIMPL], mtError, [mbOk], 0);
Exit;
end;
// Open header file
e := MainForm.EditorList.GetEditorFromFileName(fName);
if not Assigned(e) then
Exit;
// Ask CppParser for insertion line suggestion
case rgScope.ItemIndex of
0: VarScope := scsPrivate;
1: VarScope := scsProtected;
2: VarScope := scsPublic;
else
VarScope := scsNone; // shut up compiler
end;
Line := MainForm.CppParser.SuggestMemberInsertionLine(st, VarScope, AddScopeStr);
if Line = -1 then begin
MessageDlg(Lang[ID_NEWVAR_MSG_NOLINE], mtError, [mbOk], 0);
Exit;
end;
// insert the actual function in the header
S := #9#9;
if chkVirtual.Checked then
S := S + 'virtual '
else if chkStatic.Checked then
S := S + 'static ';
S := S + txtType.Text + ' ' + txtName.Text + '(' + txtArguments.Text + ')';
if chkPure.Checked then
S := S + ' = 0';
// Implement it in the class in the header file if needed
e.Text.BeginUpdate;
try
e.Text.UncollapseAroundLine(Line); // uncollapse folds around this line
if chkInline.Checked then begin
e.Text.Lines.Insert(Line, #9#9'}');
if chkToDo.Checked then
e.Text.Lines.Insert(Line, #9#9#9'/* TODO (#1#): Define ' + cmbClass.Text + '::' + txtName.Text + '(' +
txtArguments.Text + ') */');
e.Text.Lines.Insert(Line, #9#9'{');
end else
S := S + ';';
e.Text.Lines.Insert(Line, S);
// insert, if needed, the scope string
if AddScopeStr then
case VarScope of
scsPrivate: e.Text.Lines.Insert(Line, #9'private:');
scsProtected: e.Text.Lines.Insert(Line, #9'protected:');
scsPublic: e.Text.Lines.Insert(Line, #9'public:');
end;
// Mark modified and we're done editing the header file
e.Text.Modified := True;
finally
e.Text.EndUpdate;
end;
// Continue work on the source file if needed
if chkInline.Checked or chkPure.Checked then begin
e.SetCaretPosAndActivate(Line + 1, 1); // activate it if we're not modifying the source file
Exit;
end;
e := MainForm.EditorList.GetEditorFromFileName(CppFname);
if not Assigned(e) then
Exit;
// Implement it in the class if needed
e.Text.BeginUpdate;
try
// insert the definition
if Trim(e.Text.Lines[e.Text.Lines.Count - 1]) <> '' then
e.Text.Lines.Add('');
e.Text.Lines.Add(txtType.Text + ' ' + cmbClass.Text + '::' + txtName.Text + '(' + txtArguments.Text + ')');
e.Text.Lines.Add('{');
if chkToDo.Checked then
e.Text.Lines.Add(#9'/* TODO (#1#): Define ' + cmbClass.Text + '::' + txtName.Text + '() */');
e.Text.Lines.Add('}');
// Set caret and leave
e.SetCaretPosAndActivate(e.Text.Lines.Count - 1, 1);
e.Text.Modified := True;
finally
e.Text.EndUpdate;
end;
end;
procedure TNewFunctionForm.LoadText;
begin
// Set interface font
Font.Name := devData.InterfaceFont;
Font.Size := devData.InterfaceFontSize;
Caption := Lang[ID_POP_NEWMEMBER];
lblReturnType.Caption := Lang[ID_NEWVAR_VARTYPE];
lblName.Caption := Lang[ID_NEWMEMB_MEMBNAME];
lblArguments.Caption := Lang[ID_NEWMEMB_ARGS];
lblImplementIn.Caption := Lang[ID_NEWVAR_IMPLIN];
rgScope.Caption := Lang[ID_NEWVAR_SCOPE];
grpAttr.Caption := Lang[ID_NEWMEMB_ATTRS];
chkToDo.Caption := Lang[ID_ADDTODO_MENUITEM];
btnCreate.Caption := Lang[ID_NEWVAR_BTN_CREATE];
btnCancel.Caption := Lang[ID_NEWVAR_BTN_CANCEL];
end;
procedure TNewFunctionForm.chkStaticClick(Sender: TObject);
begin
// disable event
chkStatic.OnClick := nil;
chkVirtual.OnClick := nil;
chkPure.OnClick := nil;
chkInline.OnClick := nil;
if Sender = chkStatic then begin
chkInline.Enabled := True;
if chkStatic.Checked then begin
chkVirtual.Checked := False;
chkPure.Checked := False;
end;
end else if Sender = chkVirtual then begin
chkInline.Enabled := True;
if not chkVirtual.Checked then
chkPure.Checked := False
else
chkStatic.Checked := False;
end else if Sender = chkPure then begin
chkInline.Enabled := not chkPure.Checked;
chkInline.Checked := False;
chkStatic.Checked := False;
chkVirtual.Checked := True;
end;
// re-enable event
chkStatic.OnClick := chkStaticClick;
chkVirtual.OnClick := chkStaticClick;
chkPure.OnClick := chkStaticClick;
chkInline.OnClick := chkStaticClick;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.