From 5edcad104e232e322aed28572159c9f6dc7cd3de Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 25 Oct 2022 19:09:46 +0800 Subject: [PATCH] - enhancement: before run a project'executable, check if there's project file newer than the executable --- NEWS.md | 3 ++- RedPandaIDE/compiler/projectcompiler.cpp | 2 +- RedPandaIDE/mainwindow.cpp | 4 +++- RedPandaIDE/project.cpp | 12 ++++++++++++ RedPandaIDE/project.h | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 34ffd3a9..9bbcec88 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,7 +24,8 @@ Red Panda C++ Version 2.0 - enhancement: when closing project, prevent all editors that belongs to the project check syntax and parse todos. - enhancement: add "auto reformat when saving codes" in "Options" / "Editor" / "Misc" (off by default) - enhancement: use "todo" and "fixme" as the keyword for TODO comments - - fix: rules for obj missed in makefile generated for project + - fix: rules for obj missing in the makefile generated for project + - enhancement: before run a project'executable, check if there's project file newer than the executable Red Panda C++ Version 1.5 diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 396f8224..6d1bf960 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -323,7 +323,7 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) if (mProject->options().usePrecompiledHeader) precompileStr = " $(PCH) "; - QList projectUnits; + QList projectUnits=mProject->unitList(); foreach(const PProjectUnit &unit, projectUnits) { FileType fileType = getFileType(unit->fileName()); // Only process source files diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index c7207b4b..420fa14a 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1880,7 +1880,9 @@ void MainWindow::runExecutable(RunType runType) CompileTarget target =getCompileTarget(); if (target == CompileTarget::Project) { QStringList binDirs = mProject->binDirs(); - if (mProject->modified() && + QFileInfo execInfo(mProject->executable()); + QDateTime execModTime = execInfo.lastModified(); + if (execInfo.exists() && mProject->unitsModifiedSince(execModTime) && QMessageBox::question( this, tr("Rebuild Project"), diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 140cc8fd..1cb1f5d5 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -156,6 +156,18 @@ QString Project::makeFileName() return QDir(directory()).filePath(MAKEFILE_NAME); } +bool Project::unitsModifiedSince(const QDateTime& time) +{ + foreach(const PProjectUnit& unit, mUnits) { + QFileInfo info(unit->fileName()); + if (info.lastModified()>time) { + qDebug()<