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 <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-07-01 10:22:34 +02:00
parent 39707a4258
commit 8bef120f14

View File

@@ -189,32 +189,30 @@ public:
} // namespace Internal } // 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(); const Utils::FilePath stylesPath = customStylesPath();
QString baseFileName = stylesPath;
baseFileName += pattern;
// Find an available file name // Find an available file name
int i = 1; int i = 1;
QString fileName; Utils::FilePath filePath;
do { do {
fileName = baseFileName.arg((i == 1) ? QString() : QString::number(i)); filePath = stylesPath.pathAppended(pattern.arg((i == 1) ? QString() : QString::number(i)));
++i; ++i;
} while (QFile::exists(fileName)); } while (filePath.exists());
// Create the base directory when it doesn't exist // 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; qWarning() << "Failed to create color scheme directory:" << stylesPath;
return QString(); return {};
} }
return fileName; return filePath;
} }
// ------- FormatDescription // ------- FormatDescription
@@ -470,7 +468,7 @@ void FontSettingsPageWidget::copyColorScheme(const QString &name)
QString baseFileName = QFileInfo(entry.fileName).completeBaseName(); QString baseFileName = QFileInfo(entry.fileName).completeBaseName();
baseFileName += QLatin1String("_copy%1.xml"); baseFileName += QLatin1String("_copy%1.xml");
QString fileName = createColorSchemeFileName(baseFileName); Utils::FilePath fileName = createColorSchemeFileName(baseFileName);
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
// Ask about saving any existing modifactions // Ask about saving any existing modifactions
@@ -481,8 +479,8 @@ void FontSettingsPageWidget::copyColorScheme(const QString &name)
ColorScheme scheme = m_value.colorScheme(); ColorScheme scheme = m_value.colorScheme();
scheme.setDisplayName(name); scheme.setDisplayName(name);
if (scheme.save(fileName, Core::ICore::dialogParent())) if (scheme.save(fileName.path(), Core::ICore::dialogParent()))
m_value.setColorSchemeFileName(fileName); m_value.setColorSchemeFileName(fileName.path());
refreshColorSchemeList(); refreshColorSchemeList();
} }
@@ -576,7 +574,7 @@ void FontSettingsPageWidget::refreshColorSchemeList()
if (colorSchemes.isEmpty()) if (colorSchemes.isEmpty())
qWarning() << "Warning: no color schemes found in path:" << styleDir.path(); qWarning() << "Warning: no color schemes found in path:" << styleDir.path();
styleDir.setPath(customStylesPath()); styleDir.setPath(customStylesPath().path());
foreach (const QString &file, styleDir.entryList()) { foreach (const QString &file, styleDir.entryList()) {
const QString fileName = styleDir.absoluteFilePath(file); const QString fileName = styleDir.absoluteFilePath(file);