always override the default style

This commit is contained in:
Le Tan 2017-05-22 22:39:51 +08:00
parent 78d57415c4
commit 58bc995924

View File

@ -61,6 +61,10 @@ void VConfigManager::initialize()
migrateIniFile(); migrateIniFile();
// Override the default css styles on start up.
outputDefaultCssStyle();
outputDefaultEditorStyle();
m_editorFontSize = getConfigFromSettings("global", "editor_font_size").toInt(); m_editorFontSize = getConfigFromSettings("global", "editor_font_size").toInt();
if (m_editorFontSize <= 0) { if (m_editorFontSize <= 0) {
m_editorFontSize = 12; m_editorFontSize = 12;
@ -448,10 +452,23 @@ bool VConfigManager::outputDefaultCssStyle() const
} }
} }
QFileInfo finfo(c_defaultCssFile); QString srcPath = c_defaultCssFile;
return VUtils::copyFile(c_defaultCssFile, QString destPath = getStyleConfigFolder() + QDir::separator() + QFileInfo(srcPath).fileName();
getStyleConfigFolder() + QDir::separator() + finfo.fileName(),
false); if (QFileInfo::exists(destPath)) {
QString bakPath = destPath + ".bak";
// We only keep one bak file.
if (!QFileInfo::exists(bakPath)) {
QFile::rename(destPath, bakPath);
} else {
// Just delete the default style.
QFile file(destPath);
file.setPermissions(QFile::ReadUser | QFile::WriteUser);
file.remove();
}
}
return VUtils::copyFile(srcPath, destPath, false);
} }
bool VConfigManager::outputDefaultEditorStyle() const bool VConfigManager::outputDefaultEditorStyle() const
@ -464,23 +481,42 @@ bool VConfigManager::outputDefaultEditorStyle() const
} }
} }
// Always override the deafult style.
QString srcPath = c_defaultMdhlFile; QString srcPath = c_defaultMdhlFile;
QString destPath = getStyleConfigFolder() + QDir::separator() + QFileInfo(srcPath).fileName(); QString destPath = getStyleConfigFolder() + QDir::separator() + QFileInfo(srcPath).fileName();
if (QFileInfo::exists(destPath)) {
QString bakPath = destPath + ".bak";
// We only keep one bak file.
if (!QFileInfo::exists(bakPath)) {
QFile::rename(destPath, bakPath);
} else {
// Just delete the default style.
QFile file(destPath);
file.setPermissions(QFile::ReadUser | QFile::WriteUser);
file.remove();
}
}
if (!VUtils::copyFile(srcPath, destPath, false)) { if (!VUtils::copyFile(srcPath, destPath, false)) {
return false; return false;
} }
srcPath = c_solarizedDarkMdhlFile; srcPath = c_solarizedDarkMdhlFile;
destPath = getStyleConfigFolder() + QDir::separator() + QFileInfo(srcPath).fileName(); destPath = getStyleConfigFolder() + QDir::separator() + QFileInfo(srcPath).fileName();
if (!QFileInfo::exists(destPath)) {
if (!VUtils::copyFile(srcPath, destPath, false)) { if (!VUtils::copyFile(srcPath, destPath, false)) {
return false; return false;
} }
}
srcPath = c_solarizedLightMdhlFile; srcPath = c_solarizedLightMdhlFile;
destPath = getStyleConfigFolder() + QDir::separator() + QFileInfo(srcPath).fileName(); destPath = getStyleConfigFolder() + QDir::separator() + QFileInfo(srcPath).fileName();
if (!QFileInfo::exists(destPath)) {
if (!VUtils::copyFile(srcPath, destPath, false)) { if (!VUtils::copyFile(srcPath, destPath, false)) {
return false; return false;
} }
}
return true; return true;
} }