Commit fcbb3898 authored by dt's avatar dt

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
parent 12fd1dbb
......@@ -36,7 +36,10 @@
#include "cmakehighlighter.h"
#include "cmakeeditorfactory.h"
#include "cmakeprojectconstants.h"
#include "cmakeproject.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorconstants.h>
......@@ -55,7 +58,10 @@ CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
: BaseTextEditor(editor),
m_context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
TextEditor::Constants::C_TEXTEDITOR)
{ }
{
connect (this, SIGNAL(changed()),
this, SLOT(markAsChanged()));
}
Core::Context CMakeEditor::context() const
{
......@@ -76,6 +82,30 @@ QString CMakeEditor::id() const
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
//
......
......@@ -53,6 +53,7 @@ class CMakeManager;
class CMakeEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
CMakeEditor(CMakeEditorWidget *);
Core::Context context() const;
......@@ -61,6 +62,9 @@ public:
Core::IEditor *duplicate(QWidget *parent);
QString id() const;
bool isTemporary() const { return false; }
private slots:
void markAsChanged();
void build();
private:
const Core::Context m_context;
};
......
......@@ -97,7 +97,6 @@ CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
: m_manager(manager),
m_fileName(fileName),
m_rootNode(new CMakeProjectNode(m_fileName)),
m_insideFileChanged(false),
m_lastEditor(0)
{
m_file = new CMakeFile(this, fileName);
......@@ -126,15 +125,8 @@ CMakeProject::~CMakeProject()
void CMakeProject::fileChanged(const QString &fileName)
{
Q_UNUSED(fileName)
if (!activeTarget() ||
!activeTarget()->activeBuildConfiguration())
return;
if (m_insideFileChanged)
return;
m_insideFileChanged = true;
changeActiveBuildConfiguration(activeTarget()->activeBuildConfiguration());
m_insideFileChanged = false;
parseCMakeLists();
}
void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
......@@ -201,6 +193,8 @@ bool CMakeProject::parseCMakeLists()
!activeTarget()->activeBuildConfiguration())
return false;
Core::EditorManager::instance()->hideEditorInfoBar("CMakeEditor.RunCMake");
// Find cbp file
CMakeBuildConfiguration *activeBC = activeTarget()->activeBuildConfiguration();
QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory());
......@@ -212,12 +206,17 @@ bool CMakeProject::parseCMakeLists()
//qDebug()<<"Parsing file "<<cbpFile;
if (!cbpparser.parseCbpFile(cbpFile)) {
// TODO report error
qDebug()<<"Parsing failed";
// activeBC->updateToolChain(QString::null);
emit buildTargetsChanged();
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
// activeBC->updateToolChain(cbpparser.compilerName());
m_projectName = cbpparser.projectName();
......@@ -238,12 +237,6 @@ bool CMakeProject::parseCMakeLists()
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_files.clear();
......@@ -279,7 +272,6 @@ bool CMakeProject::parseCMakeLists()
}
cmakeCache.close();
//qDebug()<<"Updating CodeModel";
createUiCodeModelSupport();
if (!activeBC->toolChain())
......@@ -317,12 +309,16 @@ bool CMakeProject::parseCMakeLists()
m_codeModelFuture = modelmanager->updateSourceFiles(pinfo.sourceFiles);
}
}
emit buildTargetsChanged();
emit fileListChanged();
return true;
}
bool CMakeProject::isProjectFile(const QString &fileName)
{
return m_watchedFiles.contains(fileName);
}
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
{
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)));
if (!parseCMakeLists()) // Gets the directory from the active buildconfiguration
......
......@@ -46,9 +46,11 @@
#include <projectexplorer/filewatcher.h>
#include <projectexplorer/buildconfiguration.h>
#include <coreplugin/ifile.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <QtCore/QXmlStreamReader>
#include <QtCore/QFileSystemWatcher>
#include <QtGui/QPushButton>
#include <QtGui/QLineEdit>
......@@ -105,6 +107,8 @@ public:
QString uicCommand() const;
bool isProjectFile(const QString &fileName);
signals:
/// emitted after parsing
void buildTargetsChanged();
......@@ -142,8 +146,7 @@ private:
CMakeProjectNode *m_rootNode;
QStringList m_files;
QList<CMakeBuildTarget> m_buildTargets;
ProjectExplorer::FileWatcher *m_watcher;
bool m_insideFileChanged;
QFileSystemWatcher *m_watcher;
QSet<QString> m_watchedFiles;
QFuture<void> m_codeModelFuture;
......
......@@ -1690,6 +1690,12 @@ void ProjectExplorerPlugin::buildProjectOnly()
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()
{
queue(d->m_session->projectOrder(session()->startupProject()),
......
......@@ -124,6 +124,8 @@ public:
void addExistingFiles(ProjectExplorer::ProjectNode *projectNode, const QStringList &filePaths);
void addExistingFiles(const QStringList &filePaths);
void buildProject(ProjectExplorer::Project *p);
signals:
void aboutToShowContextMenu(ProjectExplorer::Project *project,
ProjectExplorer::Node *node);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment