forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user