- enhancement: After compiler settings changed, run/debug current file will auto recompile.

This commit is contained in:
Roy Qu 2023-10-15 16:28:55 +08:00
parent 81fab89e1f
commit 814f3a28db
7 changed files with 38 additions and 9 deletions

View File

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

View File

@ -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<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
mCompileSuccessionTask->binDirs = binDirs;

View File

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

View File

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

View File

@ -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();
}

View File

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

View File

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