Fix a couple of issues with macro recording

This commit is contained in:
wmayer
2012-12-13 15:02:15 +01:00
parent e6d84af12d
commit 23afef0b78
6 changed files with 71 additions and 54 deletions

View File

@@ -99,22 +99,22 @@ void MacroManager::commit(void)
{
// sort import lines and avoid duplicates
QTextStream str(&file);
QStringList lines = this->macroInProgress.split(QLatin1Char('\n'));
QStringList import; import << QString::fromAscii("import FreeCAD\n");
QStringList import;
import << QString::fromAscii("import FreeCAD");
QStringList body;
QStringList::Iterator it;
for ( it = lines.begin(); it != lines.end(); ++it )
for (it = this->macroInProgress.begin(); it != this->macroInProgress.end(); ++it )
{
if ((*it).startsWith(QLatin1String("import ")) ||
(*it).startsWith(QLatin1String("#import ")))
{
if (import.indexOf(*it + QLatin1Char('\n')) == -1)
import.push_back(*it + QLatin1Char('\n'));
if (import.indexOf(*it) == -1)
import.push_back(*it);
}
else
{
body.push_back(*it + QLatin1Char('\n'));
body.push_back(*it);
}
}
@@ -128,11 +128,11 @@ void MacroManager::commit(void)
// write the data to the text file
str << header;
for ( it = import.begin(); it != import.end(); ++it )
str << (*it);
for (it = import.begin(); it != import.end(); ++it)
str << (*it) << QLatin1Char('\n');
str << QLatin1Char('\n');
for ( it = body.begin(); it != body.end(); ++it )
str << (*it);
for (it = body.begin(); it != body.end(); ++it)
str << (*it) << QLatin1Char('\n');
str << footer;
Base::Console().Log("Commit macro: %s\n",(const char*)this->macroName.toUtf8());
@@ -159,18 +159,24 @@ void MacroManager::cancel(void)
void MacroManager::addLine(LineType Type, const char* sLine)
{
if (this->openMacro)
{
if(Type == Gui)
{
if (this->openMacro) {
bool comment = false;
if (Type == Gui) {
if (this->recordGui && this->guiAsComment)
this->macroInProgress += QLatin1Char('#');
comment = true;
else if (!this->recordGui)
return; // ignore Gui commands
}
else if (Type == Cmt) {
comment = true;
}
this->macroInProgress += QString::fromAscii(sLine);
this->macroInProgress += QLatin1Char('\n');
QStringList lines = QString::fromAscii(sLine).split(QLatin1String("\n"));
if (comment) {
for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it)
it->prepend(QLatin1String("#"));
}
this->macroInProgress.append(lines);
}
if (this->scriptToPyConsole) {
@@ -187,9 +193,7 @@ void MacroManager::setModule(const char* sModule)
{
if (this->openMacro && sModule && *sModule != '\0')
{
this->macroInProgress += QString::fromAscii("import ");
this->macroInProgress += QString::fromAscii(sModule);
this->macroInProgress += QLatin1Char('\n');
this->macroInProgress.append(QString::fromAscii("import %1").arg(QString::fromAscii(sModule)));
}
}