22 #include "kfinddialog_p.h"
24 #include <QtGui/QCheckBox>
25 #include <QtGui/QGroupBox>
26 #include <QtGui/QLabel>
27 #include <QtGui/QLayout>
28 #include <QtGui/QLineEdit>
29 #include <QtCore/QRegExp>
40 class KReplaceDialogPrivate
45 , initialShowDone(false)
46 , replaceExtension (0)
59 const QStringList &replaceStrings,
bool hasSelection)
60 :
KFindDialog(parent, options, findStrings, hasSelection, true ),
61 d(new KReplaceDialogPrivate(this))
63 d->replaceStrings = replaceStrings;
73 if ( !d->initialShowDone )
75 d->initialShowDone =
true;
77 if (!d->replaceStrings.isEmpty())
80 KFindDialog::d->replace->lineEdit()->setText( d->replaceStrings[0] );
92 if (KFindDialog::d->promptOnReplace->isChecked())
94 if (KFindDialog::d->backRef->isChecked())
101 if (!d->replaceExtension)
103 d->replaceExtension =
new QWidget(KFindDialog::d->replaceGrp);
104 KFindDialog::d->replaceLayout->addWidget(d->replaceExtension, 3, 0, 1, 2);
107 return d->replaceExtension;
112 return KFindDialog::d->replace->currentText();
117 QStringList lst = KFindDialog::d->replace->historyItems();
119 if ( KFindDialog::d->
replace->lineEdit()->text().isEmpty() )
127 KFindDialog::d->promptOnReplace->setChecked(options &
PromptOnReplace);
128 KFindDialog::d->backRef->setChecked(options &
BackReference);
133 if (strings.count() > 0)
134 KFindDialog::d->
replace->setHistoryItems(strings,
true);
136 KFindDialog::d->replace->clearHistory();
139 void KReplaceDialogPrivate::_k_slotOk()
142 if ( q->KFindDialog::d->regExp->isChecked() && q->KFindDialog::d->backRef->isChecked() )
144 QRegExp r ( q->pattern() );
145 int caps = r.numCaptures();
146 QRegExp check(
QString(
"((?:\\\\)+)(\\d+)"));
148 QString rep = q->replacement();
149 while ( (p = check.indexIn( rep, p ) ) > -1 )
151 if ( check.cap(1).length()%2 && check.cap(2).toInt() > caps )
154 "Your replacement string is referencing a capture greater than '\\%1', ", caps ) +
156 i18np(
"but your pattern only defines 1 capture.",
157 "but your pattern only defines %1 captures.", caps ) :
158 i18n(
"but your pattern defines no captures.") ) +
159 i18n(
"\nPlease correct.") );
162 p += check.matchedLength();
167 q->KFindDialog::d->_k_slotOk();
168 q->KFindDialog::d->replace->addToHistory(q->replacement());
172 #include "kreplacedialog.moc"