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, new OctaveVariableModel(this) ), | ||
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)) | | |||
55 | { | 54 | { | ||
56 | qDebug() << octaveScriptInstallDir; | 55 | qDebug() << octaveScriptInstallDir; | ||
57 | } | 56 | } | ||
58 | 57 | | |||
59 | void OctaveSession::login() | 58 | void OctaveSession::login() | ||
60 | { | 59 | { | ||
61 | qDebug() << "login"; | 60 | qDebug() << "login"; | ||
62 | emit loginStarted(); | 61 | emit loginStarted(); | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | |||||
137 | connect ( m_process, SIGNAL (readyReadStandardOutput()), SLOT (readOutput()) ); | 136 | connect ( m_process, SIGNAL (readyReadStandardOutput()), SLOT (readOutput()) ); | ||
138 | connect ( m_process, SIGNAL (readyReadStandardError()), SLOT (readError()) ); | 137 | connect ( m_process, SIGNAL (readyReadStandardError()), SLOT (readError()) ); | ||
139 | connect ( m_process, SIGNAL (error(QProcess::ProcessError)), SLOT (processError()) ); | 138 | connect ( m_process, SIGNAL (error(QProcess::ProcessError)), SLOT (processError()) ); | ||
140 | 139 | | |||
141 | if(!OctaveSettings::self()->autorunScripts().isEmpty()){ | 140 | if(!OctaveSettings::self()->autorunScripts().isEmpty()){ | ||
142 | QString autorunScripts = OctaveSettings::self()->autorunScripts().join(QLatin1String("\n")); | 141 | QString autorunScripts = OctaveSettings::self()->autorunScripts().join(QLatin1String("\n")); | ||
143 | 142 | | |||
144 | evaluateExpression(autorunScripts, OctaveExpression::DeleteOnFinish, true); | 143 | evaluateExpression(autorunScripts, OctaveExpression::DeleteOnFinish, true); | ||
144 | forceVariableUpdate(); | ||||
145 | } | 145 | } | ||
146 | 146 | | |||
147 | changeStatus(Cantor::Session::Done); | 147 | changeStatus(Cantor::Session::Done); | ||
148 | emit loginDone(); | 148 | emit loginDone(); | ||
149 | qDebug()<<"login done"; | 149 | qDebug()<<"login done"; | ||
150 | } | 150 | } | ||
151 | 151 | | |||
152 | void OctaveSession::logout() | 152 | void OctaveSession::logout() | ||
Show All 23 Lines | 153 | { | |||
176 | delete m_process; | 176 | delete m_process; | ||
177 | m_process = nullptr; | 177 | m_process = nullptr; | ||
178 | 178 | | |||
179 | 179 | | |||
180 | m_tempDir.clear(); | 180 | m_tempDir.clear(); | ||
181 | m_output.clear(); | 181 | m_output.clear(); | ||
182 | m_previousPromptNumber = 1; | 182 | m_previousPromptNumber = 1; | ||
183 | 183 | | |||
184 | m_variableModel->clearVariables(); | 184 | static_cast<OctaveVariableModel*>(variableModel())->clearVariables(); | ||
185 | 185 | | |||
186 | changeStatus(Status::Disable); | 186 | changeStatus(Status::Disable); | ||
187 | 187 | | |||
188 | qDebug()<<"logout done"; | 188 | qDebug()<<"logout done"; | ||
189 | } | 189 | } | ||
190 | 190 | | |||
191 | void OctaveSession::interrupt() | 191 | void OctaveSession::interrupt() | ||
192 | { | 192 | { | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 275 | { | |||
279 | { | 279 | { | ||
280 | const int promptNumber = m_prompt.cap(1).toInt(); | 280 | const int promptNumber = m_prompt.cap(1).toInt(); | ||
281 | if (!expressionQueue().isEmpty()) | 281 | if (!expressionQueue().isEmpty()) | ||
282 | { | 282 | { | ||
283 | const QString& command = expressionQueue().first()->command(); | 283 | const QString& command = expressionQueue().first()->command(); | ||
284 | if (m_previousPromptNumber + 1 == promptNumber || isSpecialOctaveCommand(command)) | 284 | if (m_previousPromptNumber + 1 == promptNumber || isSpecialOctaveCommand(command)) | ||
285 | { | 285 | { | ||
286 | if (!expressionQueue().isEmpty()) | 286 | 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); | 287 | static_cast<OctaveExpression*>(expressionQueue().first())->parseOutput(m_output); | ||
293 | } | 288 | } | ||
294 | } | | |||
295 | else | 289 | else | ||
296 | { | 290 | { | ||
297 | // Error command don't increase octave prompt number (usually, but not always) | 291 | // Error command don't increase octave prompt number (usually, but not always) | ||
298 | readError(); | 292 | readError(); | ||
299 | } | 293 | } | ||
300 | } | 294 | } | ||
301 | m_previousPromptNumber = promptNumber; | 295 | m_previousPromptNumber = promptNumber; | ||
302 | m_output.clear(); | 296 | m_output.clear(); | ||
Show All 14 Lines | |||||
317 | 311 | | |||
318 | void OctaveSession::currentExpressionStatusChanged(Cantor::Expression::Status status) | 312 | void OctaveSession::currentExpressionStatusChanged(Cantor::Expression::Status status) | ||
319 | { | 313 | { | ||
320 | qDebug() << "currentExpressionStatusChanged"; | 314 | qDebug() << "currentExpressionStatusChanged"; | ||
321 | switch (status) | 315 | switch (status) | ||
322 | { | 316 | { | ||
323 | case Cantor::Expression::Done: | 317 | case Cantor::Expression::Done: | ||
324 | case Cantor::Expression::Error: | 318 | case Cantor::Expression::Error: | ||
325 | expressionQueue().removeFirst(); | 319 | finishFirstExpression(); | ||
326 | if (expressionQueue().isEmpty()) | | |||
327 | changeStatus(Done); | | |||
328 | else | | |||
329 | runFirstExpression(); | | |||
330 | break; | 320 | break; | ||
321 | | ||||
331 | default: | 322 | default: | ||
332 | break; | 323 | break; | ||
333 | } | 324 | } | ||
334 | } | 325 | } | ||
335 | 326 | | |||
336 | void OctaveSession::plotFileChanged(const QString& filename) | 327 | void OctaveSession::plotFileChanged(const QString& filename) | ||
337 | { | 328 | { | ||
338 | if (!QFile::exists(filename) || !filename.split(QLatin1Char('/')).last().contains(QLatin1String("c-ob-"))) | 329 | if (!QFile::exists(filename) || !filename.split(QLatin1Char('/')).last().contains(QLatin1String("c-ob-"))) | ||
Show All 16 Lines | |||||
355 | { | 346 | { | ||
356 | return new OctaveSyntaxHelpObject ( cmd, this ); | 347 | return new OctaveSyntaxHelpObject ( cmd, this ); | ||
357 | } | 348 | } | ||
358 | 349 | | |||
359 | QSyntaxHighlighter* OctaveSession::syntaxHighlighter ( QObject* parent ) | 350 | QSyntaxHighlighter* OctaveSession::syntaxHighlighter ( QObject* parent ) | ||
360 | { | 351 | { | ||
361 | OctaveHighlighter* highlighter = new OctaveHighlighter ( parent, this ); | 352 | OctaveHighlighter* highlighter = new OctaveHighlighter ( parent, this ); | ||
362 | 353 | | |||
363 | connect ( this, SIGNAL(variablesChanged()), highlighter, SLOT(updateVariables()) ); | 354 | OctaveVariableModel* model = static_cast<OctaveVariableModel*>(variableModel()); | ||
364 | connect ( this, SIGNAL(statusChanged(Cantor::Session::Status)), highlighter, SLOT(sessionStatusChanged(Cantor::Session::Status)) ); | 355 | connect (model, &Cantor::DefaultVariableModel::variablesAdded, highlighter, &OctaveHighlighter::addUserVariable); | ||
356 | connect (model, &Cantor::DefaultVariableModel::variablesRemoved, highlighter, &OctaveHighlighter::removeUserVariable); | ||||
365 | 357 | | |||
366 | return highlighter; | 358 | return highlighter; | ||
367 | } | 359 | } | ||
368 | 360 | | |||
369 | QAbstractItemModel* OctaveSession::variableModel() | | |||
370 | { | | |||
371 | return m_variableModel; | | |||
372 | } | | |||
373 | | ||||
374 | | ||||
375 | void OctaveSession::runSpecificCommands() | 361 | void OctaveSession::runSpecificCommands() | ||
376 | { | 362 | { | ||
377 | m_process->write("figure(1,'visible','off')"); | 363 | m_process->write("figure(1,'visible','off')"); | ||
378 | } | 364 | } | ||
379 | 365 | | |||
380 | bool OctaveSession::isDoNothingCommand(const QString& command) | 366 | bool OctaveSession::isDoNothingCommand(const QString& command) | ||
381 | { | 367 | { | ||
382 | return PROMPT_UNCHANGEABLE_COMMAND.exactMatch(command) || command.isEmpty(); | 368 | return PROMPT_UNCHANGEABLE_COMMAND.exactMatch(command) || command.isEmpty(); | ||
383 | } | 369 | } | ||
384 | 370 | | |||
385 | bool OctaveSession::isSpecialOctaveCommand(const QString& command) | 371 | bool OctaveSession::isSpecialOctaveCommand(const QString& command) | ||
386 | { | 372 | { | ||
387 | return command.contains(QLatin1String("completion_matches")); | 373 | return command.contains(QLatin1String("completion_matches")); | ||
388 | } | 374 | } |