2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "currentdocumentfind.h"
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <aggregation/aggregate.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QWidget>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Find;
|
|
|
|
|
using namespace Find::Internal;
|
|
|
|
|
|
2009-01-21 18:09:37 +01:00
|
|
|
CurrentDocumentFind::CurrentDocumentFind()
|
|
|
|
|
: m_currentFind(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)),
|
2009-07-21 11:10:02 +02:00
|
|
|
this, SLOT(updateCandidateFindFilter(QWidget*,QWidget*)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentDocumentFind::removeConnections()
|
|
|
|
|
{
|
|
|
|
|
disconnect(qApp, 0, this, 0);
|
|
|
|
|
removeFindSupportConnections();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentDocumentFind::resetIncrementalSearch()
|
|
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return);
|
|
|
|
|
m_currentFind->resetIncrementalSearch();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentDocumentFind::clearResults()
|
|
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return);
|
|
|
|
|
m_currentFind->clearResults();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CurrentDocumentFind::isEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return m_currentFind && (!m_currentWidget || m_currentWidget->isVisible());
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
bool CurrentDocumentFind::candidateIsEnabled() const
|
|
|
|
|
{
|
|
|
|
|
return (m_candidateFind != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool CurrentDocumentFind::supportsReplace() const
|
|
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return false);
|
|
|
|
|
return m_currentFind->supportsReplace();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 13:30:04 +02:00
|
|
|
Find::FindFlags CurrentDocumentFind::supportedFindFlags() const
|
2009-07-13 14:48:45 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_currentFind, return 0);
|
|
|
|
|
return m_currentFind->supportedFindFlags();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString CurrentDocumentFind::currentFindString() const
|
|
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return QString());
|
|
|
|
|
return m_currentFind->currentFindString();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CurrentDocumentFind::completedFindString() const
|
|
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return QString());
|
|
|
|
|
return m_currentFind->completedFindString();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 13:30:04 +02:00
|
|
|
void CurrentDocumentFind::highlightAll(const QString &txt, Find::FindFlags findFlags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return);
|
|
|
|
|
m_currentFind->highlightAll(txt, findFlags);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 13:30:04 +02:00
|
|
|
IFindSupport::Result CurrentDocumentFind::findIncremental(const QString &txt, Find::FindFlags findFlags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-09-09 17:11:00 +02:00
|
|
|
QTC_ASSERT(m_currentFind, return IFindSupport::NotFound);
|
2008-12-09 15:25:01 +01:00
|
|
|
return m_currentFind->findIncremental(txt, findFlags);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 13:30:04 +02:00
|
|
|
IFindSupport::Result CurrentDocumentFind::findStep(const QString &txt, Find::FindFlags findFlags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-09-09 17:11:00 +02:00
|
|
|
QTC_ASSERT(m_currentFind, return IFindSupport::NotFound);
|
2008-12-09 15:25:01 +01:00
|
|
|
return m_currentFind->findStep(txt, findFlags);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-14 14:45:02 +02:00
|
|
|
void CurrentDocumentFind::replace(const QString &before, const QString &after,
|
2010-07-15 13:30:04 +02:00
|
|
|
Find::FindFlags findFlags)
|
2010-07-14 14:45:02 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_currentFind, return);
|
|
|
|
|
m_currentFind->replace(before, after, findFlags);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool CurrentDocumentFind::replaceStep(const QString &before, const QString &after,
|
2010-07-15 13:30:04 +02:00
|
|
|
Find::FindFlags findFlags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return false);
|
|
|
|
|
return m_currentFind->replaceStep(before, after, findFlags);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CurrentDocumentFind::replaceAll(const QString &before, const QString &after,
|
2010-07-15 13:30:04 +02:00
|
|
|
Find::FindFlags findFlags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return 0);
|
|
|
|
|
return m_currentFind->replaceAll(before, after, findFlags);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentDocumentFind::defineFindScope()
|
|
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return);
|
|
|
|
|
m_currentFind->defineFindScope();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentDocumentFind::clearFindScope()
|
|
|
|
|
{
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_currentFind, return);
|
|
|
|
|
m_currentFind->clearFindScope();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
void CurrentDocumentFind::updateCandidateFindFilter(QWidget *old, QWidget *now)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(old)
|
2008-12-02 12:01:29 +01:00
|
|
|
QWidget *candidate = now;
|
|
|
|
|
QPointer<IFindSupport> impl = 0;
|
|
|
|
|
while (!impl && candidate) {
|
|
|
|
|
impl = Aggregation::query<IFindSupport>(candidate);
|
|
|
|
|
if (!impl)
|
|
|
|
|
candidate = candidate->parentWidget();
|
|
|
|
|
}
|
2010-05-17 09:58:36 +02:00
|
|
|
if (m_candidateWidget)
|
|
|
|
|
disconnect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()),
|
|
|
|
|
this, SLOT(candidateAggregationChanged()));
|
2009-07-21 11:10:02 +02:00
|
|
|
m_candidateWidget = candidate;
|
|
|
|
|
m_candidateFind = impl;
|
2010-05-17 09:58:36 +02:00
|
|
|
if (m_candidateWidget)
|
|
|
|
|
connect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()),
|
|
|
|
|
this, SLOT(candidateAggregationChanged()));
|
2009-07-21 11:10:02 +02:00
|
|
|
emit candidateChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentDocumentFind::acceptCandidate()
|
|
|
|
|
{
|
|
|
|
|
if (!m_candidateFind || m_candidateFind == m_currentFind)
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
removeFindSupportConnections();
|
2009-01-06 13:59:17 +01:00
|
|
|
if (m_currentFind)
|
2011-08-09 11:08:01 +02:00
|
|
|
m_currentFind->clearResults();
|
2010-05-17 09:58:36 +02:00
|
|
|
|
|
|
|
|
if (m_currentWidget)
|
|
|
|
|
disconnect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()),
|
|
|
|
|
this, SLOT(aggregationChanged()));
|
2009-07-21 11:10:02 +02:00
|
|
|
m_currentWidget = m_candidateWidget;
|
2010-05-17 09:58:36 +02:00
|
|
|
connect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()),
|
|
|
|
|
this, SLOT(aggregationChanged()));
|
|
|
|
|
|
2009-07-21 11:10:02 +02:00
|
|
|
m_currentFind = m_candidateFind;
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_currentFind) {
|
|
|
|
|
connect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed()));
|
2010-05-17 09:58:36 +02:00
|
|
|
connect(m_currentFind, SIGNAL(destroyed(QObject*)), SLOT(clearFindSupport()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
if (m_currentWidget)
|
|
|
|
|
m_currentWidget->installEventFilter(this);
|
|
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentDocumentFind::removeFindSupportConnections()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentFind) {
|
|
|
|
|
disconnect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed()));
|
2010-05-17 09:58:36 +02:00
|
|
|
disconnect(m_currentFind, SIGNAL(destroyed(QObject*)), this, SLOT(clearFindSupport()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
if (m_currentWidget)
|
|
|
|
|
m_currentWidget->removeEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-17 09:58:36 +02:00
|
|
|
void CurrentDocumentFind::clearFindSupport()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
removeFindSupportConnections();
|
|
|
|
|
m_currentWidget = 0;
|
|
|
|
|
m_currentFind = 0;
|
|
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CurrentDocumentFind::setFocusToCurrentFindSupport()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentFind && m_currentWidget) {
|
2011-12-01 13:03:08 +01:00
|
|
|
QWidget *w = m_currentWidget->focusWidget();
|
|
|
|
|
if (!w)
|
|
|
|
|
w = m_currentWidget;
|
|
|
|
|
w->setFocus();
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CurrentDocumentFind::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (m_currentWidget && obj == m_currentWidget) {
|
|
|
|
|
if (event->type() == QEvent::Hide || event->type() == QEvent::Show) {
|
|
|
|
|
emit changed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QObject::eventFilter(obj, event);
|
|
|
|
|
}
|
2010-05-17 09:58:36 +02:00
|
|
|
|
|
|
|
|
void CurrentDocumentFind::aggregationChanged()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentWidget) {
|
|
|
|
|
QPointer<IFindSupport> currentFind = Aggregation::query<IFindSupport>(m_currentWidget);
|
|
|
|
|
if (currentFind != m_currentFind) {
|
|
|
|
|
// There's a change in the find support
|
|
|
|
|
if (currentFind) {
|
|
|
|
|
m_candidateWidget = m_currentWidget;
|
|
|
|
|
m_candidateFind = currentFind;
|
|
|
|
|
acceptCandidate();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
clearFindSupport();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CurrentDocumentFind::candidateAggregationChanged()
|
|
|
|
|
{
|
2010-05-17 10:36:19 +02:00
|
|
|
if (m_candidateWidget && m_candidateWidget != m_currentWidget) {
|
2010-05-17 09:58:36 +02:00
|
|
|
m_candidateFind = Aggregation::query<IFindSupport>(m_candidateWidget);
|
|
|
|
|
emit candidateChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|