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>
40class KReplaceDialogPrivate
45 , initialShowDone(false)
46 , replaceExtension (0)
53 QStringList replaceStrings;
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() )
120 lst.prepend( QString() );
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();
139void 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"
virtual void showEvent(QShowEvent *)
friend class KReplaceDialog
long options() const
Returns the state of the options.
void setOptions(long options)
Set the options which are checked.
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
Display an "Information" dialog.
A generic "replace" dialog.
QWidget * replaceExtension() const
Returns an empty widget which the user may fill with additional UI elements as required.
QStringList replacementHistory() const
Returns the list of history items.
long options() const
Returns the state of the options.
virtual void showEvent(QShowEvent *)
void setReplacementHistory(const QStringList &history)
Provide the list of strings to be displayed as the history of replacement strings.
void setOptions(long options)
Set the options which are enabled.
virtual ~KReplaceDialog()
Destructor.
QString replacement() const
Returns the replacement string.
QString i18n(const char *text)
QString i18np(const char *sing, const char *plur, const A1 &a1)