forked from qt-creator/qt-creator
		
	C++ symbols find filter for advanced find.
Required refactoring of the search result window to show real trees of search results. The backend is the backend from the Locator filter, which is a bit outdated now.
This commit is contained in:
		@@ -17,5 +17,6 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General
 | 
			
		||||
        <dependency name="TextEditor" version="2.1.80"/>
 | 
			
		||||
        <dependency name="ProjectExplorer" version="2.1.80"/>
 | 
			
		||||
        <dependency name="Locator" version="2.1.80"/>
 | 
			
		||||
        <dependency name="Find" version="2.1.80"/>
 | 
			
		||||
    </dependencyList>
 | 
			
		||||
</plugin>
 | 
			
		||||
 
 | 
			
		||||
@@ -31,8 +31,8 @@
 | 
			
		||||
 | 
			
		||||
using namespace CppTools::Internal;
 | 
			
		||||
 | 
			
		||||
CppClassesFilter::CppClassesFilter(CppModelManager *manager, Core::EditorManager *editorManager)
 | 
			
		||||
    : CppLocatorFilter(manager, editorManager)
 | 
			
		||||
CppClassesFilter::CppClassesFilter(CppModelManager *manager)
 | 
			
		||||
    : CppLocatorFilter(manager)
 | 
			
		||||
{
 | 
			
		||||
    setShortcutString("c");
 | 
			
		||||
    setIncludedByDefault(false);
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@ class CppClassesFilter : public CppLocatorFilter
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    CppClassesFilter(CppModelManager *manager, Core::EditorManager *editorManager);
 | 
			
		||||
    CppClassesFilter(CppModelManager *manager);
 | 
			
		||||
    ~CppClassesFilter();
 | 
			
		||||
 | 
			
		||||
    QString displayName() const { return tr("Classes"); }
 | 
			
		||||
 
 | 
			
		||||
@@ -313,7 +313,11 @@ void CppFindReferences::searchFinished()
 | 
			
		||||
 | 
			
		||||
void CppFindReferences::openEditor(const Find::SearchResultItem &item)
 | 
			
		||||
{
 | 
			
		||||
    TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.searchTermStart);
 | 
			
		||||
    if (item.path.size() > 0) {
 | 
			
		||||
        TextEditor::BaseTextEditor::openEditorAt(item.path.first(), item.lineNumber, item.textMarkPos);
 | 
			
		||||
    } else {
 | 
			
		||||
        Core::EditorManager::instance()->openEditor(item.text);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -31,8 +31,8 @@
 | 
			
		||||
 | 
			
		||||
using namespace CppTools::Internal;
 | 
			
		||||
 | 
			
		||||
CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager, Core::EditorManager *editorManager)
 | 
			
		||||
    : CppLocatorFilter(manager, editorManager)
 | 
			
		||||
CppFunctionsFilter::CppFunctionsFilter(CppModelManager *manager)
 | 
			
		||||
    : CppLocatorFilter(manager)
 | 
			
		||||
{
 | 
			
		||||
    setShortcutString(QString(QLatin1Char('m')));
 | 
			
		||||
    setIncludedByDefault(false);
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@ class CppFunctionsFilter : public CppLocatorFilter
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    CppFunctionsFilter(CppModelManager *manager, Core::EditorManager *editorManager);
 | 
			
		||||
    CppFunctionsFilter(CppModelManager *manager);
 | 
			
		||||
    ~CppFunctionsFilter();
 | 
			
		||||
 | 
			
		||||
    QString displayName() const { return tr("Methods"); }
 | 
			
		||||
 
 | 
			
		||||
@@ -30,8 +30,6 @@
 | 
			
		||||
#include "cpplocatorfilter.h"
 | 
			
		||||
#include "cppmodelmanager.h"
 | 
			
		||||
 | 
			
		||||
#include <coreplugin/editormanager/editormanager.h>
 | 
			
		||||
#include <coreplugin/editormanager/ieditor.h>
 | 
			
		||||
#include <texteditor/itexteditor.h>
 | 
			
		||||
#include <texteditor/basetexteditor.h>
 | 
			
		||||
 | 
			
		||||
@@ -39,9 +37,8 @@
 | 
			
		||||
 | 
			
		||||
using namespace CppTools::Internal;
 | 
			
		||||
 | 
			
		||||
CppLocatorFilter::CppLocatorFilter(CppModelManager *manager, Core::EditorManager *editorManager)
 | 
			
		||||
CppLocatorFilter::CppLocatorFilter(CppModelManager *manager)
 | 
			
		||||
    : m_manager(manager),
 | 
			
		||||
    m_editorManager(editorManager),
 | 
			
		||||
    m_forceNewSearchList(true)
 | 
			
		||||
{
 | 
			
		||||
    setShortcutString(QString(QLatin1Char(':')));
 | 
			
		||||
 
 | 
			
		||||
@@ -34,10 +34,6 @@
 | 
			
		||||
 | 
			
		||||
#include <locator/ilocatorfilter.h>
 | 
			
		||||
 | 
			
		||||
namespace Core {
 | 
			
		||||
class EditorManager;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace CppTools {
 | 
			
		||||
namespace Internal {
 | 
			
		||||
 | 
			
		||||
@@ -47,7 +43,7 @@ class CppLocatorFilter : public Locator::ILocatorFilter
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    CppLocatorFilter(CppModelManager *manager, Core::EditorManager *editorManager);
 | 
			
		||||
    CppLocatorFilter(CppModelManager *manager);
 | 
			
		||||
    ~CppLocatorFilter();
 | 
			
		||||
 | 
			
		||||
    QString displayName() const { return tr("Classes and Methods"); }
 | 
			
		||||
@@ -66,7 +62,6 @@ private slots:
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    CppModelManager *m_manager;
 | 
			
		||||
    Core::EditorManager *m_editorManager;
 | 
			
		||||
 | 
			
		||||
    struct Info {
 | 
			
		||||
        Info(): dirty(true) {}
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,8 @@ HEADERS += completionsettingspage.h \
 | 
			
		||||
    cppdoxygen.h \
 | 
			
		||||
    cppfilesettingspage.h \
 | 
			
		||||
    cppfindreferences.h \
 | 
			
		||||
    cppcodeformatter.h
 | 
			
		||||
    cppcodeformatter.h \
 | 
			
		||||
    symbolsfindfilter.h
 | 
			
		||||
 | 
			
		||||
SOURCES += completionsettingspage.cpp \
 | 
			
		||||
    cppclassesfilter.cpp \
 | 
			
		||||
@@ -40,7 +41,8 @@ SOURCES += completionsettingspage.cpp \
 | 
			
		||||
    cppfilesettingspage.cpp \
 | 
			
		||||
    abstracteditorsupport.cpp \
 | 
			
		||||
    cppfindreferences.cpp \
 | 
			
		||||
    cppcodeformatter.cpp
 | 
			
		||||
    cppcodeformatter.cpp \
 | 
			
		||||
    symbolsfindfilter.cpp
 | 
			
		||||
 | 
			
		||||
FORMS += completionsettingspage.ui \
 | 
			
		||||
    cppfilesettingspage.ui
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
include($$IDE_SOURCE_TREE/src/libs/cplusplus/cplusplus.pri)
 | 
			
		||||
include($$IDE_SOURCE_TREE/src/plugins/projectexplorer/projectexplorer.pri)
 | 
			
		||||
include($$IDE_SOURCE_TREE/src/plugins/texteditor/texteditor.pri)
 | 
			
		||||
include($$IDE_SOURCE_TREE/src/plugins/find/find.pri)
 | 
			
		||||
 
 | 
			
		||||
@@ -37,6 +37,7 @@
 | 
			
		||||
#include "cppmodelmanager.h"
 | 
			
		||||
#include "cpptoolsconstants.h"
 | 
			
		||||
#include "cpplocatorfilter.h"
 | 
			
		||||
#include "symbolsfindfilter.h"
 | 
			
		||||
 | 
			
		||||
#include <extensionsystem/pluginmanager.h>
 | 
			
		||||
 | 
			
		||||
@@ -111,14 +112,13 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
 | 
			
		||||
    CppCodeCompletion *completion = new CppCodeCompletion(m_modelManager);
 | 
			
		||||
    addAutoReleasedObject(completion);
 | 
			
		||||
 | 
			
		||||
    CppLocatorFilter *locatorFilter = new CppLocatorFilter(m_modelManager,
 | 
			
		||||
                                                                 core->editorManager());
 | 
			
		||||
    addAutoReleasedObject(locatorFilter);
 | 
			
		||||
    addAutoReleasedObject(new CppClassesFilter(m_modelManager, core->editorManager()));
 | 
			
		||||
    addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, core->editorManager()));
 | 
			
		||||
    addAutoReleasedObject(new CppLocatorFilter(m_modelManager));
 | 
			
		||||
    addAutoReleasedObject(new CppClassesFilter(m_modelManager));
 | 
			
		||||
    addAutoReleasedObject(new CppFunctionsFilter(m_modelManager));
 | 
			
		||||
    addAutoReleasedObject(new CppCurrentDocumentFilter(m_modelManager, core->editorManager()));
 | 
			
		||||
    addAutoReleasedObject(new CompletionSettingsPage);
 | 
			
		||||
    addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
 | 
			
		||||
    addAutoReleasedObject(new SymbolsFindFilter(m_modelManager));
 | 
			
		||||
 | 
			
		||||
    // Menus
 | 
			
		||||
    Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
 | 
			
		||||
 
 | 
			
		||||
@@ -32,10 +32,17 @@
 | 
			
		||||
#include <Literals.h>
 | 
			
		||||
#include <Scope.h>
 | 
			
		||||
#include <Names.h>
 | 
			
		||||
#include <cplusplus/LookupContext.h>
 | 
			
		||||
 | 
			
		||||
using namespace CPlusPlus;
 | 
			
		||||
using namespace CppTools::Internal;
 | 
			
		||||
 | 
			
		||||
SearchSymbols::SymbolTypes SearchSymbols::AllTypes =
 | 
			
		||||
        SearchSymbols::Classes
 | 
			
		||||
        | SearchSymbols::Functions
 | 
			
		||||
        | SearchSymbols::Enums
 | 
			
		||||
        | SearchSymbols::Declarations;
 | 
			
		||||
 | 
			
		||||
SearchSymbols::SearchSymbols():
 | 
			
		||||
    symbolsToSearchFor(Classes | Functions | Enums),
 | 
			
		||||
    separateScope(false)
 | 
			
		||||
@@ -204,13 +211,17 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
 | 
			
		||||
void SearchSymbols::appendItem(const QString &name,
 | 
			
		||||
                               const QString &info,
 | 
			
		||||
                               ModelItemInfo::ItemType type,
 | 
			
		||||
                               const Symbol *symbol)
 | 
			
		||||
                               Symbol *symbol)
 | 
			
		||||
{
 | 
			
		||||
    if (!symbol->name())
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    QStringList fullyQualifiedName;
 | 
			
		||||
    foreach (const Name *name, LookupContext::fullyQualifiedName(symbol))
 | 
			
		||||
        fullyQualifiedName.append(overview.prettyName(name));
 | 
			
		||||
    const QIcon icon = icons.iconForSymbol(symbol);
 | 
			
		||||
    items.append(ModelItemInfo(name, info, type,
 | 
			
		||||
                               fullyQualifiedName,
 | 
			
		||||
                               QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
 | 
			
		||||
                               symbol->line(),
 | 
			
		||||
                               symbol->column() - 1, // 1-based vs 0-based column
 | 
			
		||||
 
 | 
			
		||||
@@ -52,12 +52,14 @@ struct ModelItemInfo
 | 
			
		||||
 | 
			
		||||
    ModelItemInfo()
 | 
			
		||||
        : type(Declaration),
 | 
			
		||||
          line(0)
 | 
			
		||||
          line(0),
 | 
			
		||||
          column(0)
 | 
			
		||||
    { }
 | 
			
		||||
 | 
			
		||||
    ModelItemInfo(const QString &symbolName,
 | 
			
		||||
                  const QString &symbolType,
 | 
			
		||||
                  ItemType type,
 | 
			
		||||
                  QStringList fullyQualifiedName,
 | 
			
		||||
                  const QString &fileName,
 | 
			
		||||
                  int line,
 | 
			
		||||
                  int column,
 | 
			
		||||
@@ -65,15 +67,28 @@ struct ModelItemInfo
 | 
			
		||||
        : symbolName(symbolName),
 | 
			
		||||
          symbolType(symbolType),
 | 
			
		||||
          type(type),
 | 
			
		||||
          fullyQualifiedName(fullyQualifiedName),
 | 
			
		||||
          fileName(fileName),
 | 
			
		||||
          line(line),
 | 
			
		||||
          column(column),
 | 
			
		||||
          icon(icon)
 | 
			
		||||
    { }
 | 
			
		||||
 | 
			
		||||
    ModelItemInfo(const ModelItemInfo &otherInfo)
 | 
			
		||||
        : symbolName(otherInfo.symbolName),
 | 
			
		||||
          symbolType(otherInfo.symbolType),
 | 
			
		||||
          type(otherInfo.type),
 | 
			
		||||
          fullyQualifiedName(otherInfo.fullyQualifiedName),
 | 
			
		||||
          fileName(otherInfo.fileName),
 | 
			
		||||
          line(otherInfo.line),
 | 
			
		||||
          column(otherInfo.column),
 | 
			
		||||
          icon(otherInfo.icon)
 | 
			
		||||
    {  }
 | 
			
		||||
 | 
			
		||||
    QString symbolName;
 | 
			
		||||
    QString symbolType;
 | 
			
		||||
    ItemType type;
 | 
			
		||||
    QStringList fullyQualifiedName;
 | 
			
		||||
    QString fileName;
 | 
			
		||||
    int line;
 | 
			
		||||
    int column;
 | 
			
		||||
@@ -90,8 +105,11 @@ public:
 | 
			
		||||
        Enums        = 0x4,
 | 
			
		||||
        Declarations = 0x8
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    Q_DECLARE_FLAGS(SymbolTypes, SymbolType)
 | 
			
		||||
 | 
			
		||||
    static SymbolTypes AllTypes;
 | 
			
		||||
 | 
			
		||||
    SearchSymbols();
 | 
			
		||||
 | 
			
		||||
    void setSymbolsToSearchFor(SymbolTypes types);
 | 
			
		||||
@@ -121,7 +139,7 @@ protected:
 | 
			
		||||
    void appendItem(const QString &name,
 | 
			
		||||
                    const QString &info,
 | 
			
		||||
                    ModelItemInfo::ItemType type,
 | 
			
		||||
                    const CPlusPlus::Symbol *symbol);
 | 
			
		||||
                    CPlusPlus::Symbol *symbol);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QString findOrInsert(const QString &s)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										317
									
								
								src/plugins/cpptools/symbolsfindfilter.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										317
									
								
								src/plugins/cpptools/symbolsfindfilter.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,317 @@
 | 
			
		||||
/**************************************************************************
 | 
			
		||||
**
 | 
			
		||||
** This file is part of Qt Creator
 | 
			
		||||
**
 | 
			
		||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 | 
			
		||||
**
 | 
			
		||||
** Contact: Nokia Corporation (qt-info@nokia.com)
 | 
			
		||||
**
 | 
			
		||||
** Commercial Usage
 | 
			
		||||
**
 | 
			
		||||
** 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.
 | 
			
		||||
**
 | 
			
		||||
** GNU Lesser General Public License Usage
 | 
			
		||||
**
 | 
			
		||||
** 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.
 | 
			
		||||
**
 | 
			
		||||
** If you are unsure which license is appropriate for your use, please
 | 
			
		||||
** contact the sales department at http://qt.nokia.com/contact.
 | 
			
		||||
**
 | 
			
		||||
**************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include "symbolsfindfilter.h"
 | 
			
		||||
 | 
			
		||||
#include "cppmodelmanager.h"
 | 
			
		||||
#include "cpptoolsconstants.h"
 | 
			
		||||
 | 
			
		||||
#include <coreplugin/progressmanager/progressmanager.h>
 | 
			
		||||
#include <coreplugin/icore.h>
 | 
			
		||||
#include <find/textfindconstants.h>
 | 
			
		||||
#include <qtconcurrent/runextensions.h>
 | 
			
		||||
#include <projectexplorer/projectexplorer.h>
 | 
			
		||||
#include <projectexplorer/session.h>
 | 
			
		||||
#include <projectexplorer/project.h>
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QSet>
 | 
			
		||||
#include <QtCore/QRegExp>
 | 
			
		||||
#include <QtGui/QGridLayout>
 | 
			
		||||
#include <QtGui/QLabel>
 | 
			
		||||
#include <QtGui/QButtonGroup>
 | 
			
		||||
 | 
			
		||||
using namespace CppTools;
 | 
			
		||||
using namespace CppTools::Internal;
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
    const char * const SETTINGS_GROUP = "CppSymbols";
 | 
			
		||||
    const char * const SETTINGS_SYMBOLTYPES = "SymbolsToSearchFor";
 | 
			
		||||
    const char * const SETTINGS_SEARCHSCOPE = "SearchScope";
 | 
			
		||||
 | 
			
		||||
    void runSearch(QFutureInterface<Find::SearchResultItem> &future,
 | 
			
		||||
              QString txt, Find::FindFlags findFlags, CPlusPlus::Snapshot snapshot,
 | 
			
		||||
              SearchSymbols *search, QSet<QString> fileNames)
 | 
			
		||||
    {
 | 
			
		||||
        future.setProgressRange(0, snapshot.size());
 | 
			
		||||
        future.setProgressValue(0);
 | 
			
		||||
        int progress = 0;
 | 
			
		||||
 | 
			
		||||
        CPlusPlus::Snapshot::const_iterator it = snapshot.begin();
 | 
			
		||||
 | 
			
		||||
        QString findString = (findFlags & Find::FindRegularExpression ? txt : QRegExp::escape(txt));
 | 
			
		||||
        if (findFlags & Find::FindWholeWords)
 | 
			
		||||
            findString = QString::fromLatin1("\\b%1\\b").arg(findString);
 | 
			
		||||
        QRegExp matcher(findString, (findFlags & Find::FindCaseSensitively ? Qt::CaseSensitive : Qt::CaseInsensitive));
 | 
			
		||||
        while (it != snapshot.end() && !future.isCanceled()) {
 | 
			
		||||
            if (fileNames.isEmpty() || fileNames.contains(it.value()->fileName())) {
 | 
			
		||||
                QVector<Find::SearchResultItem> resultItems;
 | 
			
		||||
                QList<ModelItemInfo> modelInfos = (*search)(it.value());
 | 
			
		||||
                foreach (const ModelItemInfo &info, modelInfos) {
 | 
			
		||||
                    int index = matcher.indexIn(info.symbolName);
 | 
			
		||||
                    if (index != -1) {
 | 
			
		||||
                        QStringList path = info.fullyQualifiedName.mid(0, info.fullyQualifiedName.size() - 1);
 | 
			
		||||
                        Find::SearchResultItem item;
 | 
			
		||||
                        item.path = path;
 | 
			
		||||
                        item.text = info.symbolName;
 | 
			
		||||
                        item.textMarkPos = -1;
 | 
			
		||||
                        item.textMarkLength = 0;
 | 
			
		||||
                        item.icon = info.icon;
 | 
			
		||||
                        item.lineNumber = -1;
 | 
			
		||||
                        item.userData = qVariantFromValue(info);
 | 
			
		||||
                        resultItems << item;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (!resultItems.isEmpty())
 | 
			
		||||
                    future.reportResults(resultItems);
 | 
			
		||||
            }
 | 
			
		||||
            ++it;
 | 
			
		||||
            ++progress;
 | 
			
		||||
            future.setProgressValue(progress);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
} //namespace
 | 
			
		||||
 | 
			
		||||
SymbolsFindFilter::SymbolsFindFilter(CppModelManager *manager)
 | 
			
		||||
    : m_manager(manager),
 | 
			
		||||
    m_isRunning(false),
 | 
			
		||||
    m_enabled(true),
 | 
			
		||||
    m_symbolsToSearch(SearchSymbols::AllTypes),
 | 
			
		||||
    m_scope(SearchProjectsOnly)
 | 
			
		||||
{
 | 
			
		||||
    // for disabling while parser is running
 | 
			
		||||
    connect(Core::ICore::instance()->progressManager(), SIGNAL(taskStarted(QString)),
 | 
			
		||||
            this, SLOT(onTaskStarted(QString)));
 | 
			
		||||
    connect(Core::ICore::instance()->progressManager(), SIGNAL(allTasksFinished(QString)),
 | 
			
		||||
            this, SLOT(onAllTasksFinished(QString)));
 | 
			
		||||
 | 
			
		||||
    connect(&m_watcher, SIGNAL(finished()),
 | 
			
		||||
            this, SLOT(finish()));
 | 
			
		||||
    connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)),
 | 
			
		||||
            this, SLOT(addResults(int, int)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString SymbolsFindFilter::id() const
 | 
			
		||||
{
 | 
			
		||||
    return QLatin1String("CppSymbols");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString SymbolsFindFilter::displayName() const
 | 
			
		||||
{
 | 
			
		||||
    return tr("C++ Symbols");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool SymbolsFindFilter::isEnabled() const
 | 
			
		||||
{
 | 
			
		||||
    return !m_isRunning && m_enabled;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Find::FindFlags SymbolsFindFilter::supportedFindFlags() const
 | 
			
		||||
{
 | 
			
		||||
    return Find::FindCaseSensitively | Find::FindRegularExpression | Find::FindWholeWords;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
 | 
			
		||||
{
 | 
			
		||||
    m_isRunning = true;
 | 
			
		||||
    emit changed();
 | 
			
		||||
    Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
 | 
			
		||||
    Find::SearchResult *result = window->startNewSearch();
 | 
			
		||||
    connect(result, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
 | 
			
		||||
    window->popup(true);
 | 
			
		||||
 | 
			
		||||
    m_search.setSymbolsToSearchFor(m_symbolsToSearch);
 | 
			
		||||
    m_search.setSeparateScope(true);
 | 
			
		||||
    QSet<QString> projectFileNames;
 | 
			
		||||
    if (m_scope == SymbolsFindFilter::SearchProjectsOnly) {
 | 
			
		||||
        foreach (ProjectExplorer::Project *project,
 | 
			
		||||
                 ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects()) {
 | 
			
		||||
            projectFileNames += project->files(ProjectExplorer::Project::AllFiles).toSet();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    m_watcher.setFuture(QtConcurrent::run<Find::SearchResultItem, QString,
 | 
			
		||||
        Find::FindFlags, CPlusPlus::Snapshot,
 | 
			
		||||
        SearchSymbols *, QSet<QString> >(runSearch, txt, findFlags, m_manager->snapshot(),
 | 
			
		||||
                                    &m_search, projectFileNames));
 | 
			
		||||
    Core::ICore::instance()->progressManager()->addTask(m_watcher.future(),
 | 
			
		||||
                                                        tr("Searching"),
 | 
			
		||||
                                                        Find::Constants::TASK_SEARCH);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilter::addResults(int begin, int end)
 | 
			
		||||
{
 | 
			
		||||
    Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
 | 
			
		||||
    QList<Find::SearchResultItem> items;
 | 
			
		||||
    for (int i = begin; i < end; ++i)
 | 
			
		||||
        items << m_watcher.resultAt(i);
 | 
			
		||||
    window->addResults(items, Find::SearchResultWindow::AddSorted);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilter::finish()
 | 
			
		||||
{
 | 
			
		||||
    Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
 | 
			
		||||
    window->finishSearch();
 | 
			
		||||
    m_isRunning = false;
 | 
			
		||||
    emit changed();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilter::openEditor(const Find::SearchResultItem &item)
 | 
			
		||||
{
 | 
			
		||||
    if (!item.userData.canConvert<ModelItemInfo>())
 | 
			
		||||
        return;
 | 
			
		||||
    ModelItemInfo info = item.userData.value<ModelItemInfo>();
 | 
			
		||||
    TextEditor::BaseTextEditor::openEditorAt(info.fileName,
 | 
			
		||||
                                             info.line,
 | 
			
		||||
                                             info.column);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QWidget *SymbolsFindFilter::createConfigWidget()
 | 
			
		||||
{
 | 
			
		||||
    return new SymbolsFindFilterConfigWidget(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilter::writeSettings(QSettings *settings)
 | 
			
		||||
{
 | 
			
		||||
    settings->beginGroup(QLatin1String(SETTINGS_GROUP));
 | 
			
		||||
    settings->setValue(SETTINGS_SYMBOLTYPES, (int)m_symbolsToSearch);
 | 
			
		||||
    settings->setValue(SETTINGS_SEARCHSCOPE, (int)m_scope);
 | 
			
		||||
    settings->endGroup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilter::readSettings(QSettings *settings)
 | 
			
		||||
{
 | 
			
		||||
    settings->beginGroup(QLatin1String(SETTINGS_GROUP));
 | 
			
		||||
    m_symbolsToSearch = (SearchSymbols::SymbolTypes)settings->value(SETTINGS_SYMBOLTYPES,
 | 
			
		||||
                                        (int)SearchSymbols::AllTypes).toInt();
 | 
			
		||||
    m_scope = (SearchScope)settings->value(SETTINGS_SEARCHSCOPE,
 | 
			
		||||
                                           (int)SearchProjectsOnly).toInt();
 | 
			
		||||
    settings->endGroup();
 | 
			
		||||
    emit symbolsToSearchChanged();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilter::onTaskStarted(const QString &type)
 | 
			
		||||
{
 | 
			
		||||
    if (type == CppTools::Constants::TASK_INDEX) {
 | 
			
		||||
        m_enabled = false;
 | 
			
		||||
        emit changed();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilter::onAllTasksFinished(const QString &type)
 | 
			
		||||
{
 | 
			
		||||
    if (type == CppTools::Constants::TASK_INDEX) {
 | 
			
		||||
        m_enabled = true;
 | 
			
		||||
        emit changed();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// #pragma mark -- SymbolsFindFilterConfigWidget
 | 
			
		||||
 | 
			
		||||
SymbolsFindFilterConfigWidget::SymbolsFindFilterConfigWidget(SymbolsFindFilter *filter)
 | 
			
		||||
    : m_filter(filter)
 | 
			
		||||
{
 | 
			
		||||
    connect(m_filter, SIGNAL(symbolsToSearchChanged()), this, SLOT(getState()));
 | 
			
		||||
 | 
			
		||||
    QGridLayout *layout = new QGridLayout(this);
 | 
			
		||||
    setLayout(layout);
 | 
			
		||||
    layout->setMargin(0);
 | 
			
		||||
 | 
			
		||||
    QLabel *typeLabel = new QLabel(tr("Types:"));
 | 
			
		||||
    layout->addWidget(typeLabel, 0, 0);
 | 
			
		||||
 | 
			
		||||
    m_typeClasses = new QCheckBox(tr("Classes"));
 | 
			
		||||
    layout->addWidget(m_typeClasses, 0, 1);
 | 
			
		||||
 | 
			
		||||
    m_typeMethods = new QCheckBox(tr("Methods"));
 | 
			
		||||
    layout->addWidget(m_typeMethods, 0, 2);
 | 
			
		||||
 | 
			
		||||
    m_typeEnums = new QCheckBox(tr("Enums"));
 | 
			
		||||
    layout->addWidget(m_typeEnums, 1, 1);
 | 
			
		||||
 | 
			
		||||
    m_typeDeclarations = new QCheckBox(tr("Declarations"));
 | 
			
		||||
    layout->addWidget(m_typeDeclarations, 1, 2);
 | 
			
		||||
 | 
			
		||||
    // hacks to fix layouting:
 | 
			
		||||
    typeLabel->setMinimumWidth(80);
 | 
			
		||||
    typeLabel->setAlignment(Qt::AlignRight);
 | 
			
		||||
    m_typeClasses->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 | 
			
		||||
    m_typeMethods->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 | 
			
		||||
 | 
			
		||||
    connect(m_typeClasses, SIGNAL(clicked(bool)), this, SLOT(setState()));
 | 
			
		||||
    connect(m_typeMethods, SIGNAL(clicked(bool)), this, SLOT(setState()));
 | 
			
		||||
    connect(m_typeEnums, SIGNAL(clicked(bool)), this, SLOT(setState()));
 | 
			
		||||
    connect(m_typeDeclarations, SIGNAL(clicked(bool)), this, SLOT(setState()));
 | 
			
		||||
 | 
			
		||||
    m_searchProjectsOnly = new QRadioButton(tr("Projects Only"));
 | 
			
		||||
    layout->addWidget(m_searchProjectsOnly, 2, 1);
 | 
			
		||||
 | 
			
		||||
    m_searchGlobal = new QRadioButton(tr("Global"));
 | 
			
		||||
    layout->addWidget(m_searchGlobal, 2, 2);
 | 
			
		||||
 | 
			
		||||
    m_searchGroup = new QButtonGroup(this);
 | 
			
		||||
    m_searchGroup->addButton(m_searchProjectsOnly);
 | 
			
		||||
    m_searchGroup->addButton(m_searchGlobal);
 | 
			
		||||
 | 
			
		||||
    connect(m_searchProjectsOnly, SIGNAL(clicked(bool)),
 | 
			
		||||
            this, SLOT(setState()));
 | 
			
		||||
    connect(m_searchGlobal, SIGNAL(clicked(bool)),
 | 
			
		||||
            this, SLOT(setState()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilterConfigWidget::getState()
 | 
			
		||||
{
 | 
			
		||||
    SearchSymbols::SymbolTypes symbols = m_filter->symbolsToSearch();
 | 
			
		||||
    m_typeClasses->setChecked(symbols & SearchSymbols::Classes);
 | 
			
		||||
    m_typeMethods->setChecked(symbols & SearchSymbols::Functions);
 | 
			
		||||
    m_typeEnums->setChecked(symbols & SearchSymbols::Enums);
 | 
			
		||||
    m_typeDeclarations->setChecked(symbols & SearchSymbols::Declarations);
 | 
			
		||||
 | 
			
		||||
    SymbolsFindFilter::SearchScope scope = m_filter->searchScope();
 | 
			
		||||
    m_searchProjectsOnly->setChecked(scope == SymbolsFindFilter::SearchProjectsOnly);
 | 
			
		||||
    m_searchGlobal->setChecked(scope == SymbolsFindFilter::SearchGlobal);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SymbolsFindFilterConfigWidget::setState() const
 | 
			
		||||
{
 | 
			
		||||
    SearchSymbols::SymbolTypes symbols;
 | 
			
		||||
    if (m_typeClasses->isChecked())
 | 
			
		||||
        symbols |= SearchSymbols::Classes;
 | 
			
		||||
    if (m_typeMethods->isChecked())
 | 
			
		||||
        symbols |= SearchSymbols::Functions;
 | 
			
		||||
    if (m_typeEnums->isChecked())
 | 
			
		||||
        symbols |= SearchSymbols::Enums;
 | 
			
		||||
    if (m_typeDeclarations->isChecked())
 | 
			
		||||
        symbols |= SearchSymbols::Declarations;
 | 
			
		||||
    m_filter->setSymbolsToSearch(symbols);
 | 
			
		||||
 | 
			
		||||
    if (m_searchProjectsOnly->isChecked())
 | 
			
		||||
        m_filter->setSearchScope(SymbolsFindFilter::SearchProjectsOnly);
 | 
			
		||||
    else
 | 
			
		||||
        m_filter->setSearchScope(SymbolsFindFilter::SearchGlobal);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										124
									
								
								src/plugins/cpptools/symbolsfindfilter.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								src/plugins/cpptools/symbolsfindfilter.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,124 @@
 | 
			
		||||
/**************************************************************************
 | 
			
		||||
**
 | 
			
		||||
** This file is part of Qt Creator
 | 
			
		||||
**
 | 
			
		||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 | 
			
		||||
**
 | 
			
		||||
** Contact: Nokia Corporation (qt-info@nokia.com)
 | 
			
		||||
**
 | 
			
		||||
** Commercial Usage
 | 
			
		||||
**
 | 
			
		||||
** 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.
 | 
			
		||||
**
 | 
			
		||||
** GNU Lesser General Public License Usage
 | 
			
		||||
**
 | 
			
		||||
** 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.
 | 
			
		||||
**
 | 
			
		||||
** If you are unsure which license is appropriate for your use, please
 | 
			
		||||
** contact the sales department at http://qt.nokia.com/contact.
 | 
			
		||||
**
 | 
			
		||||
**************************************************************************/
 | 
			
		||||
 | 
			
		||||
#ifndef SYMBOLSFINDFILTER_H
 | 
			
		||||
#define SYMBOLSFINDFILTER_H
 | 
			
		||||
 | 
			
		||||
#include "searchsymbols.h"
 | 
			
		||||
 | 
			
		||||
#include <find/ifindfilter.h>
 | 
			
		||||
#include <find/searchresultwindow.h>
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QFutureInterface>
 | 
			
		||||
#include <QtCore/QFutureWatcher>
 | 
			
		||||
#include <QtGui/QWidget>
 | 
			
		||||
#include <QtGui/QCheckBox>
 | 
			
		||||
#include <QtGui/QRadioButton>
 | 
			
		||||
 | 
			
		||||
namespace CppTools {
 | 
			
		||||
namespace Internal {
 | 
			
		||||
 | 
			
		||||
class CppModelManager;
 | 
			
		||||
 | 
			
		||||
class SymbolsFindFilter : public Find::IFindFilter
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    enum SearchScope {
 | 
			
		||||
        SearchProjectsOnly,
 | 
			
		||||
        SearchGlobal
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    explicit SymbolsFindFilter(CppModelManager *manager);
 | 
			
		||||
 | 
			
		||||
    QString id() const;
 | 
			
		||||
    QString displayName() const;
 | 
			
		||||
    bool isEnabled() const;
 | 
			
		||||
    Find::FindFlags supportedFindFlags() const;
 | 
			
		||||
 | 
			
		||||
    void findAll(const QString &txt, Find::FindFlags findFlags);
 | 
			
		||||
 | 
			
		||||
    QWidget *createConfigWidget();
 | 
			
		||||
    void writeSettings(QSettings *settings);
 | 
			
		||||
    void readSettings(QSettings *settings);
 | 
			
		||||
 | 
			
		||||
    void setSymbolsToSearch(SearchSymbols::SymbolTypes types) { m_symbolsToSearch = types; }
 | 
			
		||||
    SearchSymbols::SymbolTypes symbolsToSearch() const { return m_symbolsToSearch; }
 | 
			
		||||
 | 
			
		||||
    void setSearchScope(SearchScope scope) { m_scope = scope; }
 | 
			
		||||
    SearchScope searchScope() const { return m_scope; }
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void symbolsToSearchChanged();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void openEditor(const Find::SearchResultItem &item);
 | 
			
		||||
 | 
			
		||||
    void addResults(int begin, int end);
 | 
			
		||||
    void finish();
 | 
			
		||||
    void onTaskStarted(const QString &type);
 | 
			
		||||
    void onAllTasksFinished(const QString &type);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    CppModelManager *m_manager;
 | 
			
		||||
    bool m_isRunning;
 | 
			
		||||
    bool m_enabled;
 | 
			
		||||
    QFutureWatcher<Find::SearchResultItem> m_watcher;
 | 
			
		||||
    SearchSymbols::SymbolTypes m_symbolsToSearch;
 | 
			
		||||
    SearchSymbols m_search;
 | 
			
		||||
    SearchScope m_scope;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SymbolsFindFilterConfigWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    SymbolsFindFilterConfigWidget(SymbolsFindFilter *filter);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void setState() const;
 | 
			
		||||
    void getState();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    SymbolsFindFilter *m_filter;
 | 
			
		||||
 | 
			
		||||
    QCheckBox *m_typeClasses;
 | 
			
		||||
    QCheckBox *m_typeMethods;
 | 
			
		||||
    QCheckBox *m_typeEnums;
 | 
			
		||||
    QCheckBox *m_typeDeclarations;
 | 
			
		||||
 | 
			
		||||
    QRadioButton *m_searchGlobal;
 | 
			
		||||
    QRadioButton *m_searchProjectsOnly;
 | 
			
		||||
    QButtonGroup *m_searchGroup;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // Internal
 | 
			
		||||
} // CppTools
 | 
			
		||||
 | 
			
		||||
#endif // SYMBOLSFINDFILTER_H
 | 
			
		||||
		Reference in New Issue
	
	Block a user