- fix: Buttons in options -> compiler -> compiler set -> programs are not usable.

- enhancement: Don't check existence of gcc/g++/make/gdb at startup.
  - enhancement: Auto disable "compile" button if gcc doesn't exist.
  - enhancement: Auto disable "debug" button if gdb doesn't exist.
  - enhancement: Auto disable "compile" button for project if make doesn't exist.
This commit is contained in:
Roy Qu 2022-12-13 15:58:27 +08:00
parent e81c08d6c8
commit 02e6748db5
11 changed files with 653 additions and 396 deletions

View File

@ -14,6 +14,11 @@ Red Panda C++ Version 2.6
- enhancement: Show memory usage for problem cases (windows only). - enhancement: Show memory usage for problem cases (windows only).
- enhancement: Show memory usage after console program exited. - enhancement: Show memory usage after console program exited.
- fix: If clang and g++ are in the same folder, only the compiler sets for gcc are auto generated. - fix: If clang and g++ are in the same folder, only the compiler sets for gcc are auto generated.
- fix: Buttons in options -> compiler -> compiler set -> programs are not usable.
- enhancement: Don't check existence of gcc/g++/make/gdb at startup.
- enhancement: Auto disable "compile" button if gcc doesn't exist.
- enhancement: Auto disable "debug" button if gdb doesn't exist.
- enhancement: Auto disable "compile" button for project if make doesn't exist.
Red Panda C++ Version 2.5 Red Panda C++ Version 2.5

View File

@ -54,7 +54,8 @@ enum class CompilerSetType {
enum class CompilerType { enum class CompilerType {
GCC, GCC,
GCC_UTF8, GCC_UTF8,
Clang Clang,
Unknown
}; };
using CompileOptionChoiceList = QList<QPair<QString,QString>>; using CompileOptionChoiceList = QList<QPair<QString,QString>>;

View File

@ -30,7 +30,10 @@ StdinCompiler::StdinCompiler(const QString &filename,const QByteArray& encoding,
bool StdinCompiler::prepareForCompile() bool StdinCompiler::prepareForCompile()
{ {
if (mOnlyCheckSyntax)
log(tr("Checking file syntax...")); log(tr("Checking file syntax..."));
else
log(tr("Compiling..."));
log("------------------"); log("------------------");
log(tr("- Filename: %1").arg(mFilename)); log(tr("- Filename: %1").arg(mFilename));
log(tr("- Compiler Set Name: %1").arg(compilerSet()->name())); log(tr("- Compiler Set Name: %1").arg(compilerSet()->name()));
@ -68,7 +71,10 @@ bool StdinCompiler::prepareForCompile()
mArguments += getLibraryArguments(fileType); mArguments += getLibraryArguments(fileType);
if (!fileExists(mCompiler)) { if (!fileExists(mCompiler)) {
if (!mOnlyCheckSyntax)
throw CompileError(tr("The Compiler '%1' doesn't exists!").arg(mCompiler)); throw CompileError(tr("The Compiler '%1' doesn't exists!").arg(mCompiler));
else
return false;
} }
log(tr("Processing %1 source file:").arg(strFileType)); log(tr("Processing %1 source file:").arg(strFileType));

View File

@ -650,14 +650,28 @@ void MainWindow::updateCompileActions()
bool forProject=false; bool forProject=false;
bool canCompile = false; bool canCompile = false;
bool canRun = false; bool canRun = false;
bool canDebug = false;
Editor * e = mEditorList->getEditor(); Editor * e = mEditorList->getEditor();
if (e) { if (e) {
if (!e->inProject()) { if (!e->inProject()) {
FileType fileType = getFileType(e->filename()); FileType fileType = getFileType(e->filename());
if (fileType == FileType::CSource if (fileType == FileType::CSource
|| fileType == FileType::CppSource || e->isNew()) { || fileType == FileType::CppSource || e->isNew()) {
canCompile = true;
canRun = true; canRun = true;
Settings::PCompilerSet set = pSettings->compilerSets().defaultSet();
if (set) {
canDebug = set->canDebug();
switch(fileType) {
case FileType::CSource:
canCompile = set->canCompileC();
break;
case FileType::CppSource:
canCompile = set->canCompileCPP();
break;
default:
break;
}
}
} }
} else { } else {
forProject = (mProject!=nullptr); forProject = (mProject!=nullptr);
@ -666,9 +680,13 @@ void MainWindow::updateCompileActions()
forProject = (mProject!=nullptr); forProject = (mProject!=nullptr);
} }
if (forProject) { if (forProject) {
canCompile = true;
canRun = (mProject->options().type !=ProjectType::DynamicLib) canRun = (mProject->options().type !=ProjectType::DynamicLib)
&& (mProject->options().type !=ProjectType::StaticLib); && (mProject->options().type !=ProjectType::StaticLib);
Settings::PCompilerSet set = pSettings->compilerSets().getSet(mProject->options().compilerSet);
if (set) {
canDebug = set->canDebug();
canCompile = set->canMake();
}
} }
if (mCompilerManager->compiling() || mCompilerManager->running() || mDebugger->executing() if (mCompilerManager->compiling() || mCompilerManager->running() || mDebugger->executing()
|| (!canCompile)) { || (!canCompile)) {
@ -681,11 +699,11 @@ void MainWindow::updateCompileActions()
ui->btnRunAllProblemCases->setEnabled(false); ui->btnRunAllProblemCases->setEnabled(false);
} else { } else {
ui->actionCompile->setEnabled(true); ui->actionCompile->setEnabled(true);
ui->actionCompile_Run->setEnabled(canRun); ui->actionCompile_Run->setEnabled(canRun && canCompile);
ui->actionRun->setEnabled(canRun); ui->actionRun->setEnabled(canRun);
ui->actionRebuild->setEnabled(true); ui->actionRebuild->setEnabled(true);
ui->actionGenerate_Assembly->setEnabled(!forProject); ui->actionGenerate_Assembly->setEnabled(!forProject);
ui->actionDebug->setEnabled(canRun); ui->actionDebug->setEnabled(canDebug);
ui->btnRunAllProblemCases->setEnabled(canRun); ui->btnRunAllProblemCases->setEnabled(canRun);
} }
if (!mDebugger->executing()) { if (!mDebugger->executing()) {
@ -5170,6 +5188,7 @@ void MainWindow::onCompilerSetChanged(int index)
if (index<0) if (index<0)
return; return;
Editor *e = mEditorList->getEditor(); Editor *e = mEditorList->getEditor();
updateCompileActions();
if ( mProject && (!e || e->inProject()) if ( mProject && (!e || e->inProject())
) { ) {
if (index==mProject->options().compilerSet) if (index==mProject->options().compilerSet)

View File

@ -1544,9 +1544,11 @@ void Settings::Editor::setTabToSpaces(bool tabToSpaces)
Settings::CompilerSet::CompilerSet(): Settings::CompilerSet::CompilerSet():
mFullLoaded(false), mFullLoaded(false),
mAutoAddCharsetParams(true), mCompilerType(CompilerType::Unknown),
mCompilerSetType(CompilerSetType::RELEASE),
mAutoAddCharsetParams(false),
mExecCharset(ENCODING_SYSTEM_DEFAULT), mExecCharset(ENCODING_SYSTEM_DEFAULT),
mStaticLink(true), mStaticLink(false),
mPreprocessingSuffix(DEFAULT_PREPROCESSING_SUFFIX), mPreprocessingSuffix(DEFAULT_PREPROCESSING_SUFFIX),
mCompilationProperSuffix(DEFAULT_COMPILATION_SUFFIX), mCompilationProperSuffix(DEFAULT_COMPILATION_SUFFIX),
mAssemblingSuffix(DEFAULT_ASSEMBLING_SUFFIX), mAssemblingSuffix(DEFAULT_ASSEMBLING_SUFFIX),
@ -1770,34 +1772,34 @@ bool Settings::CompilerSet::dirsValid(QString &msg)
return true; return true;
} }
bool Settings::CompilerSet::validateExes(QString &msg) //bool Settings::CompilerSet::validateExes(QString &msg)
{ //{
msg =""; // msg ="";
if (!fileExists(mCCompiler)) { // if (!fileExists(mCCompiler)) {
msg += QObject::tr("Cannot find the %1 \"%2\"") // msg += QObject::tr("Cannot find the %1 \"%2\"")
.arg(QObject::tr("C Compiler")) // .arg(QObject::tr("C Compiler"))
.arg(mCCompiler); // .arg(mCCompiler);
} // }
if (!fileExists(mCppCompiler)) { // if (!fileExists(mCppCompiler)) {
msg += QObject::tr("Cannot find the %1 \"%2\"") // msg += QObject::tr("Cannot find the %1 \"%2\"")
.arg(QObject::tr("C++ Compiler")) // .arg(QObject::tr("C++ Compiler"))
.arg(mCppCompiler); // .arg(mCppCompiler);
} // }
if (!mMake.isEmpty() && !fileExists(mMake)) { // if (!mMake.isEmpty() && !fileExists(mMake)) {
msg += QObject::tr("Cannot find the %1 \"%2\"") // msg += QObject::tr("Cannot find the %1 \"%2\"")
.arg(QObject::tr("Maker")) // .arg(QObject::tr("Maker"))
.arg(mMake); // .arg(mMake);
} // }
if (!fileExists(mDebugger)) { // if (!fileExists(mDebugger)) {
msg += QObject::tr("Cannot find the %1 \"%2\"") // msg += QObject::tr("Cannot find the %1 \"%2\"")
.arg(QObject::tr("Debugger")) // .arg(QObject::tr("Debugger"))
.arg(mDebugger); // .arg(mDebugger);
} // }
if (!msg.isEmpty()) // if (!msg.isEmpty())
return false; // return false;
else // else
return true; // return true;
} //}
const QString &Settings::CompilerSet::CCompiler() const const QString &Settings::CompilerSet::CCompiler() const
{ {
@ -1806,7 +1808,17 @@ const QString &Settings::CompilerSet::CCompiler() const
void Settings::CompilerSet::setCCompiler(const QString &name) void Settings::CompilerSet::setCCompiler(const QString &name)
{ {
if (mCCompiler!=name) {
mCCompiler = name; mCCompiler = name;
if (mCompilerType == CompilerType::Unknown) {
QString temp=extractFileName(mCCompiler);
if (temp == CLANG_PROGRAM) {
setCompilerType(CompilerType::Clang);
} else if (temp == GCC_PROGRAM) {
setCompilerType(CompilerType::GCC);
}
}
}
} }
const QString &Settings::CompilerSet::cppCompiler() const const QString &Settings::CompilerSet::cppCompiler() const
@ -2403,6 +2415,26 @@ int Settings::CompilerSet::mainVersion()
} }
bool Settings::CompilerSet::canCompileC()
{
return fileExists(mCCompiler);
}
bool Settings::CompilerSet::canCompileCPP()
{
return fileExists(mCppCompiler);
}
bool Settings::CompilerSet::canMake()
{
return fileExists(mMake);
}
bool Settings::CompilerSet::canDebug()
{
return fileExists(mDebugger);
}
void Settings::CompilerSet::setUserInput() void Settings::CompilerSet::setUserInput()
{ {
mUseCustomCompileParams = false; mUseCustomCompileParams = false;
@ -2800,7 +2832,7 @@ void Settings::CompilerSets::loadSets()
PCompilerSet pCurrentSet = defaultSet(); PCompilerSet pCurrentSet = defaultSet();
if (pCurrentSet) { if (pCurrentSet) {
QString msg; QString msg;
if (!pCurrentSet->dirsValid(msg) || !pCurrentSet->validateExes(msg)) { if (!pCurrentSet->dirsValid(msg)) {
if (QMessageBox::warning(nullptr,QObject::tr("Confirm"), if (QMessageBox::warning(nullptr,QObject::tr("Confirm"),
QObject::tr("The following problems were found during validation of compiler set \"%1\":") QObject::tr("The following problems were found during validation of compiler set \"%1\":")
.arg(pCurrentSet->name()) .arg(pCurrentSet->name())

View File

@ -1249,8 +1249,12 @@ public:
int mainVersion(); int mainVersion();
bool canCompileC();
bool canCompileCPP();
bool canMake();
bool canDebug();
bool dirsValid(QString& msg); bool dirsValid(QString& msg);
bool validateExes(QString& msg); // bool validateExes(QString& msg);
//properties //properties
const QString& CCompiler() const; const QString& CCompiler() const;
void setCCompiler(const QString& name); void setCCompiler(const QString& name);

View File

@ -51,6 +51,7 @@ CompilerSetOptionWidget::CompilerSetOptionWidget(const QString& name, const QStr
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
ui->txtExecutableSuffix->setReadOnly(true); ui->txtExecutableSuffix->setReadOnly(true);
#endif #endif
ui->settingTabs->setCurrentWidget(ui->tabGeneral);
} }
CompilerSetOptionWidget::~CompilerSetOptionWidget() CompilerSetOptionWidget::~CompilerSetOptionWidget()
@ -235,6 +236,16 @@ void CompilerSetOptionWidget::saveCurrentCompilerSet()
pSet->setExecutableSuffix(ui->txtExecutableSuffix->text()); pSet->setExecutableSuffix(ui->txtExecutableSuffix->text());
} }
QString CompilerSetOptionWidget::getBinDir()
{
Settings::PCompilerSet pSet = pSettings->compilerSets().defaultSet();
if (!pSet->binDirs().isEmpty())
return pSet->binDirs().front();
if (!mBinDirWidget->dirList().isEmpty())
return mBinDirWidget->dirList().front();
return QDir().absolutePath();
}
void CompilerSetOptionWidget::on_btnFindCompilers_pressed() void CompilerSetOptionWidget::on_btnFindCompilers_pressed()
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -338,3 +349,87 @@ void CompilerSetOptionWidget::on_cbEncodingDetails_currentTextChanged(const QStr
} }
void CompilerSetOptionWidget::on_btnChooseCCompiler_clicked()
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Locate C Compiler"),
getBinDir(),
tr("Executable files (*.exe)"));
if (fileExists(fileName))
ui->txtCCompiler->setText(fileName);
}
void CompilerSetOptionWidget::on_btnChooseCppCompiler_clicked()
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Locate C++ Compiler"),
getBinDir(),
tr("Executable files (*.exe)"));
if (fileExists(fileName))
ui->txtCppCompiler->setText(fileName);
}
void CompilerSetOptionWidget::on_btnChooseMake_clicked()
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Locate Make"),
getBinDir(),
tr("Executable files (*.exe)"));
if (fileExists(fileName))
ui->txtMake->setText(fileName);
}
void CompilerSetOptionWidget::on_btnChooseGDB_clicked()
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Locate GDB"),
getBinDir(),
tr("Executable files (*.exe)"));
if (fileExists(fileName))
ui->txtDebugger->setText(fileName);
}
void CompilerSetOptionWidget::on_btnChooseGDBServer_clicked()
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Locate GDB Server"),
getBinDir(),
tr("Executable files (*.exe)"));
if (fileExists(fileName))
ui->txtGDBServer->setText(fileName);
}
void CompilerSetOptionWidget::on_btnChooseResourceCompiler_clicked()
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Locate windres"),
getBinDir(),
tr("Executable files (*.exe)"));
if (fileExists(fileName))
ui->txtResourceCompiler->setText(fileName);
}
void CompilerSetOptionWidget::on_btnChooseProfiler_clicked()
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Locate gprof"),
getBinDir(),
tr("Executable files (*.exe)"));
if (fileExists(fileName))
ui->txtProfiler->setText(fileName);
}

View File

@ -52,6 +52,7 @@ protected:
private: private:
void reloadCurrentCompilerSet(); void reloadCurrentCompilerSet();
void saveCurrentCompilerSet(); void saveCurrentCompilerSet();
QString getBinDir();
private slots: private slots:
void on_cbCompilerSet_currentIndexChanged(int index); void on_cbCompilerSet_currentIndexChanged(int index);
@ -63,6 +64,13 @@ private slots:
void on_cbEncoding_currentTextChanged(const QString &arg1); void on_cbEncoding_currentTextChanged(const QString &arg1);
void on_cbEncodingDetails_currentTextChanged(const QString &arg1); void on_cbEncodingDetails_currentTextChanged(const QString &arg1);
void on_btnChooseCCompiler_clicked();
void on_btnChooseCppCompiler_clicked();
void on_btnChooseMake_clicked();
void on_btnChooseGDB_clicked();
void on_btnChooseGDBServer_clicked();
void on_btnChooseResourceCompiler_clicked();
void on_btnChooseProfiler_clicked();
}; };
#endif // COMPILERSETOPTIONWIDGET_H #endif // COMPILERSETOPTIONWIDGET_H

View File

@ -723,6 +723,38 @@
<source>Executable suffix</source> <source>Executable suffix</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Locate C Compiler</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Executable files (*.exe)</source>
<translation type="unfinished">Arquivos executáveis (*.exe)</translation>
</message>
<message>
<source>Locate C++ Compiler</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate Make</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate GDB</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate GDB Server</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate windres</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate gprof</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CppRefacter</name> <name>CppRefacter</name>
@ -5977,23 +6009,23 @@
</message> </message>
<message> <message>
<source>Cannot find the %1 &quot;%2&quot;</source> <source>Cannot find the %1 &quot;%2&quot;</source>
<translation>Impossível encontrar %1 &quot;%2&quot;</translation> <translation type="vanished">Impossível encontrar %1 &quot;%2&quot;</translation>
</message> </message>
<message> <message>
<source>C Compiler</source> <source>C Compiler</source>
<translation>Compilar C</translation> <translation type="vanished">Compilar C</translation>
</message> </message>
<message> <message>
<source>C++ Compiler</source> <source>C++ Compiler</source>
<translation>Compilador C++</translation> <translation type="vanished">Compilador C++</translation>
</message> </message>
<message> <message>
<source>Maker</source> <source>Maker</source>
<translation>Maker</translation> <translation type="vanished">Maker</translation>
</message> </message>
<message> <message>
<source>Debugger</source> <source>Debugger</source>
<translation>Depurador</translation> <translation type="vanished">Depurador</translation>
</message> </message>
<message> <message>
<source>C options</source> <source>C options</source>

File diff suppressed because it is too large Load Diff

View File

@ -632,6 +632,38 @@
<source>Executable suffix</source> <source>Executable suffix</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Locate C Compiler</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Executable files (*.exe)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate C++ Compiler</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate Make</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate GDB</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate GDB Server</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate windres</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Locate gprof</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CppRefacter</name> <name>CppRefacter</name>
@ -5752,26 +5784,6 @@
<source>C++ include</source> <source>C++ include</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Cannot find the %1 &quot;%2&quot;</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>C Compiler</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>C++ Compiler</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Maker</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Debugger</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>C options</source> <source>C options</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>