From fc07b4dcd4092d68459b6ef9b8a4010ab1f2c9b7 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 17 Dec 2022 17:20:33 +0800 Subject: [PATCH] - enhancement: Don't add "-g3" option when generate assembely. - enhancement: Generate assembly is not correctly disabled when current file is not C/C++. --- NEWS.md | 3 + RedPandaIDE/compiler/compilerinfo.h | 1 + RedPandaIDE/compiler/filecompiler.cpp | 5 +- RedPandaIDE/mainwindow.cpp | 83 +++++++++++++++------------ RedPandaIDE/mainwindow.h | 2 + 5 files changed, 57 insertions(+), 37 deletions(-) diff --git a/NEWS.md b/NEWS.md index 73490fd5..ccc74a5f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,9 @@ Red Panda C++ Version 2.7 - enhancement: Export FPS (free problem set) files. - enhancement: Run all cases button not correct disabled when no case exits. - enhancement: Speed up remove problems. + - fix: "Compile" button disabled after app start with an empty new file. + - enhancement: Don't add "-g3" option when generate assembely. + - enhancement: Generate assembly is not correctly disabled when current file is not C/C++. Red Panda C++ Version 2.6 diff --git a/RedPandaIDE/compiler/compilerinfo.h b/RedPandaIDE/compiler/compilerinfo.h index 1a94a3e3..ba07faee 100644 --- a/RedPandaIDE/compiler/compilerinfo.h +++ b/RedPandaIDE/compiler/compilerinfo.h @@ -44,6 +44,7 @@ #define CC_CMD_OPT_USE_PIPE "cc_cmd_opt_use_pipe" #define COMPILER_OPTION_ON "on" +#define COMPILER_OPTION_OFF "" enum class CompilerSetType { RELEASE, diff --git a/RedPandaIDE/compiler/filecompiler.cpp b/RedPandaIDE/compiler/filecompiler.cpp index de24433c..8b082c56 100644 --- a/RedPandaIDE/compiler/filecompiler.cpp +++ b/RedPandaIDE/compiler/filecompiler.cpp @@ -36,8 +36,10 @@ FileCompiler::FileCompiler(const QString &filename, const QByteArray &encoding, bool FileCompiler::prepareForCompile() { Settings::CompilerSet::CompilationStage oldStage = compilerSet()->compilationStage(); - auto action = finally([this,oldStage]{ + QString oldDebugOptionValue = compilerSet()->getCompileOptionValue(CC_CMD_OPT_DEBUG_INFO); + auto action = finally([this,oldStage,oldDebugOptionValue]{ compilerSet()->setCompilationStage(oldStage); + compilerSet()->setCompileOption(CC_CMD_OPT_DEBUG_INFO,oldDebugOptionValue); }); Settings::CompilerSet::CompilationStage stage = oldStage; switch(mCompileType) { @@ -46,6 +48,7 @@ bool FileCompiler::prepareForCompile() break; case CppCompileType::GenerateAssemblyOnly: stage = Settings::CompilerSet::CompilationStage::CompilationProperOnly; + compilerSet()->setCompileOption(CC_CMD_OPT_DEBUG_INFO,COMPILER_OPTION_OFF); break; default: stage = oldStage; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 250f002d..f0c8ac37 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -76,6 +76,8 @@ #include #include #include +#include + #include "mainwindow.h" #include #include @@ -92,10 +94,6 @@ #include "widgets/searchinfiledialog.h" #ifdef Q_OS_WIN -#include -#include -#include -#include #include #endif @@ -127,6 +125,10 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); addActions( this->findChildren(QString(), Qt::FindChildrenRecursively)); + + //custom actions + createCustomActions(); + // status bar //statusBar takes the owner ships @@ -421,7 +423,7 @@ MainWindow::MainWindow(QWidget *parent) //git menu connect(ui->menuGit, &QMenu::aboutToShow, this, &MainWindow::updateVCSActions); - createCustomActions(); + initToolButtons(); buildContextMenus(); updateAppTitle(); @@ -623,8 +625,8 @@ void MainWindow::updateEditorActions(const Editor *e) ui->actionLocate_in_Files_View->setEnabled(!e->isNew()); } - updateCompileActions(); - updateCompilerSet(); + updateCompileActions(e); + updateCompilerSet(e); } @@ -646,7 +648,11 @@ void MainWindow::updateProjectActions() updateCompileActions(); } -void MainWindow::updateCompileActions() +void MainWindow::updateCompileActions() { + updateCompileActions(mEditorList->getEditor()); +} + +void MainWindow::updateCompileActions(const Editor *e) { if (mCompilerManager->compiling() || mCompilerManager->running() || mDebugger->executing()) { ui->actionCompile->setEnabled(false); @@ -660,7 +666,6 @@ void MainWindow::updateCompileActions() bool forProject=false; bool canRun = false; bool canCompile = false; - Editor * e = mEditorList->getEditor(); if (e) { if (!e->inProject()) { FileType fileType = getFileType(e->filename()); @@ -684,7 +689,7 @@ void MainWindow::updateCompileActions() ui->actionCompile_Run->setEnabled(canRun && canCompile); ui->actionRun->setEnabled(canRun); ui->actionRebuild->setEnabled(canCompile); - ui->actionGenerate_Assembly->setEnabled(!forProject); + ui->actionGenerate_Assembly->setEnabled(canCompile && !forProject); ui->actionDebug->setEnabled(canRun); ui->btnRunAllProblemCases->setEnabled(canRun); } @@ -696,7 +701,6 @@ void MainWindow::updateCompileActions() //it's not a compile action, but put here for convinience ui->actionSaveAll->setEnabled(mProject!=nullptr || mEditorList->pageCount()>0); - } void MainWindow::updateEditorColorSchemes() @@ -1535,6 +1539,11 @@ void MainWindow::changeOptions(const QString &widgetName, const QString &groupNa } void MainWindow::updateCompilerSet() +{ + updateCompilerSet(mEditorList->getEditor()); +} + +void MainWindow::updateCompilerSet(const Editor *e) { mCompilerSet->blockSignals(true); mCompilerSet->clear(); @@ -1543,7 +1552,6 @@ void MainWindow::updateCompilerSet() } int index=pSettings->compilerSets().defaultIndex(); if (mProject) { - Editor *e = mEditorList->getEditor(); if ( !e || e->inProject()) { index = mProject->options().compilerSet; } else if (e->syntaxer() @@ -3781,11 +3789,14 @@ void MainWindow::onLstProblemSetContextMenu(const QPoint &pos) void MainWindow::onTableProblemCasesContextMenu(const QPoint &pos) { QMenu menu(this); + menu.addAction(mProblem_AddCase); + menu.addAction(mProblem_RemoveCases); menu.addAction(mProblem_batchSetCases); menu.addSeparator(); QModelIndex idx = ui->tblProblemCases->currentIndex(); menu.addAction(mProblem_RunAllCases); menu.addAction(mProblem_RunCurrentCase); + menu.addAction(mProblem_CaseValidationOptions); mProblem_RunAllCases->setEnabled(mOJProblemModel.count()>0 && ui->actionRun->isEnabled()); mProblem_RunCurrentCase->setEnabled(idx.isValid() && ui->actionRun->isEnabled()); menu.exec(ui->tblProblemCases->mapToGlobal(pos)); @@ -3805,7 +3816,7 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex ¤t, const QMod { QModelIndex idx = current; if (!idx.isValid()) { - ui->btnRemoveProblem->setEnabled(false); + mProblemSet_RemoveProblem->setEnabled(false); mOJProblemModel.setProblem(nullptr); ui->txtProblemCaseExpected->clear(); ui->txtProblemCaseInput->clear(); @@ -3815,7 +3826,7 @@ void MainWindow::onProblemSetIndexChanged(const QModelIndex ¤t, const QMod ui->lblProblem->setToolTip(""); ui->tabProblem->setEnabled(false); } else { - ui->btnRemoveProblem->setEnabled(true); + mProblemSet_RemoveProblem->setEnabled(true); POJProblem problem = mOJProblemSetModel.problem(idx.row()); if (problem && !problem->answerProgram.isEmpty()) { openFile(problem->answerProgram); @@ -3845,7 +3856,7 @@ void MainWindow::onProblemCaseIndexChanged(const QModelIndex ¤t, const QMo if (idx.isValid()) { POJProblemCase problemCase = mOJProblemModel.getCase(idx.row()); if (problemCase) { - ui->btnRemoveProblemCase->setEnabled(true); + mProblem_RemoveCases->setEnabled(true); ui->btnRunAllProblemCases->setEnabled(ui->actionRun->isEnabled()); fillProblemCaseInputAndExpected(problemCase); ui->txtProblemCaseOutput->clear(); @@ -3865,7 +3876,7 @@ void MainWindow::onProblemCaseIndexChanged(const QModelIndex ¤t, const QMo ui->txtProblemCaseExpectedOutputFileName->clear(); ui->txtProblemCaseExpectedOutputFileName->setToolTip(""); - ui->btnRemoveProblemCase->setEnabled(false); + mProblem_RemoveCases->setEnabled(false); ui->btnRunAllProblemCases->setEnabled(false); ui->txtProblemCaseInputFileName->clear(); ui->btnProblemCaseInputFileName->setEnabled(false); @@ -7926,27 +7937,27 @@ void MainWindow::onAddProblem() void MainWindow::onRemoveProblem() { - QList idxList; - foreach (const QModelIndex idx,ui->lstProblemSet->selectionModel()->selectedIndexes()) { - idxList.append(idx.row()); + if (ui->lstProblemSet->selectionModel()->selectedIndexes().isEmpty()) { + QModelIndex idx=ui->lstProblemSet->currentIndex(); + if (idx.isValid()) + mOJProblemSetModel.removeProblem(idx.row()); + } else { + QList idxList; + foreach (const QModelIndex idx,ui->lstProblemSet->selectionModel()->selectedIndexes()) { + idxList.append(idx.row()); + } + if (idxList.isEmpty()) + return; + std::sort(idxList.begin(),idxList.end(),[](int i1, int i2){ + return i1>i2; + }); + bool oldBlock = ui->lstProblemSet->selectionModel()->blockSignals(true); + for (int i=0;ilstProblemSet->selectionModel()->blockSignals(oldBlock); + onProblemSetIndexChanged(ui->lstProblemSet->currentIndex(),QModelIndex()); } - if (idxList.isEmpty()) - return; - std::sort(idxList.begin(),idxList.end(),[](int i1, int i2){ - return i1>i2; - }); - bool oldBlock = ui->lstProblemSet->selectionModel()->blockSignals(true); - QProgressDialog progress(tr("Removing Problems..."),tr("Abort"),0,idxList.count(),this); - progress.setWindowModality(Qt::WindowModal); - for (int i=0;ilstProblemSet->selectionModel()->blockSignals(oldBlock); - onProblemSetIndexChanged(ui->lstProblemSet->currentIndex(),QModelIndex()); } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 2b16c420..1f62d182 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -124,8 +124,10 @@ public: void updateEditorActions(const Editor *e); void updateProjectActions(); void updateCompileActions(); + void updateCompileActions(const Editor* e); void updateEditorColorSchemes(); void updateCompilerSet(); + void updateCompilerSet(const Editor* e); void updateDebuggerSettings(); void updateActionIcons(); void checkSyntaxInBack(Editor* e);