[rkward] rkward/windows: Add a note of caution.

Thomas Friedrichsmeier null at kde.org
Fri Sep 28 21:28:42 BST 2018


Git commit cc3a16798a44d6ee8a6565141c74489354cb9146 by Thomas Friedrichsmeier.
Committed on 28/09/2018 at 20:20.
Pushed by tfry into branch 'master'.

Add a note of caution.

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

https://commits.kde.org/rkward/cc3a16798a44d6ee8a6565141c74489354cb9146

diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index e530e171..5e8e224b 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -344,7 +344,7 @@ void RKCommandEditorWindow::initializeActions (KActionCollection* ac) {
 	actionmenu_preview->setCurrentItem (NoPreview);
 	actionmenu_preview->setToolBarMode (KSelectAction::MenuMode);
 	connect (preview, &RKXMLGUIPreviewArea::previewClosed, [this]() { actionmenu_preview->setCurrentItem (NoPreview); discardPreview (); });
-	connect (actionmenu_preview, static_cast<void (KSelectAction::*)(int)>(&KSelectAction::triggered), this, &RKCommandEditorWindow::textChanged);
+	connect (actionmenu_preview, static_cast<void (KSelectAction::*)(int)>(&KSelectAction::triggered), this, &RKCommandEditorWindow::changePreviewMode);
 	ac->addAction ("render_preview", actionmenu_preview);
 	
 	file_save = findAction (m_view, "file_save");
@@ -498,6 +498,19 @@ void RKCommandEditorWindow::autoSaveHandlerModifiedChanged () {
 	}
 }
 
+void RKCommandEditorWindow::changePreviewMode (int mode) {
+	RK_TRACE (COMMANDEDITOR);
+
+	if (mode != NoPreview) {
+		if (!preview_dir) {  // triggered on change from no preview to some preview, but not between previews
+			if (KMessageBox::warningContinueCancel (this, i18n ("<p>The preview feature <b>tries</b> to avoid making any lasting changes to your workspace (technically, by making use of a <i>local()</i> evaluation environment). <b>However, there are cases where using the preview feature may cause unexpected side-effects</b>.</p><p>In particular, this is the case for scripts that contain explicit assignments to <i>globalenv()</i>, or to scripts that alter files on your filesystem. Further, attaching/detaching packages or package namespaces will affect the entire running R session.</p><p>Please keep this in mind when using the preview feature, and especially when using the feature on scripts originating from untrusted sources.</p>"), i18n ("Potential side-effects of previews"), KStandardGuiItem::cont (), KStandardGuiItem::cancel (), QStringLiteral ("preview_side_effects")) != KMessageBox::Continue) {
+				actionmenu_preview->setCurrentItem (NoPreview);
+			}
+		}
+		textChanged ();
+	}
+}
+
 void RKCommandEditorWindow::discardPreview () {
 	RK_TRACE (COMMANDEDITOR);
 
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index d7132ac4..179a6869 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 changePreviewMode (int mode);
 	void discardPreview ();
 };
 



More information about the rkward-tracker mailing list