Commit b170e3ba authored by Kevin Michel's avatar Kevin Michel Committed by Thorbjørn Lindeijer
Browse files

Enable 'Remove file...' on Generic project



Merge-request: 783
Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
parent a39d7e8d
...@@ -168,19 +168,16 @@ static QStringList readLines(const QString &absoluteFileName) ...@@ -168,19 +168,16 @@ static QStringList readLines(const QString &absoluteFileName)
return lines; return lines;
} }
bool GenericProject::addFiles(const QStringList &filePaths) bool GenericProject::setFiles(const QStringList &filePaths)
{ {
// Make sure we can open the file for writing // Make sure we can open the file for writing
QFile file(filesFileName()); QFile file(filesFileName());
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return false; return false;
QStringList newFileList = m_files;
newFileList.append(filePaths);
QTextStream stream(&file); QTextStream stream(&file);
QDir baseDir(QFileInfo(m_fileName).dir()); QDir baseDir(QFileInfo(m_fileName).dir());
foreach (const QString &filePath, newFileList) foreach (const QString &filePath, filePaths)
stream << baseDir.relativeFilePath(filePath) << QLatin1Char('\n'); stream << baseDir.relativeFilePath(filePath) << QLatin1Char('\n');
file.close(); file.close();
...@@ -188,6 +185,24 @@ bool GenericProject::addFiles(const QStringList &filePaths) ...@@ -188,6 +185,24 @@ bool GenericProject::addFiles(const QStringList &filePaths)
return true; return true;
} }
bool GenericProject::addFiles(const QStringList &filePaths)
{
QStringList newFileList = m_files;
newFileList.append(filePaths);
return setFiles(newFileList);
}
bool GenericProject::removeFiles(const QStringList &filePaths)
{
// Removing using set allows O(n.log(n)) behavior
QSet<QString> newFileSet = m_files.toSet();
newFileSet.subtract(filePaths.toSet());
QStringList newFileList = newFileSet.toList();
return setFiles(newFileList);
}
void GenericProject::parseProject(RefreshOptions options) void GenericProject::parseProject(RefreshOptions options)
{ {
if (options & Files) if (options & Files)
......
...@@ -94,7 +94,9 @@ public: ...@@ -94,7 +94,9 @@ public:
QString buildParser(const QString &buildConfiguration) const; QString buildParser(const QString &buildConfiguration) const;
ProjectExplorer::ToolChain *toolChain() const; ProjectExplorer::ToolChain *toolChain() const;
bool setFiles(const QStringList &filePaths);
bool addFiles(const QStringList &filePaths); bool addFiles(const QStringList &filePaths);
bool removeFiles(const QStringList &filePaths);
enum RefreshOptions { enum RefreshOptions {
Files = 0x01, Files = 0x01,
......
...@@ -167,7 +167,8 @@ bool GenericProjectNode::hasTargets() const ...@@ -167,7 +167,8 @@ bool GenericProjectNode::hasTargets() const
QList<ProjectExplorer::ProjectNode::ProjectAction> GenericProjectNode::supportedActions() const QList<ProjectExplorer::ProjectNode::ProjectAction> GenericProjectNode::supportedActions() const
{ {
return QList<ProjectAction>() return QList<ProjectAction>()
<< AddFile; << AddFile
<< RemoveFile;
} }
bool GenericProjectNode::addSubProjects(const QStringList &proFilePaths) bool GenericProjectNode::addSubProjects(const QStringList &proFilePaths)
...@@ -195,9 +196,9 @@ bool GenericProjectNode::removeFiles(const ProjectExplorer::FileType fileType, ...@@ -195,9 +196,9 @@ bool GenericProjectNode::removeFiles(const ProjectExplorer::FileType fileType,
const QStringList &filePaths, QStringList *notRemoved) const QStringList &filePaths, QStringList *notRemoved)
{ {
Q_UNUSED(fileType); Q_UNUSED(fileType);
Q_UNUSED(filePaths);
Q_UNUSED(notRemoved); Q_UNUSED(notRemoved);
return false;
return m_project->removeFiles(filePaths);
} }
bool GenericProjectNode::renameFile(const ProjectExplorer::FileType fileType, bool GenericProjectNode::renameFile(const ProjectExplorer::FileType fileType,
......
Supports Markdown
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