2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
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.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@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 "searchresultwindow.h"
|
|
|
|
|
#include "searchresulttreemodel.h"
|
2009-10-05 16:01:50 +02:00
|
|
|
#include "searchresulttreeitems.h"
|
2010-03-24 10:43:01 +01:00
|
|
|
#include "searchresulttreeview.h"
|
2010-06-29 13:16:54 +02:00
|
|
|
#include "ifindsupport.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-06-29 13:16:54 +02:00
|
|
|
#include <aggregation/aggregate.h>
|
2009-01-21 18:09:37 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2010-06-29 13:34:43 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icontext.h>
|
2010-09-10 14:13:19 +02:00
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
2009-10-05 16:01:50 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-01-21 18:09:37 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
#include <QtCore/QTextStream>
|
|
|
|
|
#include <QtCore/QSettings>
|
2009-04-30 12:50:52 +02:00
|
|
|
#include <QtCore/QDebug>
|
2010-07-19 14:46:53 +02:00
|
|
|
#include <QtCore/QDir>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QListWidget>
|
|
|
|
|
#include <QtGui/QToolButton>
|
2009-09-29 16:40:52 +02:00
|
|
|
#include <QtGui/QLineEdit>
|
2009-10-01 16:38:08 +02:00
|
|
|
#include <QtGui/QStackedWidget>
|
|
|
|
|
#include <QtGui/QLabel>
|
2010-03-24 10:43:01 +01:00
|
|
|
#include <QtGui/QFont>
|
2010-06-29 13:34:43 +02:00
|
|
|
#include <QtGui/QAction>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-24 10:43:01 +01:00
|
|
|
static const char SETTINGSKEYSECTIONNAME[] = "SearchResults";
|
|
|
|
|
static const char SETTINGSKEYEXPANDRESULTS[] = "ExpandResults";
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-24 10:43:01 +01:00
|
|
|
namespace Find {
|
2009-09-29 16:59:19 +02:00
|
|
|
|
2010-06-29 13:16:54 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-05-21 13:47:02 +02:00
|
|
|
class WideEnoughLineEdit : public QLineEdit {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
WideEnoughLineEdit(QWidget *parent):QLineEdit(parent){
|
|
|
|
|
connect(this, SIGNAL(textChanged(QString)),
|
|
|
|
|
this, SLOT(updateGeometry()));
|
|
|
|
|
}
|
|
|
|
|
~WideEnoughLineEdit(){}
|
|
|
|
|
QSize sizeHint() const {
|
|
|
|
|
QSize sh = QLineEdit::minimumSizeHint();
|
|
|
|
|
sh.rwidth() += qMax(25 * fontMetrics().width(QLatin1Char('x')),
|
|
|
|
|
fontMetrics().width(text()));
|
|
|
|
|
return sh;
|
|
|
|
|
}
|
|
|
|
|
public slots:
|
|
|
|
|
void updateGeometry() { QLineEdit::updateGeometry(); }
|
|
|
|
|
};
|
|
|
|
|
|
2010-06-29 13:16:54 +02:00
|
|
|
class SearchResultFindSupport : public IFindSupport
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
SearchResultFindSupport(SearchResultTreeView *view)
|
2011-01-14 10:02:21 +01:00
|
|
|
: m_view(view),
|
|
|
|
|
m_incrementalWrappedState(false)
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
|
|
|
|
}
|
2010-05-21 13:47:02 +02:00
|
|
|
|
2010-06-29 13:16:54 +02:00
|
|
|
bool supportsReplace() const { return false; }
|
|
|
|
|
|
2010-07-15 13:30:04 +02:00
|
|
|
Find::FindFlags supportedFindFlags() const
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
2010-07-15 13:30:04 +02:00
|
|
|
return Find::FindBackward | Find::FindCaseSensitively
|
|
|
|
|
| Find::FindRegularExpression | Find::FindWholeWords;
|
2010-06-29 13:16:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resetIncrementalSearch()
|
|
|
|
|
{
|
|
|
|
|
m_incrementalFindStart = QModelIndex();
|
2011-01-14 10:02:21 +01:00
|
|
|
m_incrementalWrappedState = false;
|
2010-06-29 13:16:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearResults() { }
|
|
|
|
|
|
|
|
|
|
QString currentFindString() const
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString completedFindString() const
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 13:30:04 +02:00
|
|
|
void highlightAll(const QString &txt, Find::FindFlags findFlags)
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(txt)
|
|
|
|
|
Q_UNUSED(findFlags)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 13:30:04 +02:00
|
|
|
IFindSupport::Result findIncremental(const QString &txt, Find::FindFlags findFlags)
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
2011-01-14 10:02:21 +01:00
|
|
|
if (!m_incrementalFindStart.isValid()) {
|
2010-06-29 13:16:54 +02:00
|
|
|
m_incrementalFindStart = m_view->currentIndex();
|
2011-01-14 10:02:21 +01:00
|
|
|
m_incrementalWrappedState = false;
|
|
|
|
|
}
|
2010-06-29 13:16:54 +02:00
|
|
|
m_view->setCurrentIndex(m_incrementalFindStart);
|
2011-01-14 10:02:21 +01:00
|
|
|
bool wrapped = false;
|
|
|
|
|
IFindSupport::Result result = find(txt, findFlags, &wrapped);
|
|
|
|
|
if (wrapped != m_incrementalWrappedState) {
|
|
|
|
|
m_incrementalWrappedState = wrapped;
|
|
|
|
|
showWrapIndicator(m_view);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2010-06-29 13:16:54 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 13:30:04 +02:00
|
|
|
IFindSupport::Result findStep(const QString &txt, Find::FindFlags findFlags)
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
2011-01-14 10:02:21 +01:00
|
|
|
bool wrapped = false;
|
|
|
|
|
IFindSupport::Result result = find(txt, findFlags, &wrapped);
|
|
|
|
|
if (wrapped)
|
|
|
|
|
showWrapIndicator(m_view);
|
|
|
|
|
if (result == IFindSupport::Found) {
|
2010-06-29 13:16:54 +02:00
|
|
|
m_incrementalFindStart = m_view->currentIndex();
|
2011-01-14 10:02:21 +01:00
|
|
|
m_incrementalWrappedState = false;
|
|
|
|
|
}
|
2010-06-29 13:16:54 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-14 10:02:21 +01:00
|
|
|
IFindSupport::Result find(const QString &txt, Find::FindFlags findFlags, bool *wrapped)
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
2011-01-14 10:02:21 +01:00
|
|
|
if (wrapped)
|
|
|
|
|
*wrapped = false;
|
2010-06-29 13:16:54 +02:00
|
|
|
if (txt.isEmpty())
|
|
|
|
|
return IFindSupport::NotFound;
|
|
|
|
|
QModelIndex index;
|
2010-07-15 13:30:04 +02:00
|
|
|
if (findFlags & Find::FindRegularExpression) {
|
|
|
|
|
bool sensitive = (findFlags & Find::FindCaseSensitively);
|
2010-06-29 13:16:54 +02:00
|
|
|
index = m_view->model()->find(QRegExp(txt, (sensitive ? Qt::CaseSensitive : Qt::CaseInsensitive)),
|
2011-01-14 10:02:21 +01:00
|
|
|
m_view->currentIndex(),
|
|
|
|
|
Find::textDocumentFlagsForFindFlags(findFlags),
|
|
|
|
|
wrapped);
|
2010-06-29 13:16:54 +02:00
|
|
|
} else {
|
2011-01-14 10:02:21 +01:00
|
|
|
index = m_view->model()->find(txt,
|
|
|
|
|
m_view->currentIndex(),
|
|
|
|
|
Find::textDocumentFlagsForFindFlags(findFlags),
|
|
|
|
|
wrapped);
|
2010-06-29 13:16:54 +02:00
|
|
|
}
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
|
m_view->setCurrentIndex(index);
|
|
|
|
|
m_view->scrollTo(index);
|
|
|
|
|
if (index.parent().isValid())
|
|
|
|
|
m_view->expand(index.parent());
|
|
|
|
|
return IFindSupport::Found;
|
|
|
|
|
}
|
|
|
|
|
return IFindSupport::NotFound;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 14:45:02 +02:00
|
|
|
void 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
|
|
|
{
|
|
|
|
|
Q_UNUSED(before)
|
|
|
|
|
Q_UNUSED(after)
|
|
|
|
|
Q_UNUSED(findFlags)
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-29 13:16:54 +02:00
|
|
|
bool replaceStep(const QString &before, const QString &after,
|
2010-07-15 13:30:04 +02:00
|
|
|
Find::FindFlags findFlags)
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(before)
|
|
|
|
|
Q_UNUSED(after)
|
|
|
|
|
Q_UNUSED(findFlags)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int replaceAll(const QString &before, const QString &after,
|
2010-07-15 13:30:04 +02:00
|
|
|
Find::FindFlags findFlags)
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(before)
|
|
|
|
|
Q_UNUSED(after)
|
|
|
|
|
Q_UNUSED(findFlags)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
SearchResultTreeView *m_view;
|
|
|
|
|
QModelIndex m_incrementalFindStart;
|
2011-01-14 10:02:21 +01:00
|
|
|
bool m_incrementalWrappedState;
|
2010-06-29 13:16:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SearchResultWindowPrivate {
|
|
|
|
|
SearchResultWindowPrivate();
|
|
|
|
|
|
|
|
|
|
Internal::SearchResultTreeView *m_searchResultTreeView;
|
|
|
|
|
QListWidget *m_noMatchesFoundDisplay;
|
2010-06-29 13:34:43 +02:00
|
|
|
QToolButton *m_expandCollapseButton;
|
|
|
|
|
QAction *m_expandCollapseAction;
|
2010-06-29 13:16:54 +02:00
|
|
|
QLabel *m_replaceLabel;
|
|
|
|
|
QLineEdit *m_replaceTextEdit;
|
|
|
|
|
QToolButton *m_replaceButton;
|
|
|
|
|
static const bool m_initiallyExpand = false;
|
|
|
|
|
QStackedWidget *m_widget;
|
|
|
|
|
SearchResult *m_currentSearch;
|
2010-07-19 14:46:53 +02:00
|
|
|
int m_itemCount;
|
2010-06-29 13:16:54 +02:00
|
|
|
bool m_isShowingReplaceUI;
|
|
|
|
|
bool m_focusReplaceEdit;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SearchResultWindowPrivate::SearchResultWindowPrivate()
|
|
|
|
|
: m_currentSearch(0),
|
2010-07-19 14:46:53 +02:00
|
|
|
m_itemCount(0),
|
2010-06-29 13:16:54 +02:00
|
|
|
m_isShowingReplaceUI(false),
|
|
|
|
|
m_focusReplaceEdit(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
2010-03-24 10:43:01 +01:00
|
|
|
}
|
2009-09-29 16:40:52 +02:00
|
|
|
|
2010-06-29 13:16:54 +02:00
|
|
|
using namespace Find::Internal;
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\enum Find::SearchResultWindow::SearchMode
|
|
|
|
|
Specifies if a search should show the replace UI or not.
|
|
|
|
|
|
|
|
|
|
\value SearchOnly
|
|
|
|
|
The search doesn't support replace.
|
|
|
|
|
\value SearchAndReplace
|
|
|
|
|
The search supports replace, so show the UI for it.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Find::SearchResult
|
|
|
|
|
\brief Reports user interaction like activation of a search result item.
|
|
|
|
|
|
|
|
|
|
Whenever a new search is initiated via startNewSearch, an instance of this
|
|
|
|
|
class is returned to provide the initiator with the hooks for handling user
|
|
|
|
|
interaction.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void SearchResult::activated(const Find::SearchResultItem &item)
|
|
|
|
|
\brief Sent if the user activated (e.g. double-clicked) a search result
|
|
|
|
|
\a item.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void SearchResult::replaceButtonClicked(const QString &replaceText, const QList<Find::SearchResultItem> &checkedItems)
|
|
|
|
|
\brief Sent when the user initiated a replace, e.g. by pressing the replace
|
|
|
|
|
all button.
|
|
|
|
|
|
|
|
|
|
The signal reports the text to use for replacement in \a replaceText,
|
|
|
|
|
and the list of search result items that were selected by the user
|
|
|
|
|
in \a checkedItems.
|
|
|
|
|
The handler of this signal should apply the replace only on the selected
|
|
|
|
|
items.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class Find::SearchResultWindow
|
|
|
|
|
\brief The SearchResultWindow class is the implementation of a commonly
|
|
|
|
|
shared \gui{Search Results} output pane. Use it to show search results
|
|
|
|
|
to a user.
|
|
|
|
|
|
|
|
|
|
Whenever you want to show the user a list of search results, or want
|
|
|
|
|
to present UI for a global search and replace, use the single instance
|
|
|
|
|
of this class.
|
|
|
|
|
|
|
|
|
|
Except for being an implementation of a output pane, the
|
|
|
|
|
SearchResultWindow has a few methods and one enum that allows other
|
|
|
|
|
plugins to show their search results and hook into the user actions for
|
|
|
|
|
selecting an entry and performing a global replace.
|
|
|
|
|
|
|
|
|
|
Whenever you start a search, call startNewSearch(SearchMode) to initialize
|
|
|
|
|
the search result window. The parameter determines if the GUI for
|
|
|
|
|
replacing should be shown.
|
|
|
|
|
The method returns a SearchResult object that is your
|
|
|
|
|
hook into the signals from user interaction for this search.
|
|
|
|
|
When you produce search results, call addResults or addResult to add them
|
|
|
|
|
to the search result window.
|
|
|
|
|
After the search has finished call finishSearch to inform the search
|
|
|
|
|
result window about it.
|
|
|
|
|
|
|
|
|
|
After that you get activated signals via your SearchResult instance when
|
|
|
|
|
the user selects a search result item, and, if you started the search
|
|
|
|
|
with the SearchAndReplace option, the replaceButtonClicked signal
|
|
|
|
|
when the user requests a replace.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn QString SearchResultWindow::displayName() const
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-12 12:46:50 +02:00
|
|
|
SearchResultWindow *SearchResultWindow::m_instance = 0;
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn SearchResultWindow::SearchResultWindow()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2010-03-24 10:43:01 +01:00
|
|
|
SearchResultWindow::SearchResultWindow() : d(new SearchResultWindowPrivate)
|
|
|
|
|
{
|
2010-07-12 12:46:50 +02:00
|
|
|
m_instance = this;
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_widget = new QStackedWidget;
|
2010-06-16 11:56:30 +02:00
|
|
|
d->m_widget->setWindowTitle(displayName());
|
2010-03-24 10:43:01 +01:00
|
|
|
|
|
|
|
|
d->m_searchResultTreeView = new Internal::SearchResultTreeView(d->m_widget);
|
|
|
|
|
d->m_searchResultTreeView->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
d->m_searchResultTreeView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
|
d->m_widget->addWidget(d->m_searchResultTreeView);
|
2010-06-29 13:16:54 +02:00
|
|
|
Aggregation::Aggregate * agg = new Aggregation::Aggregate;
|
|
|
|
|
agg->add(d->m_searchResultTreeView);
|
|
|
|
|
agg->add(new SearchResultFindSupport(d->m_searchResultTreeView));
|
2010-03-24 10:43:01 +01:00
|
|
|
|
|
|
|
|
d->m_noMatchesFoundDisplay = new QListWidget(d->m_widget);
|
|
|
|
|
d->m_noMatchesFoundDisplay->addItem(tr("No matches found!"));
|
|
|
|
|
d->m_noMatchesFoundDisplay->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
d->m_widget->addWidget(d->m_noMatchesFoundDisplay);
|
|
|
|
|
|
2010-06-29 13:34:43 +02:00
|
|
|
d->m_expandCollapseButton = new QToolButton(d->m_widget);
|
|
|
|
|
d->m_expandCollapseButton->setAutoRaise(true);
|
|
|
|
|
|
|
|
|
|
d->m_expandCollapseAction = new QAction(tr("Expand All"), this);
|
|
|
|
|
d->m_expandCollapseAction->setCheckable(true);
|
|
|
|
|
d->m_expandCollapseAction->setIcon(QIcon(QLatin1String(":/find/images/expand.png")));
|
|
|
|
|
Core::Command *cmd = Core::ICore::instance()->actionManager()->registerAction(
|
2010-09-10 14:13:19 +02:00
|
|
|
d->m_expandCollapseAction, "Find.ExpandAll",
|
2010-06-29 13:34:43 +02:00
|
|
|
Core::Context(Core::Constants::C_GLOBAL));
|
2011-01-14 12:20:08 +01:00
|
|
|
cmd->setAttribute(Core::Command::CA_UpdateText);
|
2010-06-29 13:34:43 +02:00
|
|
|
d->m_expandCollapseButton->setDefaultAction(cmd->action());
|
2010-03-24 10:43:01 +01:00
|
|
|
|
|
|
|
|
d->m_replaceLabel = new QLabel(tr("Replace with:"), d->m_widget);
|
|
|
|
|
d->m_replaceLabel->setContentsMargins(12, 0, 5, 0);
|
2010-05-21 13:47:02 +02:00
|
|
|
d->m_replaceTextEdit = new WideEnoughLineEdit(d->m_widget);
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_replaceButton = new QToolButton(d->m_widget);
|
|
|
|
|
d->m_replaceButton->setToolTip(tr("Replace all occurrences"));
|
|
|
|
|
d->m_replaceButton->setText(tr("Replace"));
|
|
|
|
|
d->m_replaceButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
|
|
|
|
|
d->m_replaceButton->setAutoRaise(true);
|
|
|
|
|
d->m_replaceTextEdit->setTabOrder(d->m_replaceTextEdit, d->m_searchResultTreeView);
|
|
|
|
|
|
2010-07-19 14:46:53 +02:00
|
|
|
connect(d->m_searchResultTreeView, SIGNAL(jumpToSearchResult(SearchResultItem)),
|
|
|
|
|
this, SLOT(handleJumpToSearchResult(SearchResultItem)));
|
2010-06-29 13:34:43 +02:00
|
|
|
connect(d->m_expandCollapseAction, SIGNAL(toggled(bool)), this, SLOT(handleExpandCollapseToolButton(bool)));
|
2010-03-24 10:43:01 +01:00
|
|
|
connect(d->m_replaceTextEdit, SIGNAL(returnPressed()), this, SLOT(handleReplaceButton()));
|
|
|
|
|
connect(d->m_replaceButton, SIGNAL(clicked()), this, SLOT(handleReplaceButton()));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
readSettings();
|
2009-09-29 16:40:52 +02:00
|
|
|
setShowReplaceUI(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn SearchResultWindow::~SearchResultWindow()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
SearchResultWindow::~SearchResultWindow()
|
|
|
|
|
{
|
|
|
|
|
writeSettings();
|
2010-03-24 10:43:01 +01:00
|
|
|
delete d->m_currentSearch;
|
|
|
|
|
d->m_currentSearch = 0;
|
|
|
|
|
delete d->m_widget;
|
|
|
|
|
d->m_widget = 0;
|
2010-07-19 14:46:53 +02:00
|
|
|
d->m_itemCount = 0;
|
2010-03-24 10:43:01 +01:00
|
|
|
delete d;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn SearchResultWindow *SearchResultWindow::instance()
|
|
|
|
|
\brief Returns the single shared instance of the Search Results window.
|
|
|
|
|
*/
|
2010-07-12 12:46:50 +02:00
|
|
|
SearchResultWindow *SearchResultWindow::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::setTextToReplace(const QString &textToReplace)
|
|
|
|
|
\brief Sets the value in the UI element that allows the user to type
|
|
|
|
|
the text that should replace text in search results to \a textToReplace.
|
|
|
|
|
*/
|
2009-10-06 16:00:32 +02:00
|
|
|
void SearchResultWindow::setTextToReplace(const QString &textToReplace)
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_replaceTextEdit->setText(textToReplace);
|
2009-10-06 16:00:32 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn QString SearchResultWindow::textToReplace() const
|
|
|
|
|
\brief Returns the text that should replace the text in search results.
|
|
|
|
|
*/
|
2009-10-06 16:00:32 +02:00
|
|
|
QString SearchResultWindow::textToReplace() const
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
return d->m_replaceTextEdit->text();
|
2009-10-06 16:00:32 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::setShowReplaceUI(bool show)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-09-29 16:40:52 +02:00
|
|
|
void SearchResultWindow::setShowReplaceUI(bool show)
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_searchResultTreeView->model()->setShowReplaceUI(show);
|
|
|
|
|
d->m_replaceLabel->setVisible(show);
|
|
|
|
|
d->m_replaceTextEdit->setVisible(show);
|
|
|
|
|
d->m_replaceButton->setVisible(show);
|
|
|
|
|
d->m_isShowingReplaceUI = show;
|
2009-09-29 16:40:52 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::handleReplaceButton()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-09-29 16:40:52 +02:00
|
|
|
void SearchResultWindow::handleReplaceButton()
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
QTC_ASSERT(d->m_currentSearch, return);
|
2009-11-04 18:10:03 +01:00
|
|
|
// check if button is actually enabled, because this is also triggered
|
|
|
|
|
// by pressing return in replace line edit
|
2010-03-24 10:43:01 +01:00
|
|
|
if (d->m_replaceButton->isEnabled())
|
|
|
|
|
d->m_currentSearch->replaceButtonClicked(d->m_replaceTextEdit->text(), checkedItems());
|
2009-09-29 16:40:52 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn QList<SearchResultItem> SearchResultWindow::checkedItems() const
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-10-05 16:01:50 +02:00
|
|
|
QList<SearchResultItem> SearchResultWindow::checkedItems() const
|
2009-09-29 16:40:52 +02:00
|
|
|
{
|
2009-10-05 16:01:50 +02:00
|
|
|
QList<SearchResultItem> result;
|
2010-03-24 10:43:01 +01:00
|
|
|
Internal::SearchResultTreeModel *model = d->m_searchResultTreeView->model();
|
2009-10-05 16:01:50 +02:00
|
|
|
const int fileCount = model->rowCount(QModelIndex());
|
|
|
|
|
for (int i = 0; i < fileCount; ++i) {
|
|
|
|
|
QModelIndex fileIndex = model->index(i, 0, QModelIndex());
|
2010-07-19 14:46:53 +02:00
|
|
|
Internal::SearchResultTreeItem *fileItem = static_cast<Internal::SearchResultTreeItem *>(fileIndex.internalPointer());
|
2009-10-05 16:01:50 +02:00
|
|
|
Q_ASSERT(fileItem != 0);
|
|
|
|
|
for (int rowIndex = 0; rowIndex < fileItem->childrenCount(); ++rowIndex) {
|
|
|
|
|
QModelIndex textIndex = model->index(rowIndex, 0, fileIndex);
|
2010-07-19 14:46:53 +02:00
|
|
|
Internal::SearchResultTreeItem *rowItem = static_cast<Internal::SearchResultTreeItem *>(textIndex.internalPointer());
|
2009-10-05 16:01:50 +02:00
|
|
|
if (rowItem->checkState())
|
2010-07-19 14:46:53 +02:00
|
|
|
result << rowItem->item;
|
2009-10-05 16:01:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2009-09-29 16:40:52 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::visibilityChanged(bool)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
void SearchResultWindow::visibilityChanged(bool /*visible*/)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn QWidget *SearchResultWindow::outputWidget(QWidget *)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
QWidget *SearchResultWindow::outputWidget(QWidget *)
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
return d->m_widget;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn QList<QWidget*> SearchResultWindow::toolBarWidgets() const
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-07 16:59:48 +02:00
|
|
|
QList<QWidget*> SearchResultWindow::toolBarWidgets() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-06-29 13:34:43 +02:00
|
|
|
return QList<QWidget*>() << d->m_expandCollapseButton << d->m_replaceLabel << d->m_replaceTextEdit << d->m_replaceButton;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndReplace)
|
|
|
|
|
\brief Tells the search results window to start a new search.
|
|
|
|
|
|
|
|
|
|
This will clear the contents of the previous search and initialize the UI
|
|
|
|
|
with regard to showing the replace UI or not (depending on the search mode
|
|
|
|
|
in \a searchOrSearchAndReplace).
|
|
|
|
|
Returns a SearchResult object that is used for signaling user interaction
|
|
|
|
|
with the results of this search.
|
|
|
|
|
*/
|
2009-10-05 16:01:50 +02:00
|
|
|
SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndReplace)
|
|
|
|
|
{
|
|
|
|
|
clearContents();
|
|
|
|
|
setShowReplaceUI(searchOrSearchAndReplace != SearchOnly);
|
2010-03-24 10:43:01 +01:00
|
|
|
delete d->m_currentSearch;
|
|
|
|
|
d->m_currentSearch = new SearchResult;
|
|
|
|
|
return d->m_currentSearch;
|
2009-10-05 16:01:50 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::finishSearch()
|
|
|
|
|
\brief Notifies the search result window that the current search
|
|
|
|
|
has finished, and the UI should reflect that.
|
|
|
|
|
*/
|
2009-11-04 18:10:03 +01:00
|
|
|
void SearchResultWindow::finishSearch()
|
|
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
if (d->m_itemCount > 0) {
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_replaceButton->setEnabled(true);
|
2009-11-04 18:10:03 +01:00
|
|
|
} else {
|
|
|
|
|
showNoMatchesFound();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::clearContents()
|
|
|
|
|
\brief Clears the current contents in the search result window.
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
void SearchResultWindow::clearContents()
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_replaceTextEdit->setEnabled(false);
|
|
|
|
|
d->m_replaceButton->setEnabled(false);
|
|
|
|
|
d->m_replaceTextEdit->clear();
|
|
|
|
|
d->m_searchResultTreeView->clear();
|
2010-07-19 14:46:53 +02:00
|
|
|
d->m_itemCount = 0;
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_widget->setCurrentWidget(d->m_searchResultTreeView);
|
2009-04-30 12:50:52 +02:00
|
|
|
navigateStateChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::showNoMatchesFound()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-07 16:59:48 +02:00
|
|
|
void SearchResultWindow::showNoMatchesFound()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_replaceTextEdit->setEnabled(false);
|
|
|
|
|
d->m_replaceButton->setEnabled(false);
|
|
|
|
|
d->m_widget->setCurrentWidget(d->m_noMatchesFoundDisplay);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::isEmpty() const
|
|
|
|
|
Returns if the search result window currently doesn't show any results.
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
bool SearchResultWindow::isEmpty() const
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
return (d->m_searchResultTreeView->model()->rowCount() < 1);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn int SearchResultWindow::numberOfResults() const
|
|
|
|
|
Returns the number of search results currently shown in the search
|
|
|
|
|
results window.
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
int SearchResultWindow::numberOfResults() const
|
|
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
return d->m_itemCount;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::hasFocus()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-08 14:32:31 +02:00
|
|
|
bool SearchResultWindow::hasFocus()
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
return d->m_searchResultTreeView->hasFocus() || (d->m_isShowingReplaceUI && d->m_replaceTextEdit->hasFocus());
|
2009-04-08 14:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::canFocus()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-08 14:32:31 +02:00
|
|
|
bool SearchResultWindow::canFocus()
|
|
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
return d->m_itemCount > 0;
|
2009-04-08 14:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::setFocus()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-08 14:32:31 +02:00
|
|
|
void SearchResultWindow::setFocus()
|
|
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
if (d->m_itemCount > 0) {
|
2010-03-24 10:43:01 +01:00
|
|
|
if (!d->m_isShowingReplaceUI) {
|
|
|
|
|
d->m_searchResultTreeView->setFocus();
|
2009-09-29 17:33:34 +02:00
|
|
|
} else {
|
2010-03-24 10:43:01 +01:00
|
|
|
if (!d->m_widget->focusWidget()
|
|
|
|
|
|| d->m_widget->focusWidget() == d->m_replaceTextEdit
|
|
|
|
|
|| d->m_focusReplaceEdit) {
|
|
|
|
|
d->m_replaceTextEdit->setFocus();
|
|
|
|
|
d->m_replaceTextEdit->selectAll();
|
2009-09-29 17:33:34 +02:00
|
|
|
} else {
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_searchResultTreeView->setFocus();
|
2009-09-29 17:33:34 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-08 14:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::setTextEditorFont(const QFont &font)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-08 14:32:31 +02:00
|
|
|
void SearchResultWindow::setTextEditorFont(const QFont &font)
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_searchResultTreeView->setTextEditorFont(font);
|
2009-04-08 14:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
2011-03-28 14:58:12 +02:00
|
|
|
\fn void SearchResultWindow::handleJumpToSearchResult(const SearchResultItem &item)
|
2010-07-12 12:05:31 +02:00
|
|
|
\internal
|
|
|
|
|
*/
|
2010-07-19 14:46:53 +02:00
|
|
|
void SearchResultWindow::handleJumpToSearchResult(const SearchResultItem &item)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
QTC_ASSERT(d->m_currentSearch, return);
|
2010-07-19 14:46:53 +02:00
|
|
|
d->m_currentSearch->activated(item);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::addResult(const QString &fileName, int lineNumber, const QString &rowText, int searchTermStart, int searchTermLength, const QVariant &userData)
|
|
|
|
|
\brief Adds a single result line to the search results.
|
|
|
|
|
|
|
|
|
|
The \a fileName, \a lineNumber and \a rowText are shown in the result line.
|
|
|
|
|
\a searchTermStart and \a searchTermLength specify the region that
|
|
|
|
|
should be visually marked (string position and length in \a rowText).
|
|
|
|
|
You can attach arbitrary \a userData to the search result, which can
|
|
|
|
|
be used e.g. when reacting to the signals of the SearchResult for your search.
|
|
|
|
|
|
|
|
|
|
\sa addResults()
|
|
|
|
|
*/
|
2009-10-05 16:01:50 +02:00
|
|
|
void SearchResultWindow::addResult(const QString &fileName, int lineNumber, const QString &rowText,
|
|
|
|
|
int searchTermStart, int searchTermLength, const QVariant &userData)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-10-05 16:01:50 +02:00
|
|
|
SearchResultItem item;
|
2010-07-19 14:46:53 +02:00
|
|
|
item.path = QStringList() << QDir::toNativeSeparators(fileName);
|
2009-10-05 16:01:50 +02:00
|
|
|
item.lineNumber = lineNumber;
|
2010-07-19 14:46:53 +02:00
|
|
|
item.text = rowText;
|
|
|
|
|
item.textMarkPos = searchTermStart;
|
|
|
|
|
item.textMarkLength = searchTermLength;
|
|
|
|
|
item.useTextEditorFont = true;
|
2009-10-05 16:01:50 +02:00
|
|
|
item.userData = userData;
|
2010-07-19 14:46:53 +02:00
|
|
|
addResults(QList<SearchResultItem>() << item, AddOrdered);
|
2010-06-25 09:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
2011-03-28 14:58:12 +02:00
|
|
|
\fn void SearchResultWindow::addResults(QList<SearchResultItem> &items, AddMode mode)
|
2010-07-12 12:05:31 +02:00
|
|
|
\brief Adds all of the given search result \a items to the search
|
|
|
|
|
results window.
|
|
|
|
|
|
|
|
|
|
\sa addResult()
|
|
|
|
|
*/
|
2010-07-19 14:46:53 +02:00
|
|
|
void SearchResultWindow::addResults(QList<SearchResultItem> &items, AddMode mode)
|
2010-06-25 09:16:30 +02:00
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
bool firstItems = (d->m_itemCount == 0);
|
|
|
|
|
d->m_itemCount += items.size();
|
|
|
|
|
d->m_searchResultTreeView->addResults(items, mode);
|
2010-06-25 09:16:30 +02:00
|
|
|
if (firstItems) {
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_replaceTextEdit->setEnabled(true);
|
2009-11-04 18:10:03 +01:00
|
|
|
// We didn't have an item before, set the focus to the search widget
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_focusReplaceEdit = true;
|
2009-09-29 17:33:34 +02:00
|
|
|
setFocus();
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_focusReplaceEdit = false;
|
|
|
|
|
d->m_searchResultTreeView->selectionModel()->select(d->m_searchResultTreeView->model()->index(0, 0, QModelIndex()), QItemSelectionModel::Select);
|
2009-04-30 12:50:52 +02:00
|
|
|
emit navigateStateChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-10-05 16:01:50 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_searchResultTreeView->setAutoExpandResults(checked);
|
2011-01-14 12:20:08 +01:00
|
|
|
if (checked) {
|
|
|
|
|
d->m_expandCollapseAction->setText(tr("Collapse All"));
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_searchResultTreeView->expandAll();
|
2011-01-14 12:20:08 +01:00
|
|
|
} else {
|
|
|
|
|
d->m_expandCollapseAction->setText(tr("Expand All"));
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_searchResultTreeView->collapseAll();
|
2011-01-14 12:20:08 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::readSettings()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-07 16:59:48 +02:00
|
|
|
void SearchResultWindow::readSettings()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-21 18:09:37 +01:00
|
|
|
QSettings *s = Core::ICore::instance()->settings();
|
|
|
|
|
if (s) {
|
2010-03-24 10:43:01 +01:00
|
|
|
s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME));
|
2010-06-29 13:34:43 +02:00
|
|
|
d->m_expandCollapseAction->setChecked(s->value(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_initiallyExpand).toBool());
|
2008-12-02 12:01:29 +01:00
|
|
|
s->endGroup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::writeSettings()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-07 16:59:48 +02:00
|
|
|
void SearchResultWindow::writeSettings()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-21 18:09:37 +01:00
|
|
|
QSettings *s = Core::ICore::instance()->settings();
|
|
|
|
|
if (s) {
|
2010-03-24 10:43:01 +01:00
|
|
|
s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME));
|
2010-06-29 13:34:43 +02:00
|
|
|
s->setValue(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_expandCollapseAction->isChecked());
|
2008-12-02 12:01:29 +01:00
|
|
|
s->endGroup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn int SearchResultWindow::priorityInStatusBar() const
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
int SearchResultWindow::priorityInStatusBar() const
|
|
|
|
|
{
|
|
|
|
|
return 80;
|
|
|
|
|
}
|
2009-04-30 12:50:52 +02:00
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::canNext()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-30 12:50:52 +02:00
|
|
|
bool SearchResultWindow::canNext()
|
|
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
return d->m_itemCount > 0;
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::canPrevious()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-30 12:50:52 +02:00
|
|
|
bool SearchResultWindow::canPrevious()
|
|
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
return d->m_itemCount > 0;
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::goToNext()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-30 12:50:52 +02:00
|
|
|
void SearchResultWindow::goToNext()
|
|
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
if (d->m_itemCount == 0)
|
2009-04-30 12:50:52 +02:00
|
|
|
return;
|
2010-03-24 10:43:01 +01:00
|
|
|
QModelIndex idx = d->m_searchResultTreeView->model()->next(d->m_searchResultTreeView->currentIndex());
|
2009-04-30 12:50:52 +02:00
|
|
|
if (idx.isValid()) {
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_searchResultTreeView->setCurrentIndex(idx);
|
|
|
|
|
d->m_searchResultTreeView->emitJumpToSearchResult(idx);
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-12 12:05:31 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void SearchResultWindow::goToPrev()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-30 12:50:52 +02:00
|
|
|
void SearchResultWindow::goToPrev()
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
if (!d->m_searchResultTreeView->model()->rowCount())
|
2009-04-30 12:50:52 +02:00
|
|
|
return;
|
2010-03-24 10:43:01 +01:00
|
|
|
QModelIndex idx = d->m_searchResultTreeView->model()->prev(d->m_searchResultTreeView->currentIndex());
|
2009-04-30 12:50:52 +02:00
|
|
|
if (idx.isValid()) {
|
2010-03-24 10:43:01 +01:00
|
|
|
d->m_searchResultTreeView->setCurrentIndex(idx);
|
|
|
|
|
d->m_searchResultTreeView->emitJumpToSearchResult(idx);
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::canNavigate()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2009-04-30 12:50:52 +02:00
|
|
|
bool SearchResultWindow::canNavigate()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-03-24 10:43:01 +01:00
|
|
|
|
|
|
|
|
} // namespace Find
|
|
|
|
|
|
2010-05-21 13:47:02 +02:00
|
|
|
|
|
|
|
|
#include "searchresultwindow.moc"
|