ScriptConsole.cpp   ScriptConsole.cpp 
skipping to change at line 44 skipping to change at line 44
#include <QFile> #include <QFile>
#include <QFileDialog> #include <QFileDialog>
#include <QDateTime> #include <QDateTime>
#include <QSyntaxHighlighter> #include <QSyntaxHighlighter>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
ScriptConsole::ScriptConsole(QObject *parent) ScriptConsole::ScriptConsole(QObject *parent)
: StelDialog(parent) : StelDialog(parent)
, highlighter(NULL) , highlighter(NULL)
{ {
dialogName = "ScriptConsole";
ui = new Ui_scriptConsoleForm; ui = new Ui_scriptConsoleForm;
} }
ScriptConsole::~ScriptConsole() ScriptConsole::~ScriptConsole()
{ {
delete ui; delete ui;
} }
void ScriptConsole::retranslate() void ScriptConsole::retranslate()
{ {
skipping to change at line 84 skipping to change at line 85
ui->quickrunCombo->addItem(q_("quickrun...")); ui->quickrunCombo->addItem(q_("quickrun..."));
ui->quickrunCombo->addItem(q_("selected text")); ui->quickrunCombo->addItem(q_("selected text"));
ui->quickrunCombo->addItem(q_("clear text")); ui->quickrunCombo->addItem(q_("clear text"));
ui->quickrunCombo->addItem(q_("clear images")); ui->quickrunCombo->addItem(q_("clear images"));
ui->quickrunCombo->addItem(q_("natural")); ui->quickrunCombo->addItem(q_("natural"));
ui->quickrunCombo->addItem(q_("starchart")); ui->quickrunCombo->addItem(q_("starchart"));
connect(ui->scriptEdit, SIGNAL(cursorPositionChanged()), this, SLOT( rowColumnChanged())); connect(ui->scriptEdit, SIGNAL(cursorPositionChanged()), this, SLOT( rowColumnChanged()));
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ; connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ;
connect(ui->TitleBar, SIGNAL(movedTo(QPoint)), this, SLOT(handleMove dTo(QPoint)));
connect(ui->loadButton, SIGNAL(clicked()), this, SLOT(loadScript())) ; connect(ui->loadButton, SIGNAL(clicked()), this, SLOT(loadScript())) ;
connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(saveScript())) ; connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(saveScript())) ;
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearButtonPr essed())); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearButtonPr essed()));
connect(ui->preprocessSSCButton, SIGNAL(clicked()), this, SLOT(prepr ocessScript())); connect(ui->preprocessSSCButton, SIGNAL(clicked()), this, SLOT(prepr ocessScript()));
connect(ui->runButton, SIGNAL(clicked()), this, SLOT(runScript())); connect(ui->runButton, SIGNAL(clicked()), this, SLOT(runScript()));
connect(ui->stopButton, SIGNAL(clicked()), &StelApp::getInstance().g etScriptMgr(), SLOT(stopScript())); connect(ui->stopButton, SIGNAL(clicked()), &StelApp::getInstance().g etScriptMgr(), SLOT(stopScript()));
connect(ui->includeBrowseButton, SIGNAL(clicked()), this, SLOT(inclu deBrowse())); connect(ui->includeBrowseButton, SIGNAL(clicked()), this, SLOT(inclu deBrowse()));
connect(ui->quickrunCombo, SIGNAL(currentIndexChanged(int)), this, S LOT(quickRun(int))); connect(ui->quickrunCombo, SIGNAL(currentIndexChanged(int)), this, S LOT(quickRun(int)));
connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptRunning ()), this, SLOT(scriptStarted()));
connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptStopped ()), this, SLOT(scriptEnded())); connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptStopped ()), this, SLOT(scriptEnded()));
connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptDebug(c onst QString&)), this, SLOT(appendLogLine(const QString&))); connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptDebug(c onst QString&)), this, SLOT(appendLogLine(const QString&)));
connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptOutput( const QString&)), this, SLOT(appendOutputLine(const QString&))); connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptOutput( const QString&)), this, SLOT(appendOutputLine(const QString&)));
ui->tabs->setCurrentIndex(0); ui->tabs->setCurrentIndex(0);
ui->scriptEdit->setFocus(); ui->scriptEdit->setFocus();
} }
void ScriptConsole::loadScript() void ScriptConsole::loadScript()
{ {
QString fileName = QFileDialog::getOpenFileName(&StelMainView::getIn stance(), QString fileName = QFileDialog::getOpenFileName(&StelMainView::getIn stance(),
skipping to change at line 149 skipping to change at line 152
ui->scriptEdit->clear(); ui->scriptEdit->clear();
else if (ui->tabs->currentIndex() == 1) else if (ui->tabs->currentIndex() == 1)
ui->logBrowser->clear(); ui->logBrowser->clear();
else if (ui->tabs->currentIndex() == 2) else if (ui->tabs->currentIndex() == 2)
ui->outputBrowser->clear(); ui->outputBrowser->clear();
} }
void ScriptConsole::preprocessScript() void ScriptConsole::preprocessScript()
{ {
qDebug() << "ScriptConsole::preprocessScript"; qDebug() << "ScriptConsole::preprocessScript";
QTemporaryFile src(QDir::tempPath() + "/stelscriptXXXXXX"); //perform pre-processing without an intermediate temp file
QString dest; QString dest;
QString srcName; QString src = ui->scriptEdit->toPlainText();
if (src.open())
{
QTextStream out(&src);
out << ui->scriptEdit->toPlainText();
srcName = src.fileName();
if (sender() == ui->preprocessSSCButton) if (sender() == ui->preprocessSSCButton)
{ {
qDebug() << "Preprocessing with SSC proprocessor"; qDebug() << "Preprocessing with SSC proprocessor";
StelApp::getInstance().getScriptMgr().preprocessScri StelApp::getInstance().getScriptMgr().preprocessScript(src,
pt(src, dest, ui->includeEdit->text()); dest, ui->includeEdit->text());
}
else
qWarning() << "WARNING: unknown preprocessor type";
ui->scriptEdit->setPlainText(dest);
src.close();
} }
else
qWarning() << "WARNING: unknown preprocessor type";
ui->scriptEdit->setPlainText(dest);
ui->tabs->setCurrentIndex(0); ui->tabs->setCurrentIndex(0);
} }
void ScriptConsole::runScript() void ScriptConsole::runScript()
{ {
ui->tabs->setCurrentIndex(1); ui->tabs->setCurrentIndex(1);
ui->logBrowser->setHtml(""); ui->logBrowser->setHtml("");
QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc");
QString fileName; appendLogLine(QString("Starting script at %1").arg(QDateTime::curren
if (file.open()) { tDateTime().toString()));
QTextStream out(&file); if (!StelApp::getInstance().getScriptMgr().runScriptDirect(ui->scrip
out << ui->scriptEdit->toPlainText() << "\n"; tEdit->toPlainText(), ui->includeEdit->text()))
fileName = file.fileName();
file.close();
}
else
{ {
QString msg = "ERROR - cannot open tmp file for writing scri pt text"; QString msg = QString("ERROR - cannot run script");
qWarning() << "ScriptConsole::runScript " + msg; qWarning() << "ScriptConsole::runScript " + msg;
appendLogLine(msg); appendLogLine(msg);
return; return;
} }
}
void ScriptConsole::scriptStarted()
{
//prevent strating of scripts while any script is running
ui->quickrunCombo->setEnabled(false);
ui->runButton->setEnabled(false); ui->runButton->setEnabled(false);
ui->stopButton->setEnabled(true); ui->stopButton->setEnabled(true);
appendLogLine(QString("Starting script at %1").arg(QDateTime::curren
tDateTime().toString()));
if (!StelApp::getInstance().getScriptMgr().runScript(fileName, ui->i
ncludeEdit->text()))
{
QString msg = QString("ERROR - cannot run script from temp f
ile: \"%1\"").arg(fileName);
qWarning() << "ScriptConsole::runScript " + msg;
appendLogLine(msg);
if (file.open())
{
int n=0;
while(!file.atEnd())
{
appendLogLine(QString("%1:%2").arg(n,2).arg(
QString(file.readLine())));
}
file.close();
}
return;
}
} }
void ScriptConsole::scriptEnded() void ScriptConsole::scriptEnded()
{ {
qDebug() << "ScriptConsole::scriptEnded"; qDebug() << "ScriptConsole::scriptEnded";
QString html = ui->logBrowser->toHtml(); QString html = ui->logBrowser->toHtml();
appendLogLine(QString("Script finished at %1").arg(QDateTime::curren tDateTime().toString())); appendLogLine(QString("Script finished at %1").arg(QDateTime::curren tDateTime().toString()));
ui->quickrunCombo->setEnabled(true);
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->logBrowser->toHtml(); QString html = ui->logBrowser->toHtml();
html.replace(QRegExp("^\\s+"), ""); html.replace(QRegExp("^\\s+"), "");
// if (html!="") // if (html!="")
// html += "<br />"; // html += "<br />";
skipping to change at line 281 skipping to change at line 259
scriptText = "core.clear(\"natural\");\n"; scriptText = "core.clear(\"natural\");\n";
} }
if (idx==5) if (idx==5)
{ {
scriptText = "core.clear(\"starchart\");\n"; scriptText = "core.clear(\"starchart\");\n";
} }
if (scriptText.isEmpty()) if (scriptText.isEmpty())
return; return;
QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc"); appendLogLine(QString("Running: %1").arg(scriptText));
if (file.open()) StelApp::getInstance().getScriptMgr().runScriptDirect(scriptText);
{
QString fileName = file.fileName();
QTextStream out(&file);
out << scriptText;
file.close();
appendLogLine(QString("Running: %1").arg(scriptText));
StelApp::getInstance().getScriptMgr().runScript(fileName);
}
else
{
appendLogLine("Can't run quick script (could not open temp f
ile)");
}
} }
void ScriptConsole::rowColumnChanged() void ScriptConsole::rowColumnChanged()
{ {
ui->rowColumnLabel->setText(QString("R:%1 C:%2").arg(ui->scriptEdit- >textCursor().blockNumber()) ui->rowColumnLabel->setText(QString("R:%1 C:%2").arg(ui->scriptEdit- >textCursor().blockNumber())
.arg(ui->scriptEdit- >textCursor().columnNumber())); .arg(ui->scriptEdit- >textCursor().columnNumber()));
} }
QString ScriptConsole::getFileMask() QString ScriptConsole::getFileMask()
{ {
 End of changes. 14 change blocks. 
65 lines changed or deleted 28 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/