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-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@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
|
2011-11-02 15:59:12 +01:00
|
|
|
** 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"
|
2011-09-06 13:03:15 +02:00
|
|
|
#include "searchresultwidget.h"
|
2011-09-09 08:46:51 +02:00
|
|
|
#include "findtoolwindow.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
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>
|
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/QSettings>
|
2009-04-30 12:50:52 +02:00
|
|
|
#include <QtCore/QDebug>
|
2011-05-06 12:51:03 +02:00
|
|
|
#include <QtGui/QVBoxLayout>
|
2010-03-24 10:43:01 +01:00
|
|
|
#include <QtGui/QFont>
|
2010-06-29 13:34:43 +02:00
|
|
|
#include <QtGui/QAction>
|
2011-09-09 16:10:57 +02:00
|
|
|
#include <QtGui/QComboBox>
|
2011-11-24 11:38:35 +01:00
|
|
|
#include <QtGui/QScrollArea>
|
2011-09-09 08:46:51 +02:00
|
|
|
#include <QtGui/QStackedWidget>
|
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 {
|
|
|
|
|
|
2011-09-09 16:10:57 +02:00
|
|
|
class SearchResultWindowPrivate : public QObject {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
SearchResultWindowPrivate(SearchResultWindow *window);
|
|
|
|
|
bool isSearchVisible() const;
|
|
|
|
|
int visibleSearchIndex() const;
|
2010-06-29 13:16:54 +02:00
|
|
|
|
2011-09-09 16:10:57 +02:00
|
|
|
SearchResultWindow *q;
|
|
|
|
|
QList<Internal::SearchResultWidget *> m_searchResultWidgets;
|
2010-06-29 13:34:43 +02:00
|
|
|
QToolButton *m_expandCollapseButton;
|
|
|
|
|
QAction *m_expandCollapseAction;
|
2010-06-29 13:16:54 +02:00
|
|
|
static const bool m_initiallyExpand = false;
|
2011-09-09 16:10:57 +02:00
|
|
|
QWidget *m_spacer;
|
|
|
|
|
QComboBox *m_recentSearchesBox;
|
2011-09-09 08:46:51 +02:00
|
|
|
QStackedWidget *m_widget;
|
2011-09-09 16:10:57 +02:00
|
|
|
QList<SearchResult *> m_searchResults;
|
|
|
|
|
int m_currentIndex;
|
2011-11-01 11:46:22 +01:00
|
|
|
QFont m_font;
|
2011-09-09 16:10:57 +02:00
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void setCurrentIndex(int index);
|
2010-06-29 13:16:54 +02:00
|
|
|
};
|
|
|
|
|
|
2011-09-09 16:10:57 +02:00
|
|
|
SearchResultWindowPrivate::SearchResultWindowPrivate(SearchResultWindow *window)
|
|
|
|
|
: q(window)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchResultWindowPrivate::isSearchVisible() const
|
|
|
|
|
{
|
|
|
|
|
return m_currentIndex > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SearchResultWindowPrivate::visibleSearchIndex() const
|
2010-06-29 13:16:54 +02:00
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
return m_currentIndex - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchResultWindowPrivate::setCurrentIndex(int index)
|
|
|
|
|
{
|
|
|
|
|
if (isSearchVisible())
|
|
|
|
|
m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(false);
|
|
|
|
|
m_currentIndex = index;
|
|
|
|
|
m_widget->setCurrentIndex(index);
|
|
|
|
|
m_recentSearchesBox->setCurrentIndex(index);
|
|
|
|
|
if (!isSearchVisible()) {
|
|
|
|
|
m_widget->currentWidget()->setFocus();
|
|
|
|
|
m_expandCollapseButton->setEnabled(false);
|
|
|
|
|
} else {
|
|
|
|
|
m_searchResultWidgets.at(visibleSearchIndex())->setFocusInternally();
|
|
|
|
|
m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(true);
|
|
|
|
|
m_expandCollapseButton->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
q->navigateStateChanged();
|
2010-06-29 13:16:54 +02:00
|
|
|
}
|
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.
|
|
|
|
|
|
2011-09-06 13:03:15 +02:00
|
|
|
You will get activated signals via your SearchResult instance when
|
2010-07-12 12:05:31 +02:00
|
|
|
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
|
|
|
|
|
*/
|
2011-09-09 08:46:51 +02:00
|
|
|
SearchResultWindow::SearchResultWindow(QWidget *newSearchPanel)
|
2011-09-09 16:10:57 +02:00
|
|
|
: d(new SearchResultWindowPrivate(this))
|
2010-03-24 10:43:01 +01:00
|
|
|
{
|
2010-07-12 12:46:50 +02:00
|
|
|
m_instance = this;
|
2011-09-09 16:10:57 +02:00
|
|
|
d->m_spacer = new QWidget;
|
|
|
|
|
d->m_spacer->setMinimumWidth(30);
|
|
|
|
|
d->m_recentSearchesBox = new QComboBox;
|
|
|
|
|
d->m_recentSearchesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
|
|
|
|
d->m_recentSearchesBox->addItem(tr("New Search"));
|
|
|
|
|
connect(d->m_recentSearchesBox, SIGNAL(activated(int)), d, SLOT(setCurrentIndex(int)));
|
|
|
|
|
|
2011-09-09 08:46:51 +02: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
|
|
|
|
2011-11-24 11:38:35 +01:00
|
|
|
QScrollArea *newSearchArea = new QScrollArea(d->m_widget);
|
|
|
|
|
newSearchArea->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
newSearchArea->setWidget(newSearchPanel);
|
|
|
|
|
d->m_widget->addWidget(newSearchArea);
|
2011-09-09 16:10:57 +02:00
|
|
|
d->m_currentIndex = 0;
|
2011-05-06 16:06:25 +02:00
|
|
|
|
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
|
|
|
|
2010-06-29 13:34:43 +02:00
|
|
|
connect(d->m_expandCollapseAction, SIGNAL(toggled(bool)), this, SLOT(handleExpandCollapseToolButton(bool)));
|
2008-12-02 12:01:29 +01:00
|
|
|
readSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn SearchResultWindow::~SearchResultWindow()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2008-12-02 12:01:29 +01:00
|
|
|
SearchResultWindow::~SearchResultWindow()
|
|
|
|
|
{
|
|
|
|
|
writeSettings();
|
2011-09-09 16:10:57 +02:00
|
|
|
qDeleteAll(d->m_searchResults);
|
2010-03-24 10:43:01 +01:00
|
|
|
delete d->m_widget;
|
|
|
|
|
d->m_widget = 0;
|
|
|
|
|
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::visibilityChanged(bool)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2011-08-09 11:08:01 +02:00
|
|
|
void SearchResultWindow::visibilityChanged(bool visible)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
if (d->isSearchVisible())
|
|
|
|
|
d->m_searchResultWidgets.at(d->visibleSearchIndex())->notifyVisibilityChanged(visible);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
return QList<QWidget*>() << d->m_expandCollapseButton << d->m_spacer << d->m_recentSearchesBox;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\brief Tells the search results window to start a new search.
|
|
|
|
|
|
2011-09-09 16:10:57 +02:00
|
|
|
The \a label should be a string that shortly describes the type of
|
|
|
|
|
search, i.e. search filter and possibly a most relevant search option, followed by a colon ':'.
|
|
|
|
|
E.g. \code{Project 'myproject':}
|
|
|
|
|
The \a searchTerm will be shown behind the colon.
|
|
|
|
|
The \a toolTip should elaborate on the search parameters, like file patterns that are searched and
|
|
|
|
|
find flags.
|
2011-05-06 16:06:25 +02:00
|
|
|
If \a cfgGroup is not empty, it will be used for storing the "do not ask again"
|
|
|
|
|
setting of a "this change cannot be undone" warning (which is implicitly requested
|
|
|
|
|
by passing a non-empty group).
|
2010-07-12 12:05:31 +02:00
|
|
|
Returns a SearchResult object that is used for signaling user interaction
|
|
|
|
|
with the results of this search.
|
2011-09-09 16:10:57 +02:00
|
|
|
The search result window owns the returned SearchResult
|
|
|
|
|
and might delete it any time, even while the search is running
|
|
|
|
|
(e.g. when the user clears the search result pane, or if the user opens so many other searches
|
|
|
|
|
that this search falls out of the history).
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
*/
|
2011-09-09 16:10:57 +02:00
|
|
|
SearchResult *SearchResultWindow::startNewSearch(const QString &label,
|
|
|
|
|
const QString &toolTip,
|
|
|
|
|
const QString &searchTerm,
|
|
|
|
|
SearchMode searchOrSearchAndReplace,
|
|
|
|
|
const QString &cfgGroup)
|
2009-10-05 16:01:50 +02:00
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
if (d->m_searchResults.size() >= 5) {
|
|
|
|
|
d->m_searchResultWidgets.last()->notifyVisibilityChanged(false);
|
|
|
|
|
delete d->m_searchResults.takeLast();
|
|
|
|
|
delete d->m_searchResultWidgets.takeLast();
|
|
|
|
|
d->m_recentSearchesBox->removeItem(d->m_recentSearchesBox->count()-1);
|
2011-09-15 09:57:18 +02:00
|
|
|
if (d->m_currentIndex >= d->m_recentSearchesBox->count()) {
|
|
|
|
|
// temporarily set the index to the last existing
|
|
|
|
|
d->m_currentIndex = d->m_recentSearchesBox->count() - 1;
|
|
|
|
|
}
|
2011-09-09 16:10:57 +02:00
|
|
|
}
|
|
|
|
|
Internal::SearchResultWidget *widget = new Internal::SearchResultWidget;
|
|
|
|
|
d->m_searchResultWidgets.prepend(widget);
|
|
|
|
|
d->m_widget->insertWidget(1, widget);
|
|
|
|
|
connect(widget, SIGNAL(navigateStateChanged()), this, SLOT(navigateStateChanged()));
|
2011-11-01 11:46:22 +01:00
|
|
|
widget->setTextEditorFont(d->m_font);
|
2011-09-09 16:10:57 +02:00
|
|
|
widget->setShowReplaceUI(searchOrSearchAndReplace != SearchOnly);
|
2011-09-20 12:18:55 +02:00
|
|
|
widget->setAutoExpandResults(d->m_expandCollapseAction->isChecked());
|
2011-09-09 16:10:57 +02:00
|
|
|
widget->setInfo(label, toolTip, searchTerm);
|
|
|
|
|
if (searchOrSearchAndReplace == SearchAndReplace)
|
|
|
|
|
widget->setDontAskAgainGroup(cfgGroup);
|
|
|
|
|
SearchResult *result = new SearchResult(widget);
|
|
|
|
|
d->m_searchResults.prepend(result);
|
|
|
|
|
d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm));
|
|
|
|
|
if (d->m_currentIndex > 0)
|
|
|
|
|
++d->m_currentIndex; // so setCurrentIndex still knows about the right "currentIndex" and its widget
|
|
|
|
|
d->setCurrentIndex(1);
|
|
|
|
|
return result;
|
2009-10-05 16:01:50 +02:00
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
for (int i = d->m_recentSearchesBox->count() - 1; i > 0 /* don't want i==0 */; --i)
|
|
|
|
|
d->m_recentSearchesBox->removeItem(i);
|
|
|
|
|
foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets)
|
|
|
|
|
widget->notifyVisibilityChanged(false);
|
|
|
|
|
qDeleteAll(d->m_searchResultWidgets);
|
|
|
|
|
d->m_searchResultWidgets.clear();
|
|
|
|
|
qDeleteAll(d->m_searchResults);
|
|
|
|
|
d->m_searchResults.clear();
|
|
|
|
|
|
|
|
|
|
d->m_currentIndex = 0;
|
|
|
|
|
d->m_widget->currentWidget()->setFocus();
|
|
|
|
|
d->m_expandCollapseButton->setEnabled(false);
|
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 bool SearchResultWindow::hasFocus()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2011-09-27 13:47:06 +02:00
|
|
|
bool SearchResultWindow::hasFocus() const
|
2009-04-08 14:32:31 +02:00
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
return d->m_widget->focusWidget() && d->m_widget->focusWidget()->hasFocus();
|
2009-04-08 14:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::canFocus()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2011-09-27 13:47:06 +02:00
|
|
|
bool SearchResultWindow::canFocus() const
|
2009-04-08 14:32:31 +02:00
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
if (d->isSearchVisible())
|
|
|
|
|
return d->m_searchResultWidgets.at(d->visibleSearchIndex())->canFocusInternally();
|
|
|
|
|
return true;
|
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()
|
|
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
if (!d->isSearchVisible())
|
2011-09-09 08:46:51 +02:00
|
|
|
d->m_widget->currentWidget()->setFocus();
|
|
|
|
|
else
|
2011-09-09 16:10:57 +02:00
|
|
|
d->m_searchResultWidgets.at(d->visibleSearchIndex())->setFocusInternally();
|
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)
|
|
|
|
|
{
|
2011-11-01 11:46:22 +01:00
|
|
|
d->m_font = font;
|
2011-09-09 16:10:57 +02:00
|
|
|
foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets)
|
|
|
|
|
widget->setTextEditorFont(font);
|
2011-05-06 16:06:25 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-09 08:46:51 +02:00
|
|
|
void SearchResultWindow::openNewSearchPanel()
|
|
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
d->setCurrentIndex(0);
|
2011-11-24 11:38:35 +01:00
|
|
|
popup(true/*focus*/, true/*sizeHint*/);
|
2011-09-09 08:46:51 +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)
|
|
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
if (!d->isSearchVisible())
|
|
|
|
|
return;
|
|
|
|
|
d->m_searchResultWidgets.at(d->visibleSearchIndex())->setAutoExpandResults(checked);
|
2011-01-14 12:20:08 +01:00
|
|
|
if (checked) {
|
|
|
|
|
d->m_expandCollapseAction->setText(tr("Collapse All"));
|
2011-09-09 16:10:57 +02:00
|
|
|
d->m_searchResultWidgets.at(d->visibleSearchIndex())->expandAll();
|
2011-01-14 12:20:08 +01:00
|
|
|
} else {
|
|
|
|
|
d->m_expandCollapseAction->setText(tr("Expand All"));
|
2011-09-09 16:10:57 +02:00
|
|
|
d->m_searchResultWidgets.at(d->visibleSearchIndex())->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
|
|
|
|
|
*/
|
2011-09-27 13:47:06 +02:00
|
|
|
bool SearchResultWindow::canNext() const
|
2009-04-30 12:50:52 +02:00
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
if (d->isSearchVisible())
|
|
|
|
|
return d->m_searchResultWidgets.at(d->visibleSearchIndex())->count() > 0;
|
|
|
|
|
return false;
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::canPrevious()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2011-09-27 13:47:06 +02:00
|
|
|
bool SearchResultWindow::canPrevious() const
|
2009-04-30 12:50:52 +02:00
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
return canNext();
|
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()
|
|
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
int index = d->m_widget->currentIndex();
|
|
|
|
|
if (index != 0)
|
|
|
|
|
d->m_searchResultWidgets.at(index-1)->goToNext();
|
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()
|
|
|
|
|
{
|
2011-09-09 16:10:57 +02:00
|
|
|
int index = d->m_widget->currentIndex();
|
|
|
|
|
if (index != 0)
|
|
|
|
|
d->m_searchResultWidgets.at(index-1)->goToPrevious();
|
2009-04-30 12:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 12:05:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn bool SearchResultWindow::canNavigate()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
2011-09-27 13:47:06 +02:00
|
|
|
bool SearchResultWindow::canNavigate() const
|
2009-04-30 12:50:52 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-03-24 10:43:01 +01:00
|
|
|
|
2011-09-06 13:03:15 +02:00
|
|
|
/*!
|
|
|
|
|
\fn SearchResult::SearchResult(SearchResultWidget *widget)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
SearchResult::SearchResult(SearchResultWidget *widget)
|
|
|
|
|
: m_widget(widget)
|
|
|
|
|
{
|
|
|
|
|
connect(widget, SIGNAL(activated(Find::SearchResultItem)),
|
|
|
|
|
this, SIGNAL(activated(Find::SearchResultItem)));
|
|
|
|
|
connect(widget, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
|
|
|
|
this, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)));
|
2011-09-09 08:46:51 +02:00
|
|
|
connect(widget, SIGNAL(cancelled()),
|
|
|
|
|
this, SIGNAL(cancelled()));
|
2011-09-06 13:03:15 +02:00
|
|
|
connect(widget, SIGNAL(visibilityChanged(bool)),
|
|
|
|
|
this, SIGNAL(visibilityChanged(bool)));
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-02 11:51:31 +02:00
|
|
|
/*!
|
|
|
|
|
\fn void SearchResult::setUserData(const QVariant &data)
|
|
|
|
|
\brief Attach some random \a data to this search, that you can use later.
|
|
|
|
|
|
|
|
|
|
\sa userData()
|
|
|
|
|
*/
|
|
|
|
|
void SearchResult::setUserData(const QVariant &data)
|
|
|
|
|
{
|
|
|
|
|
m_userData = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void SearchResult::userData()
|
|
|
|
|
\brief Return the data that was attached to this search by calling setUserData().
|
|
|
|
|
|
|
|
|
|
\sa setUserData()
|
|
|
|
|
*/
|
|
|
|
|
QVariant SearchResult::userData() const
|
|
|
|
|
{
|
|
|
|
|
return m_userData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn QString SearchResult::textToReplace() const
|
|
|
|
|
\brief Returns the text that should replace the text in search results.
|
|
|
|
|
*/
|
|
|
|
|
QString SearchResult::textToReplace() const
|
|
|
|
|
{
|
2011-09-06 13:03:15 +02:00
|
|
|
return m_widget->textToReplace();
|
2011-09-02 11:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void SearchResult::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()
|
|
|
|
|
*/
|
|
|
|
|
void SearchResult::addResult(const QString &fileName, int lineNumber, const QString &lineText,
|
|
|
|
|
int searchTermStart, int searchTermLength, const QVariant &userData)
|
|
|
|
|
{
|
2011-09-06 13:03:15 +02:00
|
|
|
m_widget->addResult(fileName, lineNumber, lineText,
|
|
|
|
|
searchTermStart, searchTermLength, userData);
|
2011-09-02 11:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void SearchResult::addResults(const QList<SearchResultItem> &items, SearchResult::AddMode mode)
|
|
|
|
|
\brief Adds all of the given search result \a items to the search
|
|
|
|
|
results window.
|
|
|
|
|
|
|
|
|
|
\sa addResult()
|
|
|
|
|
*/
|
|
|
|
|
void SearchResult::addResults(const QList<SearchResultItem> &items, AddMode mode)
|
|
|
|
|
{
|
2011-09-06 13:03:15 +02:00
|
|
|
m_widget->addResults(items, mode);
|
2011-09-02 11:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void SearchResult::finishSearch()
|
|
|
|
|
\brief Notifies the search result window that the current search
|
|
|
|
|
has finished, and the UI should reflect that.
|
|
|
|
|
*/
|
|
|
|
|
void SearchResult::finishSearch()
|
|
|
|
|
{
|
2011-09-06 13:03:15 +02:00
|
|
|
m_widget->finishSearch();
|
2011-09-02 11:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void SearchResult::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.
|
|
|
|
|
*/
|
|
|
|
|
void SearchResult::setTextToReplace(const QString &textToReplace)
|
|
|
|
|
{
|
2011-09-06 13:03:15 +02:00
|
|
|
m_widget->setTextToReplace(textToReplace);
|
2011-09-02 11:51:31 +02:00
|
|
|
}
|
|
|
|
|
|
2010-03-24 10:43:01 +01:00
|
|
|
} // namespace Find
|
2011-09-09 16:10:57 +02:00
|
|
|
|
|
|
|
|
#include "searchresultwindow.moc"
|