forked from qt-creator/qt-creator
CMakeProjectManager: Change editing cmake files to not pop up a dialog
Stop watching the cmake files for changes, instead watch the cbp file for changes. Warn the user that changes in the CMakeLists.txt via a infobar. Fixes or obsolets a few bug reports: Task-Nr: QTCREATORBUG-3123 Task-Nr: QTCREATORBUG-3353 Task-Nr: QTCREATORBUG-2487
This commit is contained in:
@@ -36,7 +36,10 @@
|
|||||||
#include "cmakehighlighter.h"
|
#include "cmakehighlighter.h"
|
||||||
#include "cmakeeditorfactory.h"
|
#include "cmakeeditorfactory.h"
|
||||||
#include "cmakeprojectconstants.h"
|
#include "cmakeprojectconstants.h"
|
||||||
|
#include "cmakeproject.h"
|
||||||
|
|
||||||
|
#include <projectexplorer/projectexplorer.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
#include <texteditor/texteditoractionhandler.h>
|
#include <texteditor/texteditoractionhandler.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
@@ -55,7 +58,10 @@ CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
|
|||||||
: BaseTextEditor(editor),
|
: BaseTextEditor(editor),
|
||||||
m_context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
|
m_context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
|
||||||
TextEditor::Constants::C_TEXTEDITOR)
|
TextEditor::Constants::C_TEXTEDITOR)
|
||||||
{ }
|
{
|
||||||
|
connect (this, SIGNAL(changed()),
|
||||||
|
this, SLOT(markAsChanged()));
|
||||||
|
}
|
||||||
|
|
||||||
Core::Context CMakeEditor::context() const
|
Core::Context CMakeEditor::context() const
|
||||||
{
|
{
|
||||||
@@ -76,6 +82,30 @@ QString CMakeEditor::id() const
|
|||||||
return QLatin1String(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
|
return QLatin1String(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMakeEditor::markAsChanged()
|
||||||
|
{
|
||||||
|
Core::EditorManager::instance()->
|
||||||
|
showEditorInfoBar(QLatin1String("CMakeEditor.RunCMake"),
|
||||||
|
tr("Changes to cmake files are shown in the project tree after building."),
|
||||||
|
tr("Build now"),
|
||||||
|
this, SLOT(build()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMakeEditor::build()
|
||||||
|
{
|
||||||
|
QList<ProjectExplorer::Project *> projects =
|
||||||
|
ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects();
|
||||||
|
foreach (ProjectExplorer::Project *p, projects) {
|
||||||
|
CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(p);
|
||||||
|
if (cmakeProject) {
|
||||||
|
if (cmakeProject->isProjectFile(file()->fileName())) {
|
||||||
|
ProjectExplorer::ProjectExplorerPlugin::instance()->buildProject(cmakeProject);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// CMakeEditor
|
// CMakeEditor
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class CMakeManager;
|
|||||||
|
|
||||||
class CMakeEditor : public TextEditor::BaseTextEditor
|
class CMakeEditor : public TextEditor::BaseTextEditor
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CMakeEditor(CMakeEditorWidget *);
|
CMakeEditor(CMakeEditorWidget *);
|
||||||
Core::Context context() const;
|
Core::Context context() const;
|
||||||
@@ -61,6 +62,9 @@ public:
|
|||||||
Core::IEditor *duplicate(QWidget *parent);
|
Core::IEditor *duplicate(QWidget *parent);
|
||||||
QString id() const;
|
QString id() const;
|
||||||
bool isTemporary() const { return false; }
|
bool isTemporary() const { return false; }
|
||||||
|
private slots:
|
||||||
|
void markAsChanged();
|
||||||
|
void build();
|
||||||
private:
|
private:
|
||||||
const Core::Context m_context;
|
const Core::Context m_context;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
|
|||||||
: m_manager(manager),
|
: m_manager(manager),
|
||||||
m_fileName(fileName),
|
m_fileName(fileName),
|
||||||
m_rootNode(new CMakeProjectNode(m_fileName)),
|
m_rootNode(new CMakeProjectNode(m_fileName)),
|
||||||
m_insideFileChanged(false),
|
|
||||||
m_lastEditor(0)
|
m_lastEditor(0)
|
||||||
{
|
{
|
||||||
m_file = new CMakeFile(this, fileName);
|
m_file = new CMakeFile(this, fileName);
|
||||||
@@ -126,15 +125,8 @@ CMakeProject::~CMakeProject()
|
|||||||
void CMakeProject::fileChanged(const QString &fileName)
|
void CMakeProject::fileChanged(const QString &fileName)
|
||||||
{
|
{
|
||||||
Q_UNUSED(fileName)
|
Q_UNUSED(fileName)
|
||||||
if (!activeTarget() ||
|
|
||||||
!activeTarget()->activeBuildConfiguration())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (m_insideFileChanged)
|
parseCMakeLists();
|
||||||
return;
|
|
||||||
m_insideFileChanged = true;
|
|
||||||
changeActiveBuildConfiguration(activeTarget()->activeBuildConfiguration());
|
|
||||||
m_insideFileChanged = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
|
void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
|
||||||
@@ -201,6 +193,8 @@ bool CMakeProject::parseCMakeLists()
|
|||||||
!activeTarget()->activeBuildConfiguration())
|
!activeTarget()->activeBuildConfiguration())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Core::EditorManager::instance()->hideEditorInfoBar("CMakeEditor.RunCMake");
|
||||||
|
|
||||||
// Find cbp file
|
// Find cbp file
|
||||||
CMakeBuildConfiguration *activeBC = activeTarget()->activeBuildConfiguration();
|
CMakeBuildConfiguration *activeBC = activeTarget()->activeBuildConfiguration();
|
||||||
QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory());
|
QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory());
|
||||||
@@ -212,12 +206,17 @@ bool CMakeProject::parseCMakeLists()
|
|||||||
//qDebug()<<"Parsing file "<<cbpFile;
|
//qDebug()<<"Parsing file "<<cbpFile;
|
||||||
if (!cbpparser.parseCbpFile(cbpFile)) {
|
if (!cbpparser.parseCbpFile(cbpFile)) {
|
||||||
// TODO report error
|
// TODO report error
|
||||||
qDebug()<<"Parsing failed";
|
|
||||||
// activeBC->updateToolChain(QString::null);
|
|
||||||
emit buildTargetsChanged();
|
emit buildTargetsChanged();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (const QString &file, m_watcher->files())
|
||||||
|
if (file != cbpFile)
|
||||||
|
m_watcher->removePath(file);
|
||||||
|
|
||||||
|
// how can we ensure that it is completly written?
|
||||||
|
m_watcher->addPath(cbpFile);
|
||||||
|
|
||||||
// ToolChain
|
// ToolChain
|
||||||
// activeBC->updateToolChain(cbpparser.compilerName());
|
// activeBC->updateToolChain(cbpparser.compilerName());
|
||||||
m_projectName = cbpparser.projectName();
|
m_projectName = cbpparser.projectName();
|
||||||
@@ -238,12 +237,6 @@ bool CMakeProject::parseCMakeLists()
|
|||||||
projectFiles.insert(cmakeListTxt);
|
projectFiles.insert(cmakeListTxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<QString> added = projectFiles;
|
|
||||||
added.subtract(m_watchedFiles);
|
|
||||||
foreach(const QString &add, added)
|
|
||||||
m_watcher->addFile(add);
|
|
||||||
foreach(const QString &remove, m_watchedFiles.subtract(projectFiles))
|
|
||||||
m_watcher->removeFile(remove);
|
|
||||||
m_watchedFiles = projectFiles;
|
m_watchedFiles = projectFiles;
|
||||||
|
|
||||||
m_files.clear();
|
m_files.clear();
|
||||||
@@ -279,7 +272,6 @@ bool CMakeProject::parseCMakeLists()
|
|||||||
}
|
}
|
||||||
cmakeCache.close();
|
cmakeCache.close();
|
||||||
|
|
||||||
//qDebug()<<"Updating CodeModel";
|
|
||||||
createUiCodeModelSupport();
|
createUiCodeModelSupport();
|
||||||
|
|
||||||
if (!activeBC->toolChain())
|
if (!activeBC->toolChain())
|
||||||
@@ -317,12 +309,16 @@ bool CMakeProject::parseCMakeLists()
|
|||||||
m_codeModelFuture = modelmanager->updateSourceFiles(pinfo.sourceFiles);
|
m_codeModelFuture = modelmanager->updateSourceFiles(pinfo.sourceFiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit buildTargetsChanged();
|
emit buildTargetsChanged();
|
||||||
emit fileListChanged();
|
emit fileListChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CMakeProject::isProjectFile(const QString &fileName)
|
||||||
|
{
|
||||||
|
return m_watchedFiles.contains(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
|
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
|
||||||
{
|
{
|
||||||
return m_buildTargets;
|
return m_buildTargets;
|
||||||
@@ -562,7 +558,7 @@ bool CMakeProject::fromMap(const QVariantMap &map)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_watcher = new ProjectExplorer::FileWatcher(this);
|
m_watcher = new QFileSystemWatcher(this);
|
||||||
connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
|
connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
|
||||||
|
|
||||||
if (!parseCMakeLists()) // Gets the directory from the active buildconfiguration
|
if (!parseCMakeLists()) // Gets the directory from the active buildconfiguration
|
||||||
|
|||||||
@@ -46,9 +46,11 @@
|
|||||||
#include <projectexplorer/filewatcher.h>
|
#include <projectexplorer/filewatcher.h>
|
||||||
#include <projectexplorer/buildconfiguration.h>
|
#include <projectexplorer/buildconfiguration.h>
|
||||||
#include <coreplugin/ifile.h>
|
#include <coreplugin/ifile.h>
|
||||||
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
|
|
||||||
#include <QtCore/QXmlStreamReader>
|
#include <QtCore/QXmlStreamReader>
|
||||||
|
#include <QtCore/QFileSystemWatcher>
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
#include <QtGui/QLineEdit>
|
#include <QtGui/QLineEdit>
|
||||||
|
|
||||||
@@ -105,6 +107,8 @@ public:
|
|||||||
|
|
||||||
QString uicCommand() const;
|
QString uicCommand() const;
|
||||||
|
|
||||||
|
bool isProjectFile(const QString &fileName);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/// emitted after parsing
|
/// emitted after parsing
|
||||||
void buildTargetsChanged();
|
void buildTargetsChanged();
|
||||||
@@ -142,8 +146,7 @@ private:
|
|||||||
CMakeProjectNode *m_rootNode;
|
CMakeProjectNode *m_rootNode;
|
||||||
QStringList m_files;
|
QStringList m_files;
|
||||||
QList<CMakeBuildTarget> m_buildTargets;
|
QList<CMakeBuildTarget> m_buildTargets;
|
||||||
ProjectExplorer::FileWatcher *m_watcher;
|
QFileSystemWatcher *m_watcher;
|
||||||
bool m_insideFileChanged;
|
|
||||||
QSet<QString> m_watchedFiles;
|
QSet<QString> m_watchedFiles;
|
||||||
QFuture<void> m_codeModelFuture;
|
QFuture<void> m_codeModelFuture;
|
||||||
|
|
||||||
|
|||||||
@@ -1690,6 +1690,12 @@ void ProjectExplorerPlugin::buildProjectOnly()
|
|||||||
queue(QList<Project *>() << session()->startupProject(), QStringList() << Constants::BUILDSTEPS_BUILD);
|
queue(QList<Project *>() << session()->startupProject(), QStringList() << Constants::BUILDSTEPS_BUILD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectExplorerPlugin::buildProject(ProjectExplorer::Project *p)
|
||||||
|
{
|
||||||
|
queue(d->m_session->projectOrder(p),
|
||||||
|
QStringList() << Constants::BUILDSTEPS_BUILD);
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectExplorerPlugin::buildProject()
|
void ProjectExplorerPlugin::buildProject()
|
||||||
{
|
{
|
||||||
queue(d->m_session->projectOrder(session()->startupProject()),
|
queue(d->m_session->projectOrder(session()->startupProject()),
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ public:
|
|||||||
void addExistingFiles(ProjectExplorer::ProjectNode *projectNode, const QStringList &filePaths);
|
void addExistingFiles(ProjectExplorer::ProjectNode *projectNode, const QStringList &filePaths);
|
||||||
void addExistingFiles(const QStringList &filePaths);
|
void addExistingFiles(const QStringList &filePaths);
|
||||||
|
|
||||||
|
void buildProject(ProjectExplorer::Project *p);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void aboutToShowContextMenu(ProjectExplorer::Project *project,
|
void aboutToShowContextMenu(ProjectExplorer::Project *project,
|
||||||
ProjectExplorer::Node *node);
|
ProjectExplorer::Node *node);
|
||||||
|
|||||||
Reference in New Issue
Block a user