forked from qt-creator/qt-creator
Utils: add FilePath::(complete)suffix
The same as FilePath::(complete)baseName avoid some toFileInfo. Change-Id: Id1901ce2a4bef675215a9e020280df1c846df405 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -787,6 +787,34 @@ QString FilePath::completeBaseName() const
|
||||
return name.left(name.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
/// \returns the suffix (extension) of the file.
|
||||
///
|
||||
/// The suffix consists of all characters in the file after
|
||||
/// (but not including) the last '.'.
|
||||
|
||||
QString FilePath::suffix() const
|
||||
{
|
||||
const QString &name = fileName();
|
||||
const int index = name.lastIndexOf('.');
|
||||
if (index >= 0)
|
||||
return name.mid(index + 1);
|
||||
return {};
|
||||
}
|
||||
|
||||
/// \returns the complete suffix (extension) of the file.
|
||||
///
|
||||
/// The complete suffix consists of all characters in the file after
|
||||
/// (but not including) the first '.'.
|
||||
|
||||
QString FilePath::completeSuffix() const
|
||||
{
|
||||
const QString &name = fileName();
|
||||
const int index = name.indexOf('.');
|
||||
if (index >= 0)
|
||||
return name.mid(index + 1);
|
||||
return {};
|
||||
}
|
||||
|
||||
void FilePath::setScheme(const QString &scheme)
|
||||
{
|
||||
QTC_CHECK(!scheme.contains('/'));
|
||||
|
@@ -106,6 +106,8 @@ public:
|
||||
|
||||
QString baseName() const;
|
||||
QString completeBaseName() const;
|
||||
QString suffix() const;
|
||||
QString completeSuffix() const;
|
||||
|
||||
QString scheme() const { return m_scheme; }
|
||||
void setScheme(const QString &scheme);
|
||||
|
@@ -79,7 +79,7 @@ static QStringList libraryNameFilter()
|
||||
static bool hasLibSuffix(const FilePath &path)
|
||||
{
|
||||
return (HostOsInfo::isWindowsHost() && path.endsWith(".dll"))
|
||||
|| (HostOsInfo::isLinuxHost() && path.toFileInfo().completeSuffix().startsWith(".so"))
|
||||
|| (HostOsInfo::isLinuxHost() && path.completeSuffix().startsWith(".so"))
|
||||
|| (HostOsInfo::isMacHost() && path.endsWith(".dylib"));
|
||||
}
|
||||
|
||||
|
@@ -470,7 +470,7 @@ QString ModelIndexer::findFirstModel(ProjectExplorer::FolderNode *folderNode,
|
||||
if (!mimeType.isValid())
|
||||
return QString();
|
||||
foreach (ProjectExplorer::FileNode *fileNode, folderNode->fileNodes()) {
|
||||
if (mimeType.suffixes().contains(fileNode->filePath().toFileInfo().completeSuffix()))
|
||||
if (mimeType.suffixes().contains(fileNode->filePath().completeSuffix()))
|
||||
return fileNode->filePath().toString();
|
||||
}
|
||||
foreach (ProjectExplorer::FolderNode *subFolderNode, folderNode->folderNodes()) {
|
||||
|
@@ -212,7 +212,7 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
||||
|
||||
// The base name of the file was changed. Go look for other files with the same base name
|
||||
// and offer to rename them as well.
|
||||
if (orgFilePath != newFilePath && orgFileInfo.suffix() == newFilePath.toFileInfo().suffix()) {
|
||||
if (orgFilePath != newFilePath && orgFileInfo.suffix() == newFilePath.suffix()) {
|
||||
const QList<Node *> candidateNodes = ProjectTree::siblingsWithSameBaseName(node);
|
||||
if (!candidateNodes.isEmpty()) {
|
||||
const QMessageBox::StandardButton reply = QMessageBox::question(
|
||||
@@ -225,7 +225,7 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
||||
for (Node * const n : candidateNodes) {
|
||||
QString targetFilePath = orgFileInfo.absolutePath() + '/'
|
||||
+ newFilePath.completeBaseName();
|
||||
const QString suffix = n->filePath().toFileInfo().suffix();
|
||||
const QString suffix = n->filePath().suffix();
|
||||
if (!suffix.isEmpty())
|
||||
targetFilePath.append('.').append(suffix);
|
||||
toRename.emplace_back(std::make_tuple(n, n->filePath(),
|
||||
|
@@ -861,8 +861,7 @@ bool singleSelectedAndUiFile(const SelectionContext &context)
|
||||
if (!designDocument)
|
||||
return false;
|
||||
|
||||
return designDocument->fileName().toFileInfo().completeSuffix()
|
||||
== QLatin1String("ui.qml");
|
||||
return designDocument->fileName().completeSuffix() == QLatin1String("ui.qml");
|
||||
}
|
||||
|
||||
bool lowerAvailable(const SelectionContext &selectionState)
|
||||
|
@@ -172,7 +172,7 @@ Highlighter::Definitions Highlighter::definitionsForFileName(const Utils::FilePa
|
||||
= highlightRepository()->definitionsForFileName(fileName.fileName()).toList();
|
||||
|
||||
if (definitions.size() > 1) {
|
||||
const QString &fileExtension = fileName.toFileInfo().completeSuffix();
|
||||
const QString &fileExtension = fileName.completeSuffix();
|
||||
const Definition &rememberedDefinition
|
||||
= fileExtension.isEmpty()
|
||||
? definitionForSetting(kDefinitionForFilePath,
|
||||
@@ -192,7 +192,7 @@ void Highlighter::rememberDefinitionForDocument(const Highlighter::Definition &d
|
||||
if (!definition.isValid())
|
||||
return;
|
||||
const QString &mimeType = document->mimeType();
|
||||
const QString &fileExtension = document->filePath().toFileInfo().completeSuffix();
|
||||
const QString &fileExtension = document->filePath().completeSuffix();
|
||||
const QString &path = document->filePath().toFileInfo().canonicalFilePath();
|
||||
QSettings *settings = Core::ICore::settings();
|
||||
settings->beginGroup(Constants::HIGHLIGHTER_SETTINGS_CATEGORY);
|
||||
|
Reference in New Issue
Block a user