ClangFormat: Spread FilePath

Change-Id: Iedddd78b183b2290f98411e7c70807c1828f1c25
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2021-08-17 18:16:43 +02:00
parent adf1243ed9
commit 21b1bfc73c
2 changed files with 10 additions and 11 deletions

View File

@@ -329,10 +329,8 @@ void BackingUpSettingsAccessor::backupFile(const FilePath &path, const QVariantM
return;
// Do we need to do a backup?
const QString origName = path.toString();
optional<FilePath> backupFileName = m_strategy->backupName(oldSettings.data, path, data);
if (backupFileName)
QFile::copy(origName, backupFileName.value().toString());
if (optional<FilePath> backupFileName = m_strategy->backupName(oldSettings.data, path, data))
path.copyFile(backupFileName.value());
}
// --------------------------------------------------------------------

View File

@@ -42,6 +42,7 @@ using namespace llvm;
using namespace CppTools;
using namespace ProjectExplorer;
using namespace TextEditor;
using namespace Utils;
namespace ClangFormat {
@@ -279,25 +280,25 @@ static clang::format::FormatStyle constructStyle(const QByteArray &baseStyle = Q
void createStyleFileIfNeeded(bool isGlobal)
{
const Utils::FilePath path = isGlobal ? globalPath() : projectPath();
const QString configFile = path.pathAppended(Constants::SETTINGS_FILE_NAME).toString();
const FilePath path = isGlobal ? globalPath() : projectPath();
const FilePath configFile = path / Constants::SETTINGS_FILE_NAME;
if (QFile::exists(configFile))
if (configFile.exists())
return;
QDir().mkpath(path.toString());
if (!isGlobal) {
const Project *project = SessionManager::startupProject();
Utils::FilePath possibleProjectConfig = project->rootProjectDirectory().pathAppended(
Constants::SETTINGS_FILE_NAME);
FilePath possibleProjectConfig = project->rootProjectDirectory()
/ Constants::SETTINGS_FILE_NAME;
if (possibleProjectConfig.exists()) {
// Just copy th .clang-format if current project has one.
QFile::copy(possibleProjectConfig.toString(), configFile);
possibleProjectConfig.copyFile(configFile);
return;
}
}
std::fstream newStyleFile(configFile.toStdString(), std::fstream::out);
std::fstream newStyleFile(configFile.toString().toStdString(), std::fstream::out);
if (newStyleFile.is_open()) {
newStyleFile << clang::format::configurationAsText(constructStyle());
newStyleFile.close();