2
2
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3
3
* http://www.gnu.org/licenses/gpl-3.0.html
6
* $Id: classwizarddlg.cpp 4909 2008-02-27 13:15:26Z mortenmacfly $
7
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/classwizard/classwizarddlg.cpp $
6
* $Id: classwizarddlg.cpp 6104 2010-01-23 12:56:12Z mortenmacfly $
7
* $HeadURL: svn+ssh://jenslody@svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/classwizard/classwizarddlg.cpp $
12
#include <wx/arrstr.h>
13
#include <wx/checkbox.h>
14
#include <wx/combobox.h>
17
#include <wx/filename.h>
19
#include <wx/textctrl.h>
20
#include <wx/xrc/xmlres.h>
22
#include "cbproject.h"
23
#include "configmanager.h"
24
#include "editormanager.h"
27
#include "macrosmanager.h"
28
#include "projectmanager.h"
12
#include <wx/checkbox.h>
13
#include <wx/combobox.h>
16
#include <wx/filename.h>
18
#include <wx/textctrl.h>
19
#include <wx/xrc/xmlres.h>
22
#include "cbproject.h"
23
#include "configmanager.h"
24
#include "editormanager.h"
27
#include "macrosmanager.h"
28
#include "projectmanager.h"
30
30
#include "cbstyledtextctrl.h"
32
#include "classwizarddlg.h"
33
32
#include <wx/tokenzr.h>
34
33
#include <wx/dirdlg.h>
39
void ForceDirectory(const wxFileName & filename)
41
wxFileName parentname(filename);
42
parentname.RemoveLastDir();
44
if (filename != parentname)
45
ForceDirectory(parentname);
47
if (!wxDirExists(filename.GetPath()))
48
wxMkdir(filename.GetPath());
53
BEGIN_EVENT_TABLE(ClassWizardDlg, wxDialog)
54
EVT_UPDATE_UI(-1, ClassWizardDlg::OnUpdateUI)
55
EVT_TEXT(XRCID("txtName"), ClassWizardDlg::OnNameChange)
56
EVT_TEXT(XRCID("txtInheritance"), ClassWizardDlg::OnAncestorChange)
57
EVT_BUTTON(XRCID("btnCommonDir"), ClassWizardDlg::OnCommonDirClick)
58
EVT_CHECKBOX(XRCID("chkLowerCase"), ClassWizardDlg::OnLowerCaseClick)
59
EVT_BUTTON(XRCID("btnIncludeDir"), ClassWizardDlg::OnIncludeDirClick)
60
EVT_BUTTON(XRCID("btnImplDir"), ClassWizardDlg::OnImplDirClick)
61
EVT_TEXT(XRCID("txtHeader"), ClassWizardDlg::OnHeaderChange)
62
EVT_BUTTON(XRCID("wxID_OK"), ClassWizardDlg::OnOKClick)
63
EVT_BUTTON(XRCID("wxID_CANCEL"), ClassWizardDlg::OnCancelClick)
34
#include "classwizarddlg.h"
36
BEGIN_EVENT_TABLE(ClassWizardDlg, wxScrollingDialog)
37
EVT_UPDATE_UI(-1, ClassWizardDlg::OnUpdateUI)
38
EVT_TEXT (XRCID("txtName"), ClassWizardDlg::OnNameChange)
39
EVT_TEXT (XRCID("txtInheritance"), ClassWizardDlg::OnAncestorChange)
40
EVT_BUTTON (XRCID("btnAddMemberVar"), ClassWizardDlg::OnAddMemberVar)
41
EVT_BUTTON (XRCID("btnRemoveMemberVar"), ClassWizardDlg::OnRemoveMemberVar)
42
EVT_BUTTON (XRCID("btnCommonDir"), ClassWizardDlg::OnCommonDirClick)
43
EVT_CHECKBOX (XRCID("chkLowerCase"), ClassWizardDlg::OnLowerCaseClick)
44
EVT_BUTTON (XRCID("btnIncludeDir"), ClassWizardDlg::OnIncludeDirClick)
45
EVT_BUTTON (XRCID("btnImplDir"), ClassWizardDlg::OnImplDirClick)
46
EVT_TEXT (XRCID("txtHeader"), ClassWizardDlg::OnHeaderChange)
47
EVT_BUTTON (XRCID("wxID_OK"), ClassWizardDlg::OnOKClick)
48
EVT_BUTTON (XRCID("wxID_CANCEL"), ClassWizardDlg::OnCancelClick)
66
55
ClassWizardDlg::ClassWizardDlg(wxWindow* parent)
68
wxXmlResource::Get()->LoadDialog(this, parent, _T("dlgNewClass"));
57
wxXmlResource::Get()->LoadObject(this, parent, _T("dlgNewClass"),_T("wxScrollingDialog"));
70
59
ProjectManager* prjMan = Manager::Get()->GetProjectManager();
71
60
cbProject* prj = prjMan->GetActiveProject();
99
89
ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("classwizard"));
102
cfg->Write(_T("common_dir"), (bool) XRCCTRL(*this, "chkCommonDir", wxCheckBox)->GetValue());
103
cfg->Write(_T("lower_case"), (bool) XRCCTRL(*this, "chkLowerCase", wxCheckBox)->GetValue());
92
cfg->Write(_T("documentation"), (bool) XRCCTRL(*this, "chkDocumentation", wxCheckBox)->GetValue());
93
cfg->Write(_T("common_dir"), (bool) XRCCTRL(*this, "chkCommonDir", wxCheckBox)->GetValue());
94
cfg->Write(_T("lower_case"), (bool) XRCCTRL(*this, "chkLowerCase", wxCheckBox)->GetValue());
107
void ClassWizardDlg::DoGuardBlock()
109
m_Header = XRCCTRL(*this, "txtHeader", wxTextCtrl)->GetValue();
110
wxString GuardWord = m_Header;
111
GuardWord.MakeUpper();
112
while (GuardWord.Replace(_T("."), _T("_")))
114
while (GuardWord.Replace(_T("/"), _T("_")))
116
while (GuardWord.Replace(_T("\\"), _T("_")))
118
XRCCTRL(*this, "txtGuardBlock", wxTextCtrl)->SetValue(GuardWord);
121
void ClassWizardDlg::DoFileNames()
123
wxString name = XRCCTRL(*this, "txtName", wxTextCtrl)->GetValue();
124
if (XRCCTRL(*this, "chkLowerCase", wxCheckBox)->GetValue())
127
while (name.Replace(_T("::"), _T("/")))
130
XRCCTRL(*this, "txtHeader", wxTextCtrl)->SetValue(name + _T(".h"));
131
XRCCTRL(*this, "txtImplementation", wxTextCtrl)->SetValue(name + _T(".cpp"));
132
XRCCTRL(*this, "txtHeaderInclude", wxTextCtrl)->SetValue(_T("\"") + name + _T(".h\""));
137
102
void ClassWizardDlg::OnUpdateUI(wxUpdateUIEvent& WXUNUSED(event))
139
104
bool inherits = XRCCTRL(*this, "chkInherits", wxCheckBox)->GetValue();
140
XRCCTRL(*this, "txtInheritance", wxTextCtrl)->Enable(inherits);
105
XRCCTRL(*this, "txtInheritance", wxTextCtrl)->Enable(inherits);
141
106
XRCCTRL(*this, "txtInheritanceFilename", wxTextCtrl)->Enable(inherits);
142
XRCCTRL(*this, "cmbInheritanceScope", wxComboBox)->Enable(inherits);
107
XRCCTRL(*this, "cmbInheritanceScope", wxComboBox)->Enable(inherits);
144
109
bool hasdestructor = XRCCTRL(*this, "chkHasDestructor", wxCheckBox)->GetValue();
145
110
XRCCTRL(*this, "chkVirtualDestructor", wxCheckBox)->Enable(hasdestructor);
112
bool memvars = (XRCCTRL(*this, "lstMemberVars", wxListBox)->GetCount()>0);
113
XRCCTRL(*this, "btnRemoveMemberVar", wxButton)->Enable(memvars);
147
115
bool genimpl = XRCCTRL(*this, "chkImplementation", wxCheckBox)->GetValue();
148
116
XRCCTRL(*this, "txtImplementation", wxTextCtrl)->Enable(genimpl);
149
XRCCTRL(*this, "txtHeaderInclude", wxTextCtrl)->Enable(genimpl);
117
XRCCTRL(*this, "txtHeaderInclude", wxTextCtrl)->Enable(genimpl);
151
119
bool commonDir = XRCCTRL(*this, "chkCommonDir", wxCheckBox)->GetValue();
152
XRCCTRL(*this, "txtImplDir", wxTextCtrl)->Enable(genimpl && !commonDir);
153
XRCCTRL(*this, "btnImplDir", wxButton)->Enable(genimpl && !commonDir);
120
XRCCTRL(*this, "txtImplDir", wxTextCtrl)->Enable(genimpl && !commonDir);
121
XRCCTRL(*this, "btnImplDir", wxButton)->Enable(genimpl && !commonDir);
154
122
XRCCTRL(*this, "txtIncludeDir", wxTextCtrl)->Enable(!commonDir);
155
123
XRCCTRL(*this, "btnIncludeDir", wxButton)->Enable(!commonDir);
156
XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->Enable(commonDir);
157
XRCCTRL(*this, "btnCommonDir", wxButton)->Enable(commonDir);
124
XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->Enable(commonDir);
125
XRCCTRL(*this, "btnCommonDir", wxButton)->Enable(commonDir);
159
127
bool genguard = XRCCTRL(*this, "chkGuardBlock", wxCheckBox)->GetValue();
160
128
XRCCTRL(*this, "txtGuardBlock", wxTextCtrl)->Enable(genguard);
151
void ClassWizardDlg::OnAddMemberVar(wxCommandEvent& event)
153
wxString member = XRCCTRL(*this, "txtMemberVar", wxTextCtrl)->GetValue();
154
bool getter = XRCCTRL(*this, "chkGetter", wxCheckBox)->GetValue();
155
bool setter = XRCCTRL(*this, "chkSetter", wxCheckBox)->GetValue();
157
bool noprfx = XRCCTRL(*this, "chkRemovePrefix", wxCheckBox)->GetValue();
158
wxString prefix = XRCCTRL(*this, "txtPrefix", wxTextCtrl)->GetValue();
160
// Valid strings are f.ex.: unsigned int foo, wxString bar, ...
161
wxString memtyp = member.BeforeLast(_T(' ')).Trim();
162
wxString memvar = member.AfterLast(_T(' ')).Trim();
164
if (memtyp.IsEmpty())
166
cbMessageBox(_T("Please specify a valid variable type to continue."),
167
_T("Error"), wxOK | wxICON_ERROR);
171
if (memvar.IsEmpty())
173
cbMessageBox(_T("Please specify a valid variable name to continue."),
174
_T("Error"), wxOK | wxICON_ERROR);
178
std::vector<MemberVar>::iterator it = m_MemberVars.begin();
179
while( it != m_MemberVars.end() )
181
if (DoMemVarRepr((*it).Typ, (*it).Var) == DoMemVarRepr(memtyp, memvar))
183
cbMessageBox(_T("This variable does already exist."),
184
_T("Error"), wxOK | wxICON_ERROR);
190
wxString method = ( (noprfx && memvar.StartsWith(prefix)) ?
191
memvar.Right(memvar.Length()-prefix.Length()) :
197
if (getter) mv.Get = _T("Get") + method; else mv.Get = wxEmptyString;
198
if (setter) mv.Set = _T("Set") + method; else mv.Set = wxEmptyString;
199
m_MemberVars.push_back(mv);
201
XRCCTRL(*this, "lstMemberVars", wxListBox)->Append(DoMemVarRepr(memtyp, memvar));
204
void ClassWizardDlg::OnRemoveMemberVar(wxCommandEvent& event)
206
wxString selection = XRCCTRL(*this, "lstMemberVars", wxListBox)->GetStringSelection();
207
if (selection.IsEmpty())
209
cbMessageBox(_T("Please select a variable to remove."),
210
_T("Error"), wxOK | wxICON_ERROR);
214
std::vector<MemberVar>::iterator it = m_MemberVars.begin();
215
while( it != m_MemberVars.end() )
217
if (DoMemVarRepr((*it).Typ, (*it).Var) == selection)
219
m_MemberVars.erase(it);
220
break; // end while loop
225
// Re-create the list box entries
226
XRCCTRL(*this, "lstMemberVars", wxListBox)->Clear();
227
it = m_MemberVars.begin();
228
while( it != m_MemberVars.end() )
230
XRCCTRL(*this, "lstMemberVars", wxListBox)->Append(DoMemVarRepr((*it).Typ, (*it).Var));
183
235
void ClassWizardDlg::OnCommonDirClick(wxCommandEvent& WXUNUSED(event))
185
237
wxString path = XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->GetValue();
227
279
void ClassWizardDlg::OnOKClick(wxCommandEvent& WXUNUSED(event))
229
// set some variable for easy reference
230
wxString Name = XRCCTRL(*this, "txtName", wxTextCtrl)->GetValue();
282
m_Header = XRCCTRL(*this, "txtHeader", wxTextCtrl)->GetValue();
283
m_Implementation = XRCCTRL(*this, "txtImplementation", wxTextCtrl)->GetValue();
285
// obtain variable for easy reference
286
m_Name = XRCCTRL(*this, "txtName", wxTextCtrl)->GetValue();
287
m_Arguments = XRCCTRL(*this, "txtArguments", wxTextCtrl)->GetValue();
289
if (m_Name.IsEmpty())
233
291
cbMessageBox(_T("Please specify a class name to continue."),
234
292
_T("Error"), wxOK | wxICON_ERROR);
237
wxArrayString NameSpaces;
238
wxStringTokenizer tkz(Name, _T("::"));
239
Name = wxEmptyString;
295
// Extract namespaces from class name
296
wxStringTokenizer tkz(m_Name, _T("::"));
297
m_Name = wxEmptyString;
240
298
while ( tkz.HasMoreTokens() )
300
// Store the old "class name" as (another) namespace
301
if (!m_Name.IsEmpty())
244
NameSpaces.Add(Name);
303
m_NameSpaces.Add(m_Name);
246
Name = tkz.GetNextToken();
252
bool CommonDir = XRCCTRL(*this, "chkCommonDir", wxCheckBox)->GetValue();
255
includeDir = XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->GetValue();
256
implDir = XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->GetValue();
260
includeDir = XRCCTRL(*this, "txtIncludeDir", wxTextCtrl)->GetValue();
261
implDir = XRCCTRL(*this, "txtImplDir", wxTextCtrl)->GetValue();
263
//wxSetWorkingDirectory(baseDir);
264
wxString Constructor = XRCCTRL(*this, "txtConstructor", wxTextCtrl)->GetValue();
265
bool VirtualDestructor = XRCCTRL(*this, "chkVirtualDestructor", wxCheckBox)->GetValue();
266
bool HasDestructor = XRCCTRL(*this, "chkHasDestructor", wxCheckBox)->GetValue();
269
VirtualDestructor = false;
272
wxString Ancestor = XRCCTRL(*this, "txtInheritance", wxTextCtrl)->GetValue();
273
wxString AncestorFilename = XRCCTRL(*this, "txtInheritanceFilename", wxTextCtrl)->GetValue();
274
wxString AncestorScope = XRCCTRL(*this, "cmbInheritanceScope", wxComboBox)->GetValue();
275
bool Inherits = XRCCTRL(*this, "chkInherits", wxCheckBox)->GetValue() && !Ancestor.IsEmpty();
277
m_Header = XRCCTRL(*this, "txtHeader", wxTextCtrl)->GetValue();
278
m_Implementation = XRCCTRL(*this, "txtImplementation", wxTextCtrl)->GetValue();
279
wxString headerInclude = XRCCTRL(*this, "txtHeaderInclude", wxTextCtrl)->GetValue();
280
bool GenerateImplementation = XRCCTRL(*this, "chkImplementation", wxCheckBox)->GetValue();
281
bool GuardBlock = XRCCTRL(*this, "chkGuardBlock", wxCheckBox)->GetValue();
282
wxString GuardWord = XRCCTRL(*this, "txtGuardBlock", wxTextCtrl)->GetValue();
283
if (GuardWord.IsEmpty())
305
// Stor the new "class name" as true class name
306
m_Name = tkz.GetNextToken();
309
m_HasDestructor = XRCCTRL(*this, "chkHasDestructor", wxCheckBox)->GetValue();
310
m_VirtualDestructor = XRCCTRL(*this, "chkVirtualDestructor", wxCheckBox)->GetValue();
311
m_HasCopyCtor = XRCCTRL(*this, "chkHasCopyCtor", wxCheckBox)->GetValue();
312
m_HasAssignmentOp = XRCCTRL(*this, "chkHasAssignmentOp", wxCheckBox)->GetValue();
313
if (!m_HasDestructor)
315
m_VirtualDestructor = false; // Fix error
318
m_Inherits = XRCCTRL(*this, "chkInherits", wxCheckBox)->GetValue();
319
m_Ancestor = XRCCTRL(*this, "txtInheritance", wxTextCtrl)->GetValue();
320
m_AncestorFilename = XRCCTRL(*this, "txtInheritanceFilename", wxTextCtrl)->GetValue();
321
m_AncestorScope = XRCCTRL(*this, "cmbInheritanceScope", wxComboBox)->GetValue();
322
if (m_Ancestor.IsEmpty())
324
m_Inherits = false; // Fix error
327
m_Documentation = XRCCTRL(*this, "chkDocumentation", wxCheckBox)->GetValue();
329
m_CommonDir = XRCCTRL(*this, "chkCommonDir", wxCheckBox)->GetValue();
332
m_IncludeDir = XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->GetValue();
333
m_ImplDir = XRCCTRL(*this, "txtCommonDir", wxTextCtrl)->GetValue();
337
m_IncludeDir = XRCCTRL(*this, "txtIncludeDir", wxTextCtrl)->GetValue();
338
m_ImplDir = XRCCTRL(*this, "txtImplDir", wxTextCtrl)->GetValue();
341
m_GuardBlock = XRCCTRL(*this, "chkGuardBlock", wxCheckBox)->GetValue();
342
m_GuardWord = XRCCTRL(*this, "txtGuardBlock", wxTextCtrl)->GetValue();
343
if (m_GuardWord.IsEmpty())
345
m_GuardBlock = false; // Fix error
348
m_GenerateImplementation = XRCCTRL(*this, "chkImplementation", wxCheckBox)->GetValue();
349
m_HeaderInclude = XRCCTRL(*this, "txtHeaderInclude", wxTextCtrl)->GetValue();
352
bool usestabs = Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/use_tab"), false);
353
int tabsize = Manager::Get()->GetConfigManager(_T("editor"))->ReadInt(_T("/tab_size"), 4);
354
int eolmode = Manager::Get()->GetConfigManager(_T("editor"))->ReadInt(_T("/eol/eolmode"), 0);
356
m_TabStr = usestabs ? wxString(_T("\t")) : wxString(_T(' '), tabsize);
361
else if (eolmode == 1)
367
m_EolStr = _T("\r\n");
370
// actual file creation starts here
371
bool success = DoHeader();
374
if (m_GenerateImplementation)
382
void ClassWizardDlg::OnCancelClick(wxCommandEvent& WXUNUSED(event))
384
EndModal(wxID_CANCEL);
391
bool ClassWizardDlg::DoHeader()
393
// Create the header file
287
394
wxFileName headerFname(UnixFilename(m_Header));
288
wxFileName implementationFname(UnixFilename(m_Implementation));
289
headerFname.MakeAbsolute(includeDir);
290
implementationFname.MakeAbsolute(implDir);
292
bool usestabs = Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/use_tab"), false);
293
int tabsize = Manager::Get()->GetConfigManager(_T("editor"))->ReadInt(_T("/tab_size"), 4);
294
int eolmode = Manager::Get()->GetConfigManager(_T("editor"))->ReadInt(_T("/eol/eolmode"), 0);
296
ForceDirectory(headerFname);
395
headerFname.MakeAbsolute(m_IncludeDir);
396
DoForceDirectory(headerFname);
398
// Create a new editor/file (probably based on a template setup by the user)
297
399
cbEditor* new_ed = Manager::Get()->GetEditorManager()->New(headerFname.GetFullPath());
300
cbMessageBox(_T("Class wizard can't continue. Possibly the Header file name is invalid.\n"
402
cbMessageBox(_T("Class wizard can't continue.\n"
403
"Possibly the header file name is invalid.\n"
301
404
"Please check the entered file name."),
302
405
_T("Error"), wxICON_ERROR);
409
// Obtain the buffer of the new file and replace any macros that might exist
305
410
wxString buffer = new_ed->GetControl()->GetText();
306
411
Manager::Get()->GetMacrosManager()->ReplaceMacros(buffer);
308
wxString tabstr = usestabs ? wxString(_T("\t")) : wxString(_T(' '),tabsize);
314
else if (eolmode == 1)
323
// actual creation starts here
324
413
// let's start with the header file
327
buffer << _T("#ifndef ") << GuardWord << eolstr;
328
buffer << _T("#define ") << GuardWord << eolstr;
332
if (!AncestorFilename.IsEmpty() && !AncestorFilename.IsSameAs(_T("<>")))
334
buffer << _T("#include ") << AncestorFilename << eolstr;
338
for (unsigned int i=0; i<NameSpaces.GetCount(); ++i)
340
buffer << _T("namespace ") << NameSpaces[i] << _T(" {") << eolstr;
345
buffer << _T("class ") << Name;
348
buffer << _T(" : ") << AncestorScope << _T(" ") << Ancestor;
351
buffer << _T("{") << eolstr;
352
buffer << tabstr << _T("public:") << eolstr;
353
buffer << tabstr << tabstr << Name << _T("(") << Constructor << _T(")");
354
buffer << (!GenerateImplementation ? _T(" {}") : _T(";")) << eolstr;
358
buffer << tabstr << tabstr;
359
if (VirtualDestructor)
416
buffer << _T("#ifndef ") << m_GuardWord << m_EolStr;
417
buffer << _T("#define ") << m_GuardWord << m_EolStr;
421
if (!m_AncestorFilename.IsEmpty() && !m_AncestorFilename.IsSameAs(_T("<>")))
423
buffer << _T("#include ") << m_AncestorFilename << m_EolStr;
427
for (unsigned int i=0; i<m_NameSpaces.GetCount(); ++i)
429
buffer << _T("namespace ") << m_NameSpaces[i] << _T(" {") << m_EolStr;
434
buffer << _T("class ") << m_Name;
437
buffer << _T(" : ") << m_AncestorScope << _T(" ") << m_Ancestor;
440
buffer << _T("{") << m_EolStr;
443
buffer << m_TabStr << _T("public:") << m_EolStr;
448
buffer << m_TabStr << m_TabStr << _T("/** Default constructor */") << m_EolStr;
450
buffer << m_TabStr << m_TabStr << m_Name << _T("(") << m_Arguments << _T(")")
451
<< (!m_GenerateImplementation ? _T(" {}") : _T(";")) << m_EolStr;
457
buffer << m_TabStr << m_TabStr << _T("/** Default destructor */") << m_EolStr;
459
buffer << m_TabStr << m_TabStr;
460
if (m_VirtualDestructor)
361
462
buffer << _T("virtual ");
363
buffer << _T('~') << Name << _T("()");
364
buffer << (!GenerateImplementation ? _T(" {}") : _T(";")) << eolstr;
366
buffer << tabstr << _T("protected:") << eolstr;
367
buffer << tabstr << _T("private:") << eolstr;
368
buffer << _T("};") << eolstr;
370
if (NameSpaces.GetCount())
373
for (int i=NameSpaces.GetCount(); i>0; --i)
375
buffer << _T("} // namespace ") << NameSpaces[i-1] << eolstr;
382
buffer << _T("#endif // ") << GuardWord << eolstr;
464
buffer << _T('~') << m_Name << _T("()");
465
buffer << (!m_GenerateImplementation ? _T(" {}") : _T(";")) << m_EolStr;
472
buffer << m_TabStr << m_TabStr
473
<< _T("/** Copy constructor") << m_EolStr;
474
buffer << m_TabStr << m_TabStr
475
<< _T(" * \\param other Object to copy from") << m_EolStr;
476
buffer << m_TabStr << m_TabStr
477
<< _T(" */") << m_EolStr;
479
buffer << m_TabStr << m_TabStr;
480
buffer << m_Name << _T("(const ") << m_Name << _T("& other)");
481
buffer << (!m_GenerateImplementation ? _T(" {}") : _T(";")) << m_EolStr;
484
if (m_HasAssignmentOp)
488
buffer << m_TabStr << m_TabStr
489
<< _T("/** Assignment operator") << m_EolStr;
490
buffer << m_TabStr << m_TabStr
491
<< _T(" * \\param other Object to assign from") << m_EolStr;
492
buffer << m_TabStr << m_TabStr
493
<< _T(" * \\return A reference to this") << m_EolStr;
494
buffer << m_TabStr << m_TabStr
495
<< _T(" */") << m_EolStr;
497
buffer << m_TabStr << m_TabStr;
498
buffer << m_Name << _T("& ") << _T("operator=(const ") << m_Name << _T("& other)");
499
buffer << (!m_GenerateImplementation ? _T(" { return *this; }") : _T(";")) << m_EolStr;
502
std::vector<MemberVar>::iterator it = m_MemberVars.begin();
503
while( it != m_MemberVars.end() )
505
if (!(*it).Get.IsEmpty())
509
buffer << m_TabStr << m_TabStr
510
<< _T("/** Access ") << (*it).Var << m_EolStr;
511
buffer << m_TabStr << m_TabStr
512
<< _T(" * \\return The current value of ") << (*it).Var << m_EolStr;
513
buffer << m_TabStr << m_TabStr
514
<< _T(" */") << m_EolStr;
516
buffer << m_TabStr << m_TabStr << (*it).Typ << _T(" ") << (*it).Get
517
<< _T("() { return ") << (*it).Var << _T("; }") << m_EolStr;
519
if (!(*it).Set.IsEmpty())
523
buffer << m_TabStr << m_TabStr
524
<< _T("/** Set ") << (*it).Var << m_EolStr;
525
buffer << m_TabStr << m_TabStr
526
<< _T(" * \\param val New value to set") << m_EolStr;
527
buffer << m_TabStr << m_TabStr
528
<< _T(" */") << m_EolStr;
530
buffer << m_TabStr << m_TabStr << _T("void ") << (*it).Set << _T("(")
531
<< (*it).Typ << _T(" val) { ") << (*it).Var << _T(" = val; }") << m_EolStr;
537
buffer << m_TabStr << _T("protected:") << m_EolStr;
539
buffer << m_TabStr << _T("private:") << m_EolStr;
541
it = m_MemberVars.begin();
542
while( it != m_MemberVars.end() )
544
buffer << m_TabStr << m_TabStr
545
<< (*it).Typ << _T(" ") << (*it).Var << _T(";");
548
buffer << _T(" //!< Member variable \"") << (*it).Var << _T("\"");
555
buffer << _T("};") << m_EolStr;
557
if (m_NameSpaces.GetCount())
560
for (int i=m_NameSpaces.GetCount(); i>0; --i)
562
buffer << _T("} // namespace ") << m_NameSpaces[i-1] << m_EolStr;
569
buffer << _T("#endif // ") << m_GuardWord << m_EolStr;
385
572
new_ed->GetControl()->SetText(buffer);
389
576
msg.Printf(_("Could not save header file %s.\nAborting..."), headerFname.GetFullPath().c_str());
390
577
cbMessageBox(msg, _("Error"), wxICON_ERROR);
394
if (!GenerateImplementation)
396
m_Header = headerFname.GetFullPath();
397
m_Implementation = wxEmptyString;
402
// now the implementation file
403
ForceDirectory(implementationFname);
404
new_ed = Manager::Get()->GetEditorManager()->New(implementationFname.GetFullPath());
581
m_Header = headerFname.GetFullPath();
586
bool ClassWizardDlg::DoImpl()
588
// Create the implementation file
589
wxFileName implementationFname(UnixFilename(m_Implementation));
590
implementationFname.MakeAbsolute(m_ImplDir);
591
DoForceDirectory(implementationFname);
593
// Create a new editor/file (probably based on a template setup by the user)
594
cbEditor* new_ed = Manager::Get()->GetEditorManager()->New(implementationFname.GetFullPath());
407
cbMessageBox(_T("Class wizard can't continue. Possibly the Implementation file name is invalid.\n"
597
cbMessageBox(_T("Class wizard can't continue.\n"
598
"Possibly the implementation file name is invalid.\n"
408
599
"Please check the entered file name."),
409
600
_T("Error"), wxICON_ERROR);
412
buffer = new_ed->GetControl()->GetText();
604
// Obtain the buffer of the new file and replace any macros that might exist
605
wxString buffer = new_ed->GetControl()->GetText();
413
606
Manager::Get()->GetMacrosManager()->ReplaceMacros(buffer);
415
buffer << _T("#include ") << headerInclude << eolstr;
608
buffer << _T("#include ") << m_HeaderInclude << m_EolStr;
417
if (NameSpaces.GetCount())
610
if (m_NameSpaces.GetCount())
420
for (unsigned int i=0; i<NameSpaces.GetCount(); ++i)
613
for (unsigned int i=0; i<m_NameSpaces.GetCount(); ++i)
422
buffer << _T("namespace ") << NameSpaces[i] << _T(" {") << eolstr;
615
buffer << _T("namespace ") << m_NameSpaces[i] << _T(" {") << m_EolStr;
427
buffer << Name << _T("::") << Name << _T("(") << Constructor << _T(")") << eolstr;
428
buffer << _T("{") << eolstr;
429
buffer << tabstr << _T("//ctor") << eolstr;
430
buffer << _T("}") << eolstr;
435
buffer << Name << _T("::~") << Name << _T("()") << eolstr;
436
buffer << _T("{") << eolstr;
437
buffer << tabstr << _T("//dtor") << eolstr;
438
buffer << _T("}") << eolstr;
441
if (NameSpaces.GetCount())
444
for (int i=NameSpaces.GetCount(); i>0; --i)
620
buffer << m_Name << _T("::") << m_Name << _T("(") << m_Arguments << _T(")") << m_EolStr;
621
buffer << _T("{") << m_EolStr;
622
buffer << m_TabStr << _T("//ctor") << m_EolStr;
623
buffer << _T("}") << m_EolStr;
628
buffer << m_Name << _T("::~") << m_Name << _T("()") << m_EolStr;
629
buffer << _T("{") << m_EolStr;
630
buffer << m_TabStr << _T("//dtor") << m_EolStr;
631
buffer << _T("}") << m_EolStr;
637
buffer << m_Name << _T("::") << m_Name << _T("(const ") << m_Name << _T("& other)") << m_EolStr;;
638
buffer << _T("{") << m_EolStr;
639
buffer << m_TabStr << _T("//copy ctor") << m_EolStr;
640
buffer << _T("}") << m_EolStr;
643
if (m_HasAssignmentOp)
646
buffer << m_Name << _T("& ") << m_Name << _T("::operator=(const ") << m_Name << _T("& rhs)") << m_EolStr;;
647
buffer << _T("{") << m_EolStr;
648
buffer << m_TabStr << _T("if (this == &rhs) return *this; // handle self assignment") << m_EolStr;
649
buffer << m_TabStr << _T("//assignment operator") << m_EolStr;
650
buffer << m_TabStr << _T("return *this;") << m_EolStr;
651
buffer << _T("}") << m_EolStr;
654
if (m_NameSpaces.GetCount())
657
for (int i=m_NameSpaces.GetCount(); i>0; --i)
446
buffer << _T("} // namespace ") << NameSpaces[i-1] << eolstr;
659
buffer << _T("} // namespace ") << m_NameSpaces[i-1] << m_EolStr;