Changeset View
Changeset View
Standalone View
Standalone View
src/backends/octave/octavesession.cpp
Show All 34 Lines | |||||
35 | 35 | | |||
36 | #include <QTimer> | 36 | #include <QTimer> | ||
37 | #include <QFile> | 37 | #include <QFile> | ||
38 | 38 | | |||
39 | #ifndef Q_OS_WIN | 39 | #ifndef Q_OS_WIN | ||
40 | #include <signal.h> | 40 | #include <signal.h> | ||
41 | #endif | 41 | #endif | ||
42 | 42 | | |||
43 | #include <defaultvariablemodel.h> | 43 | #include "octavevariablemodel.h" | ||
44 | 44 | | |||
45 | const QRegExp OctaveSession::PROMPT_UNCHANGEABLE_COMMAND = QRegExp(QLatin1String("(,|;)+")); | 45 | const QRegExp OctaveSession::PROMPT_UNCHANGEABLE_COMMAND = QRegExp(QLatin1String("(,|;)+")); | ||
46 | 46 | | |||
47 | OctaveSession::OctaveSession ( Cantor::Backend* backend ) : Session ( backend ), | 47 | OctaveSession::OctaveSession ( Cantor::Backend* backend ) : Session ( backend ), | ||
48 | m_process(nullptr), | 48 | m_process(nullptr), | ||
49 | m_prompt(QLatin1String("CANTOR_OCTAVE_BACKEND_PROMPT:([0-9]+)> ")), | 49 | m_prompt(QLatin1String("CANTOR_OCTAVE_BACKEND_PROMPT:([0-9]+)> ")), | ||
50 | m_subprompt(QLatin1String("CANTOR_OCTAVE_BACKEND_SUBPROMPT:([0-9]+)> ")), | 50 | m_subprompt(QLatin1String("CANTOR_OCTAVE_BACKEND_SUBPROMPT:([0-9]+)> ")), | ||
51 | m_previousPromptNumber(1), | 51 | m_previousPromptNumber(1), | ||
52 | m_watch(nullptr), | 52 | m_watch(nullptr), | ||
53 | m_syntaxError(false), | 53 | m_syntaxError(false), | ||
54 | m_variableModel(new Cantor::DefaultVariableModel(this)) | 54 | m_needUpdate(false), | ||
55 | m_variableModel(new OctaveVariableModel(this)) | ||||
55 | { | 56 | { | ||
56 | qDebug() << octaveScriptInstallDir; | 57 | qDebug() << octaveScriptInstallDir; | ||
57 | } | 58 | } | ||
58 | 59 | | |||
59 | void OctaveSession::login() | 60 | void OctaveSession::login() | ||
60 | { | 61 | { | ||
61 | qDebug() << "login"; | 62 | qDebug() << "login"; | ||
62 | emit loginStarted(); | 63 | emit loginStarted(); | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | |||||
137 | connect ( m_process, SIGNAL (readyReadStandardOutput()), SLOT (readOutput()) ); | 138 | connect ( m_process, SIGNAL (readyReadStandardOutput()), SLOT (readOutput()) ); | ||
138 | connect ( m_process, SIGNAL (readyReadStandardError()), SLOT (readError()) ); | 139 | connect ( m_process, SIGNAL (readyReadStandardError()), SLOT (readError()) ); | ||
139 | connect ( m_process, SIGNAL (error(QProcess::ProcessError)), SLOT (processError()) ); | 140 | connect ( m_process, SIGNAL (error(QProcess::ProcessError)), SLOT (processError()) ); | ||
140 | 141 | | |||
141 | if(!OctaveSettings::self()->autorunScripts().isEmpty()){ | 142 | if(!OctaveSettings::self()->autorunScripts().isEmpty()){ | ||
142 | QString autorunScripts = OctaveSettings::self()->autorunScripts().join(QLatin1String("\n")); | 143 | QString autorunScripts = OctaveSettings::self()->autorunScripts().join(QLatin1String("\n")); | ||
143 | 144 | | |||
144 | evaluateExpression(autorunScripts, OctaveExpression::DeleteOnFinish, true); | 145 | evaluateExpression(autorunScripts, OctaveExpression::DeleteOnFinish, true); | ||
146 | m_needUpdate = true; | ||||
145 | } | 147 | } | ||
146 | 148 | | |||
147 | changeStatus(Cantor::Session::Done); | 149 | changeStatus(Cantor::Session::Done); | ||
148 | emit loginDone(); | 150 | emit loginDone(); | ||
149 | qDebug()<<"login done"; | 151 | qDebug()<<"login done"; | ||
150 | } | 152 | } | ||
151 | 153 | | |||
152 | void OctaveSession::logout() | 154 | void OctaveSession::logout() | ||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Line(s) | 277 | { | |||
279 | { | 281 | { | ||
280 | const int promptNumber = m_prompt.cap(1).toInt(); | 282 | const int promptNumber = m_prompt.cap(1).toInt(); | ||
281 | if (!expressionQueue().isEmpty()) | 283 | if (!expressionQueue().isEmpty()) | ||
282 | { | 284 | { | ||
283 | const QString& command = expressionQueue().first()->command(); | 285 | const QString& command = expressionQueue().first()->command(); | ||
284 | if (m_previousPromptNumber + 1 == promptNumber || isSpecialOctaveCommand(command)) | 286 | if (m_previousPromptNumber + 1 == promptNumber || isSpecialOctaveCommand(command)) | ||
285 | { | 287 | { | ||
286 | if (!expressionQueue().isEmpty()) | 288 | if (!expressionQueue().isEmpty()) | ||
287 | { | | |||
288 | if (command.contains(QLatin1String(" = ")) || command.contains(QLatin1String("clear"))) | | |||
289 | { | | |||
290 | emit variablesChanged(); | | |||
291 | } | | |||
292 | static_cast<OctaveExpression*>(expressionQueue().first())->parseOutput(m_output); | 289 | static_cast<OctaveExpression*>(expressionQueue().first())->parseOutput(m_output); | ||
293 | } | 290 | } | ||
294 | } | | |||
295 | else | 291 | else | ||
296 | { | 292 | { | ||
297 | // Error command don't increase octave prompt number (usually, but not always) | 293 | // Error command don't increase octave prompt number (usually, but not always) | ||
298 | readError(); | 294 | readError(); | ||
299 | } | 295 | } | ||
300 | } | 296 | } | ||
301 | m_previousPromptNumber = promptNumber; | 297 | m_previousPromptNumber = promptNumber; | ||
302 | m_output.clear(); | 298 | m_output.clear(); | ||
Show All 14 Lines | |||||
317 | 313 | | |||
318 | void OctaveSession::currentExpressionStatusChanged(Cantor::Expression::Status status) | 314 | void OctaveSession::currentExpressionStatusChanged(Cantor::Expression::Status status) | ||
319 | { | 315 | { | ||
320 | qDebug() << "currentExpressionStatusChanged"; | 316 | qDebug() << "currentExpressionStatusChanged"; | ||
321 | switch (status) | 317 | switch (status) | ||
322 | { | 318 | { | ||
323 | case Cantor::Expression::Done: | 319 | case Cantor::Expression::Done: | ||
324 | case Cantor::Expression::Error: | 320 | case Cantor::Expression::Error: | ||
321 | m_needUpdate |= !expressionQueue().first()->isInternal(); | ||||
325 | expressionQueue().removeFirst(); | 322 | expressionQueue().removeFirst(); | ||
326 | if (expressionQueue().isEmpty()) | 323 | if (expressionQueue().isEmpty()) | ||
324 | if (m_needUpdate) | ||||
325 | { | ||||
326 | m_variableModel->update(); | ||||
327 | m_needUpdate = false; | ||||
328 | } | ||||
329 | else | ||||
327 | changeStatus(Done); | 330 | changeStatus(Done); | ||
328 | else | 331 | else | ||
329 | runFirstExpression(); | 332 | runFirstExpression(); | ||
330 | break; | 333 | break; | ||
331 | default: | 334 | default: | ||
332 | break; | 335 | break; | ||
333 | } | 336 | } | ||
334 | } | 337 | } | ||
Show All 20 Lines | |||||
355 | { | 358 | { | ||
356 | return new OctaveSyntaxHelpObject ( cmd, this ); | 359 | return new OctaveSyntaxHelpObject ( cmd, this ); | ||
357 | } | 360 | } | ||
358 | 361 | | |||
359 | QSyntaxHighlighter* OctaveSession::syntaxHighlighter ( QObject* parent ) | 362 | QSyntaxHighlighter* OctaveSession::syntaxHighlighter ( QObject* parent ) | ||
360 | { | 363 | { | ||
361 | OctaveHighlighter* highlighter = new OctaveHighlighter ( parent, this ); | 364 | OctaveHighlighter* highlighter = new OctaveHighlighter ( parent, this ); | ||
362 | 365 | | |||
363 | connect ( this, SIGNAL(variablesChanged()), highlighter, SLOT(updateVariables()) ); | 366 | connect ( m_variableModel, &Cantor::DefaultVariableModel::variablesAdded, highlighter, &OctaveHighlighter::addUserVariable); | ||
364 | connect ( this, SIGNAL(statusChanged(Cantor::Session::Status)), highlighter, SLOT(sessionStatusChanged(Cantor::Session::Status)) ); | 367 | connect ( m_variableModel, &Cantor::DefaultVariableModel::variablesRemoved, highlighter, &OctaveHighlighter::removeUserVariable); | ||
365 | 368 | | |||
366 | return highlighter; | 369 | return highlighter; | ||
367 | } | 370 | } | ||
368 | 371 | | |||
369 | QAbstractItemModel* OctaveSession::variableModel() | 372 | QAbstractItemModel* OctaveSession::variableModel() | ||
370 | { | 373 | { | ||
371 | return m_variableModel; | 374 | return m_variableModel; | ||
372 | } | 375 | } | ||
Show All 16 Lines |