[education/rkward/devel/workspace_output] /: Fix closing of graphics windows from R.

Thomas Friedrichsmeier null at kde.org
Sat Nov 7 21:22:31 GMT 2020


Git commit 2f73f130cbc9aa3047a6c94db7fd180c7abee521 by Thomas Friedrichsmeier.
Committed on 07/11/2020 at 21:22.
Pushed by tfry into branch 'devel/workspace_output'.

Fix closing of graphics windows from R.

M  +0    -1    ChangeLog
M  +31   -28   rkward/windows/rkwindowcatcher.cpp
M  +2    -2    rkward/windows/rkwindowcatcher.h

https://invent.kde.org/education/rkward/commit/2f73f130cbc9aa3047a6c94db7fd180c7abee521

diff --git a/ChangeLog b/ChangeLog
index 56e2090e..f96087b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,6 @@
 TODOS for output directories:
   - Make sure not to activate default output while quitting (abouttoquit is too late)
   - save outputs to .rkworkplace and restore them
-  - automated tests
   - UI
   - remove explicit warnings
 
diff --git a/rkward/windows/rkwindowcatcher.cpp b/rkward/windows/rkwindowcatcher.cpp
index f4867d31..9ca6dca6 100644
--- a/rkward/windows/rkwindowcatcher.cpp
+++ b/rkward/windows/rkwindowcatcher.cpp
@@ -2,7 +2,7 @@
                           rwindowcatcher.cpp  -  description
                              -------------------
     begin                : Wed May 4 2005
-    copyright            : (C) 2005 - 2013 by Thomas Friedrichsmeier
+    copyright            : (C) 2005 - 2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -289,7 +289,6 @@ RKCaughtX11Window::RKCaughtX11Window (RKGraphicsDevice* rkward_device, int devic
 void RKCaughtX11Window::commonInit (int device_number) {
 	RK_TRACE (MISC);
 
-	in_destructor = false;
 	capture = 0;
 	embedded = 0;
 	embedding_complete = false;
@@ -357,13 +356,32 @@ RKCaughtX11Window::~RKCaughtX11Window () {
 	RK_ASSERT (device_windows.contains (device_number));
 	device_windows.remove (device_number);
 
-	in_destructor = true;
-	close (NoAskSaveModified);
+	commonClose(true);
 
 	if (embedded) RKWindowCatcher::instance ()->unregisterWatcher (embedded->winId ());
 	error_dialog->autoDeleteWhenDone ();
 }
 
+void RKCaughtX11Window::commonClose(bool in_destructor) {
+	RK_TRACE(MISC);
+
+	if (rk_native_device) rk_native_device->stopInteraction();
+
+	QString status = i18n("Closing device (saving history)");
+	if (!close_attempted) {
+		RCommand* c = new RCommand("dev.off (" + QString::number(device_number) + ')', RCommand::App, i18n("Shutting down device number %1", device_number));
+		if (!in_destructor) setStatusMessage(status, c);
+		RKGlobals::rInterface()->issueCommand(c);
+		close_attempted = true;
+	} else {
+		if (KMessageBox::questionYesNo(this, i18n("<p>The graphics device is being closed, saving the last plot to the plot history. This may take a while, if the R backend is still busy. You can close the graphics device immediately, in case it is stuck. However, the last plot may be missing from the plot history, if you do this.</p>")
+#if !defined Q_OS_WIN
+		+ i18n("<p>Note: On X11, the embedded window may be expurged, and you will have to close it manually in this case.</p>")
+#endif
+		, status, KGuiItem(i18n("Close immediately")), KGuiItem(i18n("Keep waiting"))) == KMessageBox::Yes) forceClose();
+	}
+}
+
 void RKCaughtX11Window::setWindowStyleHint (const QString& hint) {
 	RK_TRACE (MISC);
 
@@ -375,40 +393,25 @@ void RKCaughtX11Window::setWindowStyleHint (const QString& hint) {
 	RKMDIWindow::setWindowStyleHint (hint);
 }
 
-void RKCaughtX11Window::forceClose () {
+void RKCaughtX11Window::forceClose() {
 	killed_in_r = true;
 	if (embedded) {
 		// HACK: Somehow (R 3.0.0alpha), the X11() window is surprisingly die-hard, if it is not closed "the regular way".
 		// So we expurge it, and leave the rest to the user.
-		embedded->setParent (0);
-		qApp->processEvents ();
+		embedded->setParent(0);
+		qApp->processEvents();
 	}
-	RKMDIWindow::close (NoAskSaveModified);
+	RKMDIWindow::close(NoAskSaveModified);
 }
 
-bool RKCaughtX11Window::close (CloseWindowMode ask_save) {
-	RK_TRACE (MISC);
-
-	if (killed_in_r || RKGlobals::rInterface ()->backendIsDead ()) {
-		return RKMDIWindow::close (ask_save);
-	}
-
-	if (rk_native_device) rk_native_device->stopInteraction ();
+bool RKCaughtX11Window::close(CloseWindowMode ask_save) {
+	RK_TRACE(MISC);
 
-	QString status = i18n ("Closing device (saving history)");
-	if (!close_attempted) {
-		RCommand* c = new RCommand ("dev.off (" + QString::number (device_number) + ')', RCommand::App, i18n ("Shutting down device number %1", device_number));
-		if (!in_destructor) setStatusMessage (status, c);
-		RKGlobals::rInterface ()->issueCommand (c);
-		close_attempted = true;
-	} else {
-		if (KMessageBox::questionYesNo (this, i18n ("<p>The graphics device is being closed, saving the last plot to the plot history. This may take a while, if the R backend is still busy. You can close the graphics device immediately, in case it is stuck. However, the last plot may be missing from the plot history, if you do this.</p>")
-#if !defined Q_OS_WIN
-		+ i18n ("<p>Note: On X11, the embedded window may be expurged, and you will have to close it manually in this case.</p>")
-#endif
-		, status, KGuiItem (i18n ("Close immediately")), KGuiItem (i18n ("Keep waiting"))) == KMessageBox::Yes) forceClose ();
+	if (killed_in_r || RKGlobals::rInterface()->backendIsDead()) {
+		return RKMDIWindow::close(ask_save);
 	}
 
+	commonClose(false);
 	return false;
 }
 
diff --git a/rkward/windows/rkwindowcatcher.h b/rkward/windows/rkwindowcatcher.h
index 984c16e0..57e771d5 100644
--- a/rkward/windows/rkwindowcatcher.h
+++ b/rkward/windows/rkwindowcatcher.h
@@ -2,7 +2,7 @@
                           rwindowcatcher.h  -  description
                              -------------------
     begin                : Wed May 4 2005
-    copyright            : (C) 2005-2013 by Thomas Friedrichsmeier
+    copyright            : (C) 2005-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -176,11 +176,11 @@ private slots:
 private:
 	void forceClose ();
 	void commonInit (int device_number);
+	void commonClose(bool in_destructor);
 	friend class RKCaughtX11WindowPart;	// needs access to the actions
 	int device_number;
 	bool killed_in_r;
 	bool close_attempted;
-	bool in_destructor;
 	QWidget *xembed_container;
 	QScrollArea *scroll_widget;
 	RKProgressControl *error_dialog;




More information about the rkward-tracker mailing list