Commit cecd5023 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

First incarnation of classes quickopen filter

Invokable with 'c', currently shows all classes it can find.
parent c9f88bf0
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "cppclassesfilter.h"
using namespace CppTools::Internal;
CppClassesFilter::CppClassesFilter(CppModelManager *manager, Core::EditorManager *editorManager)
: CppQuickOpenFilter(manager, editorManager)
{
setShortcutString("c");
setIncludedByDefault(false);
search.setSymbolsToSearchFor(SearchSymbols::Classes);
}
CppClassesFilter::~CppClassesFilter()
{
}
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef CPPCLASSESFILTER_H
#define CPPCLASSESFILTER_H
#include <cppquickopenfilter.h>
namespace CppTools {
namespace Internal {
class CppClassesFilter : public CppQuickOpenFilter
{
Q_OBJECT
public:
CppClassesFilter(CppModelManager *manager, Core::EditorManager *editorManager);
~CppClassesFilter();
QString trName() const { return tr("Classes"); }
QString name() const { return QLatin1String("Classes"); }
Priority priority() const { return Medium; }
};
} // namespace Internal
} // namespace CppTools
#endif // CPPCLASSESFILTER_H
......@@ -32,172 +32,13 @@
***************************************************************************/
#include "cppquickopenfilter.h"
#include "cppmodelmanager.h"
#include <Literals.h>
#include <Symbols.h>
#include <SymbolVisitor.h>
#include <Scope.h>
#include <cplusplus/Overview.h>
#include <cplusplus/Icons.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h>
#include <QtCore/QMultiMap>
#include <functional>
using namespace CPlusPlus;
namespace CppTools {
namespace Internal {
class SearchSymbols: public std::unary_function<Document::Ptr, QList<ModelItemInfo> >,
protected SymbolVisitor
{
Overview overview;
Icons icons;
QList<ModelItemInfo> items;
public:
QList<ModelItemInfo> operator()(Document::Ptr doc)
{ return operator()(doc, QString()); }
QList<ModelItemInfo> operator()(Document::Ptr doc, const QString &scope)
{
QString previousScope = switchScope(scope);
items.clear();
for (unsigned i = 0; i < doc->globalSymbolCount(); ++i) {
accept(doc->globalSymbolAt(i));
}
(void) switchScope(previousScope);
return items;
}
protected:
using SymbolVisitor::visit;
void accept(Symbol *symbol)
{ Symbol::visitSymbol(symbol, this); }
QString switchScope(const QString &scope)
{
QString previousScope = _scope;
_scope = scope;
return previousScope;
}
virtual bool visit(Enum *symbol)
{
QString name = symbolName(symbol);
QString previousScope = switchScope(name);
QIcon icon = icons.iconForSymbol(symbol);
Scope *members = symbol->members();
items.append(ModelItemInfo(name, QString(), ModelItemInfo::Enum,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
symbol->line(),
icon));
for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i));
}
(void) switchScope(previousScope);
return false;
}
virtual bool visit(Function *symbol)
{
QString name = symbolName(symbol);
QString type = overview.prettyType(symbol->type());
QIcon icon = icons.iconForSymbol(symbol);
items.append(ModelItemInfo(name, type, ModelItemInfo::Method,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
symbol->line(),
icon));
return false;
}
virtual bool visit(Namespace *symbol)
{
QString name = symbolName(symbol);
QString previousScope = switchScope(name);
Scope *members = symbol->members();
for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i));
}
(void) switchScope(previousScope);
return false;
}
#if 0
// This visit method would make function declaration be included in QuickOpen
virtual bool visit(Declaration *symbol)
{
if (symbol->type()->isFunction()) {
QString name = symbolName(symbol);
QString type = overview.prettyType(symbol->type());
//QIcon icon = ...;
items.append(ModelItemInfo(name, type, ModelItemInfo::Method,
QString::fromUtf8(symbol->fileName(), symbol->line()),
symbol->line()));
}
return false;
}
#endif
virtual bool visit(Class *symbol)
{
QString name = symbolName(symbol);
QString previousScope = switchScope(name);
QIcon icon = icons.iconForSymbol(symbol);
items.append(ModelItemInfo(name, QString(), ModelItemInfo::Class,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
symbol->line(),
icon));
Scope *members = symbol->members();
for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i));
}
(void) switchScope(previousScope);
return false;
}
QString symbolName(Symbol *symbol) const
{
QString name = _scope;
if (! name.isEmpty())
name += QLatin1String("::");
QString symbolName = overview.prettyName(symbol->name());
if (symbolName.isEmpty()) {
QString type;
if (symbol->isNamespace()) {
type = QLatin1String("namespace");
} else if (symbol->isEnum()) {
type = QLatin1String("enum");
} else if (Class *c = symbol->asClass()) {
if (c->isUnion()) {
type = QLatin1String("union");
} else if (c->isStruct()) {
type = QLatin1String("struct");
} else {
type = QLatin1String("class");
}
} else {
type = QLatin1String("symbol");
}
symbolName = QLatin1String("<anonymous ");
symbolName += type;
symbolName += QLatin1String(">");
}
name += symbolName;
return name;
}
private:
QString _scope;
};
} // namespace Internal
} // namespace CppTools
using namespace CppTools::Internal;
CppQuickOpenFilter::CppQuickOpenFilter(CppModelManager *manager, Core::EditorManager *editorManager)
......@@ -225,9 +66,8 @@ void CppQuickOpenFilter::onDocumentUpdated(CPlusPlus::Document::Ptr doc)
void CppQuickOpenFilter::onAboutToRemoveFiles(const QStringList &files)
{
foreach (QString file, files) {
foreach (const QString &file, files)
m_searchList.remove(file);
}
}
void CppQuickOpenFilter::refresh(QFutureInterface<void> &future)
......@@ -245,7 +85,6 @@ QList<QuickOpen::FilterEntry> CppQuickOpenFilter::matchesFor(const QString &orig
return entries;
bool hasWildcard = (entry.contains('*') || entry.contains('?'));
SearchSymbols search;
QMutableMapIterator<QString, Info> it(m_searchList);
while (it.hasNext()) {
it.next();
......@@ -276,6 +115,5 @@ QList<QuickOpen::FilterEntry> CppQuickOpenFilter::matchesFor(const QString &orig
void CppQuickOpenFilter::accept(QuickOpen::FilterEntry selection) const
{
ModelItemInfo info = qvariant_cast<CppTools::Internal::ModelItemInfo>(selection.internalData);
TextEditor::BaseTextEditor::openEditorAt(info.fileName, info.line);
}
......@@ -34,45 +34,18 @@
#ifndef CPPQUICKOPENFILTER_H
#define CPPQUICKOPENFILTER_H
#include "cppmodelmanager.h"
#include <cplusplus/CppDocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include "searchsymbols.h"
#include <quickopen/iquickopenfilter.h>
#include <QtGui/QIcon>
#include <QFile>
#include <QMetaType>
namespace Core {
class EditorManager;
}
namespace CppTools {
namespace Internal {
struct ModelItemInfo
{
enum ItemType { Enum, Class, Method };
ModelItemInfo()
{ }
ModelItemInfo(const QString &symbolName,
const QString &symbolType,
ItemType type,
const QString &fileName,
int line,
const QIcon &icon)
: symbolName(symbolName),
symbolType(symbolType),
type(type),
fileName(fileName),
line(line),
icon(icon)
{ }
QString symbolName;
QString symbolType;
ItemType type;
QString fileName;
int line;
QIcon icon;
};
class CppModelManager;
class CppQuickOpenFilter : public QuickOpen::IQuickOpenFilter
{
......@@ -82,12 +55,15 @@ public:
~CppQuickOpenFilter();
QString trName() const { return tr("Classes and Methods"); }
QString name() const { return "Classes and Methods"; }
QString name() const { return QLatin1String("Classes and Methods"); }
Priority priority() const { return Medium; }
QList<QuickOpen::FilterEntry> matchesFor(const QString &entry);
void accept(QuickOpen::FilterEntry selection) const;
void refresh(QFutureInterface<void> &future);
protected:
SearchSymbols search;
private slots:
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
void onAboutToRemoveFiles(const QStringList &files);
......@@ -114,6 +90,4 @@ private:
} // namespace Internal
} // namespace CppTools
Q_DECLARE_METATYPE(CppTools::Internal::ModelItemInfo)
#endif // CPPQUICKOPENFILTER_H
......@@ -32,6 +32,7 @@
***************************************************************************/
#include "cpptools.h"
#include "cppclassesfilter.h"
#include "cppcodecompletion.h"
#include "cpphoverhandler.h"
#include "cppmodelmanager.h"
......@@ -87,6 +88,7 @@ bool CppToolsPlugin::initialize(const QStringList & /*arguments*/, QString *)
CppQuickOpenFilter *quickOpenFilter = new CppQuickOpenFilter(m_modelManager,
m_core->editorManager());
addAutoReleasedObject(quickOpenFilter);
addAutoReleasedObject(new CppClassesFilter(m_modelManager, m_core->editorManager()));
// Menus
Core::IActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
......
......@@ -4,31 +4,27 @@ include(../../qworkbenchplugin.pri)
include(../../plugins/quickopen/quickopen.pri)
include(cpptools_dependencies.pri)
#DEFINES += QT_NO_CAST_FROM_ASCII
# DEFINES += QT_NO_CAST_FROM_ASCII
DEFINES += QT_NO_CAST_TO_ASCII
unix:QMAKE_CXXFLAGS_DEBUG+=-O3
unix:QMAKE_CXXFLAGS_DEBUG += -O3
INCLUDEPATH += .
DEFINES += CPPTOOLS_LIBRARY
CONFIG += help
include(rpp/rpp.pri)|error("Can't find RPP")
HEADERS += \
cpptools_global.h \
cppquickopenfilter.h
SOURCES += \
cppquickopenfilter.cpp \
cpptoolseditorsupport.cpp
HEADERS += cpptools_global.h \
cppquickopenfilter.h \
cppclassesfilter.h \
searchsymbols.h
SOURCES += cppquickopenfilter.cpp \
cpptoolseditorsupport.cpp \
cppclassesfilter.cpp \
searchsymbols.cpp
# Input
SOURCES += cpptools.cpp \
cppmodelmanager.cpp \
cppcodecompletion.cpp \
cpphoverhandler.cpp
HEADERS += cpptools.h \
cppmodelmanager.h \
cppcodecompletion.h \
......@@ -36,5 +32,4 @@ HEADERS += cpptools.h \
cppmodelmanagerinterface.h \
cpptoolseditorsupport.h \
cpptoolsconstants.h
RESOURCES += cpptools.qrc
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "searchsymbols.h"
#include <Literals.h>
#include <Scope.h>
using namespace CPlusPlus;
using namespace CppTools::Internal;
SearchSymbols::SearchSymbols():
symbolsToSearchFor(ClassesMethodsFunctionsAndEnums)
{
}
void SearchSymbols::setSymbolsToSearchFor(SymbolType type)
{
symbolsToSearchFor = type;
}
QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, const QString &scope)
{
QString previousScope = switchScope(scope);
items.clear();
for (unsigned i = 0; i < doc->globalSymbolCount(); ++i) {
accept(doc->globalSymbolAt(i));
}
(void) switchScope(previousScope);
return items;
}
QString SearchSymbols::switchScope(const QString &scope)
{
QString previousScope = _scope;
_scope = scope;
return previousScope;
}
bool SearchSymbols::visit(Enum *symbol)
{
if (symbolsToSearchFor != ClassesMethodsFunctionsAndEnums)
return false;
QString name = symbolName(symbol);
QString previousScope = switchScope(name);
QIcon icon = icons.iconForSymbol(symbol);
Scope *members = symbol->members();
items.append(ModelItemInfo(name, QString(), ModelItemInfo::Enum,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
symbol->line(),
icon));
for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i));
}
(void) switchScope(previousScope);
return false;
}
bool SearchSymbols::visit(Function *symbol)
{
if (symbolsToSearchFor != ClassesMethodsFunctionsAndEnums)
return false;
QString name = symbolName(symbol);
QString type = overview.prettyType(symbol->type());
QIcon icon = icons.iconForSymbol(symbol);
items.append(ModelItemInfo(name, type, ModelItemInfo::Method,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
symbol->line(),
icon));
return false;
}
bool SearchSymbols::visit(Namespace *symbol)
{
QString name = symbolName(symbol);
QString previousScope = switchScope(name);
Scope *members = symbol->members();
for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i));
}
(void) switchScope(previousScope);
return false;
}
#if 0
bool SearchSymbols::visit(Declaration *symbol)
{
if (symbol->type()->isFunction()) {
QString name = symbolName(symbol);
QString type = overview.prettyType(symbol->type());
//QIcon icon = ...;
items.append(ModelItemInfo(name, type, ModelItemInfo::Method,
QString::fromUtf8(symbol->fileName(), symbol->line()),
symbol->line()));
}
return false;
}
#endif
bool SearchSymbols::visit(Class *symbol)
{
QString name = symbolName(symbol);
QString previousScope = switchScope(name);
QIcon icon = icons.iconForSymbol(symbol);
items.append(ModelItemInfo(name, QString(), ModelItemInfo::Class,
QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()),
symbol->line(),
icon));
Scope *members = symbol->members();
for (unsigned i = 0; i < members->symbolCount(); ++i) {
accept(members->symbolAt(i));
}
(void) switchScope(previousScope);
return false;
}
QString SearchSymbols::symbolName(const Symbol *symbol) const
{
QString name = _scope;
if (! name.isEmpty())
name += QLatin1String("::");
QString symbolName = overview.prettyName(symbol->name());
if (symbolName.isEmpty()) {
QString type;
if (symbol->isNamespace()) {
type = QLatin1String("namespace");
} else if (symbol->isEnum()) {
type = QLatin1String("enum");
} else if (const Class *c = symbol->asClass()) {
if (c->isUnion()) {
type = QLatin1String("union");
} else if (c->isStruct()) {
type = QLatin1String("struct");
} else {
type = QLatin1String("class");
}
} else {
type = QLatin1String("symbol");
}
symbolName = QLatin1String("<anonymous ");
symbolName += type;
symbolName += QLatin1String(">");
}
name += symbolName;
return name;
}
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef SEARCHSYMBOLS_H
#define SEARCHSYMBOLS_H
#include <cplusplus/CppDocument.h>
#include <cplusplus/Icons.h>
#include <cplusplus/Overview.h>
#include <Symbols.h>
#include <SymbolVisitor.h>
#include <QIcon>
#include <QMetaType>
#include <QString>
namespace CppTools {
namespace Internal {
struct ModelItemInfo
{
enum ItemType { Enum, Class, Method };
ModelItemInfo()
{ }
ModelItemInfo(const QString &symbolName,
const QString &symbolType,
ItemType type,
const QString &fileName,
int line,
const QIcon &icon)
: symbolName(symbolName),
symbolType(symbolType),
type(type),
fileName(fileName),
line(line),
icon(icon)
{ }
QString symbolName;
QString symbolType;
ItemType type;
QString fileName;
int line;
QIcon icon;
};
class SearchSymbols: public std::unary_function<CPlusPlus::Document::Ptr, QList<ModelItemInfo> >,
protected CPlusPlus::SymbolVisitor
{
public:
// TODO: Probably should use QFlags