Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline

This commit is contained in:
dt
2008-12-15 11:54:32 +01:00
22 changed files with 1029 additions and 208 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -45,7 +45,9 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class ProFile; class ProFile;
class ProFileEvaluator;
void evaluateProFile(const ProFileEvaluator &visitor, QHash<QByteArray, QStringList> *varMap);
bool evaluateProFile(const QString &fileName, bool verbose, QHash<QByteArray, QStringList> *varMap); bool evaluateProFile(const QString &fileName, bool verbose, QHash<QByteArray, QStringList> *varMap);
class ProFileEvaluator class ProFileEvaluator
@@ -66,7 +68,9 @@ public:
virtual bool contains(const QString &variableName) const; virtual bool contains(const QString &variableName) const;
QStringList absFileNames(const QString &variableName); QStringList absFileNames(const QString &variableName);
QStringList absFileName(const QString &name); QStringList absFileName(const QString &name);
void setVerbose(bool on); void setVerbose(bool on); // Default is false
void setCumulative(bool on); // Default is true!
void setOutputDir(const QString &dir); // Default is empty
bool queryProFile(ProFile *pro); bool queryProFile(ProFile *pro);
bool accept(ProFile *pro); bool accept(ProFile *pro);

View File

@@ -35,7 +35,6 @@
#include "abstractproitemvisitor.h" #include "abstractproitemvisitor.h"
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QDebug>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE

View File

@@ -45,9 +45,6 @@ struct AbstractProItemVisitor;
class ProItem class ProItem
{ {
public: public:
ProItem()
: m_lineNumber(0)
{}
enum ProItemKind { enum ProItemKind {
ValueKind, ValueKind,
FunctionKind, FunctionKind,
@@ -55,6 +52,8 @@ public:
OperatorKind, OperatorKind,
BlockKind BlockKind
}; };
ProItem() : m_lineNumber(0) {}
virtual ~ProItem() {} virtual ~ProItem() {}
virtual ProItemKind kind() const = 0; virtual ProItemKind kind() const = 0;

View File

@@ -85,6 +85,25 @@ struct Option
Option::qmakespec = QString::fromLatin1(qgetenv("QMAKESPEC").data()); Option::qmakespec = QString::fromLatin1(qgetenv("QMAKESPEC").data());
Option::field_sep = QLatin1Char(' '); Option::field_sep = QLatin1Char(' ');
} }
enum StringFixFlags {
FixNone = 0x00,
FixEnvVars = 0x01,
FixPathCanonicalize = 0x02,
FixPathToLocalSeparators = 0x04,
FixPathToTargetSeparators = 0x08
};
static QString fixString(QString string, uchar flags);
inline static QString fixPathToLocalOS(const QString &in, bool fix_env = true, bool canonical = true)
{
uchar flags = FixPathToLocalSeparators;
if (fix_env)
flags |= FixEnvVars;
if (canonical)
flags |= FixPathCanonicalize;
return fixString(in, flags);
}
}; };
#if defined(Q_OS_WIN32) #if defined(Q_OS_WIN32)
Option::TARG_MODE Option::target_mode = Option::TARG_WIN_MODE; Option::TARG_MODE Option::target_mode = Option::TARG_WIN_MODE;
@@ -113,17 +132,20 @@ static void unquote(QString *string)
} }
static void insertUnique(QHash<QString, QStringList> *map, static void insertUnique(QHash<QString, QStringList> *map,
const QString &key, const QStringList &value, bool unique = true) const QString &key, const QStringList &value)
{ {
QStringList &sl = (*map)[key]; QStringList &sl = (*map)[key];
if (!unique) { foreach (const QString &str, value)
sl += value; if (!sl.contains(str))
} else { sl.append(str);
for (int i = 0; i < value.count(); ++i) { }
if (!sl.contains(value.at(i)))
sl.append(value.at(i)); static void removeEach(QHash<QString, QStringList> *map,
} const QString &key, const QStringList &value)
} {
QStringList &sl = (*map)[key];
foreach (const QString &str, value)
sl.removeAll(str);
} }
/* /*

View File

@@ -63,7 +63,7 @@ QString GeneralSettings::trCategory() const
QWidget* GeneralSettings::createPage(QWidget *parent) QWidget* GeneralSettings::createPage(QWidget *parent)
{ {
m_page = new Ui_GeneralSettings(); m_page = new Ui_GeneralSettings;
QWidget *w = new QWidget(parent); QWidget *w = new QWidget(parent);
m_page->setupUi(w); m_page->setupUi(w);
@@ -77,7 +77,6 @@ QWidget* GeneralSettings::createPage(QWidget *parent)
connect(m_page->helpExternalEditorButton, SIGNAL(clicked()), connect(m_page->helpExternalEditorButton, SIGNAL(clicked()),
this, SLOT(showHelpForExternalEditor())); this, SLOT(showHelpForExternalEditor()));
return w; return w;
} }
@@ -89,7 +88,6 @@ void GeneralSettings::finished(bool accepted)
// Apply the new base color if accepted // Apply the new base color if accepted
StyleHelper::setBaseColor(m_page->colorButton->color()); StyleHelper::setBaseColor(m_page->colorButton->color());
EditorManager::instance()->setExternalEditor(m_page->externalEditorEdit->text()); EditorManager::instance()->setExternalEditor(m_page->externalEditorEdit->text());
} }
void GeneralSettings::resetInterfaceColor() void GeneralSettings::resetInterfaceColor()

View File

@@ -0,0 +1,86 @@
/***************************************************************************
**
** 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 "completionsettingspage.h"
#include "cppcodecompletion.h"
#include "ui_completionsettingspage.h"
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
using namespace CppTools::Internal;
CompletionSettingsPage::CompletionSettingsPage(CppCodeCompletion *completion)
: m_completion(completion)
, m_page(0)
{
}
QString CompletionSettingsPage::name() const
{
return tr("Completion");
}
QString CompletionSettingsPage::category() const
{
return QLatin1String("TextEditor");
}
QString CompletionSettingsPage::trCategory() const
{
return tr("Text Editor");
}
QWidget *CompletionSettingsPage::createPage(QWidget *parent)
{
m_page = new Ui_CompletionSettingsPage;
QWidget *w = new QWidget(parent);
m_page->setupUi(w);
m_page->caseSensitive->setChecked(m_completion->caseSensitivity() == Qt::CaseSensitive);
m_page->autoInsertBraces->setChecked(m_completion->autoInsertBraces());
return w;
}
void CompletionSettingsPage::finished(bool accepted)
{
if (accepted) {
m_completion->setCaseSensitivity(
m_page->caseSensitive->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);
m_completion->setAutoInsertBraces(m_page->autoInsertBraces->isChecked());
}
delete m_page;
m_page = 0;
}

View File

@@ -0,0 +1,68 @@
/***************************************************************************
**
** 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 COMPLETIONSETTINGSPAGE_H
#define COMPLETIONSETTINGSPAGE_H
#include <coreplugin/dialogs/ioptionspage.h>
QT_BEGIN_NAMESPACE
class Ui_CompletionSettingsPage;
QT_END_NAMESPACE
namespace CppTools {
namespace Internal {
class CppCodeCompletion;
class CompletionSettingsPage : public Core::IOptionsPage
{
public:
CompletionSettingsPage(CppCodeCompletion *completion);
QString name() const;
QString category() const;
QString trCategory() const;
QWidget *createPage(QWidget *parent);
void finished(bool accepted);
private:
CppCodeCompletion *m_completion;
Ui_CompletionSettingsPage *m_page;
};
} // namespace Internal
} // namespace CppTools
#endif // COMPLETIONSETTINGSPAGE_H

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CompletionSettingsPage</class>
<widget class="QWidget" name="CompletionSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="caseSensitive">
<property name="text">
<string>Match completions &amp;case-sensitive</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoInsertBraces">
<property name="text">
<string>&amp;Automatically insert braces</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -314,12 +314,37 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager, Core::ICore *core
: ICompletionCollector(manager), : ICompletionCollector(manager),
m_core(core), m_core(core),
m_manager(manager), m_manager(manager),
m_caseSensitivity(Qt::CaseSensitive),
m_autoInsertBraces(true),
m_forcedCompletion(false), m_forcedCompletion(false),
m_completionOperator(T_EOF_SYMBOL) m_completionOperator(T_EOF_SYMBOL)
{ } {
}
QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const
{ return m_icons.iconForSymbol(symbol); } {
return m_icons.iconForSymbol(symbol);
}
Qt::CaseSensitivity CppCodeCompletion::caseSensitivity() const
{
return m_caseSensitivity;
}
void CppCodeCompletion::setCaseSensitivity(Qt::CaseSensitivity caseSensitivity)
{
m_caseSensitivity = caseSensitivity;
}
bool CppCodeCompletion::autoInsertBraces() const
{
return m_autoInsertBraces;
}
void CppCodeCompletion::setAutoInsertBraces(bool autoInsertBraces)
{
m_autoInsertBraces = autoInsertBraces;
}
/* /*
Searches beckward for an access operator. Searches beckward for an access operator.
@@ -705,14 +730,14 @@ void CppCodeCompletion::addMacros(const LookupContext &context)
continue; continue;
processed.insert(fn); processed.insert(fn);
if (Document::Ptr doc = context.document(fn)) { if (Document::Ptr doc = context.document(fn)) {
foreach (const Macro macro, doc->definedMacros()) { foreach (const Macro &macro, doc->definedMacros()) {
macroNames.insert(macro.name); macroNames.insert(macro.name);
} }
todo += doc->includedFiles(); todo += doc->includedFiles();
} }
} }
foreach (const QByteArray macroName, macroNames) { foreach (const QByteArray &macroName, macroNames) {
TextEditor::CompletionItem item(this); TextEditor::CompletionItem item(this);
item.m_text = QString::fromLatin1(macroName.constData(), macroName.length()); item.m_text = QString::fromLatin1(macroName.constData(), macroName.length());
item.m_icon = m_icons.macroIcon(); item.m_icon = m_icons.macroIcon();
@@ -889,29 +914,25 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
* *
* Meaning it allows any sequence of lower-case characters to preceed an * Meaning it allows any sequence of lower-case characters to preceed an
* upper-case character. So for example gAC matches getActionController. * upper-case character. So for example gAC matches getActionController.
*
* The match is case-sensitive as soon as at least one upper-case character is
* present.
*/ */
QString keyRegExp; QString keyRegExp;
keyRegExp += QLatin1Char('^'); keyRegExp += QLatin1Char('^');
bool first = true; bool first = true;
Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive;
foreach (const QChar &c, key) { foreach (const QChar &c, key) {
if (c.isLower()) { if (c.isUpper() && !first) {
keyRegExp.append(c); keyRegExp += QLatin1String("[a-z0-9_]*");
} else if (c.isUpper()) { keyRegExp += c;
sensitivity = Qt::CaseSensitive; } else if (m_caseSensitivity == Qt::CaseInsensitive && c.isLower()) {
if (!first) { keyRegExp += QLatin1Char('[');
keyRegExp.append("[a-z0-9_]*"); keyRegExp += c;
} keyRegExp += c.toUpper();
keyRegExp.append(c); keyRegExp += QLatin1Char(']');
} else { } else {
keyRegExp.append(QRegExp::escape(c)); keyRegExp += QRegExp::escape(c);
} }
first = false; first = false;
} }
const QRegExp regExp(keyRegExp, sensitivity); const QRegExp regExp(keyRegExp, Qt::CaseSensitive);
foreach (TextEditor::CompletionItem item, m_completions) { foreach (TextEditor::CompletionItem item, m_completions) {
if (regExp.indexIn(item.m_text) == 0) { if (regExp.indexIn(item.m_text) == 0) {
@@ -962,7 +983,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
//qDebug() << "current symbol:" << overview.prettyName(symbol->name()) //qDebug() << "current symbol:" << overview.prettyName(symbol->name())
//<< overview.prettyType(symbol->type()); //<< overview.prettyType(symbol->type());
if (symbol) { if (m_autoInsertBraces && symbol) {
if (Function *function = symbol->type()->asFunction()) { if (Function *function = symbol->type()->asFunction()) {
// If the member is a function, automatically place the opening parenthesis, // If the member is a function, automatically place the opening parenthesis,
// except when it might take template parameters. // except when it might take template parameters.

View File

@@ -78,6 +78,12 @@ public:
QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const; QIcon iconForSymbol(CPlusPlus::Symbol *symbol) const;
Qt::CaseSensitivity caseSensitivity() const;
void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
bool autoInsertBraces() const;
void setAutoInsertBraces(bool autoInsertBraces);
private: private:
void addKeywords(); void addKeywords();
void addMacros(const CPlusPlus::LookupContext &context); void addMacros(const CPlusPlus::LookupContext &context);
@@ -126,6 +132,8 @@ private:
Core::ICore *m_core; Core::ICore *m_core;
CppModelManager *m_manager; CppModelManager *m_manager;
Qt::CaseSensitivity m_caseSensitivity;
bool m_autoInsertBraces;
bool m_forcedCompletion; bool m_forcedCompletion;

View File

@@ -13,19 +13,21 @@ HEADERS += cpptools_global.h \
cppquickopenfilter.h \ cppquickopenfilter.h \
cppclassesfilter.h \ cppclassesfilter.h \
searchsymbols.h \ searchsymbols.h \
cppfunctionsfilter.h cppfunctionsfilter.h \
completionsettingspage.h
SOURCES += cppquickopenfilter.cpp \ SOURCES += cppquickopenfilter.cpp \
cpptoolseditorsupport.cpp \ cpptoolseditorsupport.cpp \
cppclassesfilter.cpp \ cppclassesfilter.cpp \
searchsymbols.cpp \ searchsymbols.cpp \
cppfunctionsfilter.cpp cppfunctionsfilter.cpp \
completionsettingspage.cpp
# Input # Input
SOURCES += cpptools.cpp \ SOURCES += cpptoolsplugin.cpp \
cppmodelmanager.cpp \ cppmodelmanager.cpp \
cppcodecompletion.cpp \ cppcodecompletion.cpp \
cpphoverhandler.cpp cpphoverhandler.cpp
HEADERS += cpptools.h \ HEADERS += cpptoolsplugin.h \
cppmodelmanager.h \ cppmodelmanager.h \
cppcodecompletion.h \ cppcodecompletion.h \
cpphoverhandler.h \ cpphoverhandler.h \
@@ -33,3 +35,4 @@ HEADERS += cpptools.h \
cpptoolseditorsupport.h \ cpptoolseditorsupport.h \
cpptoolsconstants.h cpptoolsconstants.h
RESOURCES += cpptools.qrc RESOURCES += cpptools.qrc
FORMS += completionsettingspage.ui

View File

@@ -31,7 +31,9 @@
** **
***************************************************************************/ ***************************************************************************/
#include "cpptools.h" #include "cpptoolsplugin.h"
#include "completionsettingspage.h"
#include "cppclassesfilter.h" #include "cppclassesfilter.h"
#include "cppcodecompletion.h" #include "cppcodecompletion.h"
#include "cppfunctionsfilter.h" #include "cppfunctionsfilter.h"
@@ -52,6 +54,7 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QAction> #include <QtGui/QAction>
@@ -84,13 +87,14 @@ bool CppToolsPlugin::initialize(const QStringList & /*arguments*/, QString *)
// Objects // Objects
m_modelManager = new CppModelManager(this); m_modelManager = new CppModelManager(this);
addAutoReleasedObject(m_modelManager); addAutoReleasedObject(m_modelManager);
CppCodeCompletion *cppcodecompletion = new CppCodeCompletion(m_modelManager, m_core); CppCodeCompletion *m_completion = new CppCodeCompletion(m_modelManager, m_core);
addAutoReleasedObject(cppcodecompletion); addAutoReleasedObject(m_completion);
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())); addAutoReleasedObject(new CppClassesFilter(m_modelManager, m_core->editorManager()));
addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, m_core->editorManager())); addAutoReleasedObject(new CppFunctionsFilter(m_modelManager, m_core->editorManager()));
addAutoReleasedObject(new CompletionSettingsPage(m_completion));
// Menus // Menus
Core::IActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS); Core::IActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
@@ -110,6 +114,16 @@ bool CppToolsPlugin::initialize(const QStringList & /*arguments*/, QString *)
mcpptools->addAction(command); mcpptools->addAction(command);
connect(switchAction, SIGNAL(triggered()), this, SLOT(switchHeaderSource())); connect(switchAction, SIGNAL(triggered()), this, SLOT(switchHeaderSource()));
// Restore settings
QSettings *settings = m_core->settings();
settings->beginGroup(QLatin1String("CppTools"));
settings->beginGroup(QLatin1String("Completion"));
const bool caseSensitive = settings->value(QLatin1String("CaseSensitive"), true).toBool();
m_completion->setCaseSensitivity(caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
m_completion->setAutoInsertBraces(settings->value(QLatin1String("AutoInsertBraces"), true).toBool());
settings->endGroup();
settings->endGroup();
return true; return true;
} }
@@ -117,6 +131,18 @@ void CppToolsPlugin::extensionsInitialized()
{ {
} }
void CppToolsPlugin::shutdown()
{
// Save settings
QSettings *settings = m_core->settings();
settings->beginGroup(QLatin1String("CppTools"));
settings->beginGroup(QLatin1String("Completion"));
settings->setValue(QLatin1String("CaseSensitive"), m_completion->caseSensitivity() == Qt::CaseSensitive);
settings->setValue(QLatin1String("AutoInsertBraces"), m_completion->autoInsertBraces());
settings->endGroup();
settings->endGroup();
}
void CppToolsPlugin::switchHeaderSource() void CppToolsPlugin::switchHeaderSource()
{ {
if (!m_core) if (!m_core)
@@ -150,7 +176,12 @@ QFileInfo CppToolsPlugin::findFile(const QDir &dir, const QString &name,
} }
// Figure out file type // Figure out file type
enum FileType { HeaderFile, C_SourceFile, CPP_SourceFile, UnknownType }; enum FileType {
HeaderFile,
C_SourceFile,
CPP_SourceFile,
UnknownType
};
static inline FileType fileType(const Core::MimeDatabase *mimeDatase, const QFileInfo & fi) static inline FileType fileType(const Core::MimeDatabase *mimeDatase, const QFileInfo & fi)
{ {

View File

@@ -64,6 +64,7 @@ public:
bool initialize(const QStringList &arguments, QString *error_message); bool initialize(const QStringList &arguments, QString *error_message);
void extensionsInitialized(); void extensionsInitialized();
void shutdown();
CppModelManager *cppModelManager() { return m_modelManager; } CppModelManager *cppModelManager() { return m_modelManager; }
QString correspondingHeaderOrSource(const QString &fileName) const; QString correspondingHeaderOrSource(const QString &fileName) const;
@@ -77,6 +78,7 @@ private:
Core::ICore *m_core; Core::ICore *m_core;
int m_context; int m_context;
CppModelManager *m_modelManager; CppModelManager *m_modelManager;
CppCodeCompletion *m_completion;
static CppToolsPlugin *m_instance; static CppToolsPlugin *m_instance;
}; };

View File

@@ -1783,22 +1783,25 @@ void ProjectExplorerPlugin::openWithMenuTriggered(QAction *action)
void ProjectExplorerPlugin::updateSessionMenu() void ProjectExplorerPlugin::updateSessionMenu()
{ {
m_sessionMenu->clear(); m_sessionMenu->clear();
QActionGroup *ag = new QActionGroup(m_sessionMenu);
connect(ag, SIGNAL(triggered(QAction *)), this, SLOT(setSession(QAction *)));
const QString &activeSession = m_session->activeSession(); const QString &activeSession = m_session->activeSession();
foreach (const QString &session, m_session->sessions()) { foreach (const QString &session, m_session->sessions()) {
QAction *act = m_sessionMenu->addAction(session, this, SLOT(setSession())); QAction *act = ag->addAction(session);
act->setCheckable(true); act->setCheckable(true);
if (session == activeSession) if (session == activeSession)
act->setChecked(true); act->setChecked(true);
} }
m_sessionMenu->addActions(ag->actions());
m_sessionMenu->addSeparator(); m_sessionMenu->addSeparator();
m_sessionMenu->addAction(m_sessionManagerAction); m_sessionMenu->addAction(m_sessionManagerAction);
m_sessionMenu->setEnabled(true); m_sessionMenu->setEnabled(true);
} }
void ProjectExplorerPlugin::setSession() void ProjectExplorerPlugin::setSession(QAction *action)
{ {
QString session = static_cast<QAction *>(sender())->text(); QString session = action->text();
if (session != m_session->activeSession()) if (session != m_session->activeSession())
m_session->loadSession(session); m_session->loadSession(session);
} }

View File

@@ -151,7 +151,7 @@ private slots:
void populateOpenWithMenu(); void populateOpenWithMenu();
void openWithMenuTriggered(QAction *action); void openWithMenuTriggered(QAction *action);
void updateSessionMenu(); void updateSessionMenu();
void setSession(); void setSession(QAction *action);
void restoreSession(); void restoreSession();
void loadSession(const QString &session); void loadSession(const QString &session);

View File

@@ -40,8 +40,6 @@
#include <qtconcurrent/QtConcurrentTools> #include <qtconcurrent/QtConcurrentTools>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QtGui/QMessageBox>
Q_DECLARE_METATYPE(QuickOpen::IQuickOpenFilter*) Q_DECLARE_METATYPE(QuickOpen::IQuickOpenFilter*)
using namespace QuickOpen; using namespace QuickOpen;

View File

@@ -0,0 +1,5 @@
load(qttest_p4)
include(../shared/shared.pri)
QT = core
SOURCES += tst_ast.cpp

View File

@@ -0,0 +1,73 @@
#include <QtTest>
#include <QtDebug>
#include <Control.h>
#include <Parser.h>
#include <AST.h>
CPLUSPLUS_USE_NAMESPACE
class tst_AST: public QObject
{
Q_OBJECT
Control control;
public:
TranslationUnit *parse(const QByteArray &source,
TranslationUnit::ParseMode mode)
{
StringLiteral *fileId = control.findOrInsertFileName("<stdin>");
TranslationUnit *unit = new TranslationUnit(&control, fileId);
unit->setSource(source.constData(), source.length());
unit->parse(mode);
return unit;
}
TranslationUnit *parseStatement(const QByteArray &source)
{ return parse(source, TranslationUnit::ParseStatement); }
private slots:
void if_statement();
void if_else_statement();
};
void tst_AST::if_statement()
{
QSharedPointer<TranslationUnit> unit(parseStatement("if (a) b;"));
AST *ast = unit->ast();
QVERIFY(ast != 0);
IfStatementAST *stmt = ast->asIfStatement();
QVERIFY(stmt != 0);
QCOMPARE(stmt->if_token, 1U);
QCOMPARE(stmt->lparen_token, 2U);
QVERIFY(stmt->condition != 0);
QCOMPARE(stmt->rparen_token, 4U);
QVERIFY(stmt->statement != 0);
QCOMPARE(stmt->else_token, 0U);
QVERIFY(stmt->else_statement == 0);
}
void tst_AST::if_else_statement()
{
QSharedPointer<TranslationUnit> unit(parseStatement("if (a) b; else c;"));
AST *ast = unit->ast();
QVERIFY(ast != 0);
IfStatementAST *stmt = ast->asIfStatement();
QVERIFY(stmt != 0);
QCOMPARE(stmt->if_token, 1U);
QCOMPARE(stmt->lparen_token, 2U);
QVERIFY(stmt->condition != 0);
QCOMPARE(stmt->rparen_token, 4U);
QVERIFY(stmt->statement != 0);
QCOMPARE(stmt->else_token, 7U);
QVERIFY(stmt->else_statement != 0);
}
QTEST_APPLESS_MAIN(tst_AST)
#include "tst_ast.moc"

View File

@@ -0,0 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = shared ast
CONFIG += ordered

View File

@@ -0,0 +1,4 @@
DEFINES += HAVE_QT CPLUSPLUS_WITH_NAMESPACE
INCLUDEPATH += $$PWD/../../../../shared/cplusplus
LIBS += -L$$PWD -lCPlusPlusTestSupport

View File

@@ -0,0 +1,8 @@
TEMPLATE = lib
TARGET = CPlusPlusTestSupport
CONFIG += static
QT = core
DEFINES += HAVE_QT CPLUSPLUS_WITH_NAMESPACE
include($$PWD/../../../../shared/cplusplus/cplusplus.pri)