- fix: when run/debug the executable, add current compiler set's bin folders to path

- fix: when open in shell, add current compiler set's bin folders to path
This commit is contained in:
Roy Qu 2022-06-16 21:34:31 +08:00
parent c4ca944a15
commit 3d6d3c5210
19 changed files with 520 additions and 370 deletions

View File

@ -4,6 +4,9 @@ Red Panda C++ Version 1.1.1
- enhancement: when problem case panel is positioned at right, problem case's input, output and expected controls is layouted vertically - enhancement: when problem case panel is positioned at right, problem case's input, output and expected controls is layouted vertically
- enhancement: add ignore spaces checkbox in problem cases panel - enhancement: add ignore spaces checkbox in problem cases panel
- fix: can't paste contents copied from Clion/IDEA/PyCharm - fix: can't paste contents copied from Clion/IDEA/PyCharm
- fix: project don't have compiler set bin folder setting
- fix: when run/debug the executable, add current compiler set's bin folders to path
- fix: when open in shell, add current compiler set's bin folders to path
Red Panda C++ Version 1.1.0 Red Panda C++ Version 1.1.0
- enhancement: when ctrl+mouse cursor hovered an identifier or header name, use underline to highlight it - enhancement: when ctrl+mouse cursor hovered an identifier or header name, use underline to highlight it

View File

@ -4927,6 +4927,10 @@
<source>Resources</source> <source>Resources</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Binaries</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProjectFilesWidget</name> <name>ProjectFilesWidget</name>

File diff suppressed because it is too large Load Diff

View File

@ -4927,6 +4927,10 @@
<source>Resources</source> <source>Resources</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Binaries</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProjectFilesWidget</name> <name>ProjectFilesWidget</name>

View File

@ -422,7 +422,7 @@ QString Compiler::getProjectIncludeArguments()
{ {
QString result; QString result;
if (mProject) { if (mProject) {
foreach (const QString& folder,mProject->options().includes) { foreach (const QString& folder,mProject->options().includeDirs) {
result += QString(" -I\"%1\"").arg(folder); result += QString(" -I\"%1\"").arg(folder);
} }
// result += QString(" -I\"%1\"").arg(extractFilePath(mProject->filename())); // result += QString(" -I\"%1\"").arg(extractFilePath(mProject->filename()));
@ -450,7 +450,7 @@ QString Compiler::getLibraryArguments(FileType fileType)
//add libs added via project //add libs added via project
if (mProject) { if (mProject) {
foreach (const QString& folder, mProject->options().libs){ foreach (const QString& folder, mProject->options().libDirs){
result += QString(" -L\"%1\"").arg(folder); result += QString(" -L\"%1\"").arg(folder);
} }
} }

View File

@ -206,7 +206,11 @@ void CompilerManager::checkSyntax(const QString &filename, const QByteArray& enc
} }
} }
void CompilerManager::run(const QString &filename, const QString &arguments, const QString &workDir) void CompilerManager::run(
const QString &filename,
const QString &arguments,
const QString &workDir,
const QStringList& binDirs)
{ {
QMutexLocker locker(&mRunnerMutex); QMutexLocker locker(&mRunnerMutex);
if (mRunner!=nullptr && !mRunner->pausing()) { if (mRunner!=nullptr && !mRunner->pausing()) {
@ -279,7 +283,12 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con
execRunner->setRedirectInput(true); execRunner->setRedirectInput(true);
execRunner->setRedirectInputFilename(redirectInputFilename); execRunner->setRedirectInputFilename(redirectInputFilename);
} }
execRunner->addBinDirs(binDirs);
execRunner->addBinDir(pSettings->dirs().appDir());
mRunner = execRunner; mRunner = execRunner;
connect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); connect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated);
connect(mRunner, &Runner::finished, mRunner ,&Runner::deleteLater); connect(mRunner, &Runner::finished, mRunner ,&Runner::deleteLater);
connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished); connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished);

View File

@ -42,7 +42,11 @@ public:
void cleanProject(std::shared_ptr<Project> project); void cleanProject(std::shared_ptr<Project> project);
void buildProjectMakefile(std::shared_ptr<Project> project); void buildProjectMakefile(std::shared_ptr<Project> project);
void checkSyntax(const QString&filename, const QByteArray& encoding, const QString& content, std::shared_ptr<Project> project); void checkSyntax(const QString&filename, const QByteArray& encoding, const QString& content, std::shared_ptr<Project> project);
void run(const QString& filename, const QString& arguments, const QString& workDir); void run(
const QString& filename,
const QString& arguments,
const QString& workDir,
const QStringList& extraBinDir);
void runProblem(const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase); void runProblem(const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase);
void runProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector<POJProblemCase> &problemCases); void runProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector<POJProblemCase> &problemCases);
void stopRun(); void stopRun();

View File

@ -62,6 +62,21 @@ void ExecutableRunner::setShareMemoryId(const QString &newShareMemoryId)
mShareMemoryId = newShareMemoryId; mShareMemoryId = newShareMemoryId;
} }
const QStringList &ExecutableRunner::binDirs() const
{
return mBinDirs;
}
void ExecutableRunner::addBinDirs(const QStringList &binDirs)
{
mBinDirs.append(binDirs);
}
void ExecutableRunner::addBinDir(const QString &binDir)
{
mBinDirs.append(binDir);
}
bool ExecutableRunner::redirectInput() const bool ExecutableRunner::redirectInput() const
{ {
return mRedirectInput; return mRedirectInput;
@ -100,13 +115,7 @@ void ExecutableRunner::run()
mProcess->setWorkingDirectory(mWorkDir); mProcess->setWorkingDirectory(mWorkDir);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString path = env.value("PATH"); QString path = env.value("PATH");
QStringList pathAdded; QStringList pathAdded = mBinDirs;
if (pSettings->compilerSets().defaultSet()) {
foreach(const QString& dir, pSettings->compilerSets().defaultSet()->binDirs()) {
pathAdded.append(dir);
}
}
pathAdded.append(pSettings->dirs().appDir());
if (!path.isEmpty()) { if (!path.isEmpty()) {
path = pathAdded.join(PATH_SEPARATOR) + PATH_SEPARATOR + path; path = pathAdded.join(PATH_SEPARATOR) + PATH_SEPARATOR + path;
} else { } else {

View File

@ -41,6 +41,10 @@ public:
void setShareMemoryId(const QString &newShareMemoryId); void setShareMemoryId(const QString &newShareMemoryId);
const QStringList &binDirs() const;
void addBinDirs(const QStringList &binDirs);
void addBinDir(const QString &binDir);
private: private:
QString mRedirectInputFilename; QString mRedirectInputFilename;
QString mShareMemoryId; QString mShareMemoryId;
@ -48,6 +52,7 @@ private:
bool mStartConsole; bool mStartConsole;
std::shared_ptr<QProcess> mProcess; std::shared_ptr<QProcess> mProcess;
QSemaphore mQuitSemaphore; QSemaphore mQuitSemaphore;
QStringList mBinDirs;
// QThread interface // QThread interface
protected: protected:

View File

@ -55,7 +55,7 @@ Debugger::Debugger(QObject *parent) : QObject(parent),
this, &Debugger::fetchVarChildren); this, &Debugger::fetchVarChildren);
} }
bool Debugger::start(int compilerSetIndex, const QString& inferior) bool Debugger::start(int compilerSetIndex, const QString& inferior, const QStringList& binDirs)
{ {
Settings::PCompilerSet compilerSet = pSettings->compilerSets().getSet(compilerSetIndex); Settings::PCompilerSet compilerSet = pSettings->compilerSets().getSet(compilerSetIndex);
@ -126,6 +126,8 @@ bool Debugger::start(int compilerSetIndex, const QString& inferior)
mTarget->waitStart(); mTarget->waitStart();
} }
mReader = new DebugReader(this); mReader = new DebugReader(this);
mReader->addBinDirs(binDirs);
mReader->addBinDir(pSettings->dirs().appDir());
mReader->setDebuggerPath(debuggerPath); mReader->setDebuggerPath(debuggerPath);
connect(mReader, &QThread::finished,this,&Debugger::cleanUpReader); connect(mReader, &QThread::finished,this,&Debugger::cleanUpReader);
connect(mReader, &QThread::finished,mMemoryModel,&MemoryModel::reset); connect(mReader, &QThread::finished,mMemoryModel,&MemoryModel::reset);
@ -1327,6 +1329,21 @@ void DebugReader::asyncUpdate()
mAsyncUpdated = false; mAsyncUpdated = false;
} }
const QStringList &DebugReader::binDirs() const
{
return mBinDirs;
}
void DebugReader::addBinDirs(const QStringList &binDirs)
{
mBinDirs.append(binDirs);
}
void DebugReader::addBinDir(const QString &binDir)
{
mBinDirs.append(binDir);
}
const QString &DebugReader::signalMeaning() const const QString &DebugReader::signalMeaning() const
{ {
return mSignalMeaning; return mSignalMeaning;
@ -1420,19 +1437,22 @@ void DebugReader::run()
mProcess->setProgram(cmd); mProcess->setProgram(cmd);
mProcess->setArguments(splitProcessCommand(arguments)); mProcess->setArguments(splitProcessCommand(arguments));
mProcess->setProcessChannelMode(QProcess::MergedChannels); mProcess->setProcessChannelMode(QProcess::MergedChannels);
QString cmdDir = extractFileDir(cmd);
if (!cmdDir.isEmpty()) {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString path = env.value("PATH"); QString path = env.value("PATH");
cmdDir.replace("/",QDir::separator()); QStringList pathAdded = mBinDirs;
if (path.isEmpty()) { if (!path.isEmpty()) {
path = cmdDir; path = pathAdded.join(PATH_SEPARATOR) + PATH_SEPARATOR + path;
} else { } else {
path = pathAdded.join(PATH_SEPARATOR);
}
QString cmdDir = extractFileDir(cmd);
if (!cmdDir.isEmpty()) {
path = cmdDir + PATH_SEPARATOR + path; path = cmdDir + PATH_SEPARATOR + path;
} }
env.insert("PATH",path); env.insert("PATH",path);
mProcess->setProcessEnvironment(env); mProcess->setProcessEnvironment(env);
}
mProcess->setWorkingDirectory(workingDir); mProcess->setWorkingDirectory(workingDir);
connect(mProcess.get(), &QProcess::errorOccurred, connect(mProcess.get(), &QProcess::errorOccurred,

View File

@ -259,7 +259,7 @@ class Debugger : public QObject
public: public:
explicit Debugger(QObject *parent = nullptr); explicit Debugger(QObject *parent = nullptr);
// Play/pause // Play/pause
bool start(int compilerSetIndex, const QString& inferior); bool start(int compilerSetIndex, const QString& inferior, const QStringList& binDirs);
void sendCommand(const QString& command, const QString& params, void sendCommand(const QString& command, const QString& params,
DebugCommandSource source = DebugCommandSource::Other); DebugCommandSource source = DebugCommandSource::Other);
bool commandRunning(); bool commandRunning();
@ -428,6 +428,10 @@ public:
const QString &signalMeaning() const; const QString &signalMeaning() const;
const QStringList &binDirs() const;
void addBinDirs(const QStringList &binDirs);
void addBinDir(const QString &binDir);
signals: signals:
void parseStarted(); void parseStarted();
void invalidateAllVars(); void invalidateAllVars();
@ -463,6 +467,7 @@ signals:
const QString& newType, int newNumChildren, const QString& newType, int newNumChildren,
bool hasMore); bool hasMore);
void varsValueUpdated(); void varsValueUpdated();
private: private:
void clearCmdQueue(); void clearCmdQueue();
@ -502,6 +507,7 @@ private:
bool mCmdRunning; bool mCmdRunning;
PDebugCommand mCurrentCmd; PDebugCommand mCurrentCmd;
std::shared_ptr<QProcess> mProcess; std::shared_ptr<QProcess> mProcess;
QStringList mBinDirs;
//fWatchView: TTreeView; //fWatchView: TTreeView;

View File

@ -1550,7 +1550,7 @@ bool MainWindow::compile(bool rebuild)
} }
mProject->buildPrivateResource(); mProject->buildPrivateResource();
if (mCompileSuccessionTask) { if (mCompileSuccessionTask) {
mCompileSuccessionTask->filename = mProject->executable(); mCompileSuccessionTask->execName = mProject->executable();
} }
stretchMessagesPanel(true); stretchMessagesPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabToolsOutput); ui->tabMessages->setCurrentWidget(ui->tabToolsOutput);
@ -1566,7 +1566,7 @@ bool MainWindow::compile(bool rebuild)
return false; return false;
} }
if (mCompileSuccessionTask) { if (mCompileSuccessionTask) {
mCompileSuccessionTask->filename = getCompiledExecutableName(editor->filename()); mCompileSuccessionTask->execName = getCompiledExecutableName(editor->filename());
} }
stretchMessagesPanel(true); stretchMessagesPanel(true);
ui->tabMessages->setCurrentWidget(ui->tabToolsOutput); ui->tabMessages->setCurrentWidget(ui->tabToolsOutput);
@ -1579,7 +1579,11 @@ bool MainWindow::compile(bool rebuild)
return false; return false;
} }
void MainWindow::runExecutable(const QString &exeName,const QString &filename,RunType runType) void MainWindow::runExecutable(
const QString &exeName,
const QString &filename,
RunType runType,
const QStringList& binDirs)
{ {
mCompilerManager->stopPausing(); mCompilerManager->stopPausing();
// Check if it exists // Check if it exists
@ -1622,7 +1626,7 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename,Ru
if (pSettings->executor().minimizeOnRun()) { if (pSettings->executor().minimizeOnRun()) {
showMinimized(); showMinimized();
} }
mCompilerManager->run(exeName,params,QFileInfo(exeName).absolutePath()); mCompilerManager->run(exeName,params,QFileInfo(exeName).absolutePath(),binDirs);
} else if (runType == RunType::ProblemCases) { } else if (runType == RunType::ProblemCases) {
POJProblem problem = mOJProblemModel.problem(); POJProblem problem = mOJProblemModel.problem();
if (problem) { if (problem) {
@ -1649,6 +1653,7 @@ void MainWindow::runExecutable(RunType runType)
{ {
CompileTarget target =getCompileTarget(); CompileTarget target =getCompileTarget();
if (target == CompileTarget::Project) { if (target == CompileTarget::Project) {
QStringList binDirs = mProject->binDirs();
if (mProject->modified() && if (mProject->modified() &&
QMessageBox::question( QMessageBox::question(
this, this,
@ -1658,10 +1663,14 @@ void MainWindow::runExecutable(RunType runType)
mProject->saveAll(); mProject->saveAll();
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>(); mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::RunNormal; mCompileSuccessionTask->type = CompileSuccessionTaskType::RunNormal;
mCompileSuccessionTask->execName=mProject->executable();
mCompileSuccessionTask->binDirs=binDirs;
compile(); compile();
return; return;
} }
runExecutable(mProject->executable(),mProject->filename(),runType);
runExecutable(mProject->executable(),mProject->filename(),runType,
binDirs);
} else { } else {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor != NULL ) {
@ -1669,8 +1678,9 @@ void MainWindow::runExecutable(RunType runType)
if (!editor->save(false,false)) if (!editor->save(false,false))
return; return;
} }
QStringList binDirs = getDefaultCompilerSetBinDirs();
QString exeName= getCompiledExecutableName(editor->filename()); QString exeName= getCompiledExecutableName(editor->filename());
runExecutable(exeName,editor->filename(),runType); runExecutable(exeName,editor->filename(),runType,binDirs);
} }
} }
} }
@ -1691,8 +1701,10 @@ void MainWindow::debug()
bool stripEnabled; bool stripEnabled;
QString filePath; QString filePath;
QFileInfo debugFile; QFileInfo debugFile;
QStringList binDirs;
switch(getCompileTarget()) { switch(getCompileTarget()) {
case CompileTarget::Project: case CompileTarget::Project:
binDirs = mProject->binDirs();
// Check if we enabled proper options // Check if we enabled proper options
debugEnabled = mProject->getCompileOption(CC_CMD_OPT_DEBUG_INFO) == COMPILER_OPTION_ON; debugEnabled = mProject->getCompileOption(CC_CMD_OPT_DEBUG_INFO) == COMPILER_OPTION_ON;
stripEnabled = mProject->getCompileOption(LINK_CMD_OPT_STRIP_EXE) == COMPILER_OPTION_ON; stripEnabled = mProject->getCompileOption(LINK_CMD_OPT_STRIP_EXE) == COMPILER_OPTION_ON;
@ -1711,6 +1723,8 @@ void MainWindow::debug()
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>(); mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug; mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
mCompileSuccessionTask->execName = mProject->executable();
mCompileSuccessionTask->binDirs = binDirs;
compile(); compile();
return; return;
@ -1725,7 +1739,8 @@ void MainWindow::debug()
QMessageBox::Yes) == QMessageBox::Yes) { QMessageBox::Yes) == QMessageBox::Yes) {
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>(); mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug; mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
mCompileSuccessionTask->execName = mProject->executable();
mCompileSuccessionTask->binDirs = binDirs;
compile(); compile();
} }
return; return;
@ -1738,6 +1753,8 @@ void MainWindow::debug()
) == QMessageBox::Yes) { ) == QMessageBox::Yes) {
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>(); mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug; mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
mCompileSuccessionTask->execName = mProject->executable();
mCompileSuccessionTask->binDirs = binDirs;
compile(); compile();
return; return;
} }
@ -1766,7 +1783,7 @@ void MainWindow::debug()
// mDebugger->setUseUTF8(e->fileEncoding() == ENCODING_UTF8 || e->fileEncoding() == ENCODING_UTF8_BOM); // mDebugger->setUseUTF8(e->fileEncoding() == ENCODING_UTF8 || e->fileEncoding() == ENCODING_UTF8_BOM);
if (!mDebugger->start(mProject->options().compilerSet, filePath)) if (!mDebugger->start(mProject->options().compilerSet, filePath, binDirs))
return; return;
filePath.replace('\\','/'); filePath.replace('\\','/');
mDebugger->sendCommand("-file-exec-and-symbols", '"' + filePath + '"'); mDebugger->sendCommand("-file-exec-and-symbols", '"' + filePath + '"');
@ -1777,12 +1794,16 @@ void MainWindow::debug()
mDebugger->sendCommand("-file-exec-file", '"' + host + '"'); mDebugger->sendCommand("-file-exec-file", '"' + host + '"');
} }
includeOrSkipDirs(mProject->options().includes, includeOrSkipDirs(mProject->options().includeDirs,
pSettings->debugger().skipProjectLibraries()); pSettings->debugger().skipProjectLibraries());
includeOrSkipDirs(mProject->options().libs, includeOrSkipDirs(mProject->options().libDirs,
pSettings->debugger().skipProjectLibraries()); pSettings->debugger().skipProjectLibraries());
break; break;
case CompileTarget::File: { case CompileTarget::File: {
if (pSettings->compilerSets().defaultSet()) {
binDirs = pSettings->compilerSets().defaultSet()->binDirs();
}
// Check if we enabled proper options // Check if we enabled proper options
debugEnabled = compilerSet->getCompileOptionValue(CC_CMD_OPT_DEBUG_INFO) == COMPILER_OPTION_ON; debugEnabled = compilerSet->getCompileOptionValue(CC_CMD_OPT_DEBUG_INFO) == COMPILER_OPTION_ON;
stripEnabled = compilerSet->getCompileOptionValue(LINK_CMD_OPT_STRIP_EXE) == COMPILER_OPTION_ON; stripEnabled = compilerSet->getCompileOptionValue(LINK_CMD_OPT_STRIP_EXE) == COMPILER_OPTION_ON;
@ -1801,7 +1822,7 @@ void MainWindow::debug()
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>(); mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug; mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
mCompileSuccessionTask->binDirs = binDirs;
compile(); compile();
return; return;
} }
@ -1825,6 +1846,7 @@ void MainWindow::debug()
QMessageBox::Yes) == QMessageBox::Yes) { QMessageBox::Yes) == QMessageBox::Yes) {
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>(); mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug; mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
mCompileSuccessionTask->binDirs = binDirs;
compile(); compile();
return; return;
} }
@ -1836,6 +1858,7 @@ void MainWindow::debug()
QMessageBox::Yes) == QMessageBox::Yes) { QMessageBox::Yes) == QMessageBox::Yes) {
mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>(); mCompileSuccessionTask=std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug; mCompileSuccessionTask->type = CompileSuccessionTaskType::Debug;
mCompileSuccessionTask->binDirs = binDirs;
compile(); compile();
return; return;
} }
@ -1844,7 +1867,7 @@ void MainWindow::debug()
prepareDebugger(); prepareDebugger();
QString filePath = debugFile.filePath().replace('\\','/'); QString filePath = debugFile.filePath().replace('\\','/');
if (!mDebugger->start(pSettings->compilerSets().defaultIndex(),filePath)) if (!mDebugger->start(pSettings->compilerSets().defaultIndex(),filePath, binDirs))
return; return;
mDebugger->sendCommand("-file-exec-and-symbols", QString("\"%1\"").arg(filePath)); mDebugger->sendCommand("-file-exec-and-symbols", QString("\"%1\"").arg(filePath));
} }
@ -2746,7 +2769,29 @@ void MainWindow::maximizeEditor()
} }
} }
void MainWindow::openShell(const QString &folder, const QString &shellCommand) QStringList MainWindow::getBinDirsForCurrentEditor()
{
Editor * e=mEditorList->getEditor();
if (e) {
if (e->inProject() && mProject) {
return mProject->binDirs();
} else {
return getDefaultCompilerSetBinDirs();
}
} else if (mProject) {
return mProject->binDirs();
}
return QStringList();
}
QStringList MainWindow::getDefaultCompilerSetBinDirs()
{
if (pSettings->compilerSets().defaultSet())
return pSettings->compilerSets().defaultSet()->binDirs();
return QStringList();
}
void MainWindow::openShell(const QString &folder, const QString &shellCommand, const QStringList& binDirs)
{ {
QProcess process; QProcess process;
process.setWorkingDirectory(folder); process.setWorkingDirectory(folder);
@ -2760,11 +2805,7 @@ void MainWindow::openShell(const QString &folder, const QString &shellCommand)
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString path = env.value("PATH"); QString path = env.value("PATH");
QStringList pathAdded; QStringList pathAdded;
if (pSettings->compilerSets().defaultSet()) { pathAdded.append(binDirs);
foreach(const QString& dir, pSettings->compilerSets().defaultSet()->binDirs()) {
pathAdded.append(dir);
}
}
pathAdded.append(pSettings->dirs().appDir()); pathAdded.append(pSettings->dirs().appDir());
if (!path.isEmpty()) { if (!path.isEmpty()) {
path= pathAdded.join(PATH_SEPARATOR) + PATH_SEPARATOR + path; path= pathAdded.join(PATH_SEPARATOR) + PATH_SEPARATOR + path;
@ -3702,9 +3743,9 @@ void MainWindow::onFilesViewOpenInTerminal()
if (!path.isEmpty()) { if (!path.isEmpty()) {
QFileInfo fileInfo(path); QFileInfo fileInfo(path);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
openShell(fileInfo.path(),"cmd.exe"); openShell(fileInfo.path(),"cmd.exe",getDefaultCompilerSetBinDirs());
#else #else
openShell(fileInfo.path(),pSettings->environment().terminalPath()); openShell(fileInfo.path(),pSettings->environment().terminalPath(),getDefaultCompilerSetBinDirs());
#endif #endif
} }
} }
@ -4656,13 +4697,13 @@ void MainWindow::onCompileFinished(bool isCheckSyntax)
if (mCompileSuccessionTask && mCompilerManager->compileErrorCount()==0) { if (mCompileSuccessionTask && mCompilerManager->compileErrorCount()==0) {
switch (mCompileSuccessionTask->type) { switch (mCompileSuccessionTask->type) {
case MainWindow::CompileSuccessionTaskType::RunNormal: case MainWindow::CompileSuccessionTaskType::RunNormal:
runExecutable(mCompileSuccessionTask->filename); runExecutable(mCompileSuccessionTask->execName,QString(),RunType::Normal, mCompileSuccessionTask->binDirs);
break; break;
case MainWindow::CompileSuccessionTaskType::RunProblemCases: case MainWindow::CompileSuccessionTaskType::RunProblemCases:
runExecutable(mCompileSuccessionTask->filename,QString(),RunType::ProblemCases); runExecutable(mCompileSuccessionTask->execName,QString(),RunType::ProblemCases, mCompileSuccessionTask->binDirs);
break; break;
case MainWindow::CompileSuccessionTaskType::RunCurrentProblemCase: case MainWindow::CompileSuccessionTaskType::RunCurrentProblemCase:
runExecutable(mCompileSuccessionTask->filename,QString(),RunType::CurrentProblemCase); runExecutable(mCompileSuccessionTask->execName,QString(),RunType::CurrentProblemCase, mCompileSuccessionTask->binDirs);
break; break;
case MainWindow::CompileSuccessionTaskType::Debug: case MainWindow::CompileSuccessionTaskType::Debug:
debug(); debug();
@ -5566,9 +5607,9 @@ void MainWindow::on_actionOpen_Terminal_triggered()
QFileInfo info(editor->filename()); QFileInfo info(editor->filename());
if (!info.path().isEmpty()) { if (!info.path().isEmpty()) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
openShell(info.path(),"cmd.exe"); openShell(info.path(),"cmd.exe",getBinDirsForCurrentEditor());
#else #else
openShell(info.path(),pSettings->environment().terminalPath()); openShell(info.path(),pSettings->environment().terminalPath(),getBinDirsForCurrentEditor());
#endif #endif
} }
} }
@ -5889,9 +5930,9 @@ void MainWindow::on_actionProject_Open_In_Terminal_triggered()
if (!mProject) if (!mProject)
return; return;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
openShell(mProject->directory(),"cmd.exe"); openShell(mProject->directory(),"cmd.exe",mProject->binDirs());
#else #else
openShell(mProject->directory(),pSettings->environment().terminalPath()); openShell(mProject->directory(),pSettings->environment().terminalPath(),mProject->binDirs());
#endif #endif
} }
@ -6489,7 +6530,17 @@ void MainWindow::clearIssues()
void MainWindow::doCompileRun(RunType runType) void MainWindow::doCompileRun(RunType runType)
{ {
CompileTarget target =getCompileTarget();
QStringList binDirs;
QString execName;
if (target == CompileTarget::Project) {
binDirs = mProject->binDirs();
execName = mProject->executable();
} else {
binDirs = getDefaultCompilerSetBinDirs();
}
mCompileSuccessionTask = std::make_shared<CompileSuccessionTask>(); mCompileSuccessionTask = std::make_shared<CompileSuccessionTask>();
mCompileSuccessionTask->binDirs=binDirs;
switch (runType) { switch (runType) {
case RunType::CurrentProblemCase: case RunType::CurrentProblemCase:
mCompileSuccessionTask->type = CompileSuccessionTaskType::RunCurrentProblemCase; mCompileSuccessionTask->type = CompileSuccessionTaskType::RunCurrentProblemCase;

View File

@ -56,6 +56,7 @@ enum class RunType {
ProblemCases ProblemCases
}; };
class EditorList; class EditorList;
class QLabel; class QLabel;
class QComboBox; class QComboBox;
@ -85,8 +86,10 @@ class MainWindow : public QMainWindow
struct CompileSuccessionTask { struct CompileSuccessionTask {
CompileSuccessionTaskType type; CompileSuccessionTaskType type;
QString filename; QString execName;
QStringList binDirs;
}; };
using PCompileSuccessionTask = std::shared_ptr<CompileSuccessionTask>; using PCompileSuccessionTask = std::shared_ptr<CompileSuccessionTask>;
struct TabWidgetInfo { struct TabWidgetInfo {
@ -114,7 +117,11 @@ public:
void updateActionIcons(); void updateActionIcons();
void checkSyntaxInBack(Editor* e); void checkSyntaxInBack(Editor* e);
bool compile(bool rebuild=false); bool compile(bool rebuild=false);
void runExecutable(const QString& exeName, const QString& filename=QString(),RunType runType = RunType::Normal); void runExecutable(
const QString& exeName,
const QString& filename,
RunType runType,
const QStringList& binDirs);
void runExecutable(RunType runType = RunType::Normal); void runExecutable(RunType runType = RunType::Normal);
void debug(); void debug();
void showSearchPanel(bool showReplace = false); void showSearchPanel(bool showReplace = false);
@ -241,7 +248,9 @@ private:
void buildContextMenus(); void buildContextMenus();
void buildEncodingMenu(); void buildEncodingMenu();
void maximizeEditor(); void maximizeEditor();
void openShell(const QString& folder, const QString& shellCommand); QStringList getBinDirsForCurrentEditor();
QStringList getDefaultCompilerSetBinDirs();
void openShell(const QString& folder, const QString& shellCommand, const QStringList& binDirs);
QAction* createActionFor(const QString& text, QAction* createActionFor(const QString& text,
QWidget* parent, QWidget* parent,
QKeySequence shortcut=QKeySequence()); QKeySequence shortcut=QKeySequence());

View File

@ -463,7 +463,7 @@ void Project::resetParserProjectFiles()
foreach (const PProjectUnit& unit, mUnits) { foreach (const PProjectUnit& unit, mUnits) {
mParser->addFileToScan(unit->fileName()); mParser->addFileToScan(unit->fileName());
} }
foreach (const QString& s, mOptions.includes) { foreach (const QString& s, mOptions.includeDirs) {
mParser->addProjectIncludePath(s); mParser->addProjectIncludePath(s);
} }
} }
@ -876,8 +876,9 @@ void Project::saveOptions()
ini.SetLongValue("Project","Type", static_cast<int>(mOptions.type)); ini.SetLongValue("Project","Type", static_cast<int>(mOptions.type));
ini.SetLongValue("Project","Ver", 3); // Is 3 as of Red Panda C++.0 ini.SetLongValue("Project","Ver", 3); // Is 3 as of Red Panda C++.0
ini.SetValue("Project","ObjFiles", toByteArray(mOptions.objFiles.join(";"))); ini.SetValue("Project","ObjFiles", toByteArray(mOptions.objFiles.join(";")));
ini.SetValue("Project","Includes", toByteArray(mOptions.includes.join(";"))); ini.SetValue("Project","Includes", toByteArray(mOptions.includeDirs.join(";")));
ini.SetValue("Project","Libs", toByteArray(mOptions.libs.join(";"))); ini.SetValue("Project","Libs", toByteArray(mOptions.libDirs.join(";")));
ini.SetValue("Project","Bins", toByteArray(mOptions.binDirs.join(";")));
ini.SetValue("Project","PrivateResource", toByteArray(mOptions.privateResource)); ini.SetValue("Project","PrivateResource", toByteArray(mOptions.privateResource));
ini.SetValue("Project","ResourceIncludes", toByteArray(mOptions.resourceIncludes.join(";"))); ini.SetValue("Project","ResourceIncludes", toByteArray(mOptions.resourceIncludes.join(";")));
ini.SetValue("Project","MakeIncludes", toByteArray(mOptions.makeIncludes.join(";"))); ini.SetValue("Project","MakeIncludes", toByteArray(mOptions.makeIncludes.join(";")));
@ -1589,8 +1590,9 @@ void Project::loadOptions(SimpleIni& ini)
mOptions.cppCompilerCmd = fromByteArray(ini.GetValue("Project", "CppCompiler", "")); mOptions.cppCompilerCmd = fromByteArray(ini.GetValue("Project", "CppCompiler", ""));
mOptions.linkerCmd = fromByteArray(ini.GetValue("Project", "Linker", "")); mOptions.linkerCmd = fromByteArray(ini.GetValue("Project", "Linker", ""));
mOptions.objFiles = fromByteArray(ini.GetValue("Project", "ObjFiles", "")).split(";",QString::SkipEmptyParts); mOptions.objFiles = fromByteArray(ini.GetValue("Project", "ObjFiles", "")).split(";",QString::SkipEmptyParts);
mOptions.libs = fromByteArray(ini.GetValue("Project", "Libs", "")).split(";",QString::SkipEmptyParts); mOptions.binDirs = fromByteArray(ini.GetValue("Project", "Bins", "")).split(";",QString::SkipEmptyParts);
mOptions.includes = fromByteArray(ini.GetValue("Project", "Includes", "")).split(";",QString::SkipEmptyParts); mOptions.libDirs = fromByteArray(ini.GetValue("Project", "Libs", "")).split(";",QString::SkipEmptyParts);
mOptions.includeDirs = fromByteArray(ini.GetValue("Project", "Includes", "")).split(";",QString::SkipEmptyParts);
mOptions.privateResource = fromByteArray(ini.GetValue("Project", "PrivateResource", "")); mOptions.privateResource = fromByteArray(ini.GetValue("Project", "PrivateResource", ""));
mOptions.resourceIncludes = fromByteArray(ini.GetValue("Project", "ResourceIncludes", "")).split(";",QString::SkipEmptyParts); mOptions.resourceIncludes = fromByteArray(ini.GetValue("Project", "ResourceIncludes", "")).split(";",QString::SkipEmptyParts);
mOptions.makeIncludes = fromByteArray(ini.GetValue("Project", "MakeIncludes", "")).split(";",QString::SkipEmptyParts); mOptions.makeIncludes = fromByteArray(ini.GetValue("Project", "MakeIncludes", "")).split(";",QString::SkipEmptyParts);
@ -1708,7 +1710,7 @@ void Project::loadOptions(SimpleIni& ini)
mOptions.privateResource = fromByteArray(ini.GetValue("Project", "PrivateResource", "")); mOptions.privateResource = fromByteArray(ini.GetValue("Project", "PrivateResource", ""));
mOptions.resourceIncludes = fromByteArray(ini.GetValue("Project", "ResourceIncludes", "")).split(";",QString::SkipEmptyParts); mOptions.resourceIncludes = fromByteArray(ini.GetValue("Project", "ResourceIncludes", "")).split(";",QString::SkipEmptyParts);
mOptions.objFiles = fromByteArray(ini.GetValue("Project", "ObjFiles", "")).split(";",QString::SkipEmptyParts); mOptions.objFiles = fromByteArray(ini.GetValue("Project", "ObjFiles", "")).split(";",QString::SkipEmptyParts);
mOptions.includes = fromByteArray(ini.GetValue("Project", "IncludeDirs", "")).split(";",QString::SkipEmptyParts); mOptions.includeDirs = fromByteArray(ini.GetValue("Project", "IncludeDirs", "")).split(";",QString::SkipEmptyParts);
mOptions.compilerCmd = fromByteArray(ini.GetValue("Project", "CompilerOptions", "")); mOptions.compilerCmd = fromByteArray(ini.GetValue("Project", "CompilerOptions", ""));
mOptions.isCpp = ini.GetBoolValue("Project", "Use_GPP", false); mOptions.isCpp = ini.GetBoolValue("Project", "Use_GPP", false);
mOptions.exeOutput = fromByteArray(ini.GetValue("Project", "ExeOutput", "")); mOptions.exeOutput = fromByteArray(ini.GetValue("Project", "ExeOutput", ""));
@ -1826,6 +1828,16 @@ QString Project::fileSystemNodeFolderPath(const PProjectModelNode &node)
return result; return result;
} }
QStringList Project::binDirs()
{
QStringList lst = options().binDirs;
Settings::PCompilerSet compilerSet = pSettings->compilerSets().getSet(options().compilerSet);
if (compilerSet) {
lst.append(compilerSet->binDirs());
}
return lst;
}
EditorList *Project::editorList() const EditorList *Project::editorList() const
{ {
return mEditorList; return mEditorList;

View File

@ -245,6 +245,8 @@ public:
QString fileSystemNodeFolderPath(const PProjectModelNode& node); QString fileSystemNodeFolderPath(const PProjectModelNode& node);
QStringList binDirs();
signals: signals:
void nodesChanged(); void nodesChanged();
void modifyChanged(bool value); void modifyChanged(bool value);

View File

@ -61,8 +61,9 @@ struct ProjectOptions{
QString compilerCmd; QString compilerCmd;
QString cppCompilerCmd; QString cppCompilerCmd;
QString linkerCmd; QString linkerCmd;
QStringList includes; QStringList binDirs;
QStringList libs; QStringList includeDirs;
QStringList libDirs;
QString privateResource; QString privateResource;
QStringList resourceIncludes; QStringList resourceIncludes;
QStringList makeIncludes; QStringList makeIncludes;

View File

@ -130,8 +130,9 @@ void ProjectTemplate::readTemplateFile(const QString &fileName)
mOptions.icon = mIni->GetValue("Project", "Icon", ""); mOptions.icon = mIni->GetValue("Project", "Icon", "");
mOptions.type = static_cast<ProjectType>(mIni->GetLongValue("Project", "Type", 0)); // default = gui mOptions.type = static_cast<ProjectType>(mIni->GetLongValue("Project", "Type", 0)); // default = gui
mOptions.objFiles = fromByteArray(mIni->GetValue("Project", "ObjFiles", "")).split(";",QString::SkipEmptyParts); mOptions.objFiles = fromByteArray(mIni->GetValue("Project", "ObjFiles", "")).split(";",QString::SkipEmptyParts);
mOptions.includes = fromByteArray(mIni->GetValue("Project", "Includes", "")).split(";",QString::SkipEmptyParts); mOptions.includeDirs = fromByteArray(mIni->GetValue("Project", "Includes", "")).split(";",QString::SkipEmptyParts);
mOptions.libs = fromByteArray(mIni->GetValue("Project", "Libs", "")).split(";",QString::SkipEmptyParts); mOptions.binDirs = fromByteArray(mIni->GetValue("Project", "Bins", "")).split(";",QString::SkipEmptyParts);
mOptions.libDirs = fromByteArray(mIni->GetValue("Project", "Libs", "")).split(";",QString::SkipEmptyParts);
mOptions.resourceIncludes = fromByteArray(mIni->GetValue("Project", "ResourceIncludes", "")).split(";",QString::SkipEmptyParts); mOptions.resourceIncludes = fromByteArray(mIni->GetValue("Project", "ResourceIncludes", "")).split(";",QString::SkipEmptyParts);
mOptions.compilerCmd = fromByteArray(mIni->GetValue("Project", "Compiler", "")); mOptions.compilerCmd = fromByteArray(mIni->GetValue("Project", "Compiler", ""));
mOptions.cppCompilerCmd = fromByteArray(mIni->GetValue("Project", "CppCompiler", "")); mOptions.cppCompilerCmd = fromByteArray(mIni->GetValue("Project", "CppCompiler", ""));

View File

@ -26,6 +26,8 @@ ProjectDirectoriesWidget::ProjectDirectoriesWidget(const QString &name, const QS
{ {
ui->setupUi(this); ui->setupUi(this);
mBinDirWidget = new CompilerSetDirectoriesWidget();
ui->tabDirs->addTab(mBinDirWidget,tr("Binaries"));
mLibDirWidget = new CompilerSetDirectoriesWidget(); mLibDirWidget = new CompilerSetDirectoriesWidget();
ui->tabDirs->addTab(mLibDirWidget,tr("Libraries")); ui->tabDirs->addTab(mLibDirWidget,tr("Libraries"));
mIncludeDirWidget = new CompilerSetDirectoriesWidget(); mIncludeDirWidget = new CompilerSetDirectoriesWidget();
@ -42,16 +44,18 @@ ProjectDirectoriesWidget::~ProjectDirectoriesWidget()
void ProjectDirectoriesWidget::doLoad() void ProjectDirectoriesWidget::doLoad()
{ {
mLibDirWidget->setDirList(pMainWindow->project()->options().libs); mBinDirWidget->setDirList(pMainWindow->project()->options().binDirs);
mIncludeDirWidget->setDirList(pMainWindow->project()->options().includes); mLibDirWidget->setDirList(pMainWindow->project()->options().libDirs);
mIncludeDirWidget->setDirList(pMainWindow->project()->options().includeDirs);
mResourceDirWidget->setDirList(pMainWindow->project()->options().resourceIncludes); mResourceDirWidget->setDirList(pMainWindow->project()->options().resourceIncludes);
} }
void ProjectDirectoriesWidget::doSave() void ProjectDirectoriesWidget::doSave()
{ {
pMainWindow->project()->options().libs = mLibDirWidget->dirList(); pMainWindow->project()->options().binDirs = mBinDirWidget->dirList();
pMainWindow->project()->options().includes = mIncludeDirWidget->dirList(); pMainWindow->project()->options().libDirs = mLibDirWidget->dirList();
pMainWindow->project()->options().includeDirs = mIncludeDirWidget->dirList();
pMainWindow->project()->options().resourceIncludes = mResourceDirWidget->dirList(); pMainWindow->project()->options().resourceIncludes = mResourceDirWidget->dirList();
pMainWindow->project()->saveOptions(); pMainWindow->project()->saveOptions();
} }

View File

@ -35,6 +35,7 @@ public:
private: private:
Ui::ProjectDirectoriesWidget *ui; Ui::ProjectDirectoriesWidget *ui;
CompilerSetDirectoriesWidget *mBinDirWidget;
CompilerSetDirectoriesWidget *mLibDirWidget; CompilerSetDirectoriesWidget *mLibDirWidget;
CompilerSetDirectoriesWidget *mIncludeDirWidget; CompilerSetDirectoriesWidget *mIncludeDirWidget;
CompilerSetDirectoriesWidget *mResourceDirWidget; CompilerSetDirectoriesWidget *mResourceDirWidget;