[rkward/frameworks] /: Work around missing overwrite confirmation bug in plasma. Also check for existance of .rkworkplace file, for completeness.

Thomas Friedrichsmeier null at kde.org
Wed Jun 21 18:35:19 UTC 2017


Git commit 5f1bf437e2329d8a74e40d41a868986c4c1608ec by Thomas Friedrichsmeier.
Committed on 21/06/2017 at 18:34.
Pushed by tfry into branch 'frameworks'.

Work around missing overwrite confirmation bug in plasma. Also check for existance of .rkworkplace file, for completeness.

M  +0    -2    ChangeLog
M  +39   -1    rkward/agents/rksaveagent.cpp

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

diff --git a/ChangeLog b/ChangeLog
index d5b3ee01..41717202 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,3 @@
-TODO: Workplace save as does not as for overwrite confirmation
-
 - Implement "split view" feature, allowing to partion the main window, and to hvae several views of the same files / data side-by-side
 - Fixed: Creating trellis on-screen plots, while package lattice is not on the search path would produce errors in plot history mechanism
 - Limit the number of debug log-files to keep (at most three, each, for frontend and backend)
diff --git a/rkward/agents/rksaveagent.cpp b/rkward/agents/rksaveagent.cpp
index 9050d580..25dbc813 100644
--- a/rkward/agents/rksaveagent.cpp
+++ b/rkward/agents/rksaveagent.cpp
@@ -57,9 +57,47 @@ RKSaveAgent::~RKSaveAgent () {
 	RK_TRACE (APP);
 }
 
+// We save to several files at once, meaning the standard overwrite check is not quite good enough for us.
+// More importantly, it is entirely broken in KF5 < 5.22.0 (https://bugs.kde.org/show_bug.cgi?id=360666)
+// So check for overwriting ourselves.
+bool checkOverwriteWorkspace (QUrl url, QWidget *parent) {
+	if (url.isEmpty () || !url.isLocalFile ()) {
+		return true;
+	}
+
+	QString mainfile = url.toLocalFile ();
+//	QString addfile = mainfile.left (mainfile.lastIndexOf ('.')) + ".rkward";
+	QString addfile = mainfile + ".rkworkplace";
+	QFileInfo info (mainfile);
+	if (!info.exists ()) mainfile.clear (); // signifies: not a problem
+	else mainfile = info.fileName ();
+
+	info.setFile (addfile);
+	if (!info.exists ()) addfile.clear ();
+	else addfile = info.fileName ();
+
+	if (mainfile.isEmpty () && addfile.isEmpty ()) {
+		return true;
+	}
+
+	QString warning;
+	if (addfile.isEmpty ()) {
+		warning = i18n ("A file named \"%1\" already exists. Are you sure you want to overwrite it?", mainfile);
+	} else if (mainfile.isEmpty ()) {
+		warning = i18n ("A file named \"%1\" already exists, and will be overwritten when saving to \"%2\". Are you sure you want to overwrite it?", addfile, mainfile);
+	} else {
+		warning = i18n ("Files named \"%1\" and \"%2\" already exist, and will both be overwritten. Are you sure you want to overwrite them?", mainfile, addfile);
+	}
+
+	return KMessageBox::Cancel != KMessageBox::warningContinueCancel (parent, warning, i18n ("Overwrite File?"), KStandardGuiItem::overwrite (),
+	                                                                  KStandardGuiItem::cancel (), QString (), KMessageBox::Options (KMessageBox::Notify | KMessageBox::Dangerous));
+}
+
 bool RKSaveAgent::askURL () {
 	RK_TRACE (APP);
-	save_url = QUrl::fromLocalFile (QFileDialog::getSaveFileName (RKWardMainWindow::getMain (), QString (), save_url.toLocalFile (), i18n ("R Workspace Files [%1](%1);;All files [*](*)", RKSettingsModuleGeneral::workspaceFilenameFilter ())));
+	save_url = QUrl::fromLocalFile (QFileDialog::getSaveFileName (RKWardMainWindow::getMain (), QString (), save_url.toLocalFile (), i18n ("R Workspace Files [%1](%1);;All files [*](*)", RKSettingsModuleGeneral::workspaceFilenameFilter ()), 0, QFileDialog::DontConfirmOverwrite));
+	if (!checkOverwriteWorkspace (save_url, RKWardMainWindow::getMain ())) save_url.clear ();
+
 	if (save_url.isEmpty ()) {
 		if (when_done != DoNothing) {
 			if (KMessageBox::warningYesNo (0, i18n ("No filename given. Your data was NOT saved. Do you still want to proceed?")) != KMessageBox::Yes) when_done = DoNothing;



More information about the rkward-tracker mailing list