diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 08937cd0..236a80cd 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -608,11 +608,8 @@ qmake_qm_files.prefix = $$QM_FILES_RESOURCE_PREFIX iconsets_files.files += $$files(resources/iconsets/*.svg, true) iconsets_files.files += $$files(resources/iconsets/*.json, true) -ENABLE_LUA_ADDON { - theme_files.files += $$files(resources/themes/*.lua, false) -} else { - theme_files.files += $$files(resources/themes/*.json, false) -} +theme_files.files += $$files(resources/themes/*.lua, false) +theme_files.files += $$files(resources/themes/*.json, false) theme_files.files += $$files(resources/themes/*.png, false) colorscheme_files.files += $$files(resources/colorschemes/*.scheme, false) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index caafd093..d5705040 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -995,10 +995,6 @@ void MainWindow::updateEditorColorSchemes() void MainWindow::applySettings() { ThemeManager themeManager; - if (pSettings->environment().useCustomTheme()) { - themeManager.prepareCustomeTheme(); - } - themeManager.setUseCustomTheme(pSettings->environment().useCustomTheme()); PAppTheme appTheme; try { appTheme = themeManager.theme(pSettings->environment().theme()); diff --git a/RedPandaIDE/resources/themes/contrast.lua b/RedPandaIDE/resources/themes/contrast.lua deleted file mode 100644 index dc02c16e..00000000 --- a/RedPandaIDE/resources/themes/contrast.lua +++ /dev/null @@ -1,53 +0,0 @@ -function apiVersion() - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -local nameMap = { - en_US = "Contrast", - pt_BR = "Contraste", - zh_CN = "高对比度", - zh_TW = "高對比度", -} - -function main() - local lang = C_Desktop.language() - - return { - ["name"] = nameMap[lang] or nameMap.en_US, - ["style"] = "RedPandaDarkFusion", - ["default scheme"] = "Twilight", - ["default iconset"] = "contrast", - ["palette"] = { - PaletteWindow = "#000000", - PaletteWindowText = "#FFFFFF", - PaletteBase = "#141414", - PaletteAlternateBase = "#191919", - PaletteButton = "#141414", - PaletteButtonDisabled = "#141414", - PaletteBrightText = "#ff0000", - PaletteText = "#FFFFFF", - PaletteButtonText = "#FFFFFF", - PaletteButtonTextDisabled = "#9DA9B5", - PaletteHighlight = "#aa1f75cc", - PaletteDark = "#232323", - PaletteHighlightedText = "#e7e7e7", - PaletteToolTipBase = "#66000000", - PaletteToolTipText = "#e7e7e7", - PaletteLink = "#007af4", - PaletteLinkVisited = "#a57aff", - PaletteWindowDisabled = "#0A0A0A", - PaletteWindowTextDisabled = "#9DA9B5", - PaletteHighlightDisabled = "#9DA9B5", - PaletteHighlightedTextDisabled = "#9DA9B5", - PaletteBaseDisabled = "#000000", - PaletteTextDisabled = "#9DA9B5", - PaletteMid = "#FFFFFF", - PaletteLight = "#505050", - PaletteMidlight = "#00ff00", - }, - } -end diff --git a/RedPandaIDE/resources/themes/dark.lua b/RedPandaIDE/resources/themes/dark.lua deleted file mode 100644 index 73307fbc..00000000 --- a/RedPandaIDE/resources/themes/dark.lua +++ /dev/null @@ -1,53 +0,0 @@ -function apiVersion() - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -local nameMap = { - en_US = "Dark", - pt_BR = "Escura", - zh_CN = "深色", - zh_TW = "深色", -} - -function main() - local lang = C_Desktop.language() - - return { - ["name"] = nameMap[lang] or nameMap.en_US, - ["style"] = "RedPandaDarkFusion", - ["default scheme"] = "VS Code", - ["default iconset"] = "contrast", - ["palette"] = { - PaletteWindow = "#19232D", - PaletteWindowText = "#E0E1E3", - PaletteBase = "#1E1E1E", - PaletteAlternateBase = "#303030", - PaletteButton = "#19232D", - PaletteButtonDisabled = "#19232D", - PaletteBrightText = "#ff0000", - PaletteText = "#e7e7e7", - PaletteButtonText = "#d3d3d3", - PaletteButtonTextDisabled = "#9DA9B5", - PaletteHighlight = "#aa1f75cc", - PaletteDark = "#232323", - PaletteHighlightedText = "#e7e7e7", - PaletteToolTipBase = "#66000000", - PaletteToolTipText = "#e7e7e7", - PaletteLink = "#007af4", - PaletteLinkVisited = "#a57aff", - PaletteWindowDisabled = "#333333", - PaletteWindowTextDisabled = "#9DA9B5", - PaletteHighlightDisabled = "#26486B", - PaletteHighlightedTextDisabled = "#9DA9B5", - PaletteBaseDisabled = "#19232D", - PaletteTextDisabled = "#9DA9B5", - PaletteMid = "#707070", - PaletteLight = "#505050", - PaletteMidlight = "#00ff00", - }, - } -end diff --git a/RedPandaIDE/resources/themes/default.lua b/RedPandaIDE/resources/themes/default.lua deleted file mode 100644 index c988f203..00000000 --- a/RedPandaIDE/resources/themes/default.lua +++ /dev/null @@ -1,51 +0,0 @@ -function apiVersion() - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -local nameMap = { - en_US = "Light", - pt_BR = "Clara", - zh_CN = "浅色", - zh_TW = "淺色", -} - -function main() - local lang = C_Desktop.language() - - return { - ["name"] = nameMap[lang] or nameMap.en_US, - ["style"] = "RedPandaLightFusion", - ["default scheme"] = "Intellij Classic", - ["default iconset"] = "newlook", - ["palette"] = { - PaletteWindow = "#efefef", - PaletteWindowText = "#000000", - PaletteBase = "#ffffff", - PaletteAlternateBase = "#f7f7f7", - PaletteToolTipBase = "#ffffdc", - PaletteToolTipText = "#000000", - PaletteText = "#000000", - PaletteButton = "#efefef", - PaletteButtonText = "#000000", - PaletteBrightText = "#ffffff", - PaletteLink = "#0000ff", - PaletteLinkVisited = "#ff00ff", - PaletteLight = "#ffffff", - PaletteMidlight = "#cacaca", - PaletteDark = "#9f9f9f", - PaletteMid = "#b8b8b8", - PaletteWindowDisabled = "#efefef", - PaletteWindowTextDisabled = "#bebebe", - PaletteBaseDisabled = "#efefef", - PaletteTextDisabled = "#bebebe", - PaletteButtonDisabled = "#efefef", - PaletteButtonTextDisabled = "#bebebe", - PaletteHighlight = "#688DB2", - PaletteHighlightedText = "#ffffff", - }, - } -end diff --git a/RedPandaIDE/resources/themes/molo.lua b/RedPandaIDE/resources/themes/molo.lua deleted file mode 100644 index 3c31f23c..00000000 --- a/RedPandaIDE/resources/themes/molo.lua +++ /dev/null @@ -1,53 +0,0 @@ -function apiVersion() - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -local nameMap = { - en_US = "MoLo", - pt_BR = "Molo", - zh_CN = "墨落", - zh_TW = "墨落", -} - -function main() - local lang = C_Desktop.language() - - return { - ["name"] = nameMap[lang] or nameMap.en_US, - ["style"] = "RedPandaDarkFusion", - ["default scheme"] = "MoLo CodeBlack", - ["default iconset"] = "newlook", - ["palette"] = { - PaletteWindow = "#000000", - PaletteWindowText = "#FFFFFF", - PaletteBase = "#141414", - PaletteAlternateBase = "#191919", - PaletteButton = "#141414", - PaletteButtonDisabled = "#141414", - PaletteBrightText = "#ff0000", - PaletteText = "#FFFFFF", - PaletteButtonText = "#FFFFFF", - PaletteButtonTextDisabled = "#9DA9B5", - PaletteHighlight = "#aa1f75cc", - PaletteDark = "#232323", - PaletteHighlightedText = "#e7e7e7", - PaletteToolTipBase = "#66000000", - PaletteToolTipText = "#e7e7e7", - PaletteLink = "#007af4", - PaletteLinkVisited = "#a57aff", - PaletteWindowDisabled = "#0A0A0A", - PaletteWindowTextDisabled = "#9DA9B5", - PaletteHighlightDisabled = "#9DA9B5", - PaletteHighlightedTextDisabled = "#9DA9B5", - PaletteBaseDisabled = "#000000", - PaletteTextDisabled = "#9DA9B5", - PaletteMid = "#FFFFFF", - PaletteLight = "#505050", - PaletteMidlight = "#00ff00", - }, - } -end diff --git a/RedPandaIDE/resources/themes/one_dark.lua b/RedPandaIDE/resources/themes/one_dark.lua deleted file mode 100644 index c39dbcc4..00000000 --- a/RedPandaIDE/resources/themes/one_dark.lua +++ /dev/null @@ -1,44 +0,0 @@ -function apiVersion() - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -function main() - return { - ["name"] = "One Dark", - ["style"] = "RedPandaDarkFusion", - ["default scheme"] = "One Dark", - ["default iconset"] = "contrast", - ["palette"] = { - PaletteWindow = "#282c34", - PaletteWindowDisabled = "#21252B", - PaletteWindowText = "#9da5b4", - PaletteWindowTextDisabled = "#676D7B", - PaletteBase = "#21252B", - PaletteBaseDisabled = "#1d2026", - PaletteAlternateBase = "#282c34", - PaletteToolTipBase = "#21252B", - PaletteToolTipText = "#9da5b4", - PaletteText = "#b4b4b4", - PaletteTextDisabled = "#676D7B", - PaletteButton = "#2c313c", - PaletteButtonDisabled = "#21252B", - PaletteButtonText = "#9da5b4", - PaletteButtonTextDisabled = "#676D7B", - PaletteHighlight = "#3b4048", - PaletteHighlightDisabled = "#21252B", - PaletteHighlightedText = "#d7dae0", - PaletteHighlightedTextDisabled = "#676D7B", - PaletteLink = "#98c379", - PaletteLinkVisited = "#c9c900", - PaletteBrightText = "#E0E1E3", - PaletteDark = "#282c34", - PaletteMid = "#282c34", - PaletteMidlight = "#282c34", - PaletteLight = "#282c34", - }, - } -end diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 85489338..2da33900 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -3749,7 +3749,6 @@ void Settings::Environment::doLoad() mLanguage = stringValue("language", QLocale::system().name()); mIconSet = stringValue("icon_set","contrast"); mUseCustomIconSet = boolValue("use_custom_icon_set", false); - mUseCustomTheme = boolValue("use_custom_theme", false); mCurrentFolder = stringValue("current_folder",QDir::currentPath()); if (!fileExists(mCurrentFolder)) { @@ -3877,16 +3876,6 @@ void Settings::Environment::setUseCustomIconSet(bool newUseCustomIconSet) mUseCustomIconSet = newUseCustomIconSet; } -bool Settings::Environment::useCustomTheme() const -{ - return mUseCustomTheme; -} - -void Settings::Environment::setUseCustomTheme(bool newUseCustomTheme) -{ - mUseCustomTheme = newUseCustomTheme; -} - bool Settings::Environment::hideNonSupportFilesInFileView() const { return mHideNonSupportFilesInFileView; diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 5ca3c5a8..eac55611 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -566,9 +566,6 @@ public: bool useCustomIconSet() const; void setUseCustomIconSet(bool newUseCustomIconSet); - bool useCustomTheme() const; - void setUseCustomTheme(bool newUseCustomTheme); - bool hideNonSupportFilesInFileView() const; void setHideNonSupportFilesInFileView(bool newHideNonSupportFilesInFileView); diff --git a/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp b/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp index 0be71bed..23446489 100644 --- a/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp +++ b/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp @@ -54,7 +54,6 @@ void EnvironmentAppearanceWidget::doLoad() } ui->spinZoomFactor->setValue(pSettings->environment().iconZoomFactor()); ui->chkUseCustomIconSet->setChecked(pSettings->environment().useCustomIconSet()); - ui->chkUseCustomTheme->setChecked(pSettings->environment().useCustomTheme()); for (int i=0;icbLanguage->count();i++) { if (ui->cbLanguage->itemData(i) == pSettings->environment().language()) { @@ -68,7 +67,6 @@ void EnvironmentAppearanceWidget::doSave() { if (pSettings->environment().theme()!=ui->cbTheme->currentData().toString()) { ThemeManager themeManager; - themeManager.setUseCustomTheme(pSettings->environment().useCustomTheme()); PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString()); if (appTheme && !appTheme->defaultColorScheme().isEmpty()) { pSettings->editor().setColorScheme(appTheme->defaultColorScheme()); @@ -84,7 +82,6 @@ void EnvironmentAppearanceWidget::doSave() pSettings->environment().setIconZoomFactor(ui->spinZoomFactor->value()); pSettings->environment().setUseCustomIconSet(ui->chkUseCustomIconSet->isChecked()); - pSettings->environment().setUseCustomTheme(ui->chkUseCustomTheme->isChecked()); pSettings->environment().save(); pMainWindow->applySettings(); @@ -93,7 +90,6 @@ void EnvironmentAppearanceWidget::doSave() void EnvironmentAppearanceWidget::init() { ThemeManager themeManager; - themeManager.setUseCustomTheme(pSettings->environment().useCustomTheme()); QList appThemes = themeManager.getThemes(); foreach(const PAppTheme& appTheme, appThemes) { ui->cbTheme->addItem(appTheme->displayName(),appTheme->name()); @@ -112,9 +108,9 @@ void EnvironmentAppearanceWidget::init() void EnvironmentAppearanceWidget::on_cbTheme_currentIndexChanged(int /* index */) { ThemeManager themeManager; - themeManager.setUseCustomTheme(pSettings->environment().useCustomTheme()); PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString()); - if (appTheme && !appTheme->defaultIconSet().isEmpty()) { + ui->lblThemeCategory->setText(appTheme->category()); + if(!appTheme->defaultIconSet().isEmpty()) { for (int i=0; icbIconSet->count();i++) { if (ui->cbIconSet->itemData(i) == appTheme->defaultIconSet()) { ui->cbIconSet->setCurrentIndex(i); diff --git a/RedPandaIDE/settingsdialog/environmentappearancewidget.ui b/RedPandaIDE/settingsdialog/environmentappearancewidget.ui index 6c1a52f8..9bf0128d 100644 --- a/RedPandaIDE/settingsdialog/environmentappearancewidget.ui +++ b/RedPandaIDE/settingsdialog/environmentappearancewidget.ui @@ -136,9 +136,9 @@ - + - Use custom theme + theme category @@ -322,7 +322,6 @@ cbTheme - chkUseCustomTheme cbFont spinFontSize cbIconSet diff --git a/RedPandaIDE/settingsdialog/environmentfolderswidget.cpp b/RedPandaIDE/settingsdialog/environmentfolderswidget.cpp index ea0ba415..1a0f2bc7 100644 --- a/RedPandaIDE/settingsdialog/environmentfolderswidget.cpp +++ b/RedPandaIDE/settingsdialog/environmentfolderswidget.cpp @@ -45,11 +45,7 @@ void EnvironmentFoldersWidget::doLoad() if (pSettings->environment().useCustomIconSet()) { ui->txtIconSetFolder->setText(pSettings->dirs().config(Settings::Dirs::DataType::IconSet)); } - ui->txtThemeFolder->setEnabled(pSettings->environment().useCustomTheme()); - ui->btnOpenThemeFolderInFileBrowser->setEnabled(pSettings->environment().useCustomTheme()); - if (pSettings->environment().useCustomTheme()) { - ui->txtThemeFolder->setText(pSettings->dirs().config(Settings::Dirs::DataType::Theme)); - } + ui->txtThemeFolder->setText(pSettings->dirs().config(Settings::Dirs::DataType::Theme)); } void EnvironmentFoldersWidget::doSave() diff --git a/RedPandaIDE/thememanager.cpp b/RedPandaIDE/thememanager.cpp index 22f00ce3..cc86de10 100644 --- a/RedPandaIDE/thememanager.cpp +++ b/RedPandaIDE/thememanager.cpp @@ -33,79 +33,57 @@ #include "addon/runtime.h" #endif -ThemeManager::ThemeManager(QObject *parent) : QObject(parent), - mUseCustomTheme(false) +ThemeManager::ThemeManager(QObject *parent) : QObject(parent) { } PAppTheme ThemeManager::theme(const QString &themeName) { - if (mUseCustomTheme) - prepareCustomeTheme(); - QString themeDir; - if (mUseCustomTheme) { - themeDir = pSettings->dirs().config(Settings::Dirs::DataType::Theme); - } else { - themeDir = pSettings->dirs().data(Settings::Dirs::DataType::Theme); - } -#ifdef ENABLE_LUA_ADDON - PAppTheme appTheme = std::make_shared(QString("%1/%2.lua").arg(themeDir, themeName), AppTheme::ThemeType::Lua); -#else - PAppTheme appTheme = std::make_shared(QString("%1/%2.json").arg(themeDir, themeName), AppTheme::ThemeType::JSON); -#endif - return appTheme; -} + QString customThemeDir = pSettings->dirs().config(Settings::Dirs::DataType::Theme); + QString builtInThemeDir = pSettings->dirs().data(Settings::Dirs::DataType::Theme); + PAppTheme appTheme = nullptr; -bool ThemeManager::useCustomTheme() const -{ - return mUseCustomTheme; -} - -void ThemeManager::setUseCustomTheme(bool newUseCustomTheme) -{ - mUseCustomTheme = newUseCustomTheme; -} - -void ThemeManager::prepareCustomeTheme() -{ - - if (QFile(pSettings->dirs().config(Settings::Dirs::DataType::Theme)).exists()) - return; - copyFolder(pSettings->dirs().data(Settings::Dirs::DataType::Theme),pSettings->dirs().config(Settings::Dirs::DataType::Theme)); + // custom overrides built-in + if (tryLoadThemeFromDir(customThemeDir, tr("custom"), themeName, appTheme)) + return appTheme; + if (tryLoadThemeFromDir(builtInThemeDir, tr("built-in"), themeName, appTheme)) + return appTheme; + return AppTheme::fallbackTheme(); } QList ThemeManager::getThemes() { - if (mUseCustomTheme) - prepareCustomeTheme(); + QString customThemeDir = pSettings->dirs().config(Settings::Dirs::DataType::Theme); + QString builtInThemeDir = pSettings->dirs().data(Settings::Dirs::DataType::Theme); + std::set themes; - QList result; - QString themeDir; - QString themeExtension; - AppTheme::ThemeType themeType; - if (mUseCustomTheme) { - themeDir = pSettings->dirs().config(Settings::Dirs::DataType::Theme); - themeExtension = "json"; - themeType = AppTheme::ThemeType::JSON; - } else { - themeDir = pSettings->dirs().data(Settings::Dirs::DataType::Theme); -#ifdef ENABLE_LUA_ADDON - themeExtension = "lua"; - themeType = AppTheme::ThemeType::Lua; -#else - themeExtension = "json"; - themeType = AppTheme::ThemeType::JSON; -#endif - } - QDirIterator it(themeDir); - while (it.hasNext()) { - it.next(); - QFileInfo fileInfo = it.fileInfo(); - if (fileInfo.suffix().compare(themeExtension, PATH_SENSITIVITY)==0) { + // custom overrides built-in + loadThemesFromDir(customThemeDir, tr("custom"), themes); + loadThemesFromDir(builtInThemeDir, tr("built-in"), themes); + + QList result(themes.begin(), themes.end()); + return result; +} + +bool ThemeManager::ThemeCompare::operator()(const PAppTheme &lhs, const PAppTheme &rhs) const +{ + return QFileInfo(lhs->filename()).baseName() < QFileInfo(rhs->filename()).baseName(); +} + +bool ThemeManager::tryLoadThemeFromDir(const QString &dir, const QString &dirType, const QString &themeName, PAppTheme &theme) +{ + for (const auto &[extension, type] : searchTypes) { + QString filename = QString("%2.%3").arg(themeName, extension); + QString fullPath = QString("%1/%2").arg(dir, filename); + if (QFile::exists(fullPath)) { try { - PAppTheme appTheme = std::make_shared(fileInfo.absoluteFilePath(), themeType); - result.append(appTheme); + theme = std::make_shared(fullPath, type); + if (theme->displayName().isEmpty()) { + theme->setDisplayName(themeName); + } + theme->setCategory(QString("%1 %2").arg(dirType, filename)); + return true; } catch(FileError e) { //just skip it } @@ -116,14 +94,37 @@ QList ThemeManager::getThemes() #endif } } - std::sort(result.begin(),result.end(),[](const PAppTheme &theme1, const PAppTheme &theme2){ - return QFileInfo(theme1->filename()).baseName() < QFileInfo(theme2->filename()).baseName(); - }); - if (result.isEmpty()) - result.append(AppTheme::fallbackTheme()); - return result; + return false; } +void ThemeManager::loadThemesFromDir(const QString &dir, const QString &dirType, std::set &themes) +{ + for (const auto &[extension, type] : searchTypes) { + QDirIterator it(dir); + while (it.hasNext()) { + it.next(); + QFileInfo fileInfo = it.fileInfo(); + if (fileInfo.suffix().compare(extension, PATH_SENSITIVITY) == 0) { + try { + PAppTheme appTheme = std::make_shared(fileInfo.absoluteFilePath(), type); + if (appTheme->displayName().isEmpty()) { + QString baseName = fileInfo.baseName(); + appTheme->setDisplayName(baseName); + } + appTheme->setCategory(QString("%1 %2").arg(dirType, fileInfo.fileName())); + themes.insert(appTheme); + } catch(FileError e) { + //just skip it + } +#ifdef ENABLE_LUA_ADDON + catch(AddOn::LuaError e) { + qDebug() << e.reason(); + } +#endif + } + } + } +} QColor AppTheme::color(ColorRole role) const { @@ -335,6 +336,21 @@ const QString &AppTheme::displayName() const return mDisplayName; } +void AppTheme::setDisplayName(const QString &newDisplayName) +{ + mDisplayName = newDisplayName; +} + +const QString &AppTheme::category() const +{ + return mCategory; +} + +void AppTheme::setCategory(const QString &newCategory) +{ + mCategory = newCategory; +} + const QString &AppTheme::defaultColorScheme() const { return mDefaultColorScheme; @@ -352,7 +368,8 @@ const QString &AppTheme::style() const AppTheme::AppTheme() : mName("__failsafe__theme__"), - mDisplayName("Fusion [fail-safe hard-coded]"), + mDisplayName("Fusion"), + mCategory("fail-safe hard-coded"), mStyle("fusion"), mDefaultColorScheme("Adaptive"), mDefaultIconSet("newlook") diff --git a/RedPandaIDE/thememanager.h b/RedPandaIDE/thememanager.h index 279b5fb7..bc90408e 100644 --- a/RedPandaIDE/thememanager.h +++ b/RedPandaIDE/thememanager.h @@ -21,6 +21,7 @@ #include #include #include +#include class AppTheme; using PAppTheme = std::shared_ptr; @@ -94,6 +95,10 @@ public: void setDefaultColorScheme(const QString &newDefaultColorScheme); const QString &displayName() const; + void setDisplayName(const QString &newDisplayName); + + const QString &category() const; + void setCategory(const QString &newCategory); const QString &name() const; @@ -117,6 +122,7 @@ private: QHash mColors; QString mName; QString mDisplayName; + QString mCategory; QString mStyle; QString mDefaultColorScheme; QString mDefaultIconSet; @@ -129,13 +135,24 @@ class ThemeManager : public QObject public: explicit ThemeManager(QObject *parent = nullptr); PAppTheme theme(const QString& themeName); - bool useCustomTheme() const; - void setUseCustomTheme(bool newUseCustomTheme); - void prepareCustomeTheme(); QList getThemes(); private: - bool mUseCustomTheme; + struct ThemeCompare { + bool operator()(const PAppTheme &lhs, const PAppTheme &rhs) const; + }; + +private: + bool tryLoadThemeFromDir(const QString &dir, const QString &dirType, const QString &themeName, PAppTheme &theme); + void loadThemesFromDir(const QString &dir, const QString &dirType, std::set &themes); + + // lua overrides json + inline static const std::pair searchTypes[] = { +#ifdef ENABLE_LUA_ADDON + { "lua", AppTheme::ThemeType::Lua }, +#endif + { "json", AppTheme::ThemeType::JSON }, + }; }; #endif // THEMEMANAGER_H diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index 739c1e9f..4e0c25c3 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -10656,6 +10656,19 @@ A colocação de destaques parece estar em repetição infinita + + ThemeManager + + + custom + + + + + built-in + + + TodoModel diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index e0b4c623..624de536 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -11534,6 +11534,19 @@ p, li { white-space: pre-wrap; } 无法写入文件'%2'! + + ThemeManager + + + custom + 自定义 + + + + built-in + 内置 + + SynEdit diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index 9381e427..c39e14be 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -9887,6 +9887,19 @@ + + ThemeManager + + + custom + + + + + built-in + + + TodoModel diff --git a/RedPandaIDE/xmake.lua b/RedPandaIDE/xmake.lua index 345855a5..79bd5d11 100644 --- a/RedPandaIDE/xmake.lua +++ b/RedPandaIDE/xmake.lua @@ -179,7 +179,7 @@ target("RedPandaIDE") add_files( "resources/iconsets/**.svg", "resources/iconsets/**.json", - "resources/themes/*.png", + "resources/themes/*.lua", "resources/themes/*.json", "resources/themes/*.png", "resources/colorschemes/*.scheme", "resources/fonts/asciicontrol.ttf", {rule = "RedPandaIDE.auto_qrc"}) @@ -199,14 +199,7 @@ target("RedPandaIDE") "addon/api.cpp", "addon/executor.cpp", "addon/runtime.cpp") - add_files( - "resources/themes/*.lua", - {rule = "RedPandaIDE.auto_qrc"}) add_links("lua") - else - add_files( - "resources/themes/*.json", - {rule = "RedPandaIDE.auto_qrc"}) end if has_config("sdcc") then diff --git a/addon/theme/contrast.tl b/addon/theme/contrast.tl deleted file mode 100644 index 4b8a0efe..00000000 --- a/addon/theme/contrast.tl +++ /dev/null @@ -1,53 +0,0 @@ -global function apiVersion(): ApiVersion - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -local nameMap: {string:string} = { - en_US = "Contrast", - pt_BR = "Contraste", - zh_CN = "高对比度", - zh_TW = "高對比度", -} - -global function main(): Theme - local lang = C_Desktop.language() - - return { - ["name"] = nameMap[lang] or nameMap.en_US, - ["style"] = "RedPandaDarkFusion", - ["default scheme"] = "Twilight", - ["default iconset"] = "contrast", - ["palette"] = { - PaletteWindow = "#000000", - PaletteWindowText = "#FFFFFF", - PaletteBase = "#141414", - PaletteAlternateBase = "#191919", - PaletteButton = "#141414", - PaletteButtonDisabled = "#141414", - PaletteBrightText = "#ff0000", - PaletteText = "#FFFFFF", - PaletteButtonText = "#FFFFFF", - PaletteButtonTextDisabled = "#9DA9B5", - PaletteHighlight = "#aa1f75cc", - PaletteDark = "#232323", - PaletteHighlightedText = "#e7e7e7", - PaletteToolTipBase = "#66000000", - PaletteToolTipText = "#e7e7e7", - PaletteLink = "#007af4", - PaletteLinkVisited = "#a57aff", - PaletteWindowDisabled = "#0A0A0A", - PaletteWindowTextDisabled = "#9DA9B5", - PaletteHighlightDisabled = "#9DA9B5", - PaletteHighlightedTextDisabled = "#9DA9B5", - PaletteBaseDisabled = "#000000", - PaletteTextDisabled = "#9DA9B5", - PaletteMid = "#FFFFFF", - PaletteLight = "#505050", - PaletteMidlight = "#00ff00", - }, - } -end diff --git a/addon/theme/dark.tl b/addon/theme/dark.tl deleted file mode 100644 index ae097861..00000000 --- a/addon/theme/dark.tl +++ /dev/null @@ -1,53 +0,0 @@ -global function apiVersion(): ApiVersion - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -local nameMap: {string:string} = { - en_US = "Dark", - pt_BR = "Escura", - zh_CN = "深色", - zh_TW = "深色", -} - -global function main(): Theme - local lang = C_Desktop.language() - - return { - ["name"] = nameMap[lang] or nameMap.en_US, - ["style"] = "RedPandaDarkFusion", - ["default scheme"] = "VS Code", - ["default iconset"] = "contrast", - ["palette"] = { - PaletteWindow = "#19232D", - PaletteWindowText = "#E0E1E3", - PaletteBase = "#1E1E1E", - PaletteAlternateBase = "#303030", - PaletteButton = "#19232D", - PaletteButtonDisabled = "#19232D", - PaletteBrightText = "#ff0000", - PaletteText = "#e7e7e7", - PaletteButtonText = "#d3d3d3", - PaletteButtonTextDisabled = "#9DA9B5", - PaletteHighlight = "#aa1f75cc", - PaletteDark = "#232323", - PaletteHighlightedText = "#e7e7e7", - PaletteToolTipBase = "#66000000", - PaletteToolTipText = "#e7e7e7", - PaletteLink = "#007af4", - PaletteLinkVisited = "#a57aff", - PaletteWindowDisabled = "#333333", - PaletteWindowTextDisabled = "#9DA9B5", - PaletteHighlightDisabled = "#26486B", - PaletteHighlightedTextDisabled = "#9DA9B5", - PaletteBaseDisabled = "#19232D", - PaletteTextDisabled = "#9DA9B5", - PaletteMid = "#707070", - PaletteLight = "#505050", - PaletteMidlight = "#00ff00", - }, - } -end diff --git a/addon/theme/default.tl b/addon/theme/default.tl deleted file mode 100644 index 3605bd57..00000000 --- a/addon/theme/default.tl +++ /dev/null @@ -1,51 +0,0 @@ -global function apiVersion(): ApiVersion - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -local nameMap: {string:string} = { - en_US = "Light", - pt_BR = "Clara", - zh_CN = "浅色", - zh_TW = "淺色", -} - -global function main(): Theme - local lang = C_Desktop.language() - - return { - ["name"] = nameMap[lang] or nameMap.en_US, - ["style"] = "RedPandaLightFusion", - ["default scheme"] = "Intellij Classic", - ["default iconset"] = "newlook", - ["palette"] = { - PaletteWindow = "#efefef", - PaletteWindowText = "#000000", - PaletteBase = "#ffffff", - PaletteAlternateBase = "#f7f7f7", - PaletteToolTipBase = "#ffffdc", - PaletteToolTipText = "#000000", - PaletteText = "#000000", - PaletteButton = "#efefef", - PaletteButtonText = "#000000", - PaletteBrightText = "#ffffff", - PaletteLink = "#0000ff", - PaletteLinkVisited = "#ff00ff", - PaletteLight = "#ffffff", - PaletteMidlight = "#cacaca", - PaletteDark = "#9f9f9f", - PaletteMid = "#b8b8b8", - PaletteWindowDisabled = "#efefef", - PaletteWindowTextDisabled = "#bebebe", - PaletteBaseDisabled = "#efefef", - PaletteTextDisabled = "#bebebe", - PaletteButtonDisabled = "#efefef", - PaletteButtonTextDisabled = "#bebebe", - PaletteHighlight = "#dddddd", - PaletteHighlightedText = "#000000", - }, - } -end diff --git a/addon/theme/molo.tl b/addon/theme/molo.tl deleted file mode 100644 index f09f68cc..00000000 --- a/addon/theme/molo.tl +++ /dev/null @@ -1,53 +0,0 @@ -global function apiVersion(): ApiVersion - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -local nameMap: {string:string} = { - en_US = "MoLo", - pt_BR = "Molo", - zh_CN = "墨落", - zh_TW = "墨落", -} - -global function main(): Theme - local lang = C_Desktop.language() - - return { - ["name"] = nameMap[lang] or nameMap.en_US, - ["style"] = "RedPandaDarkFusion", - ["default scheme"] = "MoLo CodeBlack", - ["default iconset"] = "newlook", - ["palette"] = { - PaletteWindow = "#000000", - PaletteWindowText = "#FFFFFF", - PaletteBase = "#141414", - PaletteAlternateBase = "#191919", - PaletteButton = "#141414", - PaletteButtonDisabled = "#141414", - PaletteBrightText = "#ff0000", - PaletteText = "#FFFFFF", - PaletteButtonText = "#FFFFFF", - PaletteButtonTextDisabled = "#9DA9B5", - PaletteHighlight = "#aa1f75cc", - PaletteDark = "#232323", - PaletteHighlightedText = "#e7e7e7", - PaletteToolTipBase = "#66000000", - PaletteToolTipText = "#e7e7e7", - PaletteLink = "#007af4", - PaletteLinkVisited = "#a57aff", - PaletteWindowDisabled = "#0A0A0A", - PaletteWindowTextDisabled = "#9DA9B5", - PaletteHighlightDisabled = "#9DA9B5", - PaletteHighlightedTextDisabled = "#9DA9B5", - PaletteBaseDisabled = "#000000", - PaletteTextDisabled = "#9DA9B5", - PaletteMid = "#FFFFFF", - PaletteLight = "#505050", - PaletteMidlight = "#00ff00", - }, - } -end diff --git a/addon/theme/one_dark.tl b/addon/theme/one_dark.tl deleted file mode 100644 index 50fea3e1..00000000 --- a/addon/theme/one_dark.tl +++ /dev/null @@ -1,44 +0,0 @@ -global function apiVersion(): ApiVersion - return { - kind = "theme", - major = 0, - minor = 1, - } -end - -global function main(): Theme - return { - ["name"] = "One Dark", -- do not translate - ["style"] = "RedPandaDarkFusion", - ["default scheme"] = "One Dark", - ["default iconset"] = "contrast", - ["palette"] = { - PaletteWindow = "#282c34", - PaletteWindowDisabled = "#21252B", - PaletteWindowText = "#9da5b4", - PaletteWindowTextDisabled = "#676D7B", - PaletteBase = "#21252B", - PaletteBaseDisabled = "#1d2026", - PaletteAlternateBase = "#282c34", - PaletteToolTipBase = "#21252B", - PaletteToolTipText = "#9da5b4", - PaletteText = "#b4b4b4", - PaletteTextDisabled = "#676D7B", - PaletteButton = "#2c313c", - PaletteButtonDisabled = "#21252B", - PaletteButtonText = "#9da5b4", - PaletteButtonTextDisabled = "#676D7B", - PaletteHighlight = "#3b4048", - PaletteHighlightDisabled = "#21252B", - PaletteHighlightedText = "#d7dae0", - PaletteHighlightedTextDisabled = "#676D7B", - PaletteLink = "#98c379", - PaletteLinkVisited = "#c9c900", - PaletteBrightText = "#E0E1E3", - PaletteDark = "#282c34", - PaletteMid = "#282c34", - PaletteMidlight = "#282c34", - PaletteLight = "#282c34", - }, - } -end