diff --git a/src/cantor_part.h b/src/cantor_part.h --- a/src/cantor_part.h +++ b/src/cantor_part.h @@ -162,6 +162,7 @@ QProgressDialog* m_initProgressDlg; bool m_showProgressDlg; QAction * m_evaluate; + QAction * m_restart; QAction * m_save; QAction * m_findNext; QAction * m_findPrev; diff --git a/src/cantor_part.cpp b/src/cantor_part.cpp --- a/src/cantor_part.cpp +++ b/src/cantor_part.cpp @@ -264,10 +264,10 @@ actionCollection()->addAction(QLatin1String("enable_animations"), m_animateWorksheet); connect(m_animateWorksheet, SIGNAL(toggled(bool)), m_worksheet, SLOT(enableAnimations(bool))); - QAction * restart=new QAction(i18n("Restart Backend"), actionCollection()); - actionCollection()->addAction(QLatin1String("restart_backend"), restart); - restart->setIcon(QIcon::fromTheme(QLatin1String("system-reboot"))); - connect(restart, SIGNAL(triggered()), this, SLOT(restartBackend())); + m_restart=new QAction(i18n("Restart Backend"), actionCollection()); + actionCollection()->addAction(QLatin1String("restart_backend"), m_restart); + m_restart->setIcon(QIcon::fromTheme(QLatin1String("system-reboot"))); + connect(m_restart, SIGNAL(triggered()), this, SLOT(restartBackend())); QAction * evaluateCurrent=new QAction(i18n("Evaluate Entry"), actionCollection()); actionCollection()->addAction(QLatin1String("evaluate_current"), evaluateCurrent); @@ -429,6 +429,9 @@ QElapsedTimer timer; timer.start(); const bool rc = m_worksheet->load(localFilePath()); + m_restart->setVisible(!m_worksheet->isReadOnly()); + m_showBackendHelp->setVisible(!m_worksheet->isReadOnly()); + QApplication::restoreOverrideCursor(); if (rc) { @@ -563,14 +566,17 @@ void CantorPart::initialized() { - connect(m_worksheet->session(), SIGNAL(statusChanged(Cantor::Session::Status)), this, SLOT(worksheetStatusChanged(Cantor::Session::Status))); - connect(m_worksheet->session(), SIGNAL(loginStarted()),this, SLOT(worksheetSessionLoginStarted())); - connect(m_worksheet->session(), SIGNAL(loginDone()),this, SLOT(worksheetSessionLoginDone())); - connect(m_worksheet->session(), SIGNAL(error(const QString&)), this, SLOT(showSessionError(const QString&))); - - loadAssistants(); - m_panelHandler->setSession(m_worksheet->session()); - adjustGuiToSession(); + if (!m_worksheet->isReadOnly()) + { + connect(m_worksheet->session(), SIGNAL(statusChanged(Cantor::Session::Status)), this, SLOT(worksheetStatusChanged(Cantor::Session::Status))); + connect(m_worksheet->session(), SIGNAL(loginStarted()),this, SLOT(worksheetSessionLoginStarted())); + connect(m_worksheet->session(), SIGNAL(loginDone()),this, SLOT(worksheetSessionLoginDone())); + connect(m_worksheet->session(), SIGNAL(error(const QString&)), this, SLOT(showSessionError(const QString&))); + + loadAssistants(); + m_panelHandler->setSession(m_worksheet->session()); + adjustGuiToSession(); + } if (m_worksheet->isEmpty()) m_worksheet->appendCommandEntry(); @@ -620,7 +626,10 @@ if (filename.isEmpty()) filename=i18n("Unnamed"); - emit setCaption(filename, QIcon::fromTheme(m_worksheet->session()->backend()->icon())); + if (!m_worksheet->isReadOnly()) + emit setCaption(filename, QIcon::fromTheme(m_worksheet->session()->backend()->icon())); + else + emit setCaption(filename+QLatin1String("[read-only]"), QIcon()); } void CantorPart::pluginsChanged() diff --git a/src/commandentry.cpp b/src/commandentry.cpp --- a/src/commandentry.cpp +++ b/src/commandentry.cpp @@ -74,6 +74,8 @@ m_promptItem->setPlainText(Prompt); m_promptItem->setItemDragable(true); m_commandItem->enableCompletion(true); + if (worksheet->isReadOnly()) + m_commandItem->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::TextSelectableByKeyboard); KColorScheme scheme = KColorScheme(QPalette::Normal, KColorScheme::View); m_commandItem->setBackgroundColor(scheme.background(KColorScheme::AlternateBackground).color()); @@ -425,6 +427,9 @@ void CommandEntry::showCompletion() { + if (worksheet()->isReadOnly()) + return; + const QString line = currentLine(); if(!worksheet()->completionEnabled() || line.trimmed().isEmpty()) @@ -557,6 +562,13 @@ bool CommandEntry::evaluate(EvaluationOption evalOp) { + if (worksheet()->isReadOnly()) + { + // Worksheet is read only, so evaluate next + evaluateNext(evalOp); + return true; + } + removeContextHelp(); QToolTip::hideText(); diff --git a/src/lib/expression.cpp b/src/lib/expression.cpp --- a/src/lib/expression.cpp +++ b/src/lib/expression.cpp @@ -74,7 +74,7 @@ { d->session=session; d->internal = internal; - if (!internal) + if (!internal && session) d->id=session->nextExpressionId(); else d->id = -1; @@ -120,7 +120,8 @@ qDebug()<<"settting result to a type "<type()<<" result"; #ifdef WITH_EPS //If it's text, and latex typesetting is enabled, render it - if ( session()->isTypesettingEnabled()&& + if ( session() && + session()->isTypesettingEnabled()&& result->type()==TextResult::Type && dynamic_cast(result)->format()==TextResult::LatexFormat && !result->toHtml().trimmed().isEmpty() && diff --git a/src/worksheet.h b/src/worksheet.h --- a/src/worksheet.h +++ b/src/worksheet.h @@ -85,6 +85,7 @@ EpsRenderer* epsRenderer(); bool isEmpty(); bool isLoadingFromFile(); + bool isReadOnly() const; WorksheetEntry* currentEntry(); WorksheetEntry* firstEntry(); @@ -293,7 +294,9 @@ bool m_loginDone; bool m_isPrinting; bool m_isLoadingFromFile; + bool m_readOnly; + QString m_backendName; }; #endif // WORKSHEET_H diff --git a/src/worksheet.cpp b/src/worksheet.cpp --- a/src/worksheet.cpp +++ b/src/worksheet.cpp @@ -268,6 +268,11 @@ return m_isLoadingFromFile; } +bool Worksheet::isReadOnly() const +{ + return m_readOnly; +} + void Worksheet::makeVisible(WorksheetEntry* entry) { QRectF r = entry->boundingRect(); @@ -473,7 +478,7 @@ void Worksheet::evaluate() { qDebug()<<"evaluate worksheet"; - if (!m_loginDone) + if (!m_loginDone && !m_readOnly) loginToSession(); firstEntry()->evaluate(WorksheetEntry::EvaluateNext); @@ -483,7 +488,7 @@ void Worksheet::evaluateCurrentEntry() { - if (!m_loginDone) + if (!m_readOnly && !m_loginDone) loginToSession(); WorksheetEntry* entry = currentEntry(); @@ -795,7 +800,10 @@ if(m_highlighter) m_highlighter->deleteLater(); - m_highlighter=session()->syntaxHighlighter(this); + if (!m_readOnly) + m_highlighter=session()->syntaxHighlighter(this); + else + m_highlighter=nullptr; if(!m_highlighter) m_highlighter=new Cantor::DefaultHighlighter(this); @@ -823,7 +831,7 @@ bool Worksheet::isRunning() { - return m_session->status()==Cantor::Session::Running; + return (m_readOnly ? false : m_session->status()==Cantor::Session::Running); } bool Worksheet::showExpressionIds() @@ -851,7 +859,7 @@ { QDomDocument doc( QLatin1String("CantorWorksheet") ); QDomElement root=doc.createElement( QLatin1String("Worksheet") ); - root.setAttribute(QLatin1String("backend"), m_session->backend()->name()); + root.setAttribute(QLatin1String("backend"), (m_session ? m_session->backend()->name(): m_backendName)); doc.appendChild(root); for( WorksheetEntry* entry = firstEntry(); entry; entry = entry->next()) @@ -982,7 +990,7 @@ } bool rc = load(&file); - if (rc) + if (rc && !m_readOnly) m_session->setWorksheetPath(filename); return rc; @@ -1023,21 +1031,23 @@ QDomElement root=doc.documentElement(); // qDebug()<isEnabled()) + if(!m_readOnly && !b->isEnabled()) { QApplication::restoreOverrideCursor(); KMessageBox::information(worksheetView(), i18n("There are some problems with the %1 backend,\n"\ "please check your configuration or install the needed packages.\n" - "You will only be able to view this worksheet.", backendName), i18n("Cantor")); + "You will only be able to view this worksheet.", m_backendName), i18n("Cantor")); } @@ -1056,7 +1066,8 @@ } - m_session=b->createSession(); + if (!m_readOnly) + m_session=b->createSession(); qDebug()<<"loading entries"; QDomElement expressionChild = root.firstChildElement(); @@ -1096,7 +1107,7 @@ m_isLoadingFromFile = false; //Set the Highlighting, depending on the current state - //If the session isn't logged in, use the default + //If the session isn't logged in or readonly, use the default enableHighlighting( m_highlighter!=nullptr || Settings::highlightDefault() ); emit loaded(); diff --git a/src/worksheettextitem.cpp b/src/worksheettextitem.cpp --- a/src/worksheettextitem.cpp +++ b/src/worksheettextitem.cpp @@ -437,9 +437,6 @@ void WorksheetTextItem::keyPressEvent(QKeyEvent *event) { - if (!isEditable()) - return; - switch (event->key()) { case Qt::Key_Left: if (event->modifiers() == Qt::NoModifier && textCursor().atStart()) {