You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
545 lines
20 KiB
545 lines
20 KiB
15 years ago
|
/*
|
||
|
Copyright (C) 2001, S.R.Haque <srhaque@iee.org>.
|
||
|
Copyright (C) 2002, David Faure <david@mandrakesoft.com>
|
||
|
This file is part of the KDE project
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2, as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kfinddialog.h"
|
||
14 years ago
|
#include <tqcheckbox.h>
|
||
|
#include <tqcursor.h>
|
||
|
#include <tqgroupbox.h>
|
||
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqpopupmenu.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqregexp.h>
|
||
15 years ago
|
#include <kcombobox.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kmessagebox.h>
|
||
|
#include <assert.h>
|
||
14 years ago
|
#include <tqwhatsthis.h>
|
||
15 years ago
|
|
||
|
#include <kregexpeditorinterface.h>
|
||
12 years ago
|
#include <tdeparts/componentfactory.h>
|
||
15 years ago
|
|
||
|
class KFindDialog::KFindDialogPrivate
|
||
|
{
|
||
|
public:
|
||
|
KFindDialogPrivate() : m_regexpDialog(0),
|
||
|
m_regexpDialogQueryDone(false),
|
||
|
m_enabled(WholeWordsOnly | FromCursor | SelectedText | CaseSensitive | FindBackwards | RegularExpression), m_initialShowDone(false) {}
|
||
14 years ago
|
TQDialog* m_regexpDialog;
|
||
15 years ago
|
bool m_regexpDialogQueryDone;
|
||
|
long m_enabled; // uses Options to define which search options are enabled
|
||
|
bool m_initialShowDone;
|
||
14 years ago
|
TQStringList findStrings;
|
||
14 years ago
|
TQString pattern;
|
||
15 years ago
|
};
|
||
|
|
||
14 years ago
|
KFindDialog::KFindDialog(TQWidget *parent, const char *name, long options, const TQStringList &findStrings, bool hasSelection) :
|
||
15 years ago
|
KDialogBase(parent, name, true, i18n("Find Text"), Ok | Cancel, Ok),
|
||
14 years ago
|
m_findExtension (0),
|
||
|
m_replaceExtension (0)
|
||
15 years ago
|
{
|
||
|
d = new KFindDialogPrivate;
|
||
14 years ago
|
init(false, findStrings, hasSelection);
|
||
15 years ago
|
setOptions(options);
|
||
|
setButtonCancel( KStdGuiItem::close() );
|
||
|
}
|
||
|
|
||
14 years ago
|
KFindDialog::KFindDialog(bool modal, TQWidget *parent, const char *name, long options, const TQStringList &findStrings, bool hasSelection) :
|
||
15 years ago
|
KDialogBase(parent, name, modal, i18n("Find Text"), Ok | Cancel, Ok),
|
||
14 years ago
|
m_findExtension (0),
|
||
|
m_replaceExtension (0)
|
||
15 years ago
|
{
|
||
|
d = new KFindDialogPrivate;
|
||
14 years ago
|
init(false, findStrings, hasSelection);
|
||
15 years ago
|
setOptions(options);
|
||
|
setButtonCancel( KStdGuiItem::close() );
|
||
|
}
|
||
|
|
||
14 years ago
|
KFindDialog::KFindDialog(TQWidget *parent, const char *name, bool /*forReplace*/) :
|
||
15 years ago
|
KDialogBase(parent, name, true, i18n("Replace Text"), Ok | Cancel, Ok),
|
||
14 years ago
|
m_findExtension (0),
|
||
|
m_replaceExtension (0)
|
||
15 years ago
|
{
|
||
|
d = new KFindDialogPrivate;
|
||
|
setButtonCancel( KStdGuiItem::close() );
|
||
|
}
|
||
|
|
||
|
KFindDialog::~KFindDialog()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQWidget *KFindDialog::findExtension()
|
||
15 years ago
|
{
|
||
14 years ago
|
if (!m_findExtension)
|
||
15 years ago
|
{
|
||
14 years ago
|
m_findExtension = new TQWidget(m_findGrp);
|
||
|
m_findLayout->addMultiCellWidget(m_findExtension, 3, 3, 0, 1);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
return m_findExtension;
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
TQStringList KFindDialog::findHistory() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return m_find->historyItems();
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void KFindDialog::init(bool forReplace, const TQStringList &findStrings, bool hasSelection)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQVBoxLayout *topLayout;
|
||
|
TQGridLayout *optionsLayout;
|
||
15 years ago
|
|
||
|
// Create common parts of dialog.
|
||
14 years ago
|
TQWidget *page = new TQWidget(this);
|
||
15 years ago
|
setMainWidget(page);
|
||
|
|
||
14 years ago
|
topLayout = new TQVBoxLayout(page);
|
||
15 years ago
|
topLayout->setSpacing( KDialog::spacingHint() );
|
||
|
topLayout->setMargin( 0 );
|
||
|
|
||
14 years ago
|
m_findGrp = new TQGroupBox(0, Qt::Vertical, i18n("Find"), page);
|
||
13 years ago
|
m_findGrp->layout()->setSpacing( KDialog::spacingHint() );
|
||
|
// m_findGrp->layout()->setMargin( KDialog::marginHint() );
|
||
|
m_findLayout = new TQGridLayout(m_findGrp->layout());
|
||
14 years ago
|
m_findLayout->setSpacing( KDialog::spacingHint() );
|
||
|
// m_findLayout->setMargin( KDialog::marginHint() );
|
||
|
|
||
|
m_findLabel = new TQLabel(i18n("&Text to find:"), m_findGrp);
|
||
|
m_find = new KHistoryCombo(true, m_findGrp);
|
||
|
m_find->setMaxCount(10);
|
||
|
m_find->setDuplicatesEnabled(false);
|
||
|
m_regExp = new TQCheckBox(i18n("Regular e&xpression"), m_findGrp);
|
||
|
m_regExpItem = new TQPushButton(i18n("&Edit..."), m_findGrp);
|
||
15 years ago
|
m_regExpItem->setEnabled(false);
|
||
|
|
||
14 years ago
|
m_findLayout->addWidget(m_findLabel, 0, 0);
|
||
|
m_findLayout->addMultiCellWidget(m_find, 1, 1, 0, 1);
|
||
|
m_findLayout->addWidget(m_regExp, 2, 0);
|
||
|
m_findLayout->addWidget(m_regExpItem, 2, 1);
|
||
|
topLayout->addWidget(m_findGrp);
|
||
|
|
||
|
m_replaceGrp = new TQGroupBox(0, Qt::Vertical, i18n("Replace With"), page);
|
||
13 years ago
|
m_replaceGrp->layout()->setSpacing( KDialog::spacingHint() );
|
||
|
// m_replaceGrp->layout()->setMargin( KDialog::marginHint() );
|
||
|
m_replaceLayout = new TQGridLayout(m_replaceGrp->layout());
|
||
14 years ago
|
m_replaceLayout->setSpacing( KDialog::spacingHint() );
|
||
|
// m_replaceLayout->setMargin( KDialog::marginHint() );
|
||
|
|
||
|
m_replaceLabel = new TQLabel(i18n("Replace&ment text:"), m_replaceGrp);
|
||
|
m_replace = new KHistoryCombo(true, m_replaceGrp);
|
||
|
m_replace->setMaxCount(10);
|
||
|
m_replace->setDuplicatesEnabled(false);
|
||
|
m_backRef = new TQCheckBox(i18n("Use p&laceholders"), m_replaceGrp);
|
||
|
m_backRefItem = new TQPushButton(i18n("Insert Place&holder"), m_replaceGrp);
|
||
15 years ago
|
m_backRefItem->setEnabled(false);
|
||
|
|
||
14 years ago
|
m_replaceLayout->addWidget(m_replaceLabel, 0, 0);
|
||
|
m_replaceLayout->addMultiCellWidget(m_replace, 1, 1, 0, 1);
|
||
|
m_replaceLayout->addWidget(m_backRef, 2, 0);
|
||
|
m_replaceLayout->addWidget(m_backRefItem, 2, 1);
|
||
|
topLayout->addWidget(m_replaceGrp);
|
||
15 years ago
|
|
||
14 years ago
|
m_optionGrp = new TQGroupBox(0, Qt::Vertical, i18n("Options"), page);
|
||
13 years ago
|
m_optionGrp->layout()->setSpacing(KDialog::spacingHint());
|
||
|
// m_optionGrp->layout()->setMargin(KDialog::marginHint());
|
||
|
optionsLayout = new TQGridLayout(m_optionGrp->layout());
|
||
15 years ago
|
optionsLayout->setSpacing( KDialog::spacingHint() );
|
||
|
// optionsLayout->setMargin( KDialog::marginHint() );
|
||
|
|
||
14 years ago
|
m_caseSensitive = new TQCheckBox(i18n("C&ase sensitive"), m_optionGrp);
|
||
|
m_wholeWordsOnly = new TQCheckBox(i18n("&Whole words only"), m_optionGrp);
|
||
|
m_fromCursor = new TQCheckBox(i18n("From c&ursor"), m_optionGrp);
|
||
14 years ago
|
m_findBackwards = new TQCheckBox(i18n("Find &backwards"), m_optionGrp);
|
||
14 years ago
|
m_selectedText = new TQCheckBox(i18n("&Selected text"), m_optionGrp);
|
||
15 years ago
|
setHasSelection( hasSelection );
|
||
14 years ago
|
// If we have a selection, we make 'find in selection' default
|
||
15 years ago
|
// and if we don't, then the option has to be unchecked, obviously.
|
||
|
m_selectedText->setChecked( hasSelection );
|
||
|
slotSelectedTextToggled( hasSelection );
|
||
|
|
||
14 years ago
|
m_promptOnReplace = new TQCheckBox(i18n("&Prompt on replace"), m_optionGrp);
|
||
15 years ago
|
m_promptOnReplace->setChecked( true );
|
||
|
|
||
|
optionsLayout->addWidget(m_caseSensitive, 0, 0);
|
||
|
optionsLayout->addWidget(m_wholeWordsOnly, 1, 0);
|
||
|
optionsLayout->addWidget(m_fromCursor, 2, 0);
|
||
14 years ago
|
optionsLayout->addWidget(m_findBackwards, 0, 1);
|
||
15 years ago
|
optionsLayout->addWidget(m_selectedText, 1, 1);
|
||
|
optionsLayout->addWidget(m_promptOnReplace, 2, 1);
|
||
|
topLayout->addWidget(m_optionGrp);
|
||
|
|
||
|
// We delay creation of these until needed.
|
||
|
m_patterns = 0L;
|
||
|
m_placeholders = 0L;
|
||
|
|
||
|
// signals and slots connections
|
||
14 years ago
|
connect(m_selectedText, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSelectedTextToggled(bool)));
|
||
|
connect(m_regExp, TQT_SIGNAL(toggled(bool)), m_regExpItem, TQT_SLOT(setEnabled(bool)));
|
||
|
connect(m_backRef, TQT_SIGNAL(toggled(bool)), m_backRefItem, TQT_SLOT(setEnabled(bool)));
|
||
|
connect(m_regExpItem, TQT_SIGNAL(clicked()), this, TQT_SLOT(showPatterns()));
|
||
|
connect(m_backRefItem, TQT_SIGNAL(clicked()), this, TQT_SLOT(showPlaceholders()));
|
||
15 years ago
|
|
||
14 years ago
|
connect(m_find, TQT_SIGNAL(textChanged ( const TQString & )),this, TQT_SLOT(textSearchChanged( const TQString & )));
|
||
15 years ago
|
|
||
|
// tab order
|
||
14 years ago
|
setTabOrder(m_find, m_regExp);
|
||
15 years ago
|
setTabOrder(m_regExp, m_regExpItem);
|
||
14 years ago
|
setTabOrder(m_regExpItem, m_replace);
|
||
|
setTabOrder(m_replace, m_backRef);
|
||
15 years ago
|
setTabOrder(m_backRef, m_backRefItem);
|
||
|
setTabOrder(m_backRefItem, m_caseSensitive);
|
||
|
setTabOrder(m_caseSensitive, m_wholeWordsOnly);
|
||
|
setTabOrder(m_wholeWordsOnly, m_fromCursor);
|
||
14 years ago
|
setTabOrder(m_fromCursor, m_findBackwards);
|
||
|
setTabOrder(m_findBackwards, m_selectedText);
|
||
15 years ago
|
setTabOrder(m_selectedText, m_promptOnReplace);
|
||
|
|
||
|
// buddies
|
||
14 years ago
|
m_findLabel->setBuddy(m_find);
|
||
|
m_replaceLabel->setBuddy(m_replace);
|
||
15 years ago
|
|
||
|
if (!forReplace)
|
||
|
{
|
||
|
m_promptOnReplace->hide();
|
||
14 years ago
|
m_replaceGrp->hide();
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
d->findStrings = findStrings;
|
||
|
m_find->setFocus();
|
||
15 years ago
|
enableButtonOK( !pattern().isEmpty() );
|
||
|
if (forReplace)
|
||
|
{
|
||
14 years ago
|
setButtonOK(KGuiItem( i18n("&Replace"), TQString::null,
|
||
14 years ago
|
i18n("Start replace"),
|
||
15 years ago
|
i18n("<qt>If you press the <b>Replace</b> button, the text you entered "
|
||
|
"above is searched for within the document and any occurrence is "
|
||
14 years ago
|
"replaced with the replacement text.</qt>")));
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
setButtonOK(KGuiItem( i18n("&Find"), "find",
|
||
15 years ago
|
i18n("Start searching"),
|
||
|
i18n("<qt>If you press the <b>Find</b> button, the text you entered "
|
||
|
"above is searched for within the document.</qt>")));
|
||
|
}
|
||
|
|
||
|
// QWhatsthis texts
|
||
14 years ago
|
TQWhatsThis::add ( m_find, i18n(
|
||
15 years ago
|
"Enter a pattern to search for, or select a previous pattern from "
|
||
|
"the list.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_regExp, i18n(
|
||
15 years ago
|
"If enabled, search for a regular expression.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_regExpItem, i18n(
|
||
15 years ago
|
"Click here to edit your regular expression using a graphical editor.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_replace, i18n(
|
||
|
"Enter a replacement string, or select a previous one from the list.") );
|
||
14 years ago
|
TQWhatsThis::add( m_backRef, i18n(
|
||
15 years ago
|
"<qt>If enabled, any occurrence of <code><b>\\N</b></code>, where "
|
||
14 years ago
|
"<code><b>N</b></code> is a integer number, will be replaced with "
|
||
15 years ago
|
"the corresponding capture (\"parenthesized substring\") from the "
|
||
|
"pattern.<p>To include (a literal <code><b>\\N</b></code> in your "
|
||
14 years ago
|
"replacement, put an extra backslash in front of it, like "
|
||
15 years ago
|
"<code><b>\\\\N</b></code>.</qt>") );
|
||
14 years ago
|
TQWhatsThis::add ( m_backRefItem, i18n(
|
||
15 years ago
|
"Click for a menu of available captures.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_wholeWordsOnly, i18n(
|
||
15 years ago
|
"Require word boundaries in both ends of a match to succeed.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_fromCursor, i18n(
|
||
15 years ago
|
"Start searching at the current cursor location rather than at the top.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_selectedText, i18n(
|
||
15 years ago
|
"Only search within the current selection.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_caseSensitive, i18n(
|
||
15 years ago
|
"Perform a case sensitive search: entering the pattern "
|
||
|
"'Joe' will not match 'joe' or 'JOE', only 'Joe'.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_findBackwards, i18n(
|
||
15 years ago
|
"Search backwards.") );
|
||
14 years ago
|
TQWhatsThis::add ( m_promptOnReplace, i18n(
|
||
15 years ago
|
"Ask before replacing each match found.") );
|
||
|
}
|
||
|
|
||
14 years ago
|
void KFindDialog::textSearchChanged( const TQString & text)
|
||
15 years ago
|
{
|
||
|
enableButtonOK( !text.isEmpty() );
|
||
|
}
|
||
|
|
||
14 years ago
|
void KFindDialog::showEvent( TQShowEvent *e )
|
||
15 years ago
|
{
|
||
|
if ( !d->m_initialShowDone )
|
||
|
{
|
||
|
d->m_initialShowDone = true; // only once
|
||
|
kdDebug() << "showEvent\n";
|
||
14 years ago
|
if (!d->findStrings.isEmpty())
|
||
|
setFindHistory(d->findStrings);
|
||
|
d->findStrings = TQStringList();
|
||
15 years ago
|
if (!d->pattern.isEmpty()) {
|
||
14 years ago
|
m_find->lineEdit()->setText( d->pattern );
|
||
|
m_find->lineEdit()->selectAll();
|
||
14 years ago
|
d->pattern = TQString::null;
|
||
15 years ago
|
}
|
||
|
}
|
||
|
KDialogBase::showEvent(e);
|
||
|
}
|
||
|
|
||
|
long KFindDialog::options() const
|
||
|
{
|
||
|
long options = 0;
|
||
|
|
||
|
if (m_caseSensitive->isChecked())
|
||
|
options |= CaseSensitive;
|
||
|
if (m_wholeWordsOnly->isChecked())
|
||
|
options |= WholeWordsOnly;
|
||
|
if (m_fromCursor->isChecked())
|
||
|
options |= FromCursor;
|
||
14 years ago
|
if (m_findBackwards->isChecked())
|
||
15 years ago
|
options |= FindBackwards;
|
||
|
if (m_selectedText->isChecked())
|
||
|
options |= SelectedText;
|
||
|
if (m_regExp->isChecked())
|
||
|
options |= RegularExpression;
|
||
|
return options;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString KFindDialog::pattern() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return m_find->currentText();
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void KFindDialog::setPattern (const TQString &pattern)
|
||
15 years ago
|
{
|
||
14 years ago
|
m_find->lineEdit()->setText( pattern );
|
||
|
m_find->lineEdit()->selectAll();
|
||
15 years ago
|
d->pattern = pattern;
|
||
|
kdDebug() << "setPattern " << pattern<<endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
void KFindDialog::setFindHistory(const TQStringList &strings)
|
||
15 years ago
|
{
|
||
|
if (strings.count() > 0)
|
||
|
{
|
||
14 years ago
|
m_find->setHistoryItems(strings, true);
|
||
|
m_find->lineEdit()->setText( strings.first() );
|
||
|
m_find->lineEdit()->selectAll();
|
||
15 years ago
|
}
|
||
|
else
|
||
14 years ago
|
m_find->clearHistory();
|
||
15 years ago
|
}
|
||
|
|
||
|
void KFindDialog::setHasSelection(bool hasSelection)
|
||
|
{
|
||
|
if (hasSelection) d->m_enabled |= SelectedText;
|
||
|
else d->m_enabled &= ~SelectedText;
|
||
|
m_selectedText->setEnabled( hasSelection );
|
||
|
if ( !hasSelection )
|
||
|
{
|
||
|
m_selectedText->setChecked( false );
|
||
|
slotSelectedTextToggled( hasSelection );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KFindDialog::slotSelectedTextToggled(bool selec)
|
||
|
{
|
||
|
// From cursor doesn't make sense if we have a selection
|
||
|
m_fromCursor->setEnabled( !selec && (d->m_enabled & FromCursor) );
|
||
|
if ( selec ) // uncheck if disabled
|
||
|
m_fromCursor->setChecked( false );
|
||
|
}
|
||
|
|
||
|
void KFindDialog::setHasCursor(bool hasCursor)
|
||
|
{
|
||
|
if (hasCursor) d->m_enabled |= FromCursor;
|
||
|
else d->m_enabled &= ~FromCursor;
|
||
|
m_fromCursor->setEnabled( hasCursor );
|
||
|
m_fromCursor->setChecked( hasCursor && (options() & FromCursor) );
|
||
|
}
|
||
|
|
||
|
void KFindDialog::setSupportsBackwardsFind( bool supports )
|
||
|
{
|
||
|
// ########## Shouldn't this hide the checkbox instead?
|
||
|
if (supports) d->m_enabled |= FindBackwards;
|
||
|
else d->m_enabled &= ~FindBackwards;
|
||
14 years ago
|
m_findBackwards->setEnabled( supports );
|
||
|
m_findBackwards->setChecked( supports && (options() & FindBackwards) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KFindDialog::setSupportsCaseSensitiveFind( bool supports )
|
||
|
{
|
||
|
// ########## This should hide the checkbox instead
|
||
|
if (supports) d->m_enabled |= CaseSensitive;
|
||
|
else d->m_enabled &= ~CaseSensitive;
|
||
|
m_caseSensitive->setEnabled( supports );
|
||
|
m_caseSensitive->setChecked( supports && (options() & CaseSensitive) );
|
||
|
}
|
||
|
|
||
|
void KFindDialog::setSupportsWholeWordsFind( bool supports )
|
||
|
{
|
||
|
// ########## This should hide the checkbox instead
|
||
|
if (supports) d->m_enabled |= WholeWordsOnly;
|
||
|
else d->m_enabled &= ~WholeWordsOnly;
|
||
|
m_wholeWordsOnly->setEnabled( supports );
|
||
|
m_wholeWordsOnly->setChecked( supports && (options() & WholeWordsOnly) );
|
||
|
}
|
||
|
|
||
|
void KFindDialog::setSupportsRegularExpressionFind( bool supports )
|
||
|
{
|
||
|
// ########## This should hide the checkbox instead
|
||
|
if (supports) d->m_enabled |= RegularExpression;
|
||
|
else d->m_enabled &= ~RegularExpression;
|
||
|
m_regExp->setEnabled( supports );
|
||
|
m_regExp->setChecked( supports && (options() & RegularExpression) );
|
||
|
}
|
||
|
|
||
|
void KFindDialog::setOptions(long options)
|
||
|
{
|
||
|
m_caseSensitive->setChecked((d->m_enabled & CaseSensitive) && (options & CaseSensitive));
|
||
|
m_wholeWordsOnly->setChecked((d->m_enabled & WholeWordsOnly) && (options & WholeWordsOnly));
|
||
|
m_fromCursor->setChecked((d->m_enabled & FromCursor) && (options & FromCursor));
|
||
14 years ago
|
m_findBackwards->setChecked((d->m_enabled & FindBackwards) && (options & FindBackwards));
|
||
15 years ago
|
m_selectedText->setChecked((d->m_enabled & SelectedText) && (options & SelectedText));
|
||
|
m_regExp->setChecked((d->m_enabled & RegularExpression) && (options & RegularExpression));
|
||
|
}
|
||
|
|
||
|
// Create a popup menu with a list of regular expression terms, to help the user
|
||
|
// compose a regular expression search pattern.
|
||
|
void KFindDialog::showPatterns()
|
||
|
{
|
||
|
if ( !d->m_regexpDialogQueryDone )
|
||
|
{
|
||
14 years ago
|
d->m_regexpDialog = KParts::ComponentFactory::createInstanceFromQuery<TQDialog>( "KRegExpEditor/KRegExpEditor", TQString(), TQT_TQOBJECT(this) );
|
||
15 years ago
|
d->m_regexpDialogQueryDone = true;
|
||
|
}
|
||
|
|
||
|
if ( d->m_regexpDialog )
|
||
|
{
|
||
14 years ago
|
KRegExpEditorInterface *iface = tqt_dynamic_cast<KRegExpEditorInterface *>( d->m_regexpDialog );
|
||
15 years ago
|
assert( iface );
|
||
|
|
||
|
iface->setRegExp( pattern() );
|
||
14 years ago
|
if ( d->m_regexpDialog->exec() == TQDialog::Accepted )
|
||
15 years ago
|
setPattern( iface->regExp() );
|
||
|
}
|
||
|
else // No complete regexp-editor available, bring up the old popupmenu
|
||
|
{
|
||
|
typedef struct
|
||
|
{
|
||
|
const char *description;
|
||
|
const char *regExp;
|
||
|
int cursorAdjustment;
|
||
|
} term;
|
||
|
static const term items[] =
|
||
|
{
|
||
|
{ I18N_NOOP("Any Character"), ".", 0 },
|
||
|
{ I18N_NOOP("Start of Line"), "^", 0 },
|
||
|
{ I18N_NOOP("End of Line"), "$", 0 },
|
||
|
{ I18N_NOOP("Set of Characters"), "[]", -1 },
|
||
|
{ I18N_NOOP("Repeats, Zero or More Times"), "*", 0 },
|
||
|
{ I18N_NOOP("Repeats, One or More Times"), "+", 0 },
|
||
|
{ I18N_NOOP("Optional"), "?", 0 },
|
||
|
{ I18N_NOOP("Escape"), "\\", 0 },
|
||
|
{ I18N_NOOP("TAB"), "\\t", 0 },
|
||
|
{ I18N_NOOP("Newline"), "\\n", 0 },
|
||
|
{ I18N_NOOP("Carriage Return"), "\\r", 0 },
|
||
|
{ I18N_NOOP("White Space"), "\\s", 0 },
|
||
|
{ I18N_NOOP("Digit"), "\\d", 0 },
|
||
|
};
|
||
|
int i;
|
||
|
|
||
|
// Populate the popup menu.
|
||
|
if (!m_patterns)
|
||
|
{
|
||
14 years ago
|
m_patterns = new TQPopupMenu(this);
|
||
15 years ago
|
for (i = 0; (unsigned)i < sizeof(items) / sizeof(items[0]); i++)
|
||
|
{
|
||
|
m_patterns->insertItem(i18n(items[i].description), i, i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Insert the selection into the edit control.
|
||
|
i = m_patterns->exec(m_regExpItem->mapToGlobal(m_regExpItem->rect().bottomLeft()));
|
||
|
if (i != -1)
|
||
|
{
|
||
14 years ago
|
TQLineEdit *editor = m_find->lineEdit();
|
||
15 years ago
|
|
||
|
editor->insert(items[i].regExp);
|
||
|
editor->setCursorPosition(editor->cursorPosition() + items[i].cursorAdjustment);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Create a popup menu with a list of backreference terms, to help the user
|
||
14 years ago
|
// compose a regular expression replacement pattern.
|
||
15 years ago
|
void KFindDialog::showPlaceholders()
|
||
|
{
|
||
|
// Populate the popup menu.
|
||
|
if (!m_placeholders)
|
||
|
{
|
||
14 years ago
|
m_placeholders = new TQPopupMenu(this);
|
||
|
connect( m_placeholders, TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(slotPlaceholdersAboutToShow()) );
|
||
15 years ago
|
}
|
||
|
|
||
|
// Insert the selection into the edit control.
|
||
|
int i = m_placeholders->exec(m_backRefItem->mapToGlobal(m_backRefItem->rect().bottomLeft()));
|
||
|
if (i != -1)
|
||
|
{
|
||
14 years ago
|
TQLineEdit *editor = m_replace->lineEdit();
|
||
14 years ago
|
editor->insert( TQString("\\%1").arg( i ) );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void KFindDialog::slotPlaceholdersAboutToShow()
|
||
|
{
|
||
|
m_placeholders->clear();
|
||
|
m_placeholders->insertItem( i18n("Complete Match"), 0 );
|
||
|
|
||
14 years ago
|
TQRegExp r( pattern() );
|
||
15 years ago
|
uint n = r.numCaptures();
|
||
|
for ( uint i=0; i < n; i++ )
|
||
|
m_placeholders->insertItem( i18n("Captured Text (%1)").arg( i+1 ), i+1 );
|
||
|
}
|
||
|
|
||
|
void KFindDialog::slotOk()
|
||
|
{
|
||
14 years ago
|
// Nothing to find?
|
||
15 years ago
|
if (pattern().isEmpty())
|
||
|
{
|
||
|
KMessageBox::error(this, i18n("You must enter some text to search for."));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (m_regExp->isChecked())
|
||
|
{
|
||
|
// Check for a valid regular expression.
|
||
14 years ago
|
TQRegExp regExp(pattern());
|
||
15 years ago
|
|
||
|
if (!regExp.isValid())
|
||
|
{
|
||
|
KMessageBox::error(this, i18n("Invalid regular expression."));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
m_find->addToHistory(pattern());
|
||
15 years ago
|
emit okClicked();
|
||
|
if ( testWFlags( WShowModal ) )
|
||
|
accept();
|
||
|
}
|
||
14 years ago
|
// kate: space-indent on; indent-width 4; replace-tabs on;
|
||
15 years ago
|
#include "kfinddialog.moc"
|