Commit 147ab7cc authored by Daniel Teske's avatar Daniel Teske

GenericProject: Also change .include on adding files

Task-number: QTCREATORBUG-12727
Change-Id: I3653f505739ace39cabbb63e227302fc0e71d055
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 8eac129b
......@@ -140,18 +140,24 @@ static QStringList readLines(const QString &absoluteFileName)
}
bool GenericProject::saveRawFileList(const QStringList &rawFileList)
{
bool result = saveRawList(rawFileList, filesFileName());
refresh(GenericProject::Files);
return result;
}
bool GenericProject::saveRawList(const QStringList &rawList, const QString &fileName)
{
// Make sure we can open the file for writing
Utils::FileSaver saver(filesFileName(), QIODevice::Text);
Utils::FileSaver saver(fileName, QIODevice::Text);
if (!saver.hasError()) {
QTextStream stream(saver.file());
foreach (const QString &filePath, rawFileList)
foreach (const QString &filePath, rawList)
stream << filePath << QLatin1Char('\n');
saver.setResult(&stream);
}
if (!saver.finalize(ICore::mainWindow()))
return false;
refresh(GenericProject::Files);
return true;
}
......@@ -163,7 +169,30 @@ bool GenericProject::addFiles(const QStringList &filePaths)
foreach (const QString &filePath, filePaths)
newList.append(baseDir.relativeFilePath(filePath));
return saveRawFileList(newList);
QSet<QString> includes = projectIncludePaths().toSet();
QSet<QString> toAdd;
foreach (const QString &filePaths, filePaths) {
QString directory = QFileInfo(filePaths).absolutePath();
if (!includes.contains(directory)
&& !toAdd.contains(directory))
toAdd << directory;
}
const QDir dir(projectDirectory().toString());
foreach (const QString &path, toAdd) {
QString relative = dir.relativeFilePath(path);
if (relative.isEmpty())
relative = QLatin1String(".");
m_rawProjectIncludePaths.append(relative);
}
bool result = saveRawList(newList, filesFileName());
result &= saveRawList(m_rawProjectIncludePaths, includesFileName());
refresh(GenericProject::Everything);
return result;
}
bool GenericProject::removeFiles(const QStringList &filePaths)
......@@ -214,7 +243,8 @@ void GenericProject::parseProject(RefreshOptions options)
}
if (options & Configuration) {
m_projectIncludePaths = processEntries(readLines(includesFileName()));
m_rawProjectIncludePaths = readLines(includesFileName());
m_projectIncludePaths = processEntries(m_rawProjectIncludePaths);
// TODO: Possibly load some configuration from the project file
//QSettings projectInfo(m_fileName, QSettings::IniFormat);
......
......@@ -89,6 +89,7 @@ protected:
private:
bool saveRawFileList(const QStringList &rawFileList);
bool saveRawList(const QStringList &rawList, const QString &fileName);
void parseProject(RefreshOptions options);
QStringList processEntries(const QStringList &paths,
QHash<QString, QString> *map = 0) const;
......@@ -106,6 +107,7 @@ private:
QStringList m_rawFileList;
QStringList m_files;
QHash<QString, QString> m_rawListEntries;
QStringList m_rawProjectIncludePaths;
QStringList m_projectIncludePaths;
GenericProjectNode *m_rootNode;
......
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