00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
#include "abbrevpart.h"
00017
00018
#include <qfile.h>
00019
#include <qfileinfo.h>
00020
#include <qregexp.h>
00021
#include <qvbox.h>
00022
#include <kdebug.h>
00023
#include <kdialogbase.h>
00024
#include <klocale.h>
00025
#include <kparts/part.h>
00026
#include <kstandarddirs.h>
00027
#include <kdevgenericfactory.h>
00028
#include <kaction.h>
00029
#include <kconfig.h>
00030
#include <kio/netaccess.h>
00031
00032
#include <ktexteditor/document.h>
00033
#include <ktexteditor/editinterface.h>
00034
#include <ktexteditor/viewcursorinterface.h>
00035
#include <ktexteditor/codecompletioninterface.h>
00036
00037
#include "kdevcore.h"
00038
#include "kdevpartcontroller.h"
00039
#include "abbrevconfigwidget.h"
00040
00041
static const KAboutData data(
"kdevabbrev",
I18N_NOOP(
"Abbreviations"),
"1.0");
00042
00043 class AbbrevFactory :
public KDevGenericFactory<AbbrevPart>
00044 {
00045
public:
00046 AbbrevFactory()
00047 :
KDevGenericFactory<
AbbrevPart>( &
data )
00048 { }
00049
00050 virtual KInstance *
createInstance()
00051 {
00052
KInstance *instance =
KDevGenericFactory<AbbrevPart>::createInstance();
00053
KStandardDirs *dirs = instance->
dirs();
00054 dirs->
addResourceType(
"codetemplates",
00055 KStandardDirs::kde_default(
"data" ) +
"kdevabbrev/templates/" );
00056 dirs->
addResourceType(
"sources",
00057 KStandardDirs::kde_default(
"data" ) +
"kdevabbrev/sources" );
00058
00059
return instance;
00060 }
00061 };
00062
00063
K_EXPORT_COMPONENT_FACTORY( libkdevabbrev,
AbbrevFactory )
00064
00065 AbbrevPart::
AbbrevPart(
QObject *parent, const
char *name, const
QStringList &)
00066 :
KDevPlugin("Abbrev", "abbrev", parent, name ? name : "
AbbrevPart")
00067 {
00068 setInstance(AbbrevFactory::instance());
00069 setXMLFile(
"kdevabbrev.rc");
00070
00071 connect(partController(), SIGNAL(activePartChanged(
KParts::Part*)),
00072
this, SLOT(slotActivePartChanged(
KParts::Part*)) );
00073
00074 connect(core(), SIGNAL(configWidget(
KDialogBase*)),
this, SLOT(configWidget(
KDialogBase*)));
00075
00076
KAction *action;
00077 action =
new KAction( i18n(
"Expand Text"), CTRL + Key_J,
00078
this, SLOT(slotExpandText()),
00079 actionCollection(),
"edit_expandtext" );
00080 action->setToolTip( i18n(
"Expand current word") );
00081 action->setWhatsThis( i18n(
"<b>Expand current word</b><p>Current word can be completed using the list of similar words in source files.") );
00082
00083 action =
new KAction( i18n(
"Expand Abbreviation"), CTRL + Key_L,
00084
this, SLOT(slotExpandAbbrev()),
00085 actionCollection(),
"edit_expandabbrev" );
00086 action->setToolTip( i18n(
"Expand abbreviation") );
00087 action->setWhatsThis( i18n(
"<b>Expand abbreviation</b><p>Enable and configure abbreviations in <b>KDevelop Settings</b>, <b>Abbrevations</b> tab.") );
00088
00089 load();
00090
00091 m_inCompletion =
false;
00092 docIface = 0;
00093 editIface = 0;
00094 viewCursorIface = 0;
00095 completionIface = 0;
00096
00097 m_prevLine = -1;
00098 m_prevColumn = -1;
00099 m_sequenceLength = 0;
00100
00101
KConfig* config = AbbrevFactory::instance()->config();
00102
KConfigGroupSaver group( config,
"General" );
00103 m_autoWordCompletionEnabled = config->
readBoolEntry(
"AutoWordCompletion",
false );
00104
00105 updateActions();
00106
00107 slotActivePartChanged( partController()->activePart() );
00108 }
00109
00110
00111 AbbrevPart::~AbbrevPart()
00112 {
00113
save();
00114 }
00115
00116 bool AbbrevPart::autoWordCompletionEnabled()
const
00117
{
00118
return m_autoWordCompletionEnabled;
00119 }
00120
00121 void AbbrevPart::setAutoWordCompletionEnabled(
bool enabled )
00122 {
00123
if( enabled ==
m_autoWordCompletionEnabled )
00124
return;
00125
00126
KConfig* config = AbbrevFactory::instance()->config();
00127
KConfigGroupSaver group( config,
"General" );
00128
00129
m_autoWordCompletionEnabled = enabled;
00130 config->
writeEntry(
"AutoWordCompletion",
m_autoWordCompletionEnabled );
00131 config->
sync();
00132
00133
if( !
docIface || !
docIface->
widget() )
00134
return;
00135
00136 disconnect(
docIface, 0,
this, 0 );
00137 disconnect(
docIface->
widget(), 0,
this, 0 );
00138
00139
if(
m_autoWordCompletionEnabled ){
00140 connect(
docIface->
widget(), SIGNAL(completionAborted()),
00141
this, SLOT(
slotCompletionAborted()) );
00142 connect(
docIface->
widget(), SIGNAL(completionDone()),
00143
this, SLOT(
slotCompletionDone()) );
00144 connect(
docIface->
widget(), SIGNAL(aboutToShowCompletionBox()),
00145
this, SLOT(
slotAboutToShowCompletionBox()) );
00146
00147 connect(
docIface, SIGNAL(textChanged()),
this, SLOT(
slotTextChanged()) );
00148 }
00149 }
00150 void AbbrevPart::load()
00151 {
00152
KStandardDirs *dirs = AbbrevFactory::instance()->dirs();
00153
QString localTemplatesFile =
locateLocal(
"codetemplates",
"templates", AbbrevFactory::instance());
00154
QStringList files;
00155
if (
QFileInfo(localTemplatesFile).exists())
00156 files << localTemplatesFile;
00157
else
00158 files = dirs->
findAllResources(
"codetemplates", QString::null,
false,
true);
00159
00160
QString localSourcesFile =
locateLocal(
"sources",
"sources", AbbrevFactory::instance());
00161
QStringList sourceFiles;
00162
if (
QFileInfo(localSourcesFile).exists())
00163 sourceFiles << localSourcesFile;
00164
else
00165 sourceFiles = dirs->
findAllResources(
"sources", QString::null,
false,
true);
00166
kdDebug(9028) <<
"=========> sourceFiles: " << sourceFiles.join(
" ") <<
endl;
00167
00168 this->
m_completionFile = QString::null;
00169
for( QStringList::Iterator it=sourceFiles.begin(); it!=sourceFiles.end(); ++it ) {
00170
QString fn = *it;
00171
kdDebug(9028) <<
"===> load file: " << fn <<
endl;
00172
QFile f( fn );
00173
if ( f.open(IO_ReadOnly) ) {
00174
QTextStream stream( &f );
00175
m_completionFile += ( stream.read() +
QString(
"\n") );
00176 f.close();
00177 }
00178 }
00179
00180 QStringList::ConstIterator it;
00181
for (it = files.begin(); it != files.end(); ++it) {
00182
QString fn = *it;
00183
kdDebug(9028) <<
"fn = " << fn <<
endl;
00184
QFile f( fn );
00185
if ( f.open(IO_ReadOnly) ) {
00186
QDomDocument doc;
00187 doc.setContent( &f );
00188
QDomElement root = doc.firstChild().toElement();
00189
QDomElement e = root.firstChild().toElement();
00190
while ( !e.isNull() ){
00191
addTemplate( e.attribute(
"name"),
00192 e.attribute(
"description"),
00193 e.attribute(
"suffixes"),
00194 e.attribute(
"code") );
00195 e = e.nextSibling().toElement();
00196 }
00197 f.close();
00198 }
00199 }
00200 }
00201
00202
00203 void AbbrevPart::save()
00204 {
00205
QString fn = AbbrevFactory::instance()->dirs()->saveLocation(
"codetemplates",
"",
true);
00206
kdDebug(9028) <<
"fn = " << fn <<
endl;
00207
00208
QDomDocument doc(
"Templates" );
00209
QDomElement root = doc.createElement(
"Templates" );
00210 doc.appendChild( root );
00211
00212
QPtrList<CodeTemplate> templates =
m_templates.
allTemplates();
00213
CodeTemplate *templ;
00214
for (templ = templates.first(); templ; templ = templates.next())
00215 {
00216
QDomElement e = doc.createElement(
"Template" );
00217 e.setAttribute(
"name", templ->
name );
00218 e.setAttribute(
"description", templ->
description );
00219 e.setAttribute(
"suffixes", templ->
suffixes );
00220 e.setAttribute(
"code", templ->
code );
00221 root.appendChild( e );
00222 }
00223
00224
QFile f( fn +
"templates" );
00225
if( f.open(IO_WriteOnly) ){
00226
QTextStream stream( &f );
00227 stream << doc.toString();
00228 f.close();
00229 }
00230 }
00231
00232
00233 QString AbbrevPart::currentWord()
const
00234
{
00235 uint line, col;
00236
viewCursorIface->
cursorPositionReal(&line, &col);
00237
QString str =
editIface->
textLine(line);
00238
int i;
00239
for (i = col-1; i >= 0; --i)
00240
if( ! (str[i].isLetter() || str[i] ==
'_') )
00241
break;
00242
00243
return str.mid(i+1, col-i-1);
00244 }
00245
00246
00247 void AbbrevPart::configWidget(
KDialogBase *dlg)
00248 {
00249
QVBox *vbox = dlg->
addVBoxPage(i18n(
"Abbreviations"));
00250
AbbrevConfigWidget *w =
new AbbrevConfigWidget(
this, vbox,
"abbrev config widget");
00251 connect(dlg, SIGNAL(okClicked()), w, SLOT(accept()));
00252 }
00253
00254
00255 void AbbrevPart::slotExpandText()
00256 {
00257
if( !
editIface || !
completionIface || !
viewCursorIface )
00258
return;
00259
00260
QString word =
currentWord();
00261
if (word.isEmpty())
00262
return;
00263
00264
QValueList<KTextEditor::CompletionEntry> entries =
findAllWords(
editIface->
text(), word);
00265
if (entries.count() == 0) {
00266 ;
00267
00268
00269
00270
00271
00272
00273 }
else {
00274
m_inCompletion =
true;
00275
completionIface->
showCompletionBox(entries, word.length());
00276 }
00277 }
00278
00279
00280 QValueList<KTextEditor::CompletionEntry> AbbrevPart::findAllWords(
const QString &text,
const QString &prefix)
00281 {
00282
QValueList<KTextEditor::CompletionEntry> entries;
00283
00284
KParts::ReadWritePart *part = dynamic_cast<KParts::ReadWritePart*>(
partController()->
activePart());
00285
QWidget *view =
partController()->
activeWidget();
00286
if (!part || !view) {
00287
kdDebug(9028) <<
"no rw part" <<
endl;
00288
return entries;
00289 }
00290
00291
QString suffix = part->
url().
url();
00292
int pos = suffix.findRev(
'.');
00293
if (pos != -1)
00294 suffix.remove(0, pos+1);
00295
kdDebug(9028) <<
"AbbrevPart::findAllWords with suffix " << suffix <<
endl;
00296
00297
QMap<QString, bool> map;
00298
QRegExp rx(
QString(
"\\b") + prefix +
"[a-zA-Z0-9_]+\\b" );
00299
00300
int idx = 0;
00301 pos = 0;
00302
int len = 0;
00303
while ( (pos = rx.search(
text, idx)) != -1 ) {
00304
len = rx.matchedLength();
00305
QString word =
text.mid(pos,
len);
00306
if (map.find(word) == map.end()) {
00307
KTextEditor::CompletionEntry e;
00308 e.
text = word;
00309 entries << e;
00310 map[ word ] = TRUE;
00311 }
00312 idx = pos +
len + 1;
00313 }
00314
00315 idx = 0;
00316 pos = 0;
00317
len = 0;
00318
while ( (pos = rx.search(
m_completionFile, idx)) != -1 ) {
00319
len = rx.matchedLength();
00320
QString word =
m_completionFile.mid(pos,
len);
00321
if (map.find(word) == map.end()) {
00322
KTextEditor::CompletionEntry e;
00323 e.
text = word;
00324 entries << e;
00325 map[ word ] = TRUE;
00326 }
00327 idx = pos +
len + 1;
00328 }
00329
00330
00331
QMap<QString, CodeTemplate*> m =
m_templates[suffix];
00332
for (
QMap<QString, CodeTemplate*>::const_iterator it = m.begin(); it != m.end() ; ++it) {
00333
KTextEditor::CompletionEntry e;
00334 e.
text = it.data()->description +
" <abbrev>";
00335 e.
userdata = it.key();
00336 entries << e;
00337 }
00338
00339
return entries;
00340 }
00341
00342
00343 void AbbrevPart::slotExpandAbbrev()
00344 {
00345
KParts::ReadWritePart *part = dynamic_cast<KParts::ReadWritePart*>(
partController()->
activePart());
00346
QWidget *view =
partController()->
activeWidget();
00347
if (!part || !view) {
00348
kdDebug(9028) <<
"no rw part" <<
endl;
00349
return;
00350 }
00351
00352
QString suffix = part->
url().
url();
00353
int pos = suffix.findRev(
'.');
00354
if (pos != -1)
00355 suffix.remove(0, pos+1);
00356
00357
KTextEditor::EditInterface *editiface
00358 = dynamic_cast<KTextEditor::EditInterface*>(part);
00359
if (!editiface) {
00360
kdDebug(9028) <<
"no editiface" <<
endl;
00361
return;
00362 }
00363
KTextEditor::ViewCursorInterface *cursoriface
00364 = dynamic_cast<KTextEditor::ViewCursorInterface*>(view);
00365
if (!cursoriface) {
00366
kdDebug(9028) <<
"no viewcursoriface" <<
endl;
00367
return;
00368 }
00369
00370
QString word =
currentWord();
00371
kdDebug(9028) <<
"Expanding word " << word <<
" with suffix " << suffix <<
"." <<
endl;
00372
00373
QMap<QString, CodeTemplate*> m =
m_templates[suffix];
00374
for (
QMap<QString, CodeTemplate*>::const_iterator it = m.begin(); it != m.end() ; ++it) {
00375
if (it.key() != word)
00376
continue;
00377
00378 uint line, col;
00379 cursoriface->
cursorPositionReal(&line, &col);
00380 editiface->
removeText( line, col-word.length(), line, col );
00381
insertChars(it.data()->code );
00382 }
00383 }
00384
00385
00386 void AbbrevPart::insertChars(
const QString &chars )
00387 {
00388
unsigned line=0, col=0;
00389
viewCursorIface->
cursorPositionReal( &line, &col );
00390
00391
unsigned int currentLine=line, currentCol=col;
00392
00393
QString spaces;
00394
QString s =
editIface->
textLine( currentLine );
00395 uint i=0;
00396
while( i<s.length() && s[ i ].isSpace() ){
00397 spaces += s[ i ];
00398 ++i;
00399 }
00400
00401
bool foundPipe =
false;
00402
QString str;
00403
QTextStream stream( &str, IO_WriteOnly );
00404
QStringList lines = QStringList::split(
"\n", chars );
00405 QStringList::Iterator it = lines.begin();
00406 line = currentLine;
00407
while( it != lines.end() ){
00408
QString lineText = *it;
00409
if( it != lines.begin() ){
00410 stream << spaces;
00411
if( !foundPipe )
00412 currentCol += spaces.length();
00413 }
00414
00415
int idx = lineText.find(
'|' );
00416
if( idx != -1 ){
00417 stream << lineText.left( idx ) << lineText.mid( idx+1 );
00418
if( !foundPipe ){
00419 foundPipe =
true;
00420 currentCol += lineText.left( idx ).length();
00421
kdDebug(9007) <<
"found pipe at " << currentLine <<
", " << currentCol <<
endl;
00422 }
00423 }
else {
00424 stream << lineText;
00425 }
00426
00427 ++it;
00428
00429
if( it != lines.end() ){
00430 stream <<
"\n";
00431
if( !foundPipe ){
00432 ++currentLine;
00433 currentCol = 0;
00434 }
00435 }
00436 }
00437
editIface->
insertText( line, col, str );
00438
kdDebug(9007) <<
"go to " << currentLine <<
", " << currentCol <<
endl;
00439
viewCursorIface->
setCursorPositionReal( currentLine, currentCol );
00440 }
00441
00442 void AbbrevPart::addTemplate(
const QString& templ,
00443
const QString& descr,
00444
const QString& suffixes,
00445
const QString& code)
00446 {
00447
m_templates.
insert(templ, descr, code, suffixes);
00448 }
00449
00450
00451 void AbbrevPart::removeTemplate(
const QString &suffixes,
const QString &name )
00452 {
00453
m_templates.
remove( suffixes, name );
00454 }
00455
00456
00457 void AbbrevPart::clearTemplates()
00458 {
00459
m_templates.
clear();
00460 }
00461
00462 CodeTemplateList AbbrevPart::templates()
const
00463
{
00464
return m_templates;
00465 }
00466
00467 void AbbrevPart::slotActivePartChanged(
KParts::Part* part )
00468 {
00469
kdDebug(9028) <<
"AbbrevPart::slotActivePartChanged()" <<
endl;
00470
KTextEditor::Document* doc = dynamic_cast<KTextEditor::Document*>( part );
00471
00472
if( !doc || !part->
widget() || doc ==
docIface )
00473 {
00474
actionCollection()->
action(
"edit_expandtext" )->
setEnabled(
false );
00475
actionCollection()->
action(
"edit_expandabbrev" )->
setEnabled(
false );
00476
return;
00477 }
00478
00479
docIface = doc;
00480
00481
if( !
docIface ){
00482
docIface = 0;
00483
editIface = 0;
00484
viewCursorIface = 0;
00485
completionIface = 0;
00486 }
00487
00488
editIface = dynamic_cast<KTextEditor::EditInterface*>( part );
00489
viewCursorIface = dynamic_cast<KTextEditor::ViewCursorInterface*>( part->
widget() );
00490
completionIface = dynamic_cast<KTextEditor::CodeCompletionInterface*>( part->
widget() );
00491
00492
updateActions();
00493
00494
if( !
editIface || !
viewCursorIface || !
completionIface )
00495
return;
00496
00497 disconnect( part->
widget(), 0,
this, 0 );
00498 disconnect( doc, 0,
this, 0 );
00499
00500 connect( part->
widget(), SIGNAL(filterInsertString(
KTextEditor::CompletionEntry*,
QString*)),
00501
this, SLOT(
slotFilterInsertString(
KTextEditor::CompletionEntry*,
QString*)) );
00502
00503
if(
autoWordCompletionEnabled() ){
00504 connect( part->
widget(), SIGNAL(completionAborted()),
this, SLOT(
slotCompletionAborted()) );
00505 connect( part->
widget(), SIGNAL(completionDone()),
this, SLOT(
slotCompletionDone()) );
00506 connect( part->
widget(), SIGNAL(aboutToShowCompletionBox()),
this, SLOT(
slotAboutToShowCompletionBox()) );
00507 connect( doc, SIGNAL(textChanged()),
this, SLOT(
slotTextChanged()) );
00508 }
00509
00510
m_prevLine = -1;
00511
m_prevColumn = -1;
00512
m_sequenceLength = 0;
00513
kdDebug(9028) <<
"AbbrevPart::slotActivePartChanged() -- OK" <<
endl;
00514 }
00515
00516 void AbbrevPart::slotTextChanged()
00517 {
00518
if(
m_inCompletion )
00519
return;
00520
00521
unsigned int line, col;
00522
viewCursorIface->
cursorPositionReal( &line, &col );
00523
00524
if(
m_prevLine != int(line) ||
m_prevColumn+1 != int(col) || col == 0 ){
00525
m_prevLine = line;
00526
m_prevColumn = col;
00527
m_sequenceLength = 1;
00528
return;
00529 }
00530
00531
QString textLine =
editIface->
textLine( line );
00532
QChar ch = textLine[ col-1 ];
00533
QChar currentChar = textLine[ col ];
00534
00535
if( currentChar.isLetterOrNumber() || currentChar ==
QChar(
'_') || !(ch.isLetterOrNumber() || ch == QChar(
'_')) ){
00536
00537
m_prevLine = -1;
00538
return;
00539 }
00540
00541
if(
m_sequenceLength >= 3 )
00542
slotExpandText();
00543
00544 ++
m_sequenceLength;
00545
m_prevLine = line;
00546
m_prevColumn = col;
00547 }
00548
00549 void AbbrevPart::slotFilterInsertString(
KTextEditor::CompletionEntry* entry,
QString* text )
00550 {
00551
kdDebug(9028) <<
"AbbrevPart::slotFilterInsertString()" <<
endl;
00552
KParts::ReadWritePart *part = dynamic_cast<KParts::ReadWritePart*>(
partController()->
activePart());
00553
QWidget *view =
partController()->
activeWidget();
00554
if (!part || !view) {
00555
kdDebug(9028) <<
"no rw part" <<
endl;
00556
return;
00557 }
00558
00559
QString suffix = part->
url().
url();
00560
int pos = suffix.findRev(
'.');
00561
if (pos != -1)
00562 suffix.remove(0, pos+1);
00563
kdDebug(9028) <<
"AbbrevPart::slotFilterInsertString with suffix " << suffix <<
endl;
00564
00565
if( !entry || !
text || !
viewCursorIface || !
editIface )
00566
return;
00567
00568
QString expand(
" <abbrev>" );
00569
if( !entry->
userdata.isNull() && entry->
text.endsWith(expand) ){
00570
QString macro = entry->
text.left( entry->
text.length() - expand.length() );
00571 *
text =
"";
00572 uint line, col;
00573
viewCursorIface->
cursorPositionReal( &line, &col );
00574
editIface->
removeText( line, col-
currentWord().
length(), line, col );
00575
insertChars(
m_templates[suffix][entry->
userdata]->code );
00576 }
00577 }
00578
00579 void AbbrevPart::updateActions()
00580 {
00581
actionCollection()->
action(
"edit_expandtext" )->
setEnabled(
docIface != 0 );
00582
actionCollection()->
action(
"edit_expandabbrev" )->
setEnabled(
docIface != 0 );
00583 }
00584
00585 void AbbrevPart::slotCompletionAborted()
00586 {
00587
kdDebug(9028) <<
"AbbrevPart::slotCompletionAborted()" <<
endl;
00588
m_inCompletion =
false;
00589 }
00590
00591 void AbbrevPart::slotCompletionDone()
00592 {
00593
kdDebug(9028) <<
"AbbrevPart::slotCompletionDone()" <<
endl;
00594
m_inCompletion =
false;
00595 }
00596
00597 void AbbrevPart::slotAboutToShowCompletionBox()
00598 {
00599
kdDebug(9028) <<
"AbbrevPart::slotAboutToShowCompletionBox()" <<
endl;
00600
m_inCompletion =
true;
00601 }
00602
00603 CodeTemplateList::CodeTemplateList( )
00604 {
00605
allCodeTemplates.setAutoDelete(
true);
00606 }
00607
00608 CodeTemplateList::~ CodeTemplateList( )
00609 {
00610 }
00611
00612 QMap< QString, CodeTemplate * > CodeTemplateList::operator [ ](
QString suffix )
00613 {
00614
kdDebug(9028) <<
"CodeTemplateList::operator []" <<
endl;
00615
QMap< QString, CodeTemplate * > selectedTemplates;
00616
for (
QMap<QString, QMap<QString, CodeTemplate* > >::const_iterator it =
templates.begin(); it !=
templates.end(); ++it)
00617 {
00618
kdDebug(9028) <<
"CodeTemplateList::operator [] - suffixes " << it.key() <<
endl;
00619
if (QStringList::split(
",", it.key()).contains(suffix))
00620 {
00621
kdDebug(9028) <<
"CodeTemplateList::operator [] - suffixes " << it.key() <<
" contains " << suffix <<
endl;
00622
00623
QMap<QString, CodeTemplate* > m = it.data();
00624
for (
QMap<QString, CodeTemplate* >::const_iterator itt = m.begin(); itt != m.end(); ++itt)
00625 {
00626
kdDebug(9028) <<
"x" <<
endl;
00627 selectedTemplates[itt.key()] = itt.data();
00628 }
00629 }
00630 }
00631
return selectedTemplates;
00632 }
00633
00634 void CodeTemplateList::insert(
QString name,
QString description,
QString code,
QString suffixes )
00635 {
00636
QString origSuffixes = suffixes;
00637
00638
int pos = suffixes.find(
'(');
00639
if (pos == -1)
00640
return;
00641 suffixes.remove(0, pos+1);
00642 pos = suffixes.find(
')');
00643
if (pos == -1)
00644
return;
00645 suffixes.remove(pos, suffixes.length()-pos);
00646
00647
00648
CodeTemplate *t;
00649
if (
templates.contains(suffixes) &&
templates[suffixes].contains(name))
00650 {
00651
kdDebug(9028) <<
"found template for suffixes " << suffixes <<
" and name " << name <<
endl;
00652 t =
templates[suffixes][name];
00653 }
00654
else
00655 {
00656
kdDebug(9028) <<
"creating template for suffixes " << suffixes <<
" and name " << name <<
endl;
00657 t =
new CodeTemplate();
00658
allCodeTemplates.append(t);
00659
templates[suffixes][name] = t;
00660 }
00661 t->
name = name;
00662 t->
description = description;
00663 t->
code = code;
00664 t->
suffixes = origSuffixes;
00665
if (!
m_suffixes.contains(origSuffixes))
00666
m_suffixes.append(origSuffixes);
00667 }
00668
00669 QPtrList< CodeTemplate > CodeTemplateList::allTemplates( )
const
00670
{
00671
return allCodeTemplates;
00672 }
00673
00674 void CodeTemplateList::remove(
const QString & suffixes,
const QString & name )
00675 {
00676
allCodeTemplates.remove(
templates[suffixes][name]);
00677
templates[suffixes].remove(name);
00678 }
00679
00680 void CodeTemplateList::clear( )
00681 {
00682
templates.clear();
00683
allCodeTemplates.clear();
00684 }
00685
00686 QStringList CodeTemplateList::suffixes( )
00687 {
00688
return m_suffixes;
00689 }
00690
00691
#include "abbrevpart.moc"