Commit 233797f6 authored by Thomas Friedrichsmeier's avatar Thomas Friedrichsmeier
Browse files

Some fine-tuning to script previews

parent e8a2de95
......@@ -832,7 +832,13 @@ void RKCommandEditorWindow::doRenderPreview () {
if (actionmenu_preview->currentItem () == NoPreview) return;
if (!preview_manager->needsCommand ()) return;
if (!preview_dir) preview_dir = new QTemporaryDir ();
if (!preview_dir) {
if (!preview->findChild<RKMDIWindow*>()) {
// (lazily) initialize the preview window with _something_, as an RKMDIWindow is needed to display messages (important, if there is an error during the first preview)
RKGlobals::rInterface()->issueCommand (".rk.with.window.hints (rk.show.html(\"\"), " + RObject::rQuote (preview_manager->previewId ()) + ", style=\"preview\")", RCommand::App | RCommand::Sync);
}
preview_dir = new QTemporaryDir ();
}
QFile save (QDir (preview_dir->path()).absoluteFilePath ("script.R"));
if (actionmenu_preview->currentItem () == RMarkdownPreview) save.setFileName (QDir (preview_dir->path()).absoluteFilePath ("markdownscript.Rmd"));
RK_ASSERT (save.open (QIODevice::WriteOnly));
......@@ -841,8 +847,6 @@ void RKCommandEditorWindow::doRenderPreview () {
out << m_doc->text ();
save.close ();
// TODO: Make sure to initialze the preview region with some window, so it will be able to display status messages at all!
QString command;
if (actionmenu_preview->currentItem () == RMarkdownPreview) {
preview->setLabel (i18n ("Preview of rendered R Markdown"));
......@@ -883,17 +887,20 @@ void RKCommandEditorWindow::doRenderPreview () {
command = "output <- rk.set.output.html.file(%2, silent=TRUE)\n"
"on.exit(rk.set.output.html.file(output, silent=TRUE))\n"
"try(rk.flush.output(ask=FALSE, style=\"preview\", silent=TRUE))\n"
"exprs <- expression(NULL)\n"
"rk.capture.output(suppress.messages=TRUE)\n"
"try({\n"
" exprs <- parse (%1, keep.source=TRUE)\n"
" for (i in 1:length (exprs)) {\n"
" rk.print.code(as.character(attr(exprs, \"srcref\")[[i]]))\n"
" rk.capture.output()\n"
" try({\n"
" withAutoprint(exprs[[i]], evaluated=TRUE, echo=FALSE)\n"
" })\n"
" .rk.cat.output(rk.end.capture.output(TRUE))\n"
" }\n"
"})\n"
".rk.cat.output(rk.end.capture.output(TRUE))\n"
"for (i in 1:length (exprs)) {\n"
" rk.print.code(as.character(attr(exprs, \"srcref\")[[i]]))\n"
" rk.capture.output(suppress.messages=TRUE)\n"
" try({\n"
" withAutoprint(exprs[[i]], evaluated=TRUE, echo=FALSE)\n"
" })\n"
" .rk.cat.output(rk.end.capture.output(TRUE))\n"
"}\n"
"rk.set.output.html.file(output, silent=TRUE)\n"
"rk.show.html(%2)\n";
command = command.arg (RObject::rQuote (save.fileName ())).arg (output_file);
......
......@@ -344,17 +344,18 @@ void RKMDIWindow::setStatusMessage (const QString& message, RCommand *command) {
status_popup->setMessageType (KMessageWidget::Warning);
layout->addWidget (status_popup);
layout->addStretch ();
// when animation is finished, squeeze the popup-container, so as not to interfere with mouse events in the main window
connect (status_popup, &KMessageWidget::showAnimationFinished, [this]() { status_popup_container->resize (QSize(width(), status_popup->height () + 20)); });
connect (status_popup, &KMessageWidget::hideAnimationFinished, status_popup_container, &QWidget::hide);
}
if (command) connect (command->notifier (), &RCommandNotifier::commandFinished, this, &RKMDIWindow::clearStatusMessage);
if (!message.isEmpty ()) {
status_popup_container->resize (size ());
status_popup_container->show ();
// when animation is finished, squeeze the popup-container, so as not to interfere with mouse events in the main window
connect (status_popup, &KMessageWidget::showAnimationFinished, [this]() { status_popup_container->resize (QSize(width(), status_popup->height () + 20)); });
connect (status_popup, &KMessageWidget::hideAnimationFinished, status_popup_container, &QWidget::hide);
if (status_popup->text () == message) {
if (!status_popup->isVisible ()) status_popup->animatedShow (); // it might have been close by user. And no, simply show() is _not_ good enough. KF5 (5.15.0)
if (!status_popup->isVisible ()) status_popup->animatedShow (); // it might have been closed by user. And no, simply show() is _not_ good enough. KF5 (5.15.0)
}
if (status_popup->text () != message) {
if (status_popup->isVisible ()) status_popup->hide (); // otherwise, the KMessageWidget does not update geometry (KF5, 5.15.0)
......
Supports Markdown
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