work save

This commit is contained in:
royqh1979@gmail.com 2021-07-26 22:29:47 +08:00
parent b39f0e64a8
commit 9c111be41f
3 changed files with 62 additions and 47 deletions

View File

@ -6,6 +6,7 @@
#include "executablerunner.h"
#include "utils.h"
#include "../settings.h"
#include <QMessageBox>
CompilerManager::CompilerManager(QObject *parent) : QObject(parent)
{
@ -36,41 +37,54 @@ bool CompilerManager::running()
void CompilerManager::compile(const QString& filename, const QByteArray& encoding, bool rebuild, bool silent, bool onlyCheckSyntax)
{
QMutexLocker locker(&mCompileMutex);
if (mCompiler!=nullptr) {
if (!pSettings->compilerSets().defaultSet()) {
QMessageBox::critical(pMainWindow,
tr("No compiler set"),
tr("No compiler set is configured.")+tr("Can't start debugging."));
return;
}
if (!pSettings->compilerSets().defaultSet())
return;
mCompileErrorCount = 0;
mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax);
mCompiler->setRebuild(rebuild);
connect(mCompiler, &Compiler::compileFinished, this ,&CompilerManager::onCompileFinished);
connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue);
connect(mCompiler, &Compiler::compileFinished, pMainWindow, &MainWindow::onCompileFinished);
connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog);
connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
mCompiler->start();
{
QMutexLocker locker(&mCompileMutex);
if (mCompiler!=nullptr) {
return;
}
mCompileErrorCount = 0;
mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax);
mCompiler->setRebuild(rebuild);
connect(mCompiler, &Compiler::compileFinished, this ,&CompilerManager::onCompileFinished);
connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue);
connect(mCompiler, &Compiler::compileFinished, pMainWindow, &MainWindow::onCompileFinished);
connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog);
connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
mCompiler->start();
}
}
void CompilerManager::checkSyntax(const QString &filename, const QString &content)
{
QMutexLocker locker(&mBackgroundSyntaxCheckMutex);
if (mBackgroundSyntaxChecker!=nullptr) {
if (!pSettings->compilerSets().defaultSet()) {
QMessageBox::critical(pMainWindow,
tr("No compiler set"),
tr("No compiler set is configured.")+tr("Can't start debugging."));
return;
}
if (!pSettings->compilerSets().defaultSet())
return;
mSyntaxCheckErrorCount = 0;
mBackgroundSyntaxChecker = new StdinCompiler(filename,content,true,true);
connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, this ,&CompilerManager::onSyntaxCheckFinished);
connect(mBackgroundSyntaxChecker, &Compiler::compileIssue, this, &CompilerManager::onSyntaxCheckIssue);
connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, pMainWindow, &MainWindow::onCompileFinished);
connect(mBackgroundSyntaxChecker, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog);
connect(mBackgroundSyntaxChecker, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
connect(mBackgroundSyntaxChecker, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
mBackgroundSyntaxChecker->start();
{
QMutexLocker locker(&mBackgroundSyntaxCheckMutex);
if (mBackgroundSyntaxChecker!=nullptr) {
return;
}
mSyntaxCheckErrorCount = 0;
mBackgroundSyntaxChecker = new StdinCompiler(filename,content,true,true);
connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, this ,&CompilerManager::onSyntaxCheckFinished);
connect(mBackgroundSyntaxChecker, &Compiler::compileIssue, this, &CompilerManager::onSyntaxCheckIssue);
connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, pMainWindow, &MainWindow::onCompileFinished);
connect(mBackgroundSyntaxChecker, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog);
connect(mBackgroundSyntaxChecker, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
connect(mBackgroundSyntaxChecker, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
mBackgroundSyntaxChecker->start();
}
}
void CompilerManager::run(const QString &filename, const QString &arguments, const QString &workDir)

View File

@ -18,8 +18,6 @@ Debugger::Debugger(QObject *parent) : QObject(parent)
void Debugger::start()
{
mExecuting = true;
Settings::PCompilerSet compilerSet = pSettings->compilerSets().defaultSet();
if (!compilerSet) {
QMessageBox::critical(pMainWindow,
@ -27,6 +25,7 @@ void Debugger::start()
tr("No compiler set is configured.")+tr("Can't start debugging."));
return;
}
mExecuting = true;
QString debuggerPath = compilerSet->debugger();
QFile debuggerProgram(debuggerPath);
if (!debuggerProgram.exists()) {

View File

@ -247,23 +247,23 @@ void MainWindow::updateAppTitle()
else
str = e->filename();
if (mDebugger->executing()) {
setWindowTitle(QString("%s - [%s] - %s %s").arg(str).arg(appName)
setWindowTitle(QString("%1 - [%2] - %3 %4").arg(str).arg(appName)
.arg(tr("Debugging")).arg(DEVCPP_VERSION));
app->setApplicationName(QString("%s - [%s] - %s").arg(str).arg(appName)
app->setApplicationName(QString("%1 - [%2] - %3").arg(str).arg(appName)
.arg(tr("Debugging")));
} else if (mCompilerManager->running()) {
setWindowTitle(QString("%s - [%s] - %s %s").arg(str).arg(appName)
setWindowTitle(QString("%1 - [%2] - %3 %4").arg(str).arg(appName)
.arg(tr("Running")).arg(DEVCPP_VERSION));
app->setApplicationName(QString("%s - [%s] - %s").arg(str).arg(appName)
app->setApplicationName(QString("%1 - [%2] - %3").arg(str).arg(appName)
.arg(tr("Running")));
} else if (mCompilerManager->compiling()) {
setWindowTitle(QString("%s - [%s] - %s %s").arg(str).arg(appName)
setWindowTitle(QString("%1 - [%2] - %3 %4").arg(str).arg(appName)
.arg(tr("Compiling")).arg(DEVCPP_VERSION));
app->setApplicationName(QString("%s - [%s] - %s").arg(str).arg(appName)
app->setApplicationName(QString("%1 - [%2] - %3").arg(str).arg(appName)
.arg(tr("Compiling")));
} else {
this->setWindowTitle(QString("%s - %s %s").arg(str).arg(appName).arg(DEVCPP_VERSION));
app->setApplicationName(QString("%s - %s").arg(str).arg(appName));
this->setWindowTitle(QString("%1 - %2 %3").arg(str).arg(appName).arg(DEVCPP_VERSION));
app->setApplicationName(QString("%1 - %2").arg(str).arg(appName));
}
}
// else if Assigned(fProject) then begin
@ -427,10 +427,11 @@ bool MainWindow::compile(bool rebuild)
if (mCompileSuccessionTask) {
mCompileSuccessionTask->filename = getCompiledExecutableName(editor->filename());
}
mCompilerManager->compile(editor->filename(),editor->fileEncoding(),rebuild);
updateCompileActions();
openCloseMessageSheet(true);
ui->tabMessages->setCurrentWidget(ui->tabCompilerOutput);
updateAppTitle();
mCompilerManager->compile(editor->filename(),editor->fileEncoding(),rebuild);
return true;
}
return false;
@ -441,7 +442,7 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename)
// Check if it exists
if (!QFile(exeName).exists()) {
if (ui->actionCompile_Run->isEnabled()) {
if (QMessageBox::warning(this,tr("Confirm"),
if (QMessageBox::question(this,tr("Confirm"),
tr("Source file is not compiled.")
+"<br /><br />"+tr("Compile now?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
@ -482,17 +483,12 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename)
// FileToRun := FileToRun;
// end;
// if devData.MinOnRun then
// Application.Minimize;
// devExecutor.ExecuteAndWatch(FileToRun, Parameters, ExtractFilePath(fSourceFile),
// True, UseInputFile,InputFile, INFINITE, RunTerminate);
// MainForm.UpdateAppTitle;
// end;
mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath());
updateCompileActions();
if (pSettings->executor().minimizeOnRun()) {
showMinimized();
}
updateAppTitle();
mCompilerManager->run(exeName,"",QFileInfo(exeName).absolutePath());
}
void MainWindow::runExecutable()
@ -513,8 +509,12 @@ void MainWindow::debug()
if (mCompilerManager->compiling())
return;
Settings::PCompilerSet compilerSet = pSettings->compilerSets().defaultSet();
if (!compilerSet)
if (!compilerSet) {
QMessageBox::critical(pMainWindow,
tr("No compiler set"),
tr("No compiler set is configured.")+"<BR/>"+tr("Can't start debugging."));
return;
}
bool debugEnabled;
bool stripEnabled;
QString filePath;
@ -1003,6 +1003,7 @@ void MainWindow::onCompileFinished()
}
mCheckSyntaxInBack=false;
updateCompileActions();
updateAppTitle();
}
void MainWindow::onCompileErrorOccured(const QString &reason)
@ -1021,6 +1022,7 @@ void MainWindow::onRunFinished()
if (pSettings->executor().minimizeOnRun()) {
showNormal();
}
updateAppTitle();
}
void MainWindow::on_actionCompile_triggered()