forked from qt-creator/qt-creator
Generic Project: cut common part of path in project explorer
This is necessary, if the project files on a different directory than the source files. In this case, the project explorer will show the full path e.g. in windows starting by C: for each directory until the source files. use-case: some directory |- project directory |- *.creator & *.files & ... generic project files |- source directory |- some sub-directories and the source files Fixes: QTCREATORBUG-19454 Change-Id: I95eee4afdc11adf4281220edc5f6ff29da41a3a5 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
@@ -382,6 +382,23 @@ void GenericProject::parseProject(RefreshOptions options)
|
||||
}
|
||||
}
|
||||
|
||||
QString GenericProject::findCommonSourceRoot(const QStringList &list)
|
||||
{
|
||||
QString root = list.front();
|
||||
for (const QString &item : list) {
|
||||
if (root.length() > item.length())
|
||||
root.truncate(item.length());
|
||||
|
||||
for (int i = 0; i < root.length(); ++i) {
|
||||
if (root[i] != item[i]) {
|
||||
root.truncate(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QFileInfo(root).absolutePath();
|
||||
}
|
||||
|
||||
void GenericProject::refresh(RefreshOptions options)
|
||||
{
|
||||
emitParsingStarted();
|
||||
@@ -390,11 +407,14 @@ void GenericProject::refresh(RefreshOptions options)
|
||||
if (options & Files) {
|
||||
auto newRoot = std::make_unique<GenericProjectNode>(this);
|
||||
|
||||
// find the common base directory of all source files
|
||||
Utils::FileName baseDir = FileName::fromFileInfo(QFileInfo(findCommonSourceRoot(m_files)));
|
||||
|
||||
for (const QString &f : m_files) {
|
||||
FileType fileType = FileType::Source; // ### FIXME
|
||||
if (f.endsWith(".qrc"))
|
||||
fileType = FileType::Resource;
|
||||
newRoot->addNestedNode(std::make_unique<FileNode>(FileName::fromString(f), fileType));
|
||||
newRoot->addNestedNode(std::make_unique<FileNode>(FileName::fromString(f), fileType), baseDir);
|
||||
}
|
||||
|
||||
newRoot->addNestedNode(std::make_unique<FileNode>(FileName::fromString(m_filesFileName),
|
||||
@@ -408,6 +428,7 @@ void GenericProject::refresh(RefreshOptions options)
|
||||
newRoot->addNestedNode(std::make_unique<FileNode>(FileName::fromString(m_cflagsFileName),
|
||||
FileType::Project));
|
||||
|
||||
newRoot->compress();
|
||||
setRootProjectNode(std::move(newRoot));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user