From 319c26902c4ceebc0e8f7ffed5e7009ae4359d18 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 9 Dec 2021 08:10:14 +0800 Subject: [PATCH] - fix: path in macros should use system's path separator --- RedPandaIDE/compiler/compilermanager.cpp | 2 +- RedPandaIDE/mainwindow.cpp | 24 +++++++------ RedPandaIDE/utils.cpp | 44 +++++++++++++----------- RedPandaIDE/utils.h | 2 +- RedPandaIDE/widgets/macroinfomodel.cpp | 2 ++ 5 files changed, 41 insertions(+), 33 deletions(-) diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index c9ddc372..65ab3023 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -219,7 +219,7 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con if (consoleFlag!=0) { QString newArguments = QString(" %1 \"%2\" %3") .arg(consoleFlag) - .arg(toLocalPath(filename)).arg(arguments); + .arg(localizePath(filename)).arg(arguments); execRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().app())+"ConsolePauser.exe",newArguments,workDir); } else { execRunner = new ExecutableRunner(filename,arguments,workDir); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 9276e452..f7f4c372 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1802,18 +1802,20 @@ void MainWindow::updateTools() foreach (const PToolItem& item, mToolsManager->tools()) { QAction* action = new QAction(item->title,ui->menuTools); connect(action, &QAction::triggered, - [item,this] (){ - QString params = parseMacros(item->parameters); - params.replace("/",QDir::separator()); - QByteArray newContent = runAndGetOutput( + [item] (){ + if (item->pauseAfterExit + && programHasConsole(parseMacros(item->program))) { + executeFile( + includeTrailingPathDelimiter(pSettings->dirs().app())+"ConsolePauser.exe", + " 0 \""+parseMacros(item->program)+"\" "+parseMacros(item->parameters), + parseMacros(item->workingDirectory)); + } else { + executeFile( parseMacros(item->program), - parseMacros(item->workingDirectory), - QProcess::splitCommand(params), - QByteArray(), - true - ); - qDebug()<<"running"<program; - ui->txtCompilerOutput->appendPlainText(QString::fromLocal8Bit(newContent)); + parseMacros(item->parameters), + parseMacros(item->workingDirectory)); + + } }); ui->menuTools->addAction(action); } diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index c99c2526..6e4ec89d 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -293,13 +293,6 @@ bool programHasConsole(const QString &filename) return result; } -QString toLocalPath(const QString &filename) -{ - QString newPath {filename}; - newPath.replace("/",QDir::separator()); - return newPath; -} - QStringList textToLines(const QString &text) { QTextStream stream(&((QString&)text),QIODevice::ReadOnly); @@ -767,10 +760,10 @@ QString parseMacros(const QString &s) QString result = s; Editor *e = pMainWindow->editorList()->getEditor(); - result.replace("", QDir::currentPath()); - result.replace("", pSettings->dirs().executable()); + result.replace("", localizePath(QDir::currentPath())); + result.replace("", localizePath(pSettings->dirs().executable())); result.replace("", DEVCPP_VERSION); - result.replace("", pSettings->dirs().app()); + result.replace("", localizePath(pSettings->dirs().app())); QDate today = QDate::currentDate(); QDateTime now = QDateTime::currentDateTime(); @@ -781,30 +774,34 @@ QString parseMacros(const QString &s) if (compilerSet) { // Only provide the first cpp include dir if (compilerSet->defaultCppIncludeDirs().count()>0) - result.replace("", compilerSet->defaultCppIncludeDirs().front()); + result.replace("", localizePath(compilerSet->defaultCppIncludeDirs().front())); else result.replace("",""); // Only provide the first lib dir if (compilerSet->defaultLibDirs().count()>0) - result.replace("", compilerSet->defaultCppIncludeDirs().front()); + result.replace("", localizePath(compilerSet->defaultCppIncludeDirs().front())); else result.replace("",""); } // Project-dependent macros if (pMainWindow->project()) { - result.replace("", pMainWindow->project()->executable()); + result.replace("", extractFileName(pMainWindow->project()->executable())); + result.replace("", localizePath(pMainWindow->project()->executable())); result.replace("", pMainWindow->project()->name()); - result.replace("", pMainWindow->project()->filename()); - result.replace("", pMainWindow->project()->directory()); + result.replace("", localizePath(pMainWindow->project()->filename())); + result.replace("", extractFileName(pMainWindow->project()->filename())); + result.replace("", localizePath(pMainWindow->project()->directory())); // result.replace("', MainForm.Project.ListUnitStr(' ')); // result.replace("",""); } else if (e!=nullptr) { // Non-project editor macros - result.replace("", changeFileExt(e->filename(),EXECUTABLE_EXT)); + result.replace("", extractFileName(changeFileExt(e->filename(),EXECUTABLE_EXT))); + result.replace("", localizePath(changeFileExt(e->filename(),EXECUTABLE_EXT))); result.replace("", extractFileName(e->filename())); - result.replace("",e->filename()); - result.replace("", extractFileDir(e->filename())); + result.replace("", localizePath(e->filename())); + result.replace("", extractFileName(e->filename())); + result.replace("", localizePath(extractFileDir(e->filename()))); // result.replace("", ""); // clear unchanged macros } else { result.replace("", ""); @@ -817,8 +814,8 @@ QString parseMacros(const QString &s) // Editor macros if (e!=nullptr) { result.replace("", extractFileName(e->filename())); - result.replace("", e->filename()); - result.replace("", extractFileDir(e->filename())); + result.replace("", localizePath(e->filename())); + result.replace("", localizePath(extractFileDir(e->filename()))); result.replace("", e->wordAtCursor()); } else { result.replace("", ""); @@ -928,3 +925,10 @@ QList splitByteArrayToLines(const QByteArray &content) } return lines; } + +QString localizePath(const QString &path) +{ + QString result = path; + result.replace("/",QDir::separator()); + return result; +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index cf10d8df..7eb0d070 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -138,7 +138,6 @@ QString genMakePath2(const QString& fileName); QString getCompiledExecutableName(const QString& filename); void splitStringArguments(const QString& arguments, QStringList& argumentList); bool programHasConsole(const QString& filename); -QString toLocalPath(const QString& filename); using LineProcessFunc = std::function; QStringList readStreamToLines(QTextStream* stream); @@ -178,6 +177,7 @@ bool findComplement(const QString& s, int increment); void logToFile(const QString& s, const QString& filename, bool append=true); +QString localizePath(const QString& path); QString extractFileName(const QString& fileName); QString extractFileDir(const QString& fileName); QString extractFilePath(const QString& filePath); diff --git a/RedPandaIDE/widgets/macroinfomodel.cpp b/RedPandaIDE/widgets/macroinfomodel.cpp index 20d25ad7..6d4df062 100644 --- a/RedPandaIDE/widgets/macroinfomodel.cpp +++ b/RedPandaIDE/widgets/macroinfomodel.cpp @@ -11,12 +11,14 @@ MacroInfoModel::MacroInfoModel(QObject *parent) : QAbstractListModel(parent) addMacroInfo("", tr("The first include directory of the working compiler set.")); addMacroInfo("", tr("The first lib directory of the working compiler set.")); addMacroInfo("", tr("The compiled filename")); + addMacroInfo("", tr("Full path to the compiled file")); addMacroInfo("", tr("Filename of the current source file")); addMacroInfo("", tr("Full path to the current source file")); addMacroInfo("", tr("Path to the current source file's parent folder")); addMacroInfo("", tr("Word at the cursor in the active editor")); addMacroInfo("", tr("Name of the current project")); addMacroInfo("", tr("Full path to the current project file")); + addMacroInfo("", tr("Name of the current project file")); addMacroInfo("", tr("Path to the current project's folder")); }