forked from qt-creator/qt-creator
First incarnation of classes quickopen filter
Invokable with 'c', currently shows all classes it can find.
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
** 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()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "cppquickopenfilter.h"
|
||||||
|
#include "cppmodelmanager.h"
|
||||||
|
|
||||||
#include <Literals.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <Symbols.h>
|
|
||||||
#include <SymbolVisitor.h>
|
|
||||||
#include <Scope.h>
|
|
||||||
#include <cplusplus/Overview.h>
|
|
||||||
#include <cplusplus/Icons.h>
|
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <texteditor/itexteditor.h>
|
#include <texteditor/itexteditor.h>
|
||||||
#include <texteditor/basetexteditor.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;
|
using namespace CppTools::Internal;
|
||||||
|
|
||||||
CppQuickOpenFilter::CppQuickOpenFilter(CppModelManager *manager, Core::EditorManager *editorManager)
|
CppQuickOpenFilter::CppQuickOpenFilter(CppModelManager *manager, Core::EditorManager *editorManager)
|
||||||
@@ -225,9 +66,8 @@ void CppQuickOpenFilter::onDocumentUpdated(CPlusPlus::Document::Ptr doc)
|
|||||||
|
|
||||||
void CppQuickOpenFilter::onAboutToRemoveFiles(const QStringList &files)
|
void CppQuickOpenFilter::onAboutToRemoveFiles(const QStringList &files)
|
||||||
{
|
{
|
||||||
foreach (QString file, files) {
|
foreach (const QString &file, files)
|
||||||
m_searchList.remove(file);
|
m_searchList.remove(file);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppQuickOpenFilter::refresh(QFutureInterface<void> &future)
|
void CppQuickOpenFilter::refresh(QFutureInterface<void> &future)
|
||||||
@@ -245,7 +85,6 @@ QList<QuickOpen::FilterEntry> CppQuickOpenFilter::matchesFor(const QString &orig
|
|||||||
return entries;
|
return entries;
|
||||||
bool hasWildcard = (entry.contains('*') || entry.contains('?'));
|
bool hasWildcard = (entry.contains('*') || entry.contains('?'));
|
||||||
|
|
||||||
SearchSymbols search;
|
|
||||||
QMutableMapIterator<QString, Info> it(m_searchList);
|
QMutableMapIterator<QString, Info> it(m_searchList);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
@@ -276,6 +115,5 @@ QList<QuickOpen::FilterEntry> CppQuickOpenFilter::matchesFor(const QString &orig
|
|||||||
void CppQuickOpenFilter::accept(QuickOpen::FilterEntry selection) const
|
void CppQuickOpenFilter::accept(QuickOpen::FilterEntry selection) const
|
||||||
{
|
{
|
||||||
ModelItemInfo info = qvariant_cast<CppTools::Internal::ModelItemInfo>(selection.internalData);
|
ModelItemInfo info = qvariant_cast<CppTools::Internal::ModelItemInfo>(selection.internalData);
|
||||||
|
|
||||||
TextEditor::BaseTextEditor::openEditorAt(info.fileName, info.line);
|
TextEditor::BaseTextEditor::openEditorAt(info.fileName, info.line);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,45 +34,18 @@
|
|||||||
#ifndef CPPQUICKOPENFILTER_H
|
#ifndef CPPQUICKOPENFILTER_H
|
||||||
#define CPPQUICKOPENFILTER_H
|
#define CPPQUICKOPENFILTER_H
|
||||||
|
|
||||||
#include "cppmodelmanager.h"
|
#include "searchsymbols.h"
|
||||||
#include <cplusplus/CppDocument.h>
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <quickopen/iquickopenfilter.h>
|
#include <quickopen/iquickopenfilter.h>
|
||||||
#include <QtGui/QIcon>
|
|
||||||
#include <QFile>
|
namespace Core {
|
||||||
#include <QMetaType>
|
class EditorManager;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
struct ModelItemInfo
|
class CppModelManager;
|
||||||
{
|
|
||||||
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 CppQuickOpenFilter : public QuickOpen::IQuickOpenFilter
|
class CppQuickOpenFilter : public QuickOpen::IQuickOpenFilter
|
||||||
{
|
{
|
||||||
@@ -82,12 +55,15 @@ public:
|
|||||||
~CppQuickOpenFilter();
|
~CppQuickOpenFilter();
|
||||||
|
|
||||||
QString trName() const { return tr("Classes and Methods"); }
|
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; }
|
Priority priority() const { return Medium; }
|
||||||
QList<QuickOpen::FilterEntry> matchesFor(const QString &entry);
|
QList<QuickOpen::FilterEntry> matchesFor(const QString &entry);
|
||||||
void accept(QuickOpen::FilterEntry selection) const;
|
void accept(QuickOpen::FilterEntry selection) const;
|
||||||
void refresh(QFutureInterface<void> &future);
|
void refresh(QFutureInterface<void> &future);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SearchSymbols search;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
||||||
void onAboutToRemoveFiles(const QStringList &files);
|
void onAboutToRemoveFiles(const QStringList &files);
|
||||||
@@ -114,6 +90,4 @@ private:
|
|||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(CppTools::Internal::ModelItemInfo)
|
|
||||||
|
|
||||||
#endif // CPPQUICKOPENFILTER_H
|
#endif // CPPQUICKOPENFILTER_H
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include "cpptools.h"
|
#include "cpptools.h"
|
||||||
|
#include "cppclassesfilter.h"
|
||||||
#include "cppcodecompletion.h"
|
#include "cppcodecompletion.h"
|
||||||
#include "cpphoverhandler.h"
|
#include "cpphoverhandler.h"
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
@@ -87,6 +88,7 @@ bool CppToolsPlugin::initialize(const QStringList & /*arguments*/, QString *)
|
|||||||
CppQuickOpenFilter *quickOpenFilter = new CppQuickOpenFilter(m_modelManager,
|
CppQuickOpenFilter *quickOpenFilter = new CppQuickOpenFilter(m_modelManager,
|
||||||
m_core->editorManager());
|
m_core->editorManager());
|
||||||
addAutoReleasedObject(quickOpenFilter);
|
addAutoReleasedObject(quickOpenFilter);
|
||||||
|
addAutoReleasedObject(new CppClassesFilter(m_modelManager, m_core->editorManager()));
|
||||||
|
|
||||||
// Menus
|
// Menus
|
||||||
Core::IActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
|
Core::IActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
|
||||||
|
|||||||
@@ -4,31 +4,27 @@ include(../../qworkbenchplugin.pri)
|
|||||||
include(../../plugins/quickopen/quickopen.pri)
|
include(../../plugins/quickopen/quickopen.pri)
|
||||||
include(cpptools_dependencies.pri)
|
include(cpptools_dependencies.pri)
|
||||||
|
|
||||||
#DEFINES += QT_NO_CAST_FROM_ASCII
|
# DEFINES += QT_NO_CAST_FROM_ASCII
|
||||||
DEFINES += QT_NO_CAST_TO_ASCII
|
DEFINES += QT_NO_CAST_TO_ASCII
|
||||||
unix:QMAKE_CXXFLAGS_DEBUG+=-O3
|
unix:QMAKE_CXXFLAGS_DEBUG += -O3
|
||||||
|
|
||||||
INCLUDEPATH += .
|
INCLUDEPATH += .
|
||||||
|
|
||||||
DEFINES += CPPTOOLS_LIBRARY
|
DEFINES += CPPTOOLS_LIBRARY
|
||||||
|
|
||||||
CONFIG += help
|
CONFIG += help
|
||||||
include(rpp/rpp.pri)|error("Can't find RPP")
|
include(rpp/rpp.pri)|error("Can't find RPP")
|
||||||
|
HEADERS += cpptools_global.h \
|
||||||
HEADERS += \
|
cppquickopenfilter.h \
|
||||||
cpptools_global.h \
|
cppclassesfilter.h \
|
||||||
cppquickopenfilter.h
|
searchsymbols.h
|
||||||
|
SOURCES += cppquickopenfilter.cpp \
|
||||||
SOURCES += \
|
cpptoolseditorsupport.cpp \
|
||||||
cppquickopenfilter.cpp \
|
cppclassesfilter.cpp \
|
||||||
cpptoolseditorsupport.cpp
|
searchsymbols.cpp
|
||||||
|
|
||||||
# Input
|
# Input
|
||||||
SOURCES += cpptools.cpp \
|
SOURCES += cpptools.cpp \
|
||||||
cppmodelmanager.cpp \
|
cppmodelmanager.cpp \
|
||||||
cppcodecompletion.cpp \
|
cppcodecompletion.cpp \
|
||||||
cpphoverhandler.cpp
|
cpphoverhandler.cpp
|
||||||
|
|
||||||
HEADERS += cpptools.h \
|
HEADERS += cpptools.h \
|
||||||
cppmodelmanager.h \
|
cppmodelmanager.h \
|
||||||
cppcodecompletion.h \
|
cppcodecompletion.h \
|
||||||
@@ -36,5 +32,4 @@ HEADERS += cpptools.h \
|
|||||||
cppmodelmanagerinterface.h \
|
cppmodelmanagerinterface.h \
|
||||||
cpptoolseditorsupport.h \
|
cpptoolseditorsupport.h \
|
||||||
cpptoolsconstants.h
|
cpptoolsconstants.h
|
||||||
|
|
||||||
RESOURCES += cpptools.qrc
|
RESOURCES += cpptools.qrc
|
||||||
|
|||||||
@@ -0,0 +1,178 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
** 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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
** 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
|
||||||
|
enum SymbolType {
|
||||||
|
Classes,
|
||||||
|
ClassesMethodsFunctionsAndEnums
|
||||||
|
};
|
||||||
|
|
||||||
|
SearchSymbols();
|
||||||
|
|
||||||
|
void setSymbolsToSearchFor(SymbolType type);
|
||||||
|
|
||||||
|
QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc)
|
||||||
|
{ return operator()(doc, QString()); }
|
||||||
|
|
||||||
|
QList<ModelItemInfo> operator()(CPlusPlus::Document::Ptr doc, const QString &scope);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
using SymbolVisitor::visit;
|
||||||
|
|
||||||
|
void accept(CPlusPlus::Symbol *symbol)
|
||||||
|
{ CPlusPlus::Symbol::visitSymbol(symbol, this); }
|
||||||
|
|
||||||
|
QString switchScope(const QString &scope);
|
||||||
|
virtual bool visit(CPlusPlus::Enum *symbol);
|
||||||
|
virtual bool visit(CPlusPlus::Function *symbol);
|
||||||
|
virtual bool visit(CPlusPlus::Namespace *symbol);
|
||||||
|
#if 0
|
||||||
|
// This visit method would make function declaration be included in QuickOpen
|
||||||
|
virtual bool visit(CPlusPlus::Declaration *symbol);
|
||||||
|
#endif
|
||||||
|
virtual bool visit(CPlusPlus::Class *symbol);
|
||||||
|
QString symbolName(const CPlusPlus::Symbol *symbol) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString _scope;
|
||||||
|
CPlusPlus::Overview overview;
|
||||||
|
CPlusPlus::Icons icons;
|
||||||
|
QList<ModelItemInfo> items;
|
||||||
|
SymbolType symbolsToSearchFor;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace CppTools
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(CppTools::Internal::ModelItemInfo)
|
||||||
|
|
||||||
|
#endif // SEARCHSYMBOLS_H
|
||||||
@@ -501,7 +501,8 @@ void BaseTextEditor::currentEditorChanged(Core::IEditor *editor)
|
|||||||
if (editor == d->m_editable) {
|
if (editor == d->m_editable) {
|
||||||
if (d->m_document->hasDecodingError()) {
|
if (d->m_document->hasDecodingError()) {
|
||||||
Core::EditorManager::instance()->showEditorInfoBar(QLatin1String(Constants::SELECT_ENCODING),
|
Core::EditorManager::instance()->showEditorInfoBar(QLatin1String(Constants::SELECT_ENCODING),
|
||||||
tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.").arg(displayName()).arg(QString::fromLatin1(d->m_document->codec()->name())),
|
tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.")
|
||||||
|
.arg(displayName()).arg(QString::fromLatin1(d->m_document->codec()->name())),
|
||||||
tr("Select Encoding"),
|
tr("Select Encoding"),
|
||||||
this, SLOT(selectEncoding()));
|
this, SLOT(selectEncoding()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user