2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, 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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
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 "findtoolwindow.h"
|
|
|
|
|
#include "findplugin.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QMainWindow>
|
|
|
|
|
|
|
|
|
|
using namespace Find;
|
|
|
|
|
using namespace Find::Internal;
|
|
|
|
|
|
|
|
|
|
FindToolWindow::FindToolWindow(FindPlugin *plugin)
|
2009-01-20 11:52:04 +01:00
|
|
|
: QDialog(Core::ICore::instance()->mainWindow()),
|
2008-12-02 12:01:29 +01:00
|
|
|
m_plugin(plugin),
|
2009-04-03 15:53:29 +02:00
|
|
|
m_findCompleter(new QCompleter(this)),
|
|
|
|
|
m_currentFilter(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
connect(m_ui.closeButton, SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
|
|
connect(m_ui.searchButton, SIGNAL(clicked()), this, SLOT(accept()));
|
|
|
|
|
connect(m_ui.matchCase, SIGNAL(toggled(bool)), m_plugin, SLOT(setCaseSensitive(bool)));
|
|
|
|
|
connect(m_ui.wholeWords, SIGNAL(toggled(bool)), m_plugin, SLOT(setWholeWord(bool)));
|
2009-04-03 15:53:29 +02:00
|
|
|
connect(m_ui.filterList, SIGNAL(activated(int)), this, SLOT(setCurrentFilter(int)));
|
2008-12-02 12:01:29 +01:00
|
|
|
connect(this, SIGNAL(accepted()), this, SLOT(search()));
|
|
|
|
|
m_findCompleter->setModel(m_plugin->findCompletionModel());
|
|
|
|
|
m_ui.searchTerm->setCompleter(m_findCompleter);
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
m_ui.configWidget->setLayout(layout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FindToolWindow::~FindToolWindow()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_configWidgets);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolWindow::setFindFilters(const QList<IFindFilter *> &filters)
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_configWidgets);
|
|
|
|
|
m_configWidgets.clear();
|
|
|
|
|
m_filters = filters;
|
|
|
|
|
m_ui.filterList->clear();
|
|
|
|
|
QStringList names;
|
|
|
|
|
foreach (IFindFilter *filter, filters) {
|
|
|
|
|
names << filter->name();
|
|
|
|
|
m_configWidgets.append(filter->createConfigWidget());
|
|
|
|
|
}
|
|
|
|
|
m_ui.filterList->addItems(names);
|
2009-04-03 15:53:29 +02:00
|
|
|
if (m_filters.size() > 0)
|
|
|
|
|
setCurrentFilter(0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolWindow::setFindText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
m_ui.searchTerm->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolWindow::open(IFindFilter *filter)
|
|
|
|
|
{
|
2009-04-03 15:53:29 +02:00
|
|
|
if (!filter)
|
|
|
|
|
filter = m_currentFilter;
|
2008-12-02 12:01:29 +01:00
|
|
|
int index = m_filters.indexOf(filter);
|
|
|
|
|
if (index >= 0) {
|
2009-04-03 15:53:29 +02:00
|
|
|
setCurrentFilter(index);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
m_ui.matchCase->setChecked(m_plugin->findFlags() & QTextDocument::FindCaseSensitively);
|
|
|
|
|
m_ui.wholeWords->setChecked(m_plugin->findFlags() & QTextDocument::FindWholeWords);
|
|
|
|
|
m_ui.searchTerm->setFocus();
|
|
|
|
|
m_ui.searchTerm->selectAll();
|
|
|
|
|
exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolWindow::setCurrentFilter(int index)
|
|
|
|
|
{
|
2009-04-03 15:53:29 +02:00
|
|
|
m_ui.filterList->setCurrentIndex(index);
|
2008-12-02 12:01:29 +01:00
|
|
|
for (int i = 0; i < m_configWidgets.size(); ++i) {
|
|
|
|
|
QWidget *configWidget = m_configWidgets.at(i);
|
|
|
|
|
if (!configWidget)
|
|
|
|
|
continue;
|
2009-02-10 12:13:45 +01:00
|
|
|
if (i == index) {
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.configWidget->layout()->addWidget(configWidget);
|
2009-02-10 12:13:45 +01:00
|
|
|
bool enabled = m_filters.at(i)->isEnabled();
|
|
|
|
|
m_ui.matchCase->setEnabled(enabled);
|
|
|
|
|
m_ui.wholeWords->setEnabled(enabled);
|
|
|
|
|
m_ui.searchTerm->setEnabled(enabled);
|
|
|
|
|
m_ui.searchButton->setEnabled(enabled);
|
|
|
|
|
configWidget->setEnabled(enabled);
|
|
|
|
|
} else {
|
2008-12-02 12:01:29 +01:00
|
|
|
configWidget->setParent(0);
|
2009-02-10 12:13:45 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-04-03 15:53:29 +02:00
|
|
|
m_currentFilter = m_filters.at(index);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolWindow::search()
|
|
|
|
|
{
|
|
|
|
|
m_plugin->updateFindCompletion(m_ui.searchTerm->text());
|
|
|
|
|
int index = m_ui.filterList->currentIndex();
|
|
|
|
|
QString term = m_ui.searchTerm->text();
|
|
|
|
|
if (term.isEmpty() || index < 0)
|
|
|
|
|
return;
|
|
|
|
|
IFindFilter *filter = m_filters.at(index);
|
|
|
|
|
filter->findAll(term, m_plugin->findFlags());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolWindow::writeSettings()
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
2008-12-02 12:01:29 +01:00
|
|
|
settings->beginGroup("Find");
|
2009-04-03 15:53:29 +02:00
|
|
|
settings->setValue("CurrentFilter", m_currentFilter->id());
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (IFindFilter *filter, m_filters)
|
|
|
|
|
filter->writeSettings(settings);
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindToolWindow::readSettings()
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
2008-12-02 12:01:29 +01:00
|
|
|
settings->beginGroup("Find");
|
2009-04-03 15:53:29 +02:00
|
|
|
const QString currentFilter = settings->value("CurrentFilter").toString();
|
|
|
|
|
for (int i = 0; i < m_filters.size(); ++i) {
|
|
|
|
|
IFindFilter *filter = m_filters.at(i);
|
2008-12-02 12:01:29 +01:00
|
|
|
filter->readSettings(settings);
|
2009-04-03 15:53:29 +02:00
|
|
|
if (filter->id() == currentFilter) {
|
|
|
|
|
setCurrentFilter(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
settings->endGroup();
|
|
|
|
|
}
|