forked from qt-creator/qt-creator
Utils: add FilePath::completeBaseName
Removing some FilePath::toFileInfo() calls again. Change-Id: I6610beebf2c30754fde525b71f4c4a34ceb5e30b Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -761,12 +761,28 @@ QString FilePath::fileNameWithPathComponents(int pathComponents) const
|
||||
return m_data;
|
||||
}
|
||||
|
||||
/// \returns the base name of the file without the path.
|
||||
///
|
||||
/// The base name consists of all characters in the file up to
|
||||
/// (but not including) the first '.' character.
|
||||
|
||||
QString FilePath::baseName() const
|
||||
{
|
||||
const QString &name = fileName();
|
||||
return name.left(name.indexOf('.'));
|
||||
}
|
||||
|
||||
/// \returns the complete base name of the file without the path.
|
||||
///
|
||||
/// The complete base name consists of all characters in the file up to
|
||||
/// (but not including) the last '.' character
|
||||
|
||||
QString FilePath::completeBaseName() const
|
||||
{
|
||||
const QString &name = fileName();
|
||||
return name.left(name.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
void FilePath::setScheme(const QString &scheme)
|
||||
{
|
||||
QTC_CHECK(!scheme.contains('/'));
|
||||
|
@@ -103,7 +103,9 @@ public:
|
||||
|
||||
QString fileName() const;
|
||||
QString fileNameWithPathComponents(int pathComponents) const;
|
||||
|
||||
QString baseName() const;
|
||||
QString completeBaseName() const;
|
||||
|
||||
QString scheme() const { return m_scheme; }
|
||||
void setScheme(const QString &scheme);
|
||||
|
@@ -195,7 +195,7 @@ GenericProject::GenericProject(const Utils::FilePath &fileName)
|
||||
{
|
||||
setId(Constants::GENERICPROJECT_ID);
|
||||
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||
setDisplayName(fileName.toFileInfo().completeBaseName());
|
||||
setDisplayName(fileName.completeBaseName());
|
||||
setBuildSystemCreator([](Target *t) { return new GenericBuildSystem(t); });
|
||||
}
|
||||
|
||||
@@ -475,7 +475,7 @@ void GenericBuildSystem::refresh(RefreshOptions options)
|
||||
|
||||
if (options & Files) {
|
||||
auto newRoot = std::make_unique<ProjectNode>(projectDirectory());
|
||||
newRoot->setDisplayName(projectFilePath().toFileInfo().completeBaseName());
|
||||
newRoot->setDisplayName(projectFilePath().completeBaseName());
|
||||
|
||||
// find the common base directory of all source files
|
||||
FilePath baseDir = findCommonSourceRoot();
|
||||
|
@@ -38,7 +38,7 @@ NimbleProject::NimbleProject(const Utils::FilePath &fileName)
|
||||
: ProjectExplorer::Project(Constants::C_NIMBLE_MIMETYPE, fileName)
|
||||
{
|
||||
setId(Constants::C_NIMBLEPROJECT_ID);
|
||||
setDisplayName(fileName.toFileInfo().completeBaseName());
|
||||
setDisplayName(fileName.completeBaseName());
|
||||
// ensure debugging is enabled (Nim plugin translates nim code to C code)
|
||||
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||
setBuildSystemCreator([] (Target *t) { return new NimbleBuildSystem(t); });
|
||||
|
@@ -41,7 +41,7 @@ namespace Nim {
|
||||
NimProject::NimProject(const FilePath &fileName) : Project(Constants::C_NIM_MIMETYPE, fileName)
|
||||
{
|
||||
setId(Constants::C_NIMPROJECT_ID);
|
||||
setDisplayName(fileName.toFileInfo().completeBaseName());
|
||||
setDisplayName(fileName.completeBaseName());
|
||||
// ensure debugging is enabled (Nim plugin translates nim code to C code)
|
||||
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||
|
||||
|
@@ -118,7 +118,7 @@ void DesktopRunConfiguration::updateTargetInformation()
|
||||
if (profile.isEmpty())
|
||||
setDefaultDisplayName(tr("Qt Run Configuration"));
|
||||
else
|
||||
setDefaultDisplayName(profile.toFileInfo().completeBaseName());
|
||||
setDefaultDisplayName(profile.completeBaseName());
|
||||
|
||||
aspect<EnvironmentAspect>()->environmentChanged();
|
||||
|
||||
|
@@ -1022,7 +1022,7 @@ QList<ToolChain *> GccToolChainFactory::autoDetect(const QList<ToolChain *> &alr
|
||||
|
||||
QList<ToolChain *> GccToolChainFactory::detectForImport(const ToolChainDescription &tcd)
|
||||
{
|
||||
const QString fileName = tcd.compilerPath.toFileInfo().completeBaseName();
|
||||
const QString fileName = tcd.compilerPath.completeBaseName();
|
||||
if ((tcd.language == Constants::C_LANGUAGE_ID && (fileName.startsWith("gcc")
|
||||
|| fileName.endsWith("gcc")
|
||||
|| fileName == "cc"))
|
||||
@@ -1806,7 +1806,7 @@ QList<ToolChain *> MingwToolChainFactory::autoDetect(const QList<ToolChain *> &a
|
||||
|
||||
QList<ToolChain *> MingwToolChainFactory::detectForImport(const ToolChainDescription &tcd)
|
||||
{
|
||||
const QString fileName = tcd.compilerPath.toFileInfo().completeBaseName();
|
||||
const QString fileName = tcd.compilerPath.completeBaseName();
|
||||
if ((tcd.language == Constants::C_LANGUAGE_ID && (fileName.startsWith("gcc")
|
||||
|| fileName.endsWith("gcc")))
|
||||
|| (tcd.language == Constants::CXX_LANGUAGE_ID && (fileName.startsWith("g++")
|
||||
|
@@ -1788,8 +1788,7 @@ QString MsvcToolChainFactory::vcVarsBatFor(const QString &basePath,
|
||||
return result;
|
||||
}
|
||||
|
||||
static QList<ToolChain *> findOrCreateToolChain(const QList<ToolChain *> &alreadyKnown,
|
||||
const QString &name,
|
||||
static QList<ToolChain *> findOrCreateToolChain(const QList<ToolChain *> &alreadyKnown, const QString &name,
|
||||
const Abi &abi,
|
||||
const QString &varsBat,
|
||||
const QString &varsBatArg)
|
||||
|
@@ -224,7 +224,7 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
||||
if (reply == QMessageBox::Yes) {
|
||||
for (Node * const n : candidateNodes) {
|
||||
QString targetFilePath = orgFileInfo.absolutePath() + '/'
|
||||
+ newFilePath.toFileInfo().completeBaseName();
|
||||
+ newFilePath.completeBaseName();
|
||||
const QString suffix = n->filePath().toFileInfo().suffix();
|
||||
if (!suffix.isEmpty())
|
||||
targetFilePath.append('.').append(suffix);
|
||||
|
@@ -477,7 +477,7 @@ const QList<Node *> ProjectTree::siblingsWithSameBaseName(const Node *fileNode)
|
||||
const auto filter = [&fi](const Node *n) {
|
||||
return n->asFileNode()
|
||||
&& n->filePath().toFileInfo().dir() == fi.dir()
|
||||
&& n->filePath().toFileInfo().completeBaseName() == fi.completeBaseName()
|
||||
&& n->filePath().completeBaseName() == fi.completeBaseName()
|
||||
&& n->filePath().toString() != fi.filePath();
|
||||
};
|
||||
return productNode->findNodes(filter);
|
||||
|
@@ -205,7 +205,7 @@ public:
|
||||
PythonProjectNode(const Utils::FilePath &path)
|
||||
: ProjectNode(path)
|
||||
{
|
||||
setDisplayName(path.toFileInfo().completeBaseName());
|
||||
setDisplayName(path.completeBaseName());
|
||||
setAddFileFilter("*.py");
|
||||
}
|
||||
};
|
||||
@@ -215,7 +215,7 @@ PythonProject::PythonProject(const FilePath &fileName)
|
||||
{
|
||||
setId(PythonProjectId);
|
||||
setProjectLanguages(Context(ProjectExplorer::Constants::PYTHON_LANGUAGE_ID));
|
||||
setDisplayName(fileName.toFileInfo().completeBaseName());
|
||||
setDisplayName(fileName.completeBaseName());
|
||||
|
||||
setNeedsBuildConfigurations(false);
|
||||
setBuildSystemCreator([](Target *t) { return new PythonBuildSystem(t); });
|
||||
|
@@ -504,9 +504,8 @@ static QStringList replImportArgs(const FilePath &pythonFile, ReplType type)
|
||||
if (type == ReplType::Unmodified || !isPython)
|
||||
return {};
|
||||
const auto import = type == ReplType::Import
|
||||
? QString("import %1").arg(pythonFile.toFileInfo().completeBaseName())
|
||||
: QString("from %1 import *")
|
||||
.arg(pythonFile.toFileInfo().completeBaseName());
|
||||
? QString("import %1").arg(pythonFile.completeBaseName())
|
||||
: QString("from %1 import *").arg(pythonFile.completeBaseName());
|
||||
return {"-c", QString("%1; print('Running \"%1\"')").arg(import)};
|
||||
}
|
||||
|
||||
|
@@ -64,7 +64,7 @@ static FilePath defaultBuildDirectory(const FilePath &projectFilePath, const Kit
|
||||
const QString &bcName,
|
||||
BuildConfiguration::BuildType buildType)
|
||||
{
|
||||
const QString projectName = projectFilePath.toFileInfo().completeBaseName();
|
||||
const QString projectName = projectFilePath.completeBaseName();
|
||||
ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType);
|
||||
FilePath projectDir = Project::projectDirectory(projectFilePath);
|
||||
QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
|
||||
|
@@ -213,7 +213,7 @@ QbsProjectNode *QbsNodeTreeBuilder::buildTree(const QString &projectName,
|
||||
if (root->displayName().isEmpty())
|
||||
root->setDisplayName(projectName);
|
||||
if (root->displayName().isEmpty())
|
||||
root->setDisplayName(projectFile.toFileInfo().completeBaseName());
|
||||
root->setDisplayName(projectFile.completeBaseName());
|
||||
|
||||
auto buildSystemFiles = std::make_unique<FolderNode>(projectDir);
|
||||
buildSystemFiles->setDisplayName(QCoreApplication::translate("QbsProjectNode", "Qbs files"));
|
||||
|
@@ -123,7 +123,7 @@ QbsProject::QbsProject(const FilePath &fileName)
|
||||
setId(Constants::PROJECT_ID);
|
||||
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||
setCanBuildProducts();
|
||||
setDisplayName(fileName.toFileInfo().completeBaseName());
|
||||
setDisplayName(fileName.completeBaseName());
|
||||
}
|
||||
|
||||
QbsProject::~QbsProject()
|
||||
|
@@ -88,7 +88,7 @@ QbsProjectImporter::QbsProjectImporter(const FilePath &path) : QtProjectImporter
|
||||
|
||||
static FilePath buildDir(const FilePath &projectFilePath, const Kit *k)
|
||||
{
|
||||
const QString projectName = projectFilePath.toFileInfo().completeBaseName();
|
||||
const QString projectName = projectFilePath.completeBaseName();
|
||||
ProjectMacroExpander expander(projectFilePath, projectName, k, QString(),
|
||||
BuildConfiguration::Unknown);
|
||||
const FilePath projectDir = Project::projectDirectory(projectFilePath);
|
||||
@@ -222,7 +222,7 @@ const QList<BuildInfo> QbsProjectImporter::buildInfoList(void *directoryData) co
|
||||
{
|
||||
const auto * const bgData = static_cast<BuildGraphData *>(directoryData);
|
||||
BuildInfo info;
|
||||
info.displayName = bgData->bgFilePath.toFileInfo().completeBaseName();
|
||||
info.displayName = bgData->bgFilePath.completeBaseName();
|
||||
info.buildType = bgData->buildVariant == "debug"
|
||||
? BuildConfiguration::Debug : BuildConfiguration::Release;
|
||||
info.buildDirectory = bgData->bgFilePath.parentDir().parentDir();
|
||||
|
@@ -105,7 +105,7 @@ FilePath QmakeBuildConfiguration::shadowBuildDirectory(const FilePath &proFilePa
|
||||
if (proFilePath.isEmpty())
|
||||
return {};
|
||||
|
||||
const QString projectName = proFilePath.toFileInfo().completeBaseName();
|
||||
const QString projectName = proFilePath.completeBaseName();
|
||||
ProjectMacroExpander expander(proFilePath, projectName, k, suffix, buildType);
|
||||
FilePath projectDir = Project::projectDirectory(proFilePath);
|
||||
QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
|
||||
|
@@ -197,7 +197,7 @@ static void createTree(QmakeBuildSystem *buildSystem,
|
||||
auto topLevel = std::make_unique<ResourceEditor::ResourceTopLevelNode>
|
||||
(file.first, vfolder->filePath(), contents);
|
||||
topLevel->setEnabled(file.second == FileOrigin::ExactParse);
|
||||
const QString baseName = file.first.toFileInfo().completeBaseName();
|
||||
const QString baseName = file.first.completeBaseName();
|
||||
topLevel->setIsGenerated(baseName.startsWith("qmake_")
|
||||
|| baseName.endsWith("_qmlcache"));
|
||||
vfolder->addNode(std::move(topLevel));
|
||||
|
@@ -165,7 +165,7 @@ FilePath QmakePriFile::directoryPath() const
|
||||
|
||||
QString QmakePriFile::displayName() const
|
||||
{
|
||||
return filePath().toFileInfo().completeBaseName();
|
||||
return filePath().completeBaseName();
|
||||
}
|
||||
|
||||
QmakePriFile *QmakePriFile::parent() const
|
||||
@@ -2068,13 +2068,13 @@ FilePaths QmakeProFile::generatedFiles(const FilePath &buildDir,
|
||||
if (location.isEmpty())
|
||||
return { };
|
||||
location = location.pathAppended("ui_"
|
||||
+ sourceFile.toFileInfo().completeBaseName()
|
||||
+ sourceFile.completeBaseName()
|
||||
+ singleVariableValue(Variable::HeaderExtension));
|
||||
return { Utils::FilePath::fromString(QDir::cleanPath(location.toString())) };
|
||||
} else if (sourceFileType == FileType::StateChart) {
|
||||
if (buildDir.isEmpty())
|
||||
return { };
|
||||
const FilePath location = buildDir.pathAppended(sourceFile.toFileInfo().completeBaseName());
|
||||
const FilePath location = buildDir.pathAppended(sourceFile.completeBaseName());
|
||||
return {
|
||||
location.stringAppended(singleVariableValue(Variable::HeaderExtension)),
|
||||
location.stringAppended(singleVariableValue(Variable::CppExtension))
|
||||
|
@@ -174,7 +174,7 @@ QmakeProject::QmakeProject(const FilePath &fileName) :
|
||||
{
|
||||
setId(Constants::QMAKEPROJECT_ID);
|
||||
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||
setDisplayName(fileName.toFileInfo().completeBaseName());
|
||||
setDisplayName(fileName.completeBaseName());
|
||||
setCanBuildProducts();
|
||||
setHasMakeInstallEquivalent(true);
|
||||
}
|
||||
@@ -1162,7 +1162,7 @@ void QmakeBuildSystem::updateBuildSystemData()
|
||||
bti.targetFilePath = FilePath::fromString(executableFor(node->proFile()));
|
||||
bti.projectFilePath = node->filePath();
|
||||
bti.workingDirectory = FilePath::fromString(workingDir);
|
||||
bti.displayName = bti.projectFilePath.toFileInfo().completeBaseName();
|
||||
bti.displayName = bti.projectFilePath.completeBaseName();
|
||||
const FilePath relativePathInProject
|
||||
= bti.projectFilePath.relativeChildPath(projectDirectory());
|
||||
if (!relativePathInProject.isEmpty()) {
|
||||
|
@@ -96,7 +96,7 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
|
||||
{
|
||||
setId(QmlProjectManager::Constants::QML_PROJECT_ID);
|
||||
setProjectLanguages(Context(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID));
|
||||
setDisplayName(fileName.toFileInfo().completeBaseName());
|
||||
setDisplayName(fileName.completeBaseName());
|
||||
|
||||
setNeedsBuildConfigurations(false);
|
||||
setBuildSystemCreator([](Target *t) { return new QmlBuildSystem(t); });
|
||||
|
@@ -38,7 +38,7 @@ namespace Internal {
|
||||
QmlProjectNode::QmlProjectNode(Project *project)
|
||||
: ProjectNode(project->projectDirectory())
|
||||
{
|
||||
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
|
||||
setDisplayName(project->projectFilePath().completeBaseName());
|
||||
|
||||
setIcon(DirectoryIcon(":/projectexplorer/images/fileoverlay_qml.png"));
|
||||
}
|
||||
|
@@ -235,7 +235,7 @@ ICodeStylePreferences *CodeStylePool::loadCodeStyle(const Utils::FilePath &fileN
|
||||
reader.load(fileName);
|
||||
QVariantMap m = reader.restoreValues();
|
||||
if (m.contains(QLatin1String(codeStyleDataKey))) {
|
||||
const QByteArray id = fileName.toFileInfo().completeBaseName().toUtf8();
|
||||
const QByteArray id = fileName.completeBaseName().toUtf8();
|
||||
const QString displayName = reader.restoreValue(QLatin1String(displayNameKey)).toString();
|
||||
const QVariantMap map = reader.restoreValue(QLatin1String(codeStyleDataKey)).toMap();
|
||||
if (d->m_factory) {
|
||||
|
@@ -132,7 +132,7 @@ Highlighter::Definitions Highlighter::definitionsForDocument(const TextDocument
|
||||
// cmake configure_file input filenames without the .in extension
|
||||
if (filePath.endsWith(".in")) {
|
||||
definitions = definitionsForFileName(
|
||||
Utils::FilePath::fromString(filePath.toFileInfo().completeBaseName()));
|
||||
Utils::FilePath::fromString(filePath.completeBaseName()));
|
||||
}
|
||||
}
|
||||
if (definitions.isEmpty()) {
|
||||
|
Reference in New Issue
Block a user