From 7e69b9ae65eaa8fcfb462658acc69c36f160973f Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 18 Jan 2024 17:15:37 +0800 Subject: [PATCH] sort themes by the filename --- RedPandaIDE/thememanager.cpp | 23 +++++++++++++---------- RedPandaIDE/thememanager.h | 13 +++++++------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/RedPandaIDE/thememanager.cpp b/RedPandaIDE/thememanager.cpp index 34d4b7c4..9b308f56 100644 --- a/RedPandaIDE/thememanager.cpp +++ b/RedPandaIDE/thememanager.cpp @@ -43,7 +43,6 @@ PAppTheme ThemeManager::theme(const QString &themeName) { if (mUseCustomTheme) prepareCustomeTheme(); - PAppTheme appTheme = std::make_shared(); QString themeDir; if (mUseCustomTheme) { themeDir = pSettings->dirs().config(Settings::Dirs::DataType::Theme); @@ -51,9 +50,9 @@ PAppTheme ThemeManager::theme(const QString &themeName) themeDir = pSettings->dirs().data(Settings::Dirs::DataType::Theme); } #ifdef ENABLE_LUA_ADDON - appTheme->load(QString("%1/%2.lua").arg(themeDir, themeName), AppTheme::ThemeType::Lua); + PAppTheme appTheme = std::make_shared(QString("%1/%2.lua").arg(themeDir, themeName), AppTheme::ThemeType::Lua); #else - appTheme->load(QString("%1/%2.json").arg(themeDir, themeName), AppTheme::ThemeType::JSON); + PAppTheme appTheme = std::make_shared(QString("%1/%2.json").arg(themeDir, themeName), AppTheme::ThemeType::JSON); #endif return appTheme; } @@ -105,8 +104,7 @@ QList ThemeManager::getThemes() QFileInfo fileInfo = it.fileInfo(); if (fileInfo.suffix().compare(themeExtension, PATH_SENSITIVITY)==0) { try { - PAppTheme appTheme = std::make_shared(); - appTheme->load(fileInfo.absoluteFilePath(), themeType); + PAppTheme appTheme = std::make_shared(fileInfo.absoluteFilePath(), themeType); result.append(appTheme); } catch(FileError e) { //just skip it @@ -118,13 +116,12 @@ 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(); + }); return result; } -AppTheme::AppTheme(QObject *parent):QObject(parent) -{ - -} QColor AppTheme::color(ColorRole role) const { @@ -198,8 +195,9 @@ QPalette AppTheme::palette() const return pal; } -void AppTheme::load(const QString &filename, ThemeType type) +AppTheme::AppTheme(const QString &filename, ThemeType type, QObject *parent):QObject(parent) { + mFilename = filename; QFile file(filename); if (!file.exists()) { throw FileError(tr("Theme file '%1' doesn't exist!") @@ -308,6 +306,11 @@ QString AppTheme::initialStyle() return style; } +const QString &AppTheme::filename() const +{ + return mFilename; +} + const QString &AppTheme::defaultIconSet() const { return mDefaultIconSet; diff --git a/RedPandaIDE/thememanager.h b/RedPandaIDE/thememanager.h index b920ce3a..dbb1d9e3 100644 --- a/RedPandaIDE/thememanager.h +++ b/RedPandaIDE/thememanager.h @@ -16,17 +16,15 @@ */ #ifndef THEMEMANAGER_H #define THEMEMANAGER_H -#include #include #include #include #include +#include -class AppTheme:public QObject { +class AppTheme : public QObject{ Q_OBJECT public: - explicit AppTheme(QObject* parent = nullptr); - enum ColorRole { /* Color for QPalette */ @@ -80,11 +78,11 @@ public: Lua, }; + AppTheme(const QString& filename, ThemeType type, QObject* parent=nullptr); + QColor color(ColorRole role) const; QPalette palette() const; - void load(const QString& filename, ThemeType type); - const QString &style() const; const QString &defaultColorScheme() const; @@ -100,6 +98,8 @@ public: static bool isSystemInDarkMode(); static QString initialStyle(); + const QString& filename() const; + private: static QPalette initialPalette(); private: @@ -109,6 +109,7 @@ private: QString mStyle; QString mDefaultColorScheme; QString mDefaultIconSet; + QString mFilename; }; using PAppTheme = std::shared_ptr;