update: only define functions in class/namespace/global scopes.

update: add remove custom theme button
This commit is contained in:
Roy Qu 2024-04-24 10:26:55 +08:00
parent 565e7914f8
commit 4797e53b61
8 changed files with 129 additions and 31 deletions

View File

@ -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) {

View File

@ -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; i<ui->cbIconSet->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 &currentThemeName)
{
ThemeManager themeManager;
ui->cbTheme->clear();
QString currentThemeName = appTheme->name();
QList<PAppTheme> appThemes = themeManager.getThemes();
for (int i=0; i<appThemes.count();i++) {
const PAppTheme& appTheme =appThemes[i];
@ -145,9 +165,13 @@ void EnvironmentAppearanceWidget::on_btnCustomize_clicked()
}
void EnvironmentAppearanceWidget::on_btnOpenCustomThemeFolder_clicked()
void EnvironmentAppearanceWidget::on_btnRemoveCustomTheme_clicked()
{
QString customThemeFolder = pSettings->dirs().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());
}

View File

@ -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

View File

@ -136,17 +136,33 @@
<widget class="QComboBox" name="cbTheme"/>
</item>
<item>
<widget class="QPushButton" name="btnCustomize">
<property name="text">
<widget class="QToolButton" name="btnCustomize">
<property name="toolTip">
<string>Create a customized copy</string>
</property>
<property name="text">
<string>Customize</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnOpenCustomThemeFolder">
<widget class="QToolButton" name="btnRemoveCustomTheme">
<property name="toolTip">
<string>Remove custom theme</string>
</property>
<property name="text">
<string>Remove custom theme</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnOpenCustomThemeFolder">
<property name="toolTip">
<string>Open custom themes folder</string>
</property>
<property name="text">
<string>Open Folder</string>
</property>
</widget>
</item>
<item>

View File

@ -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

View File

@ -2357,10 +2357,26 @@
<translation>Fonte:</translation>
</message>
<message>
<location line="+83"/>
<location line="+79"/>
<source>Customize</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+7"/>
<source>Open custom themes folder</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+3"/>
<source>Open Folder</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+7"/>
<location line="+3"/>
<source>Remove custom theme</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+103"/>
<source>*Needs restart</source>
@ -2372,12 +2388,12 @@
<translation>Tema:</translation>
</message>
<message>
<location line="-30"/>
<location line="-46"/>
<source>Create a customized copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+85"/>
<location line="+101"/>
<source>Language:</source>
<translation>Idioma:</translation>
</message>
@ -2391,17 +2407,17 @@
<translation type="vanished">Usar tema personalizado</translation>
</message>
<message>
<location line="-158"/>
<location line="-174"/>
<source>Icon Set:</source>
<translation>Conjunto de ícones:</translation>
</message>
<message>
<location line="+183"/>
<location line="+199"/>
<source>Use custom icon set</source>
<translation>Usar conjunto de ícones personalizado</translation>
</message>
<message>
<location filename="../settingsdialog/environmentappearancewidget.cpp" line="+98"/>
<location filename="../settingsdialog/environmentappearancewidget.cpp" line="+105"/>
<source>English</source>
<translation>Inglês</translation>
</message>

View File

@ -2643,7 +2643,7 @@ p, li { white-space: pre-wrap; }
<translation></translation>
</message>
<message>
<location line="+157"/>
<location line="+173"/>
<source>Theme:</source>
<translation>:</translation>
</message>
@ -2652,12 +2652,12 @@ p, li { white-space: pre-wrap; }
<translation type="vanished">使</translation>
</message>
<message>
<location line="-151"/>
<location line="-167"/>
<source>Icon Set:</source>
<translation></translation>
</message>
<message>
<location line="+183"/>
<location line="+199"/>
<source>Use custom icon set</source>
<translation>使</translation>
</message>
@ -2667,7 +2667,7 @@ p, li { white-space: pre-wrap; }
<translation></translation>
</message>
<message>
<location line="-209"/>
<location line="-225"/>
<source>Font:</source>
<translation>:</translation>
</message>
@ -2676,11 +2676,27 @@ p, li { white-space: pre-wrap; }
<source>Create a customized copy</source>
<translation></translation>
</message>
<message>
<location line="+3"/>
<source>Customize</source>
<translation></translation>
</message>
<message>
<location line="+7"/>
<source>Open custom themes folder</source>
<translation></translation>
</message>
<message>
<location line="+3"/>
<source>Open Folder</source>
<translation></translation>
</message>
<message>
<location line="+7"/>
<location line="+3"/>
<source>Remove custom theme</source>
<translation></translation>
</message>
<message>
<location line="+78"/>
<source>Language:</source>
@ -2697,7 +2713,7 @@ p, li { white-space: pre-wrap; }
<translation>:</translation>
</message>
<message>
<location filename="../settingsdialog/environmentappearancewidget.cpp" line="+98"/>
<location filename="../settingsdialog/environmentappearancewidget.cpp" line="+105"/>
<source>English</source>
<translation></translation>
</message>

View File

@ -2130,7 +2130,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+186"/>
<location line="+202"/>
<source>*Needs restart</source>
<translation type="unfinished"></translation>
</message>
@ -2150,7 +2150,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="-158"/>
<location line="-174"/>
<source>Icon Set:</source>
<translation type="unfinished"></translation>
</message>
@ -2159,18 +2159,34 @@
<source>Create a customized copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+3"/>
<source>Customize</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+7"/>
<source>Open custom themes folder</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+3"/>
<source>Open Folder</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+7"/>
<location line="+3"/>
<source>Remove custom theme</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+55"/>
<source>Use custom icon set</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../settingsdialog/environmentappearancewidget.cpp" line="+98"/>
<location filename="../settingsdialog/environmentappearancewidget.cpp" line="+105"/>
<source>English</source>
<translation type="unfinished"></translation>
</message>