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
|
/***************************************************************************
* Copyright (C) 2003 by Alexander Dymo *
* cloudtemple@mksat.net *
* *
* This program 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. *
* *
***************************************************************************/
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqtextedit.h>
#include <tqfile.h>
#include <tqfileinfo.h>
#include <kstandarddirs.h>
#include <tdeconfig.h>
#include "cppsupportfactory.h"
#include "classgeneratorconfig.h"
ClassGeneratorConfig::ClassGeneratorConfig( TQWidget* parent, const char* name, WFlags fl )
: ClassGeneratorConfigBase( parent, name, fl )
{
readConfig();
currTemplate = &cppHeaderText;
template_edit->setText( *currTemplate );
}
ClassGeneratorConfig::ClassGeneratorConfig( TQString v_cppHeaderText, TQString v_cppSourceText,
TQString v_objcHeaderText, TQString v_objcSourceText,
TQString v_gtkHeaderText, TQString v_gtkSourceText,
NameCase v_fileCase, NameCase v_defCase, NameCase v_superCase,
bool v_showAuthor, bool v_genDoc, bool v_reformat,
TQWidget* parent, const char* name, WFlags fl )
: ClassGeneratorConfigBase( parent, name, fl ),
cppHeaderText( v_cppHeaderText ), cppSourceText( v_cppSourceText ),
objcHeaderText( v_objcHeaderText ), objcSourceText( v_objcSourceText ),
gtkHeaderText( v_gtkHeaderText ), gtkSourceText( v_gtkSourceText )
{
filecase_box->setCurrentItem( ( int ) v_fileCase );
defcase_box->setCurrentItem( ( int ) v_defCase );
supercase_box->setCurrentItem( ( int ) v_superCase );
author_box->setChecked( v_showAuthor );
doc_box->setChecked( v_genDoc );
reformat_box->setChecked( v_reformat );
currTemplate = &cppHeaderText;
}
ClassGeneratorConfig::~ClassGeneratorConfig()
{}
/*$SPECIALIZATION$*/
void ClassGeneratorConfig::templateTypeChanged( int type )
{
*currTemplate = template_edit->text();
currTemplate = identifyTemplate( type );
template_edit->setText( *currTemplate );
}
TQString ClassGeneratorConfig::cppHeader()
{
if ( currTemplate == &cppHeaderText )
* currTemplate = template_edit->text();
return cppHeaderText;
}
TQString ClassGeneratorConfig::cppSource()
{
if ( currTemplate == &cppSourceText )
* currTemplate = template_edit->text();
return cppSourceText;
}
TQString ClassGeneratorConfig::objcHeader()
{
if ( currTemplate == &objcHeaderText )
* currTemplate = template_edit->text();
return objcHeaderText;
}
TQString ClassGeneratorConfig::objcSource()
{
if ( currTemplate == &objcSourceText )
* currTemplate = template_edit->text();
return objcSourceText;
}
TQString ClassGeneratorConfig::gtkHeader()
{
if ( currTemplate == >kHeaderText )
* currTemplate = template_edit->text();
return gtkHeaderText;
}
TQString ClassGeneratorConfig::gtkSource()
{
if ( currTemplate == >kSourceText )
* currTemplate = template_edit->text();
return gtkSourceText;
}
ClassGeneratorConfig::NameCase ClassGeneratorConfig::fileCase()
{
return ( NameCase ) filecase_box->currentItem();
}
ClassGeneratorConfig::NameCase ClassGeneratorConfig::defCase()
{
return ( NameCase ) defcase_box->currentItem();
}
ClassGeneratorConfig::NameCase ClassGeneratorConfig::superCase()
{
return ( NameCase ) supercase_box->currentItem();
}
bool ClassGeneratorConfig::showAuthor()
{
return author_box->isChecked();
}
bool ClassGeneratorConfig::genDoc()
{
return doc_box->isChecked();
}
TQString *ClassGeneratorConfig::identifyTemplate( int value )
{
switch ( value )
{
case 0:
return & cppHeaderText;
case 1:
return &cppSourceText;
case 2:
return &objcHeaderText;
case 3:
return &objcSourceText;
case 4:
return >kHeaderText;
case 5:
return >kSourceText;
}
return 0;
}
void ClassGeneratorConfig::readConfig()
{
TDEConfig * config = CppSupportFactory::instance() ->config();
if ( config )
{
config->setGroup( "Class Generator" );
filecase_box->setCurrentItem( config->readNumEntry( "File Name Case", 0 ) );
defcase_box->setCurrentItem( config->readNumEntry( "Defines Case", 1 ) );
supercase_box->setCurrentItem( config->readNumEntry( "Superclasss Name Case", 0 ) );
author_box->setChecked( config->readBoolEntry( "Show Author Name", 1 ) );
doc_box->setChecked( config->readBoolEntry( "Generate Empty Documentation", 1 ) );
reformat_box->setChecked( config->readBoolEntry( "Reformat Source", 0 ) );
KStandardDirs *dirs = CppSupportFactory::instance() ->dirs();
cppHeaderText = templateText( dirs->findResource( "newclasstemplates", "cpp_header" ) );
cppSourceText = templateText( dirs->findResource( "newclasstemplates", "cpp_source" ) );
objcHeaderText = templateText( dirs->findResource( "newclasstemplates", "objc_header" ) );
objcSourceText = templateText( dirs->findResource( "newclasstemplates", "objc_source" ) );
gtkHeaderText = templateText( dirs->findResource( "newclasstemplates", "gtk_header" ) );
gtkSourceText = templateText( dirs->findResource( "newclasstemplates", "gtk_source" ) );
}
}
TQString ClassGeneratorConfig::templateText( TQString path )
{
TQFileInfo f( path );
if ( f.exists() )
{
TQFile file( path );
if ( file.open( IO_ReadOnly ) )
{
TQTextStream stream( &file );
return stream.read();
}
else
return "";
}
else
return "";
}
void ClassGeneratorConfig::storeConfig()
{
TDEConfig * config = CppSupportFactory::instance() ->config();
if ( config )
{
config->setGroup( "Class Generator" );
config->writeEntry( "File Name Case", filecase_box->currentItem() );
config->writeEntry( "Defines Case", defcase_box->currentItem() );
config->writeEntry( "Superclasss Name Case", supercase_box->currentItem() );
config->writeEntry( "Show Author Name", author_box->isChecked() );
config->writeEntry( "Generate Empty Documentation", doc_box->isChecked() );
config->writeEntry( "Reformat Source", reformat_box->isChecked() );
KStandardDirs *dirs = CppSupportFactory::instance() ->dirs();
saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "cpp_header", cppHeader() );
saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "cpp_source", cppSource() );
saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "objc_header", objcHeader() );
saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "objc_source", objcSource() );
saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "gtk_header", gtkHeader() );
saveTemplateText( dirs->saveLocation( "newclasstemplates" ) + "gtk_source", gtkSource() );
}
}
void ClassGeneratorConfig::saveTemplateText( TQString path, TQString content )
{
TQFile f( path );
if ( f.open( IO_WriteOnly ) )
{
TQTextStream stream( &f );
stream << content;
f.close();
}
}
#include "classgeneratorconfig.moc"
|