forked from qt-creator/qt-creator
CMakeProjectManager: Add Ui completion
That is get code completion without saving the file or building. Task-Nr: QTCREATORBUG-1657
This commit is contained in:
@@ -18,5 +18,6 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General
|
||||
<dependency name="ProjectExplorer" version="2.1.81"/>
|
||||
<dependency name="CppTools" version="2.1.81"/>
|
||||
<dependency name="CppEditor" version="2.1.81"/>
|
||||
<dependency name="Designer" version="2.1.81"/>
|
||||
</dependencyList>
|
||||
</plugin>
|
||||
|
||||
@@ -35,14 +35,19 @@
|
||||
#include "makestep.h"
|
||||
#include "cmakeopenprojectwizard.h"
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakeuicodemodelsupport.h"
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/buildenvironmentwidget.h>
|
||||
#include <projectexplorer/buildsteplist.h>
|
||||
#include <projectexplorer/buildmanager.h>
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <designer/formwindoweditor.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QDebug>
|
||||
@@ -74,7 +79,8 @@ CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
|
||||
m_fileName(fileName),
|
||||
m_rootNode(new CMakeProjectNode(m_fileName)),
|
||||
m_insideFileChanged(false),
|
||||
m_targetFactory(new CMakeTargetFactory(this))
|
||||
m_targetFactory(new CMakeTargetFactory(this)),
|
||||
m_lastEditor(0)
|
||||
{
|
||||
m_file = new CMakeFile(this, fileName);
|
||||
|
||||
@@ -84,6 +90,17 @@ CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
|
||||
|
||||
CMakeProject::~CMakeProject()
|
||||
{
|
||||
// Remove CodeModel support
|
||||
CppTools::CppModelManagerInterface *modelManager
|
||||
= ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
|
||||
QMap<QString, CMakeUiCodeModelSupport *>::const_iterator it, end;
|
||||
it = m_uiCodeModelSupport.constBegin();
|
||||
end = m_uiCodeModelSupport.constEnd();
|
||||
for (; it!=end; ++it) {
|
||||
modelManager->removeEditorSupport(it.value());
|
||||
delete it.value();
|
||||
}
|
||||
|
||||
m_codeModelFuture.cancel();
|
||||
delete m_rootNode;
|
||||
}
|
||||
@@ -229,7 +246,24 @@ bool CMakeProject::parseCMakeLists()
|
||||
// qDebug()<<"";
|
||||
// }
|
||||
|
||||
|
||||
// TOOD this code ain't very pretty ...
|
||||
m_uicCommand.clear();
|
||||
QFile cmakeCache(activeBC->buildDirectory() + "/CMakeCache.txt");
|
||||
cmakeCache.open(QIODevice::ReadOnly);
|
||||
while (!cmakeCache.atEnd()) {
|
||||
QString line = cmakeCache.readLine();
|
||||
if (line.startsWith("QT_UIC_EXECUTABLE")) {
|
||||
if (int pos = line.indexOf('=')) {
|
||||
m_uicCommand = line.mid(pos + 1).trimmed();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
cmakeCache.close();
|
||||
|
||||
//qDebug()<<"Updating CodeModel";
|
||||
createUiCodeModelSupport();
|
||||
|
||||
QStringList allIncludePaths;
|
||||
QStringList allFrameworkPaths;
|
||||
@@ -533,6 +567,16 @@ bool CMakeProject::fromMap(const QVariantMap &map)
|
||||
connect(t, SIGNAL(environmentChanged()),
|
||||
this, SLOT(changeEnvironment()));
|
||||
}
|
||||
|
||||
connect(Core::EditorManager::instance(), SIGNAL(editorAboutToClose(Core::IEditor*)),
|
||||
this, SLOT(editorAboutToClose(Core::IEditor*)));
|
||||
|
||||
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||
this, SLOT(editorChanged(Core::IEditor*)));
|
||||
|
||||
connect(ProjectExplorer::ProjectExplorerPlugin::instance()->buildManager(), SIGNAL(buildStateChanged(ProjectExplorer::Project*)),
|
||||
this, SLOT(buildStateChanged(ProjectExplorer::Project*)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -544,6 +588,140 @@ CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title)
|
||||
return CMakeBuildTarget();
|
||||
}
|
||||
|
||||
QString CMakeProject::uicCommand() const
|
||||
{
|
||||
return m_uicCommand;
|
||||
}
|
||||
|
||||
QString CMakeProject::uiHeaderFile(const QString &uiFile)
|
||||
{
|
||||
QDir srcDirRoot = QDir(projectDirectory());
|
||||
QString relativePath = srcDirRoot.relativeFilePath(uiFile);
|
||||
QDir buildDir = QDir(activeTarget()->activeBuildConfiguration()->buildDirectory());
|
||||
QString uiHeaderFilePath = buildDir.absoluteFilePath(relativePath);
|
||||
|
||||
QFileInfo fi(uiHeaderFilePath);
|
||||
uiHeaderFilePath = fi.absolutePath();
|
||||
uiHeaderFilePath += QLatin1String("/ui_");
|
||||
uiHeaderFilePath += fi.completeBaseName();
|
||||
uiHeaderFilePath += QLatin1String(".h");
|
||||
return QDir::cleanPath(uiHeaderFilePath);
|
||||
}
|
||||
|
||||
void CMakeProject::createUiCodeModelSupport()
|
||||
{
|
||||
// qDebug()<<"creatUiCodeModelSupport()";
|
||||
CppTools::CppModelManagerInterface *modelManager
|
||||
= ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
|
||||
|
||||
// First move all to
|
||||
QMap<QString, CMakeUiCodeModelSupport *> oldCodeModelSupport;
|
||||
oldCodeModelSupport = m_uiCodeModelSupport;
|
||||
m_uiCodeModelSupport.clear();
|
||||
|
||||
// Find all ui files
|
||||
foreach (const QString &uiFile, m_files) {
|
||||
if (uiFile.endsWith(".ui")) {
|
||||
// UI file, not convert to
|
||||
QString uiHeaderFilePath = uiHeaderFile(uiFile);
|
||||
QMap<QString, CMakeUiCodeModelSupport *>::iterator it
|
||||
= oldCodeModelSupport.find(uiFile);
|
||||
if (it != oldCodeModelSupport.end()) {
|
||||
// qDebug()<<"updated old codemodelsupport";
|
||||
CMakeUiCodeModelSupport *cms = it.value();
|
||||
cms->setFileName(uiHeaderFilePath);
|
||||
m_uiCodeModelSupport.insert(it.key(), cms);
|
||||
oldCodeModelSupport.erase(it);
|
||||
} else {
|
||||
// qDebug()<<"adding new codemodelsupport";
|
||||
CMakeUiCodeModelSupport *cms = new CMakeUiCodeModelSupport(modelManager, this, uiFile, uiHeaderFilePath);
|
||||
m_uiCodeModelSupport.insert(uiFile, cms);
|
||||
modelManager->addEditorSupport(cms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove old
|
||||
QMap<QString, CMakeUiCodeModelSupport *>::const_iterator it, end;
|
||||
end = oldCodeModelSupport.constEnd();
|
||||
for (it = oldCodeModelSupport.constBegin(); it!=end; ++it) {
|
||||
modelManager->removeEditorSupport(it.value());
|
||||
delete it.value();
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeProject::updateCodeModelSupportFromEditor(const QString &uiFileName,
|
||||
const QString &contents)
|
||||
{
|
||||
const QMap<QString, CMakeUiCodeModelSupport *>::const_iterator it =
|
||||
m_uiCodeModelSupport.constFind(uiFileName);
|
||||
if (it != m_uiCodeModelSupport.constEnd())
|
||||
it.value()->updateFromEditor(contents);
|
||||
}
|
||||
|
||||
void CMakeProject::editorChanged(Core::IEditor *editor)
|
||||
{
|
||||
// Handle old editor
|
||||
Designer::FormWindowEditor *lastFormEditor = qobject_cast<Designer::FormWindowEditor *>(m_lastEditor);
|
||||
if (lastFormEditor) {
|
||||
disconnect(lastFormEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
|
||||
|
||||
if (m_dirtyUic) {
|
||||
const QString contents = lastFormEditor->contents();
|
||||
updateCodeModelSupportFromEditor(lastFormEditor->file()->fileName(), contents);
|
||||
m_dirtyUic = false;
|
||||
}
|
||||
}
|
||||
|
||||
m_lastEditor = editor;
|
||||
|
||||
// Handle new editor
|
||||
if (Designer::FormWindowEditor *fw = qobject_cast<Designer::FormWindowEditor *>(editor))
|
||||
connect(fw, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
|
||||
}
|
||||
|
||||
void CMakeProject::editorAboutToClose(Core::IEditor *editor)
|
||||
{
|
||||
if (m_lastEditor == editor) {
|
||||
// Oh no our editor is going to be closed
|
||||
// get the content first
|
||||
Designer::FormWindowEditor *lastEditor = qobject_cast<Designer::FormWindowEditor *>(m_lastEditor);
|
||||
if (lastEditor) {
|
||||
disconnect(lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
|
||||
if (m_dirtyUic) {
|
||||
const QString contents = lastEditor->contents();
|
||||
updateCodeModelSupportFromEditor(lastEditor->file()->fileName(), contents);
|
||||
m_dirtyUic = false;
|
||||
}
|
||||
}
|
||||
m_lastEditor = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeProject::uiEditorContentsChanged()
|
||||
{
|
||||
// cast sender, get filename
|
||||
if (m_dirtyUic)
|
||||
return;
|
||||
Designer::FormWindowEditor *fw = qobject_cast<Designer::FormWindowEditor *>(sender());
|
||||
if (!fw)
|
||||
return;
|
||||
m_dirtyUic = true;
|
||||
}
|
||||
|
||||
void CMakeProject::buildStateChanged(ProjectExplorer::Project *project)
|
||||
{
|
||||
if (project == this) {
|
||||
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->buildManager()->isBuilding(this)) {
|
||||
QMap<QString, CMakeUiCodeModelSupport *>::const_iterator it, end;
|
||||
end = m_uiCodeModelSupport.constEnd();
|
||||
for (it = m_uiCodeModelSupport.constBegin(); it != end; ++it) {
|
||||
it.value()->updateFromBuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CMakeFile
|
||||
|
||||
CMakeFile::CMakeFile(CMakeProject *parent, QString fileName)
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <projectexplorer/filewatcher.h>
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
#include <coreplugin/ifile.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
#include <QtCore/QXmlStreamReader>
|
||||
#include <QtGui/QPushButton>
|
||||
@@ -53,6 +54,7 @@ namespace Internal {
|
||||
|
||||
class CMakeFile;
|
||||
class CMakeBuildSettingsWidget;
|
||||
class CMakeUiCodeModelSupport;
|
||||
|
||||
struct CMakeBuildTarget
|
||||
{
|
||||
@@ -100,6 +102,8 @@ public:
|
||||
|
||||
bool parseCMakeLists();
|
||||
|
||||
QString uicCommand() const;
|
||||
|
||||
signals:
|
||||
/// emitted after parsing
|
||||
void buildTargetsChanged();
|
||||
@@ -115,15 +119,23 @@ private slots:
|
||||
void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
|
||||
void targetAdded(ProjectExplorer::Target *);
|
||||
|
||||
void editorChanged(Core::IEditor *editor);
|
||||
void editorAboutToClose(Core::IEditor *editor);
|
||||
void uiEditorContentsChanged();
|
||||
void buildStateChanged(ProjectExplorer::Project *project);
|
||||
private:
|
||||
void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
|
||||
void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
|
||||
ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
|
||||
void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
|
||||
void createUiCodeModelSupport();
|
||||
QString uiHeaderFile(const QString &uiFile);
|
||||
|
||||
CMakeManager *m_manager;
|
||||
QString m_fileName;
|
||||
CMakeFile *m_file;
|
||||
QString m_projectName;
|
||||
QString m_uicCommand;
|
||||
|
||||
// TODO probably need a CMake specific node structure
|
||||
CMakeProjectNode *m_rootNode;
|
||||
@@ -134,6 +146,10 @@ private:
|
||||
QSet<QString> m_watchedFiles;
|
||||
CMakeTargetFactory *m_targetFactory;
|
||||
QFuture<void> m_codeModelFuture;
|
||||
|
||||
QMap<QString, CMakeUiCodeModelSupport *> m_uiCodeModelSupport;
|
||||
Core::IEditor *m_lastEditor;
|
||||
bool m_dirtyUic;
|
||||
};
|
||||
|
||||
class CMakeCbpParser : public QXmlStreamReader
|
||||
|
||||
@@ -14,7 +14,8 @@ HEADERS = cmakeproject.h \
|
||||
cmakebuildconfiguration.h \
|
||||
cmakeeditorfactory.h \
|
||||
cmakeeditor.h \
|
||||
cmakehighlighter.h
|
||||
cmakehighlighter.h \
|
||||
cmakeuicodemodelsupport.h
|
||||
SOURCES = cmakeproject.cpp \
|
||||
cmakeprojectplugin.cpp \
|
||||
cmakeprojectmanager.cpp \
|
||||
@@ -26,7 +27,8 @@ SOURCES = cmakeproject.cpp \
|
||||
cmakebuildconfiguration.cpp \
|
||||
cmakeeditorfactory.cpp \
|
||||
cmakeeditor.cpp \
|
||||
cmakehighlighter.cpp
|
||||
cmakehighlighter.cpp \
|
||||
cmakeuicodemodelsupport.cpp
|
||||
RESOURCES += cmakeproject.qrc
|
||||
FORMS +=
|
||||
|
||||
|
||||
@@ -2,3 +2,4 @@ include(../../plugins/projectexplorer/projectexplorer.pri)
|
||||
include(../../plugins/cpptools/cpptools.pri)
|
||||
include(../../plugins/cppeditor/cppeditor.pri)
|
||||
include(../../plugins/texteditor/texteditor.pri)
|
||||
include(../../plugins/designer/designer.pri)
|
||||
|
||||
64
src/plugins/cmakeprojectmanager/cmakeuicodemodelsupport.cpp
Normal file
64
src/plugins/cmakeprojectmanager/cmakeuicodemodelsupport.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** 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 "cmakeuicodemodelsupport.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmaketarget.h"
|
||||
#include "cmakebuildconfiguration.h"
|
||||
|
||||
#include <QtCore/QProcess>
|
||||
|
||||
using namespace CMakeProjectManager;
|
||||
using namespace Internal;
|
||||
|
||||
CMakeUiCodeModelSupport::CMakeUiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager,
|
||||
CMakeProject *project,
|
||||
const QString &source,
|
||||
const QString &uiHeaderFile)
|
||||
: CppTools::UiCodeModelSupport(modelmanager, source, uiHeaderFile),
|
||||
m_project(project)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CMakeUiCodeModelSupport::~CMakeUiCodeModelSupport()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString CMakeUiCodeModelSupport::uicCommand() const
|
||||
{
|
||||
return m_project->uicCommand();
|
||||
}
|
||||
|
||||
QStringList CMakeUiCodeModelSupport::environment() const
|
||||
{
|
||||
CMakeBuildConfiguration *bc = m_project->activeTarget()->activeBuildConfiguration();
|
||||
return bc->environment().toStringList();
|
||||
}
|
||||
61
src/plugins/cmakeprojectmanager/cmakeuicodemodelsupport.h
Normal file
61
src/plugins/cmakeprojectmanager/cmakeuicodemodelsupport.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** 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 CMAKEUICODEMODELSUPPORT_H
|
||||
#define CMAKEUICODEMODELSUPPORT_H
|
||||
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
#include <cpptools/uicodecompletionsupport.h>
|
||||
|
||||
#include <QtCore/QDateTime>
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class CMakeProject;
|
||||
|
||||
class CMakeUiCodeModelSupport : public CppTools::UiCodeModelSupport
|
||||
{
|
||||
public:
|
||||
CMakeUiCodeModelSupport(CppTools::CppModelManagerInterface *modelmanager,
|
||||
CMakeProject *project,
|
||||
const QString &sourceFile,
|
||||
const QString &uiHeaderFile);
|
||||
~CMakeUiCodeModelSupport();
|
||||
protected:
|
||||
virtual QString uicCommand() const;
|
||||
virtual QStringList environment() const;
|
||||
private:
|
||||
CMakeProject *m_project;
|
||||
};
|
||||
|
||||
|
||||
} // Internal
|
||||
} // Qt4ProjectManager
|
||||
#endif // CMAKEUICODEMODELSUPPORT_H
|
||||
Reference in New Issue
Block a user