Actually watch all the project files of a CMake project.

And react to changes to one of them.
This commit is contained in:
dt
2009-09-14 16:09:17 +02:00
parent 0b05bc2e18
commit f291b669c3
2 changed files with 30 additions and 17 deletions

View File

@@ -84,18 +84,20 @@ void CMakeProject::slotActiveBuildConfiguration()
{ {
// Pop up a dialog asking the user to rerun cmake // Pop up a dialog asking the user to rerun cmake
QFileInfo sourceFileInfo(m_fileName); QFileInfo sourceFileInfo(m_fileName);
QStringList needToCreate;
QStringList needToUpdate;
QString cbpFile = CMakeManager::findCbpFile(QDir(buildDirectory(activeBuildConfiguration()))); QString cbpFile = CMakeManager::findCbpFile(QDir(buildDirectory(activeBuildConfiguration())));
QFileInfo cbpFileFi(cbpFile); QFileInfo cbpFileFi(cbpFile);
CMakeOpenProjectWizard::Mode mode; CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
if (!cbpFileFi.exists()) if (!cbpFileFi.exists()) {
mode = CMakeOpenProjectWizard::NeedToCreate; mode = CMakeOpenProjectWizard::NeedToCreate;
else if (cbpFileFi.lastModified() < sourceFileInfo.lastModified()) } else {
mode = CMakeOpenProjectWizard::NeedToUpdate; foreach(const QString &file, m_watchedFiles) {
else if (QFileInfo(file).lastModified() > sourceFileInfo.lastModified()) {
mode = CMakeOpenProjectWizard::Nothing; mode = CMakeOpenProjectWizard::NeedToUpdate;
break;
}
}
}
if (mode != CMakeOpenProjectWizard::Nothing) { if (mode != CMakeOpenProjectWizard::Nothing) {
CMakeOpenProjectWizard copw(m_manager, CMakeOpenProjectWizard copw(m_manager,
@@ -115,10 +117,7 @@ void CMakeProject::fileChanged(const QString &fileName)
if (m_insideFileChanged== true) if (m_insideFileChanged== true)
return; return;
m_insideFileChanged = true; m_insideFileChanged = true;
if (fileName == m_fileName) { slotActiveBuildConfiguration();
// Oh we have changed...
slotActiveBuildConfiguration();
}
m_insideFileChanged = false; m_insideFileChanged = false;
} }
@@ -189,13 +188,27 @@ bool CMakeProject::parseCMakeLists()
QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList(); QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
QSet<QString> projectFiles;
if (cbpparser.hasCMakeFiles()) { if (cbpparser.hasCMakeFiles()) {
fileList.append(cbpparser.cmakeFileList()); fileList.append(cbpparser.cmakeFileList());
foreach(ProjectExplorer::FileNode *node, cbpparser.cmakeFileList())
projectFiles.insert(node->path());
} else { } else {
// Manually add the CMakeLists.txt file // Manually add the CMakeLists.txt file
fileList.append(new ProjectExplorer::FileNode(sourceDirectory() + "/CMakeLists.txt", ProjectExplorer::ProjectFileType, false)); QString cmakeListTxt = sourceDirectory() + "/CMakeLists.txt";
fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, false));
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(); m_files.clear();
foreach (ProjectExplorer::FileNode *fn, fileList) foreach (ProjectExplorer::FileNode *fn, fileList)
m_files.append(fn->path()); m_files.append(fn->path());
@@ -620,16 +633,15 @@ bool CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
setValue(activeBuildConfiguration(), "msvcVersion", copw.msvcVersion()); setValue(activeBuildConfiguration(), "msvcVersion", copw.msvcVersion());
} }
} }
bool result = parseCMakeLists(); // Gets the directory from the active buildconfiguration
if (!result)
return false;
if (!hasUserFile && targets().contains("all")) if (!hasUserFile && targets().contains("all"))
makeStep->setBuildTarget("all", "all", true); makeStep->setBuildTarget("all", "all", true);
m_watcher = new ProjectExplorer::FileWatcher(this); m_watcher = new ProjectExplorer::FileWatcher(this);
connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString))); connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
m_watcher->addFile(m_fileName); bool result = parseCMakeLists(); // Gets the directory from the active buildconfiguration
if (!result)
return false;
connect(this, SIGNAL(activeBuildConfigurationChanged()), connect(this, SIGNAL(activeBuildConfigurationChanged()),
this, SLOT(slotActiveBuildConfiguration())); this, SLOT(slotActiveBuildConfiguration()));

View File

@@ -139,6 +139,7 @@ private:
ProjectExplorer::ToolChain *m_toolChain; ProjectExplorer::ToolChain *m_toolChain;
ProjectExplorer::FileWatcher *m_watcher; ProjectExplorer::FileWatcher *m_watcher;
bool m_insideFileChanged; bool m_insideFileChanged;
QSet<QString> m_watchedFiles;
}; };
class CMakeCbpParser : public QXmlStreamReader class CMakeCbpParser : public QXmlStreamReader