[rkward/work/render_rmd] rkward/windows: Some fixes for script plot previews

Thomas Friedrichsmeier null at kde.org
Fri Sep 28 17:19:24 BST 2018


Git commit 81ce95926cae5480899cd542ceff4b6b6d710122 by Thomas Friedrichsmeier.
Committed on 28/09/2018 at 16:17.
Pushed by tfry into branch 'work/render_rmd'.

Some fixes for script plot previews

M  +18   -7    rkward/windows/rkcommandeditorwindow.cpp
M  +1    -0    rkward/windows/rkcommandeditorwindow.h

https://commits.kde.org/rkward/81ce95926cae5480899cd542ceff4b6b6d710122

diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index fc4423d3..e46f593e 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -266,6 +266,7 @@ RKCommandEditorWindow::~RKCommandEditorWindow () {
 	}
 
 	delete hinter;
+	discardPreview ();
 	delete m_view;
 	QList<KTextEditor::View*> views = m_doc->views ();
 	if (views.isEmpty ()) {
@@ -277,7 +278,6 @@ RKCommandEditorWindow::~RKCommandEditorWindow () {
 	if (have_url && !_id.isEmpty ()) {
 		unnamed_documents.remove (_id);
 	}
-	delete preview_dir;
 }
 
 void RKCommandEditorWindow::fixupPartGUI () {
@@ -343,7 +343,7 @@ void RKCommandEditorWindow::initializeActions (KActionCollection* ac) {
 	actionmenu_preview->addAction (RKStandardIcons::getIcon (RKStandardIcons::WindowConsole), i18n ("R Console"));
 	actionmenu_preview->setCurrentItem (NoPreview);
 	actionmenu_preview->setToolBarMode (KSelectAction::MenuMode);
-	connect (preview, &RKXMLGUIPreviewArea::previewClosed, [this]() { actionmenu_preview->setCurrentItem (NoPreview); });
+	connect (preview, &RKXMLGUIPreviewArea::previewClosed, [this]() { actionmenu_preview->setCurrentItem (NoPreview); discardPreview (); });
 	connect (actionmenu_preview, static_cast<void (KSelectAction::*)(int)>(&KSelectAction::triggered), this, &RKCommandEditorWindow::textChanged);
 	ac->addAction ("render_preview", actionmenu_preview);
 	
@@ -498,6 +498,18 @@ void RKCommandEditorWindow::autoSaveHandlerModifiedChanged () {
 	}
 }
 
+void RKCommandEditorWindow::discardPreview () {
+	RK_TRACE (COMMANDEDITOR);
+
+	if (preview_dir) {
+		preview->wrapperWidget ()->hide ();
+		preview_manager->setPreviewDisabled ();
+		RKGlobals::rInterface ()->issueCommand (QString (".rk.killPreviewDevice(%1)\nrk.discard.preview.data (%1)").arg (RObject::rQuote(preview_manager->previewId ())), RCommand::App | RCommand::Sync);
+		delete preview_dir;
+		preview_dir = 0;
+	}
+}
+
 void RKCommandEditorWindow::textChanged () {
 	RK_TRACE (COMMANDEDITOR);
 
@@ -506,8 +518,7 @@ void RKCommandEditorWindow::textChanged () {
 		preview_manager->setUpdatePending ();
 		preview_timer.start (500);              // brief delay to buffer keystrokes
 	} else {
-		preview->wrapperWidget ()->hide ();
-		preview_manager->setPreviewDisabled ();
+		discardPreview ();
 	}
 
 	// auto save
@@ -843,10 +854,10 @@ void RKCommandEditorWindow::doRenderPreview () {
 		command = command.arg (RObject::rQuote (save.fileName ()), RObject::rQuote (output_file));
 	} else if (actionmenu_preview->currentItem () == GraphPreview) {
 		command = "olddev <- dev.cur()\n"
-		          "RK()\n"
+		          ".rk.startPreviewDevice(%2)\n"
 		          "try(source(%1))\n"
-		          "dev.set(olddev)\n";
-		command = command.arg (RObject::rQuote (save.fileName ()));
+		          "if (olddev != 1) dev.set(olddev)\n";
+		command = command.arg (RObject::rQuote (save.fileName ()), RObject::rQuote (preview_manager->previewId ()));
 	} else {
 		RK_ASSERT (actionmenu_preview->currentItem () == ConsolePreview);
 	}
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index cf1b3f59..d7132ac4 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -286,6 +286,7 @@ private:
 	QTimer preview_timer;
 	RKPreviewManager *preview_manager;
 	QTemporaryDir *preview_dir;
+	void discardPreview ();
 };
 
 /** Simple class to provide HTML highlighting for arbitrary R code. */



More information about the rkward-tracker mailing list