[rkward] rkward/windows: Fix (error) status message display for HTML previews

Thomas Friedrichsmeier null at kde.org
Thu Oct 4 08:37:51 BST 2018


Git commit 5ea992de6ec0f5c76b1a7f82a0a3286aff0c43f5 by Thomas Friedrichsmeier.
Committed on 04/10/2018 at 07:36.
Pushed by tfry into branch 'master'.

Fix (error) status message display for HTML previews

M  +7    -5    rkward/windows/rkcommandeditorwindow.cpp
M  +15   -0    rkward/windows/rkworkplace.cpp

https://commits.kde.org/rkward/5ea992de6ec0f5c76b1a7f82a0a3286aff0c43f5

diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 00aa875c..968943e5 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -833,13 +833,16 @@ void RKCommandEditorWindow::doRenderPreview () {
 	if (!preview_manager->needsCommand ()) return;
 
 	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"));
+	QString output_file = QDir (preview_dir->path()).absoluteFilePath ("output.html");  // NOTE: not needed by all types of preview
+
+	if (actionmenu_preview->currentItem () != GraphPreview && !preview->wrapperWidget ()->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 (output_file) + "), \"\", " + RObject::rQuote (preview_manager->previewId ()) + ", style=\"preview\")", RCommand::App | RCommand::Sync);
+	}
+
 	if (actionmenu_preview->currentItem () == RMarkdownPreview) save.setFileName (QDir (preview_dir->path()).absoluteFilePath ("markdownscript.Rmd"));
 	RK_ASSERT (save.open (QIODevice::WriteOnly));
 	QTextStream out (&save);
@@ -867,7 +870,6 @@ void RKCommandEditorWindow::doRenderPreview () {
 		command = command.arg (RObject::rQuote (save.fileName ()), RObject::rQuote (save.fileName () + ".html"));
 	} else if (actionmenu_preview->currentItem () == RKOutputPreview) {
 		preview->setLabel (i18n ("Preview of generated RKWard output"));
-		QString output_file = QDir (preview_dir->path()).absoluteFilePath ("output.html");
 		command = "output <- rk.set.output.html.file(%2, silent=TRUE)\n"
 		          "try(rk.flush.output(ask=FALSE, style=\"preview\", silent=TRUE))\n"
 		          "try(source(%1, local=TRUE))\n"
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index 81984175..4d527c52 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -476,6 +476,21 @@ RKMDIWindow* RKWorkplace::openHelpWindow (const QUrl &url, bool only_once) {
 			}
 		}
 	}
+	// if we're working with a window hint, try to _reuse_ the existing window, even if it did not get found, above
+	if (!window_name_override.isEmpty ()) {
+		int pos = -1;
+		for (int i = 0; i < named_windows.size (); ++i) {
+			if (named_windows[i].id == window_name_override) {
+				RKMDIWindow *w = dynamic_cast<RKHTMLWindow*> (named_windows[i].window);
+				if (w) {
+					w->activate ();
+					return w;
+				}
+				break;
+			}
+		}
+	}
+
 
 	RKHTMLWindow *hw = new RKHTMLWindow (view (), RKHTMLWindow::HTMLHelpWindow);
 	hw->openURL (url);



More information about the rkward-tracker mailing list