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())
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"
long options() const
Returns the state of the options.
TQString pattern() const
Returns the pattern to find.
void setOptions(long options)
Set the options which are checked.
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
TQString replacement() const
Returns the replacement string.
void setReplacementHistory(const TQStringList &history)
Provide the list of strings to be displayed as the history of replacement strings.
long options() const
Returns the state of the options.
void setOptions(long options)
Set the options which are enabled.
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.
virtual ~KReplaceDialog()
Destructor.
TQStringList replacementHistory() const
Returns the list of history items.
@ PromptOnReplace
Should the user be prompted before the replace operation?
TQWidget * replaceExtension()
Returns an empty widget which the user may fill with additional UI elements as required.