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