ScriptConsole.cpp   ScriptConsole.cpp 
skipping to change at line 23 skipping to change at line 23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "ScriptConsole.hpp" #include "ScriptConsole.hpp"
#include "ui_scriptConsole.h" #include "ui_scriptConsole.h"
#include "StelMainGraphicsView.hpp" #include "StelMainView.hpp"
#include "StelScriptMgr.hpp" #include "StelScriptMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include "StelScriptSyntaxHighlighter.hpp" #include "StelScriptSyntaxHighlighter.hpp"
#include <QDialog> #include <QDialog>
#include <QTextStream> #include <QTextStream>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QDir> #include <QDir>
skipping to change at line 87 skipping to change at line 87
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->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()), &StelMainGraphicsView::ge tInstance().getScriptMgr(), 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(&StelMainGraphicsView::getInstance().getScriptMgr(), SIGNAL( connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptStopped
scriptStopped()), this, SLOT(scriptEnded())); ()), this, SLOT(scriptEnded()));
connect(&StelMainGraphicsView::getInstance().getScriptMgr(), SIGNAL( connect(&StelApp::getInstance().getScriptMgr(), SIGNAL(scriptDebug(c
scriptDebug(const QString&)), this, SLOT(appendLogLine(const QString&))); onst QString&)), this, SLOT(appendLogLine(const QString&)));
#ifndef ENABLE_STRATOSCRIPT_COMPAT #ifndef ENABLE_STRATOSCRIPT_COMPAT
ui->preprocessSTSButton->setHidden(true); ui->preprocessSTSButton->setHidden(true);
#else #else
connect(ui->preprocessSTSButton, SIGNAL(clicked()), this, SLOT(prepr ocessScript())); connect(ui->preprocessSTSButton, SIGNAL(clicked()), this, SLOT(prepr ocessScript()));
#endif #endif
ui->tabs->setCurrentIndex(0); ui->tabs->setCurrentIndex(0);
ui->scriptEdit->setFocus(); ui->scriptEdit->setFocus();
} }
void ScriptConsole::loadScript() void ScriptConsole::loadScript()
{ {
QString fileName = QFileDialog::getOpenFileName(&StelMainGraphicsVie w::getInstance(), QString fileName = QFileDialog::getOpenFileName(&StelMainView::getIn stance(),
tr("Load Script"), tr("Load Script"),
StelFileMgr::getInst allationDir() + "/scripts", StelFileMgr::getInst allationDir() + "/scripts",
tr("Script Files") + " " + getFileMask()); tr("Script Files") + " " + getFileMask());
QFile file(fileName); QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) if (file.open(QIODevice::ReadOnly))
{ {
ui->scriptEdit->setPlainText(file.readAll()); ui->scriptEdit->setPlainText(file.readAll());
ui->includeEdit->setText(StelFileMgr::dirName(fileName)); ui->includeEdit->setText(StelFileMgr::dirName(fileName));
file.close(); file.close();
} }
ui->tabs->setCurrentIndex(0); ui->tabs->setCurrentIndex(0);
} }
void ScriptConsole::saveScript() void ScriptConsole::saveScript()
{ {
QString saveDir; QString saveDir = StelFileMgr::findFile("scripts", StelFileMgr::Flag
try s(StelFileMgr::Writable|StelFileMgr::Directory));
{ if (saveDir.isEmpty())
saveDir = StelFileMgr::findFile("scripts", StelFileMgr::Flag
s(StelFileMgr::Writable|StelFileMgr::Directory));
}
catch (std::runtime_error& e)
{
saveDir = StelFileMgr::getUserDir(); saveDir = StelFileMgr::getUserDir();
}
QString fileName = QFileDialog::getSaveFileName(&StelMainGraphicsVie w::getInstance(), QString fileName = QFileDialog::getSaveFileName(&StelMainView::getIn stance(),
tr("Save Script"), tr("Save Script"),
saveDir, saveDir,
tr("Script Files") + " " + getFileMask()); tr("Script Files") + " " + getFileMask());
QFile file(fileName); QFile file(fileName);
if (file.open(QIODevice::WriteOnly)) if (file.open(QIODevice::WriteOnly))
{ {
QTextStream out(&file); QTextStream out(&file);
out << ui->scriptEdit->toPlainText(); out << ui->scriptEdit->toPlainText();
file.close(); file.close();
} }
skipping to change at line 163 skipping to change at line 157
{ {
qDebug() << "ScriptConsole::preprocessScript"; qDebug() << "ScriptConsole::preprocessScript";
QTemporaryFile src(QDir::tempPath() + "/stelscriptXXXXXX"); QTemporaryFile src(QDir::tempPath() + "/stelscriptXXXXXX");
QString dest; 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.open();
if (sender() == ui->preprocessSSCButton) if (sender() == ui->preprocessSSCButton)
{ {
qDebug() << "Preprocessing with SSC proproce qDebug() << "Preprocessing with SSC proprocessor";
ssor"; StelApp::getInstance().getScriptMgr().preprocessScri
StelMainGraphicsView::getInstance().getScrip pt(src, dest, ui->includeEdit->text());
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 qDebug() << "Preprocessing with STS proprocessor";
ssor"; StelApp::getInstance().getScriptMgr().preprocessStra
StelMainGraphicsView::getInstance().getScrip toScript(src, dest, ui->includeEdit->text());
tMgr().preprocessStratoScript(src, dest, ui->includeEdit->text()); }
}
#endif #endif
else else
qWarning() << "WARNING: unknown preprocessor qWarning() << "WARNING: unknown preprocessor type";
type";
ui->scriptEdit->setPlainText(dest); ui->scriptEdit->setPlainText(dest);
src.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 210 skipping to change at line 203
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->runButton->setEnabled(false);
ui->stopButton->setEnabled(true); 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 (!StelApp::getInstance().getScriptMgr().runScript(fileName, ui->i ncludeEdit->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())));
skipping to change at line 250 skipping to change at line 243
html.replace(QRegExp("^\\s+"), ""); 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 View::getInstance(),
tr("Selec t Script Includ Directory"), tr("Selec t Script Includ Directory"),
StelFileM gr::getInstallationDir() + "/scripts")); StelFileM gr::getInstallationDir() + "/scripts"));
} }
void ScriptConsole::quickRun(int idx) void ScriptConsole::quickRun(int idx)
{ {
ui->quickrunCombo->setCurrentIndex(0); ui->quickrunCombo->setCurrentIndex(0);
QString scriptText; QString scriptText;
if (idx==1) if (idx==1)
{ {
skipping to change at line 292 skipping to change at line 285
return; return;
QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc"); QTemporaryFile file(QDir::tempPath() + "/stelscriptXXXXXX.ssc");
if (file.open()) if (file.open())
{ {
QString fileName = file.fileName(); QString fileName = file.fileName();
QTextStream out(&file); QTextStream out(&file);
out << scriptText; out << scriptText;
file.close(); file.close();
appendLogLine(QString("Running: %1").arg(scriptText)); appendLogLine(QString("Running: %1").arg(scriptText));
StelMainGraphicsView::getInstance().getScriptMgr().runScript (fileName); StelApp::getInstance().getScriptMgr().runScript(fileName);
} }
else else
{ {
appendLogLine("Can't run quick script (could not open temp f ile)"); 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())
 End of changes. 15 change blocks. 
40 lines changed or deleted 30 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/