[education/rkward/devel/workspace_output] /: Remove output working directories on exit. This is still buggy.

Thomas Friedrichsmeier null at kde.org
Tue Nov 3 14:48:22 GMT 2020


Git commit c1c407ebb34a892b7b05e9582c4e844234f37aa2 by Thomas Friedrichsmeier.
Committed on 03/11/2020 at 14:47.
Pushed by tfry into branch 'devel/workspace_output'.

Remove output working directories on exit. This is still buggy.

M  +8    -0    ChangeLog
M  +1    -1    rkward/agents/rkloadagent.cpp
M  +12   -1    rkward/misc/rkoutputdirectory.cpp
M  +1    -0    rkward/misc/rkoutputdirectory.h
M  +1    -0    rkward/rbackend/rkrinterface.cpp
M  +1    -1    rkward/rkward.cpp
M  +14   -5    rkward/windows/rkworkplace.cpp
M  +6    -3    rkward/windows/rkworkplace.h

https://invent.kde.org/education/rkward/commit/c1c407ebb34a892b7b05e9582c4e844234f37aa2

diff --git a/ChangeLog b/ChangeLog
index 294e3487..e77bc892 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+TODOS for output directories:
+  - Fix R backend requests that may have both a return value *and* subcommands
+  - 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
+
 - Fixed: Calling (rk.)select.list() without a title would fail
 - Hide or remove several purely internal functions (most can still be assessed from the rkward namespace as rkward:::xyz())
 
diff --git a/rkward/agents/rkloadagent.cpp b/rkward/agents/rkloadagent.cpp
index 82b2a2b1..ef4ef206 100644
--- a/rkward/agents/rkloadagent.cpp
+++ b/rkward/agents/rkloadagent.cpp
@@ -62,7 +62,7 @@ RKLoadAgent::RKLoadAgent (const QUrl &url, bool merge) {
 	RCommand *command;
 	
 	if (!merge) {
-		RKWardMainWindow::getMain ()->slotCloseAllWindows ();
+		RKWorkplace::mainWorkplace()->closeWorkspace();
 		command = new RCommand ("remove (list=ls (all.names=TRUE))", RCommand::App | RCommand::ObjectListUpdate);
 		RKGlobals::rInterface ()->issueCommand (command);
 	}
diff --git a/rkward/misc/rkoutputdirectory.cpp b/rkward/misc/rkoutputdirectory.cpp
index b2b1b1a4..21919626 100644
--- a/rkward/misc/rkoutputdirectory.cpp
+++ b/rkward/misc/rkoutputdirectory.cpp
@@ -327,9 +327,9 @@ GenericRRequestResult RKOutputDirectory::purge(RKOutputDirectory::OverwriteBehav
 		}
 	}
 
+	bool active = isActive();
 	QDir dir(work_dir);
 	dir.removeRecursively();
-	bool active = isActive();
 	outputs.remove(id);
 	deleteLater();
 	if (active) {
@@ -342,6 +342,16 @@ GenericRRequestResult RKOutputDirectory::purge(RKOutputDirectory::OverwriteBehav
 	return GenericRRequestResult();
 }
 
+void RKOutputDirectory::purgeAllNoAsk() {
+	RK_TRACE(APP);
+
+	auto outputs_copy = outputs;
+	for (auto it = outputs_copy.constBegin(); it != outputs_copy.constEnd(); ++it) {
+		auto res = outputs.constBegin().value()->purge(Force);
+		RK_ASSERT(!res.failed());
+	}
+}
+
 QString RKOutputDirectory::workPath() const {
 	RK_TRACE(APP);
 
@@ -397,6 +407,7 @@ RKOutputDirectory* RKOutputDirectory::getCurrentOutput(RCommandChain* chain) {
 	}
 #warning generate a warning, when a new output is created or activated
 	if (!candidate) candidate = outputs[0];
+	RK_ASSERT(candidate);
 	candidate->activate(chain);
 	return candidate;
 }
diff --git a/rkward/misc/rkoutputdirectory.h b/rkward/misc/rkoutputdirectory.h
index 0836bb91..2d76cb07 100644
--- a/rkward/misc/rkoutputdirectory.h
+++ b/rkward/misc/rkoutputdirectory.h
@@ -66,6 +66,7 @@ public:
  *  If that does not exist, create a new output, activate and return it. */
 	static RKOutputDirectory* getCurrentOutput(RCommandChain *chain=0);
 	static QList<RKOutputDirectory*> allOutputs();
+	static void purgeAllNoAsk();
 private:
 	RKOutputDirectory();
 	~RKOutputDirectory();
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index f617ae3b..3b8ef364 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -746,6 +746,7 @@ void RInterface::processHistoricalSubstackRequest (const QStringList &calllist,
 			RK_ASSERT (false);
 		}
 	} else if (call == QStringLiteral ("output")) {
+#warning Gaaah. This does not work, if a subcommand has been run (request is "used up" in that case)
 		request->setResult(RKOutputDirectory::handleRCall(calllist.mid(1), in_chain));
 	} else {
 		request->setResult(GenericRRequestResult::makeError(i18n("Unrecognized call '%1'", call)));
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 7218c398..d061b898 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -792,7 +792,7 @@ bool RKWardMainWindow::doQueryQuit () {
 	if (RKSettingsModuleGeneral::workplaceSaveMode () == RKSettingsModuleGeneral::SaveWorkplaceWithSession) {
 		RKSettingsModuleGeneral::setSavedWorkplace (RKWorkplace::mainWorkplace ()->makeWorkplaceDescription ().join ("\n"), KSharedConfig::openConfig ().data ());
 	}
-	if (!RKWorkplace::mainWorkplace()->closeAll(RKMDIWindow::AnyType, RKMDIWindow::AnyWindowState, true)) {
+	if (!RKWorkplace::mainWorkplace()->closeWorkspace()) {
 		slotSetStatusReady ();
 		return false;
 	}
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index e0289666..aab524df 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -53,6 +53,7 @@
 #include "../windows/rkwindowcatcher.h"
 #include "../rbackend/rcommand.h"
 #include "../misc/rkcommonfunctions.h"
+#include "../misc/rkoutputdirectory.h"
 #include "../rkglobals.h"
 #include "../rkward.h"
 
@@ -663,19 +664,18 @@ RKWorkplace::RKWorkplaceObjectList RKWorkplace::getObjectList (int type, int sta
 	return ret;
 }
 
-bool RKWorkplace::closeAll(int type, int state, bool ask_close_project) {
+bool RKWorkplace::closeAll(int type, int state) {
 	RK_TRACE(APP);
 
-	return closeWindows(getObjectList(type, state), ask_close_project);
+	return closeWindows(getObjectList(type, state));
 }
 
-bool RKWorkplace::closeWindows(QList<RKMDIWindow*> windows, bool ask_close_project) {
+bool RKWorkplace::closeWindows(QList<RKMDIWindow*> windows, RKMDIWindow::CloseWindowMode ask_save) {
 	RK_TRACE(APP);
 
-	bool allclosed = true;
 	RKWardMainWindow::getMain()->lockGUIRebuild(true);
 
-	bool ok = RKSaveModifiedDialog::askSaveModified(this, windows, ask_close_project);
+	bool ok = (ask_save == RKMDIWindow::NoAskSaveModified) || RKSaveModifiedDialog::askSaveModified(this, windows, false);
 	if (ok) {
 		for (int i = windows.size() - 1; i >= 0; --i) {
 			RK_ASSERT(closeWindow(windows[i], RKMDIWindow::NoAskSaveModified));
@@ -685,6 +685,15 @@ bool RKWorkplace::closeWindows(QList<RKMDIWindow*> windows, bool ask_close_proje
 	return ok;
 }
 
+bool RKWorkplace::closeWorkspace() {
+	RK_TRACE(APP);
+
+	bool ok = RKSaveModifiedDialog::askSaveModified(this, windows, true);
+	if (!ok) return false;
+	RKOutputDirectory::purgeAllNoAsk();
+	return closeWindows(windows, RKMDIWindow::NoAskSaveModified);
+}
+
 void RKWorkplace::removeWindow (QObject *object) {
 	RK_TRACE (APP);
 	RKMDIWindow *window = static_cast<RKMDIWindow *> (object);
diff --git a/rkward/windows/rkworkplace.h b/rkward/windows/rkworkplace.h
index 9d76cf1d..40d616c6 100644
--- a/rkward/windows/rkworkplace.h
+++ b/rkward/windows/rkworkplace.h
@@ -157,16 +157,19 @@ public:
 /** Close the given window, whether it is attached or detached.
 @param window window to close
 @returns true, if the window was actually closed (not cancelled) */
-	bool closeWindow (RKMDIWindow *window, RKMDIWindow::CloseWindowMode ask_save = RKMDIWindow::AutoAskSaveModified);
+	bool closeWindow(RKMDIWindow *window, RKMDIWindow::CloseWindowMode ask_save = RKMDIWindow::AutoAskSaveModified);
 /** Close the given windows, whether they are attached or detached.
 @param windows list windows to close
 @returns true, if _all_ windows were actually closed. */
-	bool closeWindows (QList<RKMDIWindow*> windows, bool ask_close_project=false);
+	bool closeWindows(QList<RKMDIWindow*> windows, RKMDIWindow::CloseWindowMode ask_save = RKMDIWindow::AutoAskSaveModified);
+/** Close all windows and all outputs (aksing to save workspace)
+ at returns true, if the workspace really was closed. */
+	bool closeWorkspace();
 /** Closes all windows of the given type(s). Default call (no arguments) closes all windows
 @param type: A bitwise OR of RKWorkplaceObjectType
 @param state: A bitwise OR of RKWorkplaceObjectState
 @returns false if cancelled by user (user was prompted for saving, and chose cancel) */
-	bool closeAll(int type=RKMDIWindow::AnyType, int state=RKMDIWindow::AnyWindowState, bool ask_close_project=false);
+	bool closeAll(int type=RKMDIWindow::AnyType, int state=RKMDIWindow::AnyWindowState);
 
 /** Write a description of all current windows to the R backend. This can later be read by restoreWorkplace (). Has no effect, if RKSettingsModuleGeneral::workplaceSaveMode () != RKSettingsModuleGeneral::SaveWorkplaceWithWorkspace
 @param url the url to use. Can be left null, in which case the current workspace url will be used.




More information about the rkward-tracker mailing list