Commit c9ba1a37 authored by Alexander Semke's avatar Alexander Semke
Browse files

Allow to enable/disable the LaTeX typesetting before the session login.

Reasoning:
In the past the login was done together with the creation of the worksheet and the latex typesetting was set during this step.
After an optimization that was done in this area, the login was postponed to the point in time when the first expression needs to be evaluated.
With this it's not possible to the user to change the latex typesetting until the first evaluation is done which is wrong. We want to allow the user
to modify this setting before anything is processed so also the results of the first evaluation are obtained in the proper format (with or without latex).
parent 8af7dc91
Pipeline #125138 passed with stage
in 23 minutes and 22 seconds
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009-2012 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2017-2018 Alexander Semke (alexander.semke@web.de)
SPDX-FileCopyrightText: 2017-2022 Alexander Semke (alexander.semke@web.de)
*/
#include "maximasession.h"
......@@ -14,7 +14,6 @@
#include "settings.h"
#include <QDebug>
#include <QProcess>
#include <QTimer>
#include <QStandardPaths>
......@@ -35,9 +34,7 @@ const QRegularExpression MaximaSession::MaximaInputPrompt =
QRegularExpression(QStringLiteral("(\\(\\s*%\\s*i\\s*[0-9\\s]*\\))"));
MaximaSession::MaximaSession( Cantor::Backend* backend ) : Session(backend),
m_process(nullptr),
m_justRestarted(false)
MaximaSession::MaximaSession( Cantor::Backend* backend ) : Session(backend)
{
setVariableModel(new MaximaVariableModel(this));
}
......@@ -59,8 +56,8 @@ void MaximaSession::login()
m_process->start(MaximaSettings::self()->path().toLocalFile(), arguments);
m_process->waitForStarted();
QString input;
// Wait until first maxima prompt
QString input;
while (!input.contains(QLatin1String("</cantor-prompt>")))
{
m_process->waitForReadyRead();
......@@ -73,6 +70,11 @@ void MaximaSession::login()
connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr()));
connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(reportProcessError(QProcess::ProcessError)));
//enable latex typesetting if needed
const QString& val = QLatin1String((isTypesettingEnabled() ? "t":"nil"));
evaluateExpression(QString::fromLatin1(":lisp(setf $display2d %1)").arg(val), Cantor::Expression::DeleteOnFinish, true);
//auto-run scripts
if(!MaximaSettings::self()->autorunScripts().isEmpty()){
QString autorunScripts = MaximaSettings::self()->autorunScripts().join(QLatin1String(";"));
autorunScripts.append(QLatin1String(";kill(labels)")); // Reset labels after running autorun scripts
......@@ -284,10 +286,13 @@ void MaximaSession::restartsCooledDown()
void MaximaSession::setTypesettingEnabled(bool enable)
{
//we use the lisp command to set the variable, as those commands
//don't mess with the labels and history
const QString& val = QLatin1String((enable==true ? "t":"nil"));
evaluateExpression(QString::fromLatin1(":lisp(setf $display2d %1)").arg(val), Cantor::Expression::DeleteOnFinish, true);
if (m_process)
{
//we use the lisp command to set the variable, as those commands
//don't mess with the labels and history
const QString& val = QLatin1String((enable ? "t":"nil"));
evaluateExpression(QString::fromLatin1(":lisp(setf $display2d %1)").arg(val), Cantor::Expression::DeleteOnFinish, true);
}
Cantor::Session::setTypesettingEnabled(enable);
}
......
......@@ -21,7 +21,7 @@ class MaximaSession : public Cantor::Session
static const QRegularExpression MaximaOutputPrompt;
static const QRegularExpression MaximaInputPrompt;
explicit MaximaSession( Cantor::Backend* backend);
explicit MaximaSession(Cantor::Backend*);
void login() override;
void logout() override;
......@@ -51,9 +51,9 @@ class MaximaSession : public Cantor::Session
private:
void write(const QString&);
QProcess* m_process;
QProcess* m_process{nullptr};
QString m_cache;
bool m_justRestarted;
bool m_justRestarted{false};
};
#endif /* _MAXIMASESSION_H */
......@@ -148,6 +148,11 @@ void SageSession::login()
evaluateExpression(cmd.arg(m_worksheetPath), Cantor::Expression::DeleteOnFinish, true);
}
//enable latex typesetting if needed
const QString cmd = QLatin1String("__cantor_enable_typesetting(%1)");
evaluateExpression(cmd.arg(isTypesettingEnabled() ? QLatin1String("true"):QLatin1String("false")), Cantor::Expression::DeleteOnFinish);
//auto-run scripts
if(!SageSettings::self()->autorunScripts().isEmpty()){
QString autorunScripts = SageSettings::self()->autorunScripts().join(QLatin1String("\n"));
evaluateExpression(autorunScripts, SageExpression::DeleteOnFinish, true);
......@@ -440,11 +445,14 @@ void SageSession::fileCreated( const QString& path )
void SageSession::setTypesettingEnabled(bool enable)
{
Cantor::Session::setTypesettingEnabled(enable);
if (m_process)
{
//tell the sage server to enable/disable pretty_print
const QString cmd = QLatin1String("__cantor_enable_typesetting(%1)");
evaluateExpression(cmd.arg(enable ? QLatin1String("true"):QLatin1String("false")), Cantor::Expression::DeleteOnFinish);
}
//tell the sage server to enable/disable pretty_print
const QString cmd = QLatin1String("__cantor_enable_typesetting(%1)");
evaluateExpression(cmd.arg(enable ? QLatin1String("true"):QLatin1String("false")), Cantor::Expression::DeleteOnFinish);
Cantor::Session::setTypesettingEnabled(enable);
}
void SageSession::setWorksheetPath(const QString& path)
......
......@@ -236,12 +236,8 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
m_typeset = new KToggleAction(i18n("Typeset using LaTeX"), collection);
m_typeset->setChecked(Settings::self()->typesetDefault());
// Disable until login, because we use session command for this action
m_typeset->setEnabled(false);
collection->addAction(QLatin1String("enable_typesetting"), m_typeset);
connect(m_typeset, &KToggleAction::toggled, this, &CantorPart::enableTypesetting);
if (!Cantor::LatexRenderer::isLatexAvailable())
m_typeset->setVisible(false);
m_highlight = new KToggleAction(i18n("Syntax Highlighting"), collection);
m_highlight->setChecked(Settings::self()->highlightDefault());
......@@ -713,10 +709,7 @@ void CantorPart::worksheetSessionLoginStarted() {
void CantorPart::worksheetSessionLoginDone() {
setStatusMessage(i18n("Ready"));
m_typeset->setEnabled(true);
m_restart->setEnabled(true);
QApplication::restoreOverrideCursor();
}
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2019 Alexander Semke <alexander.semke@web.de>
*/
#include "session.h"
......@@ -21,31 +22,39 @@ using namespace Cantor;
class Cantor::SessionPrivate
{
public:
SessionPrivate() : backend(nullptr), status(Session::Disable), typesettingEnabled(false), expressionCount(0), variableModel(nullptr), needUpdate(false)
{
}
SessionPrivate() { }
Backend* backend;
Session::Status status;
bool typesettingEnabled;
int expressionCount;
Backend* backend{nullptr};
Session::Status status{Session::Disable};
bool typesettingEnabled{false};
int expressionCount{0};
QList<Cantor::Expression*> expressionQueue;
DefaultVariableModel* variableModel;
DefaultVariableModel* variableModel{nullptr};
QList<GraphicPackage> usableGraphicPackages;
QList<GraphicPackage> enabledGraphicPackages;
QList<QString> ignorableGraphicPackageIds;
bool needUpdate;
bool needUpdate{false};
};
Session::Session( Backend* backend ) : QObject(backend), d(new SessionPrivate)
Session::Session(Backend* backend ) : QObject(backend), d(new SessionPrivate)
{
d->backend=backend;
d->backend = backend;
#ifdef WITH_EPS
if (Cantor::LatexRenderer::isLatexAvailable())
d->typesettingEnabled = Settings::self()->typesetDefault();
#endif
}
Session::Session( Backend* backend, DefaultVariableModel* model) : QObject(backend), d(new SessionPrivate)
Session::Session(Backend* backend, DefaultVariableModel* model) : QObject(backend), d(new SessionPrivate)
{
d->backend=backend;
d->variableModel=model;
d->backend = backend;
d->variableModel = model;
#ifdef WITH_EPS
if (Cantor::LatexRenderer::isLatexAvailable())
d->typesettingEnabled = Settings::self()->typesetDefault();
#endif
}
Session::~Session()
......@@ -110,6 +119,7 @@ void Session::logout()
d->variableModel->clearVariables();
d->variableModel->clearFunctions();
}
d->expressionCount = 0;
changeStatus(Status::Disable);
......@@ -178,13 +188,13 @@ Cantor::Session::Status Session::status()
void Session::changeStatus(Session::Status newStatus)
{
d->status=newStatus;
d->status = newStatus;
emit statusChanged(newStatus);
}
void Session::setTypesettingEnabled(bool enable)
{
d->typesettingEnabled=enable;
d->typesettingEnabled = enable;
}
bool Session::isTypesettingEnabled()
......@@ -192,36 +202,27 @@ bool Session::isTypesettingEnabled()
return d->typesettingEnabled;
}
void Session::setWorksheetPath(const QString& path)
{
Q_UNUSED(path);
return;
}
void Session::setWorksheetPath(const QString&) { }
CompletionObject* Session::completionFor(const QString& cmd, int index)
CompletionObject* Session::completionFor(const QString&, int)
{
Q_UNUSED(cmd);
Q_UNUSED(index);
//Return 0 per default, so Backends not offering tab completions don't have
//Return nullptr per default, so Backends not offering tab completions don't have
//to reimplement this. This method should only be called on backends with
//the Completion Capability flag
return nullptr;
}
SyntaxHelpObject* Session::syntaxHelpFor(const QString& cmd)
SyntaxHelpObject* Session::syntaxHelpFor(const QString&)
{
Q_UNUSED(cmd);
//Return 0 per default, so Backends not offering tab completions don't have
//Return nullptr per default, so Backends not offering tab completions don't have
//to reimplement this. This method should only be called on backends with
//the SyntaxHelp Capability flag
return nullptr;
}
QSyntaxHighlighter* Session::syntaxHighlighter(QObject* parent)
QSyntaxHighlighter* Session::syntaxHighlighter(QObject*)
{
Q_UNUSED(parent);
return nullptr;
}
......@@ -295,7 +296,7 @@ QList<Cantor::GraphicPackage> Cantor::Session::usableGraphicPackages()
return d->usableGraphicPackages;
}
const QList<Cantor::GraphicPackage> & Cantor::Session::enabledGraphicPackages() const
const QList<Cantor::GraphicPackage>& Cantor::Session::enabledGraphicPackages() const
{
return d->enabledGraphicPackages;
}
......@@ -347,7 +348,6 @@ void Cantor::Session::updateEnabledGraphicPackages(const QList<Cantor::GraphicPa
d->enabledGraphicPackages = willEnabledPackages;
QList<Cantor::GraphicPackage> allPackages = backend()->availableGraphicPackages();
for (const Cantor::GraphicPackage& notEnabledPackage : unavailablePackages)
{
if (d->ignorableGraphicPackageIds.contains(notEnabledPackage.id()) == false)
......@@ -363,4 +363,3 @@ void Cantor::Session::updateEnabledGraphicPackages(const QList<Cantor::GraphicPa
}
}
}
......@@ -109,14 +109,6 @@ Worksheet::~Worksheet()
void Worksheet::loginToSession()
{
m_session->login();
#ifdef WITH_EPS
if (Cantor::LatexRenderer::isLatexAvailable())
session()->setTypesettingEnabled(Settings::self()->typesetDefault());
else
session()->setTypesettingEnabled(false);
#else
session()->setTypesettingEnabled(false);
#endif
}
void Worksheet::print(QPrinter* printer)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment