From 2fe15c87cf264562c943053fe8dbb64d8b6774df Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 9 Aug 2019 17:49:51 +0800 Subject: [PATCH] Gui: output Cmt type macro line as comment in python console --- src/Gui/Command.cpp | 2 +- src/Gui/Macro.cpp | 64 ++++++++++++++++++++++++++------------------- src/Gui/Macro.h | 3 +-- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 6992aed6af..f95a1797f2 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -661,7 +661,7 @@ void Command::printCaller(const char *file, int line) { #else const char *_f = std::strstr(file, "/src/"); #endif - str << "# " << (_f?_f+5:file)<<'('<macroManager()->addLine(MacroManager::Cmt,str.str().c_str()); } diff --git a/src/Gui/Macro.cpp b/src/Gui/Macro.cpp index dfe49d3ae8..faae471de8 100644 --- a/src/Gui/Macro.cpp +++ b/src/Gui/Macro.cpp @@ -172,47 +172,57 @@ void MacroManager::addLine(LineType Type, const char* sLine, bool pending) if(pending) { if(!sLine) pendingLine.clear(); - else { - pendingType = Type; - pendingLine = sLine; - } + else + pendingLine.emplace_back(Type,sLine); return; } if(!sLine) return; - if(pendingLine.size() && pendingLine.c_str()!=sLine) { - addLine(pendingType,pendingLine.c_str()); - pendingLine.clear(); + + if(pendingLine.size()) { + if(Type == Cmt) { + pendingLine.emplace_back(Type,sLine); + return; + } + decltype(pendingLine) lines; + lines.swap(pendingLine); + for(auto &v : lines) + addLine(v.first,v.second.c_str()); } - ++totalLines; - if (this->openMacro) { - bool comment = false; - if (Type == Gui) { - if (this->recordGui && this->guiAsComment) - comment = true; - else if (!this->recordGui) - return; // ignore Gui commands - } - else if (Type == Cmt) { + if(Type != Cmt) + ++totalLines; + + bool comment = (Type == Cmt); + bool record = this->openMacro; + + if (record && Type == Gui) { + if (this->recordGui && this->guiAsComment) comment = true; - } - - QStringList lines = QString::fromLatin1(sLine).split(QLatin1String("\n")); - if (comment) { - for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it) - it->prepend(QLatin1String("#")); - } - this->macroInProgress.append(lines); + else if (!this->recordGui) + record = false; } + QStringList lines = QString::fromUtf8(sLine).split(QLatin1String("\n")); + if (comment) { + for (auto &line : lines) { + if(!line.startsWith(QLatin1String("#"))) + line.prepend(QLatin1String("# ")); + } + } + + if(record) + this->macroInProgress.append(lines); + if (this->scriptToPyConsole) { // search for the Python console if (!this->pyConsole) this->pyConsole = Gui::getMainWindow()->findChild(); // Python console found? - if (this->pyConsole) - this->pyConsole->printStatement(QString::fromUtf8(sLine)); + if (this->pyConsole) { + for(auto &line : lines) + this->pyConsole->printStatement(line); + } } } diff --git a/src/Gui/Macro.h b/src/Gui/Macro.h index 263cc3ac94..4ef6c4d24c 100644 --- a/src/Gui/Macro.h +++ b/src/Gui/Macro.h @@ -108,8 +108,7 @@ protected: PythonDebugger* pyDebugger; Base::Reference params; // link to the Macro parameter group long totalLines; - std::string pendingLine; - LineType pendingType; + std::vector > pendingLine; friend struct ApplicationP; };