From 814f3a28dbc0c987c5e053776ff1811a70e39900 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 15 Oct 2023 16:28:55 +0800 Subject: [PATCH] - enhancement: After compiler settings changed, run/debug current file will auto recompile. --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 8 +++++-- RedPandaIDE/settings.cpp | 21 ++++++++++++------- RedPandaIDE/settings.h | 3 +++ .../compilersetoptionwidget.cpp | 2 ++ libs/redpanda_qt_utils/qt_utils/utils.cpp | 11 ++++++++++ libs/redpanda_qt_utils/qt_utils/utils.h | 1 + 7 files changed, 38 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 27018902..2e3cc7bd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,7 @@ Red Panda C++ Version 2.25 - fix: Press '>' after '-' don't show completion suggestion info. - fix: Icon position not correct under hiPDI devices. - change: Add Mesa3D for windows opengl driver to the integrated mingw-gcc for windows 32 version. + - enhancement: After compiler settings changed, run/debug current file will auto recompile. Red Panda C++ Version 2.24 diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 67b95e5d..97c3a101 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -2126,7 +2126,9 @@ void MainWindow::runExecutable( return; } } else { - if (!filename.isEmpty() && compareFileModifiedTime(filename,exeName)>=0) { + if (!filename.isEmpty() && + ( compareFileModifiedTime(filename,exeName)>=0 + || compareFileModifiedTime(exeName, pSettings->compilerSets().defaultIndexTimestamp())<=0 )) { doCompileRun(runType); return; } @@ -2435,7 +2437,9 @@ void MainWindow::debug() mCompileSuccessionTask->binDirs = binDirs; compile(); return; - } else if (compareFileModifiedTime(e->filename(),filePath)>=0) { + } else if ( + compareFileModifiedTime(e->filename(),filePath)>=0 + || compareFileModifiedTime(filePath, pSettings->compilerSets().defaultIndexTimestamp())<=0 ) { mCompileSuccessionTask=std::make_shared(); mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug; mCompileSuccessionTask->binDirs = binDirs; diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index bc42d6bc..d4fc3e0d 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -3158,11 +3158,13 @@ void Settings::CompilerSets::saveSets() saveSet(i); } if (mDefaultIndex>=(int)mList.size()) { - mDefaultIndex = mList.size()-1; + setDefaultIndex( mList.size()-1 ); } mSettings->mSettings.beginGroup(SETTING_COMPILTER_SETS); mSettings->mSettings.setValue(SETTING_COMPILTER_SETS_DEFAULT_INDEX,mDefaultIndex); + mSettings->mSettings.setValue(SETTING_COMPILTER_SETS_DEFAULT_INDEX_TIMESTAMP,mDefaultIndexTimeStamp); mSettings->mSettings.setValue(SETTING_COMPILTER_SETS_COUNT,(int)mList.size()); + mSettings->mSettings.endGroup(); } @@ -3170,7 +3172,8 @@ void Settings::CompilerSets::loadSets() { mList.clear(); mSettings->mSettings.beginGroup(SETTING_COMPILTER_SETS); - mDefaultIndex =mSettings->mSettings.value(SETTING_COMPILTER_SETS_DEFAULT_INDEX,-1).toInt(); + mDefaultIndex = mSettings->mSettings.value(SETTING_COMPILTER_SETS_DEFAULT_INDEX,-1).toInt(); + mDefaultIndexTimeStamp = mSettings->mSettings.value(SETTING_COMPILTER_SETS_DEFAULT_INDEX_TIMESTAMP,0).toLongLong(); int listSize = mSettings->mSettings.value(SETTING_COMPILTER_SETS_COUNT,0).toInt(); mSettings->mSettings.endGroup(); bool loadError = false; @@ -3184,7 +3187,7 @@ void Settings::CompilerSets::loadSets() } if (loadError) { mList.clear(); - mDefaultIndex = -1; + setDefaultIndex(-1); } PCompilerSet pCurrentSet = defaultSet(); if (pCurrentSet) { @@ -3241,7 +3244,7 @@ void Settings::CompilerSets::loadSets() pCurrentSet = defaultSet(); if (!pCurrentSet) { mList.clear(); - mDefaultIndex = -1; + setDefaultIndex(-1); saveSets(); return; } @@ -3254,6 +3257,7 @@ void Settings::CompilerSets::saveDefaultIndex() { mSettings->mSettings.beginGroup(SETTING_COMPILTER_SETS); mSettings->mSettings.setValue(SETTING_COMPILTER_SETS_DEFAULT_INDEX,mDefaultIndex); + mSettings->mSettings.setValue(SETTING_COMPILTER_SETS_DEFAULT_INDEX_TIMESTAMP,mDefaultIndexTimeStamp); mSettings->mSettings.endGroup(); } @@ -3266,9 +3270,6 @@ void Settings::CompilerSets::deleteSet(int index) mSettings->mSettings.endGroup(); } mList.erase(std::begin(mList)+index); - if (mDefaultIndex>=(int)mList.size()) { - mDefaultIndex = mList.size()-1; - } saveSets(); } @@ -3282,9 +3283,15 @@ int Settings::CompilerSets::defaultIndex() const return mDefaultIndex; } +qint64 Settings::CompilerSets::defaultIndexTimestamp() const +{ + return mDefaultIndexTimeStamp; +} + void Settings::CompilerSets::setDefaultIndex(int value) { mDefaultIndex = value; + mDefaultIndexTimeStamp = QDateTime::currentMSecsSinceEpoch(); } Settings::PCompilerSet Settings::CompilerSets::defaultSet() diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 0fbbb8ab..3f2d8ea5 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -45,6 +45,7 @@ #define SETTING_CODE_FORMATTER "CodeFormatter" #define SETTING_COMPILTER_SETS "CompilerSets" #define SETTING_COMPILTER_SETS_DEFAULT_INDEX "defaultIndex" +#define SETTING_COMPILTER_SETS_DEFAULT_INDEX_TIMESTAMP "defaultIndexTimestamp" #define SETTING_COMPILTER_SETS_COUNT "count" #define SETTING_COMPILTER_SET "CompilerSet_%1" #define SETTING_EDITOR_DEFAULT_ENCODING "default_encoding" @@ -1547,6 +1548,7 @@ public: size_t size() const; int defaultIndex() const; void setDefaultIndex(int value); + qint64 defaultIndexTimestamp() const; PCompilerSet defaultSet(); PCompilerSet getSet(int index); @@ -1567,6 +1569,7 @@ public: private: CompilerSetList mList; int mDefaultIndex; + qint64 mDefaultIndexTimeStamp; Settings* mSettings; QStringList mCompilerCompatibleIndex; // index for old settings compatibility }; diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index e79b619f..2314974f 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -202,6 +202,8 @@ void CompilerSetOptionWidget::doSave() if (pSettings->compilerSets().size()>0) { saveCurrentCompilerSet(); } + //update default index timestamp + pSettings->compilerSets().setDefaultIndex(pSettings->compilerSets().defaultIndex()); pSettings->compilerSets().saveSets(); pMainWindow->updateCompilerSet(); } diff --git a/libs/redpanda_qt_utils/qt_utils/utils.cpp b/libs/redpanda_qt_utils/qt_utils/utils.cpp index cbc04cae..c022c1a1 100644 --- a/libs/redpanda_qt_utils/qt_utils/utils.cpp +++ b/libs/redpanda_qt_utils/qt_utils/utils.cpp @@ -743,3 +743,14 @@ void clearQPlainTextEditFormat(QTextEdit *editor) cursor.setCharFormat(QTextCharFormat()); cursor.clearSelection(); } + +int compareFileModifiedTime(const QString &filename, qint64 timestamp) +{ + QFileInfo fileInfo1(filename); + qint64 time=fileInfo1.lastModified().toMSecsSinceEpoch(); + if (time > timestamp) + return 1; + if (time < timestamp) + return -1; + return 0; +} diff --git a/libs/redpanda_qt_utils/qt_utils/utils.h b/libs/redpanda_qt_utils/qt_utils/utils.h index ee194853..cf387433 100644 --- a/libs/redpanda_qt_utils/qt_utils/utils.h +++ b/libs/redpanda_qt_utils/qt_utils/utils.h @@ -147,6 +147,7 @@ QString escapeSpacesInString(const QString& str); bool isReadOnly(const QString& filename); int compareFileModifiedTime(const QString& filename1, const QString& filename2); +int compareFileModifiedTime(const QString& filename1, qint64 timestamp); /* UI utils */ void inflateRect(QRect& rect, int delta);