From 4797e53b611907598a6dcb8444f7cc4377b1b98e Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 24 Apr 2024 10:26:55 +0800 Subject: [PATCH] update: only define functions in class/namespace/global scopes. update: add remove custom theme button --- RedPandaIDE/parser/cppparser.cpp | 10 ++---- .../environmentappearancewidget.cpp | 32 ++++++++++++++++--- .../environmentappearancewidget.h | 6 ++++ .../environmentappearancewidget.ui | 22 +++++++++++-- RedPandaIDE/thememanager.cpp | 14 ++++++-- RedPandaIDE/translations/RedPandaIDE_pt_BR.ts | 28 ++++++++++++---- RedPandaIDE/translations/RedPandaIDE_zh_CN.ts | 26 ++++++++++++--- RedPandaIDE/translations/RedPandaIDE_zh_TW.ts | 22 +++++++++++-- 8 files changed, 129 insertions(+), 31 deletions(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index d305f884..5c6e6025 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -2332,20 +2332,14 @@ void CppParser::checkAndHandleMethodOrVar(KeywordType keywordType, int maxIndex) //Won't implement: ignore function decl like int (text)(int x) { }; return; } - //it's a chain function call - if (mTokenizer[indexAfter]->text == "." - || mTokenizer[indexAfter]->text == "->" - || mTokenizer[indexAfter]->text == "::" ) { - mIndex = indexOfNextPeriodOrSemicolon(indexAfter, maxIndex); - return; - } + //it's not a function define if (mTokenizer[indexAfter]->text == ',') { // var decl with init handleVar(sType+" "+sName,isExtern,isStatic, maxIndex); return; } - if (mTokenizer[indexAfter]->text[0] == ';' && sType!="void") { + if (sType!="void") { //function can only be defined in global/namespaces/classes PStatement currentScope=getCurrentScope(); if (currentScope) { diff --git a/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp b/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp index 64d85b78..4a61dd28 100644 --- a/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp +++ b/RedPandaIDE/settingsdialog/environmentappearancewidget.cpp @@ -88,6 +88,13 @@ void EnvironmentAppearanceWidget::doSave() pMainWindow->applySettings(); } +void EnvironmentAppearanceWidget::updateIcons(const QSize &size) +{ + pIconsManager->setIcon(ui->btnCustomize, IconsManager::ACTION_EDIT_COPY); + pIconsManager->setIcon(ui->btnOpenCustomThemeFolder, IconsManager::ACTION_MISC_FOLDER); + pIconsManager->setIcon(ui->btnRemoveCustomTheme, IconsManager::ACTION_MISC_REMOVE); +} + void EnvironmentAppearanceWidget::init() { ThemeManager themeManager; @@ -112,6 +119,7 @@ void EnvironmentAppearanceWidget::on_cbTheme_currentIndexChanged(int /* index */ PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString()); ui->btnCustomize->setVisible(appTheme->category() == AppTheme::ThemeCategory::BuiltIn); ui->btnOpenCustomThemeFolder->setVisible(appTheme->category() == AppTheme::ThemeCategory::Custom); + ui->btnRemoveCustomTheme->setVisible(appTheme->category() == AppTheme::ThemeCategory::Custom); if(!appTheme->defaultIconSet().isEmpty()) { for (int i=0; icbIconSet->count();i++) { if (ui->cbIconSet->itemData(i) == appTheme->defaultIconSet()) { @@ -133,8 +141,20 @@ void EnvironmentAppearanceWidget::on_btnCustomize_clicked() dir.mkpath(customThemeFolder); } appTheme->copyTo(customThemeFolder); + refreshThemeList(appTheme->name()); +} + + +void EnvironmentAppearanceWidget::on_btnOpenCustomThemeFolder_clicked() +{ + QString customThemeFolder = pSettings->dirs().config(Settings::Dirs::DataType::Theme); + openFileFolderInExplorer(customThemeFolder); +} + +void EnvironmentAppearanceWidget::refreshThemeList(const QString ¤tThemeName) +{ + ThemeManager themeManager; ui->cbTheme->clear(); - QString currentThemeName = appTheme->name(); QList appThemes = themeManager.getThemes(); for (int i=0; idirs().config(Settings::Dirs::DataType::Theme); - openFileFolderInExplorer(customThemeFolder); + ThemeManager themeManager; + PAppTheme appTheme = themeManager.theme(ui->cbTheme->currentData().toString()); + if (appTheme->category() != AppTheme::ThemeCategory::Custom) + return; + QFile::remove(appTheme->filename()); + refreshThemeList(appTheme->name()); } diff --git a/RedPandaIDE/settingsdialog/environmentappearancewidget.h b/RedPandaIDE/settingsdialog/environmentappearancewidget.h index b86acedc..b6e73dc7 100644 --- a/RedPandaIDE/settingsdialog/environmentappearancewidget.h +++ b/RedPandaIDE/settingsdialog/environmentappearancewidget.h @@ -39,6 +39,7 @@ private: protected: void doLoad() override; void doSave() override; + void updateIcons(const QSize &size) override; // SettingsWidget interface public: @@ -47,6 +48,11 @@ private slots: void on_cbTheme_currentIndexChanged(int index); void on_btnCustomize_clicked(); void on_btnOpenCustomThemeFolder_clicked(); + void on_btnRemoveCustomTheme_clicked(); + +private: + void refreshThemeList(const QString& currentThemeName); + }; #endif // ENVIRONMENTAPPEARANCEWIDGET_H diff --git a/RedPandaIDE/settingsdialog/environmentappearancewidget.ui b/RedPandaIDE/settingsdialog/environmentappearancewidget.ui index 0b6aaa3e..549871bf 100644 --- a/RedPandaIDE/settingsdialog/environmentappearancewidget.ui +++ b/RedPandaIDE/settingsdialog/environmentappearancewidget.ui @@ -136,17 +136,33 @@ - - + + Create a customized copy + + Customize + - + + + Remove custom theme + + Remove custom theme + + + + + + Open custom themes folder + + Open Folder + diff --git a/RedPandaIDE/thememanager.cpp b/RedPandaIDE/thememanager.cpp index db2bbf47..89e0b24a 100644 --- a/RedPandaIDE/thememanager.cpp +++ b/RedPandaIDE/thememanager.cpp @@ -337,8 +337,18 @@ const QString AppTheme::categoryIcon() const bool AppTheme::copyTo(const QString &targetFolder) { QFileInfo fileInfo{mFilename}; - return QFile::copy(fileInfo.absoluteFilePath(), - QDir(targetFolder).absoluteFilePath(fileInfo.fileName())); + QFile originFile{fileInfo.absoluteFilePath()}; + QFile targetFile{QDir(targetFolder).absoluteFilePath(fileInfo.fileName())}; + if (!originFile.open(QFile::ReadOnly)) + return false; + if (!targetFile.open(QFile::WriteOnly)) + return false; + QByteArray contents = originFile.readAll(); + if (targetFile.write(contents)!=contents.length()) + return false; + targetFile.close(); + originFile.close(); + return true; } const QString &AppTheme::defaultIconSet() const diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index 68d07b52..1d8a8bfb 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -2357,10 +2357,26 @@ Fonte: - + + Customize + + + + Open custom themes folder + + + Open Folder + + + + + + Remove custom theme + + *Needs restart @@ -2372,12 +2388,12 @@ Tema: - + Create a customized copy - + Language: Idioma: @@ -2391,17 +2407,17 @@ Usar tema personalizado - + Icon Set: Conjunto de ícones: - + Use custom icon set Usar conjunto de ícones personalizado - + English Inglês diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index 5fb503fd..46c79b0b 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -2643,7 +2643,7 @@ p, li { white-space: pre-wrap; } 表单 - + Theme: 主题: @@ -2652,12 +2652,12 @@ p, li { white-space: pre-wrap; } 使用自定义主题 - + Icon Set: 图标集: - + Use custom icon set 使用自定义图标 @@ -2667,7 +2667,7 @@ p, li { white-space: pre-wrap; } 图标缩放: - + Font: 字体: @@ -2676,11 +2676,27 @@ p, li { white-space: pre-wrap; } Create a customized copy 自定义 + + + Customize + 自定义 + Open custom themes folder 打开自定义主题文件夹 + + + Open Folder + 打开文件夹 + + + + + Remove custom theme + 删除自定义主题 + Language: @@ -2697,7 +2713,7 @@ p, li { white-space: pre-wrap; } 大小: - + English 英语 diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index 43d7371a..8f7b6736 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -2130,7 +2130,7 @@ - + *Needs restart @@ -2150,7 +2150,7 @@ - + Icon Set: @@ -2159,18 +2159,34 @@ Create a customized copy + + + Customize + + Open custom themes folder + + + Open Folder + + + + + + Remove custom theme + + Use custom icon set - + English