From 762c27b86026d23c46611d3cdc244caf388ba5f5 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 6 Apr 2024 04:03:14 +0800 Subject: [PATCH] fix: cppparser : #included files not correctly handled refactor project options -> file page --- RedPandaIDE/parser/cpppreprocessor.cpp | 26 ++++++++++++------- .../settingsdialog/projectfileswidget.cpp | 20 +++++--------- .../settingsdialog/projectfileswidget.h | 3 --- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 8e2ad7a1..53095fd0 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -810,22 +810,28 @@ void CppPreprocessor::openInclude(QString fileName) fileName.squeeze(); } if (mIncludes.size()>0) { - PParsedFile topFile = mIncludes.front(); - if (topFile->fileIncludes->includeFiles.contains(fileName)) { - PParsedFile innerMostFile = mIncludes.back(); - innerMostFile->fileIncludes->includeFiles.insert(fileName, false); - return; //already included - } + // PParsedFile topFile = mIncludes.front(); + // if (topFile->fileIncludes->includeFiles.contains(fileName)) { + // PParsedFile innerMostFile = mIncludes.back(); + // innerMostFile->fileIncludes->includeFiles.insert(fileName, false); + // return; //already included + // } + bool alreadyIncluded = false; for (PParsedFile& parsedFile:mIncludes) { + if (parsedFile->fileIncludes->includeFiles.contains(fileName)) { + alreadyIncluded = true; + continue; + } parsedFile->fileIncludes->includeFiles.insert(fileName,false); } - // Backup old position if we're entering a new file PParsedFile innerMostFile = mIncludes.back(); - innerMostFile->index = mIndex; - innerMostFile->branches = mBranchResults.count(); - innerMostFile->fileIncludes->includeFiles.insert(fileName,true); innerMostFile->fileIncludes->directIncludes.append(fileName); + if (alreadyIncluded) + return; + // Backup old position if we're entering a new file + innerMostFile->index = mIndex; + innerMostFile->branches = mBranchResults.count(); } // // Add the new file to the includes of the current file diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.cpp b/RedPandaIDE/settingsdialog/projectfileswidget.cpp index 20423a63..6ddf940d 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.cpp +++ b/RedPandaIDE/settingsdialog/projectfileswidget.cpp @@ -34,6 +34,13 @@ ProjectFilesWidget::~ProjectFilesWidget() void ProjectFilesWidget::doLoad() { + if (ui->cbEncoding->count()>0) { + if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) { + ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(tr("ANSI"))); + } else { + ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding))); + } + } ui->treeProject->expandAll(); ui->grpFileOptions->setEnabled(false); } @@ -274,19 +281,6 @@ void ProjectFilesWidget::init() SettingsWidget::init(); } -void ProjectFilesWidget::showEvent(QShowEvent *event) -{ - if (ui->cbEncoding->count()>0) { - if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) { - ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(tr("ANSI"))); - } else { - ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding))); - } - } - SettingsWidget::showEvent(event); -} - - void ProjectFilesWidget::on_cbEncodingDetail_currentTextChanged(const QString &) { PProjectUnit unit = currentUnit(); diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.h b/RedPandaIDE/settingsdialog/projectfileswidget.h index ee929cd2..b1be7244 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.h +++ b/RedPandaIDE/settingsdialog/projectfileswidget.h @@ -65,9 +65,6 @@ private slots: public: void init() override; - // QWidget interface -protected: - void showEvent(QShowEvent *event) override; }; #endif // PROJECTFILESWIDGET_H