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; return;
// Do we need to do a backup? // Do we need to do a backup?
const QString origName = path.toString(); if (optional<FilePath> backupFileName = m_strategy->backupName(oldSettings.data, path, data))
optional<FilePath> backupFileName = m_strategy->backupName(oldSettings.data, path, data); path.copyFile(backupFileName.value());
if (backupFileName)
QFile::copy(origName, backupFileName.value().toString());
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

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