ScriptConsole.cpp   ScriptConsole.cpp 
skipping to change at line 40 skipping to change at line 40
#include <QDialog> #include <QDialog>
#include <QTextStream> #include <QTextStream>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QDateTime> #include <QDateTime>
#include <QSyntaxHighlighter> #include <QSyntaxHighlighter>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
ScriptConsole::ScriptConsole() ScriptConsole::ScriptConsole() : highlighter(NULL)
{ {
ui = new Ui_scriptConsoleForm; ui = new Ui_scriptConsoleForm;
} }
ScriptConsole::~ScriptConsole() ScriptConsole::~ScriptConsole()
{ {
delete ui; delete ui;
} }
void ScriptConsole::languageChanged() void ScriptConsole::languageChanged()
{ {
if (dialog) if (dialog)
ui->retranslateUi(dialog); ui->retranslateUi(dialog);
} }
void ScriptConsole::styleChanged() void ScriptConsole::styleChanged()
{ {
// Nothing for now if (highlighter)
{
highlighter->setFormats();
highlighter->rehighlight();
}
} }
void ScriptConsole::createDialogContent() void ScriptConsole::createDialogContent()
{ {
ui->setupUi(dialog); ui->setupUi(dialog);
highlighter = new StelScriptSyntaxHighlighter(ui->scriptEdit->docume nt()); highlighter = new StelScriptSyntaxHighlighter(ui->scriptEdit->docume nt());
ui->includeEdit->setText(StelFileMgr::getInstallationDir() + "/scrip ts"); ui->includeEdit->setText(StelFileMgr::getInstallationDir() + "/scrip ts");
ui->quickrunCombo->addItem(q_("quickrun...")); ui->quickrunCombo->addItem(q_("quickrun..."));
skipping to change at line 151 skipping to change at line 155
if (ui->tabs->currentIndex() == 0) if (ui->tabs->currentIndex() == 0)
ui->scriptEdit->clear(); ui->scriptEdit->clear();
else if (ui->tabs->currentIndex() == 1) else if (ui->tabs->currentIndex() == 1)
ui->outputBrowser->clear(); ui->outputBrowser->clear();
} }
void ScriptConsole::preprocessScript() void ScriptConsole::preprocessScript()
{ {
qDebug() << "ScriptConsole::preprocessScript"; qDebug() << "ScriptConsole::preprocessScript";
QTemporaryFile src(QDir::tempPath() + "/stelscriptXXXXXX"); QTemporaryFile src(QDir::tempPath() + "/stelscriptXXXXXX");
QTemporaryFile dest(QDir::tempPath() + "/stelscriptXXXXXX"); QString dest;
QString srcName; QString srcName;
if (src.open()) if (src.open())
{ {
QTextStream out(&src); QTextStream out(&src);
out << ui->scriptEdit->toPlainText(); out << ui->scriptEdit->toPlainText();
srcName = src.fileName(); srcName = src.fileName();
src.close(); src.close();
src.open(); src.open();
if (dest.open())
{
if (sender() == ui->preprocessSSCButton) if (sender() == ui->preprocessSSCButton)
{ {
qDebug() << "Preprocessing with SSC proproce ssor"; qDebug() << "Preprocessing with SSC proproce ssor";
StelMainGraphicsView::getInstance().getScrip tMgr().preprocessScript(src, dest, ui->includeEdit->text()); StelMainGraphicsView::getInstance().getScrip tMgr().preprocessScript(src, dest, ui->includeEdit->text());
} }
#ifdef ENABLE_STRATOSCRIPT_COMPAT #ifdef ENABLE_STRATOSCRIPT_COMPAT
else if (sender() == ui->preprocessSTSButton) else if (sender() == ui->preprocessSTSButton)
{ {
qDebug() << "Preprocessing with STS proproce ssor"; qDebug() << "Preprocessing with STS proproce ssor";
StelMainGraphicsView::getInstance().getScrip tMgr().preprocessStratoScript(src, dest, ui->includeEdit->text()); StelMainGraphicsView::getInstance().getScrip tMgr().preprocessStratoScript(src, dest, ui->includeEdit->text());
} }
#endif #endif
else else
qWarning() << "WARNING: unknown preprocessor type"; qWarning() << "WARNING: unknown preprocessor type";
dest.seek(0); ui->scriptEdit->setPlainText(dest);
ui->scriptEdit->setPlainText(dest.readAll());
dest.close();
}
} }
ui->tabs->setCurrentIndex(0); ui->tabs->setCurrentIndex(0);
} }
void ScriptConsole::runScript() void ScriptConsole::runScript()
{ {
ui->tabs->setCurrentIndex(1); ui->tabs->setCurrentIndex(1);
ui->outputBrowser->setHtml(""); ui->outputBrowser->setHtml("");
QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc"); QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc");
QString fileName; QString fileName;
skipping to change at line 205 skipping to change at line 205
file.close(); file.close();
} }
else else
{ {
QString msg = "ERROR - cannot open tmp file for writing scri pt text"; QString msg = "ERROR - cannot open tmp file for writing scri pt text";
qWarning() << "ScriptConsole::runScript " + msg; qWarning() << "ScriptConsole::runScript " + msg;
appendLogLine(msg); appendLogLine(msg);
return; return;
} }
ui->runButton->setEnabled(false);
ui->stopButton->setEnabled(true);
appendLogLine(QString("Starting script at %1").arg(QDateTime::curren tDateTime().toString())); appendLogLine(QString("Starting script at %1").arg(QDateTime::curren tDateTime().toString()));
if (!StelMainGraphicsView::getInstance().getScriptMgr().runScript(fi leName, ui->includeEdit->text())) if (!StelMainGraphicsView::getInstance().getScriptMgr().runScript(fi leName, ui->includeEdit->text()))
{ {
QString msg = QString("ERROR - cannot run script from temp f ile: \"%1\"").arg(fileName); QString msg = QString("ERROR - cannot run script from temp f ile: \"%1\"").arg(fileName);
qWarning() << "ScriptConsole::runScript " + msg; qWarning() << "ScriptConsole::runScript " + msg;
appendLogLine(msg); appendLogLine(msg);
if (file.open()) if (file.open())
{ {
int n=0; int n=0;
while(!file.atEnd()) while(!file.atEnd())
{ {
appendLogLine(QString("%1:%2").arg(n,2).arg( QString(file.readLine()))); appendLogLine(QString("%1:%2").arg(n,2).arg( QString(file.readLine())));
} }
file.close(); file.close();
} }
return; return;
} }
ui->runButton->setEnabled(false);
ui->stopButton->setEnabled(true);
} }
void ScriptConsole::scriptEnded() void ScriptConsole::scriptEnded()
{ {
qDebug() << "ScriptConsole::scriptEnded";
QString html = ui->outputBrowser->toHtml(); QString html = ui->outputBrowser->toHtml();
appendLogLine(QString("Script finished at %1").arg(QDateTime::curren tDateTime().toString())); appendLogLine(QString("Script finished at %1").arg(QDateTime::curren tDateTime().toString()));
ui->runButton->setEnabled(true); ui->runButton->setEnabled(true);
ui->stopButton->setEnabled(false); ui->stopButton->setEnabled(false);
} }
void ScriptConsole::appendLogLine(const QString& s) void ScriptConsole::appendLogLine(const QString& s)
{ {
QString html = ui->outputBrowser->toHtml(); QString html = ui->outputBrowser->toHtml();
html.replace(QRegExp("^\\s+"), "");
// if (html!="") // if (html!="")
// html += "<br />"; // html += "<br />";
html += s; html += s;
ui->outputBrowser->setHtml(html); ui->outputBrowser->setHtml(html);
} }
void ScriptConsole::includeBrowse() void ScriptConsole::includeBrowse()
{ {
ui->includeEdit->setText(QFileDialog::getExistingDirectory(&StelMain GraphicsView::getInstance(), ui->includeEdit->setText(QFileDialog::getExistingDirectory(&StelMain GraphicsView::getInstance(),
 End of changes. 9 change blocks. 
11 lines changed or deleted 14 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/