From 8bef120f14fd4dd543a1cd8c83e0cbb4c0a32465 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 1 Jul 2021 10:22:34 +0200 Subject: [PATCH] Editor: fix duplicating color schemes Core::ICore::userResourcePath seems to have returned a string with a trailing slash before it returned a Utils::FilePath. This allowed us to just concatenate the resource path with the pattern. Use FilePath::pathAppended to make sure the styles end up in the correct directory. Fixes: QTCREATORBUG-25944 Fixes: QTCREATORBUG-25910 Change-Id: I6ac735e3746e4328b5bbae4e55d91ef642277886 Reviewed-by: Christian Stenger --- src/plugins/texteditor/fontsettingspage.cpp | 30 ++++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp index 2487e31fff9..c7cf43ddfaa 100644 --- a/src/plugins/texteditor/fontsettingspage.cpp +++ b/src/plugins/texteditor/fontsettingspage.cpp @@ -189,32 +189,30 @@ public: } // namespace Internal -static QString customStylesPath() +static Utils::FilePath customStylesPath() { - return Core::ICore::userResourcePath("styles").toString(); + return Core::ICore::userResourcePath("styles"); } -static QString createColorSchemeFileName(const QString &pattern) +static Utils::FilePath createColorSchemeFileName(const QString &pattern) { - const QString stylesPath = customStylesPath(); - QString baseFileName = stylesPath; - baseFileName += pattern; + const Utils::FilePath stylesPath = customStylesPath(); // Find an available file name int i = 1; - QString fileName; + Utils::FilePath filePath; do { - fileName = baseFileName.arg((i == 1) ? QString() : QString::number(i)); + filePath = stylesPath.pathAppended(pattern.arg((i == 1) ? QString() : QString::number(i))); ++i; - } while (QFile::exists(fileName)); + } while (filePath.exists()); // Create the base directory when it doesn't exist - if (!QFile::exists(stylesPath) && !QDir().mkpath(stylesPath)) { + if (!stylesPath.exists() && !stylesPath.createDir()) { qWarning() << "Failed to create color scheme directory:" << stylesPath; - return QString(); + return {}; } - return fileName; + return filePath; } // ------- FormatDescription @@ -470,7 +468,7 @@ void FontSettingsPageWidget::copyColorScheme(const QString &name) QString baseFileName = QFileInfo(entry.fileName).completeBaseName(); baseFileName += QLatin1String("_copy%1.xml"); - QString fileName = createColorSchemeFileName(baseFileName); + Utils::FilePath fileName = createColorSchemeFileName(baseFileName); if (!fileName.isEmpty()) { // Ask about saving any existing modifactions @@ -481,8 +479,8 @@ void FontSettingsPageWidget::copyColorScheme(const QString &name) ColorScheme scheme = m_value.colorScheme(); scheme.setDisplayName(name); - if (scheme.save(fileName, Core::ICore::dialogParent())) - m_value.setColorSchemeFileName(fileName); + if (scheme.save(fileName.path(), Core::ICore::dialogParent())) + m_value.setColorSchemeFileName(fileName.path()); refreshColorSchemeList(); } @@ -576,7 +574,7 @@ void FontSettingsPageWidget::refreshColorSchemeList() if (colorSchemes.isEmpty()) qWarning() << "Warning: no color schemes found in path:" << styleDir.path(); - styleDir.setPath(customStylesPath()); + styleDir.setPath(customStylesPath().path()); foreach (const QString &file, styleDir.entryList()) { const QString fileName = styleDir.absoluteFilePath(file);