21 #include "kreplacedialog.h"
23 #include <tqcheckbox.h>
24 #include <tqgroupbox.h>
28 #include <kcombobox.h>
30 #include <tdemessagebox.h>
38 class KReplaceDialog::KReplaceDialogPrivate {
40 KReplaceDialogPrivate() : m_initialShowDone(false) {}
41 TQStringList replaceStrings;
42 bool m_initialShowDone;
45 KReplaceDialog::KReplaceDialog(TQWidget *parent,
const char *name,
long options,
const TQStringList &findStrings,
const TQStringList &replaceStrings,
bool hasSelection) :
48 d =
new KReplaceDialogPrivate;
49 d->replaceStrings = replaceStrings;
50 init(
true, findStrings, hasSelection);
59 void KReplaceDialog::showEvent( TQShowEvent *e )
61 if ( !d->m_initialShowDone )
63 d->m_initialShowDone =
true;
65 if (!d->replaceStrings.isEmpty())
68 m_replace->lineEdit()->setText( d->replaceStrings[0] );
72 KFindDialog::showEvent(e);
80 if (m_promptOnReplace->isChecked())
82 if (m_backRef->isChecked())
83 options |= BackReference;
89 if (!m_replaceExtension)
91 m_replaceExtension =
new TQWidget(m_replaceGrp);
92 m_replaceLayout->addMultiCellWidget(m_replaceExtension, 3, 3, 0, 1);
95 return m_replaceExtension;
100 return m_replace->currentText();
105 TQStringList lst = m_replace->historyItems();
107 if ( m_replace->lineEdit()->text().isEmpty() )
108 lst.prepend( TQString::null );
116 m_backRef->setChecked(options & BackReference);
121 if (strings.count() > 0)
122 m_replace->setHistoryItems(strings,
true);
124 m_replace->clearHistory();
127 void KReplaceDialog::slotOk()
130 if ( m_regExp->isChecked() && m_backRef->isChecked() )
133 int caps = r.numCaptures();
134 TQRegExp check(TQString(
"((?:\\\\)+)(\\d+)"));
137 while ( (p = check.search( rep, p ) ) > -1 )
139 if ( check.cap(1).length()%2 && check.cap(2).toInt() > caps )
142 "Your replacement string is referencing a capture greater than '\\%1', ").arg( caps ) +
144 i18n(
"but your pattern only defines 1 capture.",
145 "but your pattern only defines %n captures.", caps ) :
146 i18n(
"but your pattern defines no captures.") ) +
147 i18n(
"\nPlease correct.") );
150 p += check.matchedLength();
155 KFindDialog::slotOk();
158 #include "kreplacedialog.moc"
TQString pattern() const
Returns the pattern to find.
TQString replacement() const
Returns the replacement string.
TQStringList replacementHistory() const
Returns the list of history items.
long options() const
Returns the state of the options.
long options() const
Returns the state of the options.
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
virtual ~KReplaceDialog()
Destructor.
void setReplacementHistory(const TQStringList &history)
Provide the list of strings to be displayed as the history of replacement strings.
KReplaceDialog(TQWidget *parent=0, const char *name=0, long options=0, const TQStringList &findStrings=TQStringList(), const TQStringList &replaceStrings=TQStringList(), bool hasSelection=true)
Construct a replace dialog.read-only or rather select-only combo box with a parent object and a name...
Should the user be prompted before the replace operation?
void setOptions(long options)
Set the options which are checked.
void setOptions(long options)
Set the options which are enabled.
TQWidget * replaceExtension()
Returns an empty widget which the user may fill with additional UI elements as required.