[education/rkward] /: Fix quirks around output -> Save As

Thomas Friedrichsmeier null at kde.org
Wed Apr 20 14:02:40 BST 2022


Git commit d04f06a83d2fd4691bb6d3431f813311358c0b7f by Thomas Friedrichsmeier.
Committed on 19/04/2022 at 19:29.
Pushed by tfry into branch 'master'.

Fix quirks around output -> Save As

M  +2    -0    ChangeLog
A  +70   -0    rkward/check_copyright.py
M  +1    -1    rkward/dialogs/rksavemodifieddialog.cpp
M  +9    -9    rkward/misc/rkoutputdirectory.cpp
M  +1    -2    rkward/windows/rkhtmlwindow.cpp

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

diff --git a/ChangeLog b/ChangeLog
index fb2c0cdd..1f0a1341 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+- Fix quirks around "Save as" for rkward output documents
+
 --- Version 0.7.3 - Apr-21-2022
 - Add option to show standardized coefficients for linear regression
 - Fixed: Possible backend hang when closing a data editor before it was done fetching its data
diff --git a/rkward/check_copyright.py b/rkward/check_copyright.py
new file mode 100755
index 00000000..f9a0cc19
--- /dev/null
+++ b/rkward/check_copyright.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+import sys
+import re
+
+print("Processing " + sys.argv[1])
+
+f = open(sys.argv[1], "r")
+lines = f.readlines()
+
+line_num = 0
+fname = ""
+begin = ""
+copyright = ""
+gplfound = False
+delims_found = 0
+
+def die(message):
+	print("error " + message + " in file " + sys.argv[1])
+	exit()
+
+for line in lines:
+	if (line_num > 20):
+		die("too long")
+	line = line.strip()
+	if (line.__contains__("description")):
+		fname = re.split(r"\s+", line)[0]
+	elif (line.startswith("begin")):
+		begin = re.split(r":", line, maxsplit=1)[1].strip()
+	elif (line.startswith("copyright")):
+		copyright = re.split(r":", line)[1].strip()
+	elif (line.__contains__("the Free Software Foundation; either version 2 of the License, or")):
+		gplfound = True
+	elif line.endswith("*************************/"):
+		delims_found += 1
+		if (delims_found == 2):
+			break
+	line_num += 1
+
+begin = re.sub(r"\d\d:\d\d:\d\d\s[A-Z][A-Z][A-Z]\s", "", begin)
+copyright = re.sub(r"(C) ", "", copyright)
+cyears, cholder = re.split(r" by ", copyright, maxsplit=1)
+years = re.findall(r"\d\d\d\d", cyears)
+year1 = years[0]
+year2 = years[len(years)-1]
+if (year1 != year2):
+	years = year1 + "-" + year2
+else:
+	years = year1
+
+cholder = cholder.strip()
+if cholder != "Thomas Friedrichsmeier":
+	die("Notme")
+if fname == "":
+	die("empty")
+if not gplfound:
+	die("nogpl")
+
+o = open(sys.argv[1], "w")
+o.write("/*\n")
+o.write(fname + " - This file is part of the RKWard project. Created: " + begin + "\n")
+o.write("SPDX-FileCopyrightText: " + years + " by " + cholder + " <thomas.friedrichsmeier at kdemail.net>\n")
+o.write("SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>\n")
+o.write("SPDX-License-Identifier: GPL-2.0-or-later\n")
+o.write("*/\n")
+lines = lines[line_num+1 : ]
+for line in lines:
+	o.write(line)
+	if not line.endswith("\n"):
+		o.write("\n")
+o.close()
diff --git a/rkward/dialogs/rksavemodifieddialog.cpp b/rkward/dialogs/rksavemodifieddialog.cpp
index e1cb3830..0e9e7fa1 100644
--- a/rkward/dialogs/rksavemodifieddialog.cpp
+++ b/rkward/dialogs/rksavemodifieddialog.cpp
@@ -147,7 +147,7 @@ void RKSaveModifiedDialog::saveSelected() {
 		if (it.key ()->checkState (0) != Qt::Checked) continue;
 		RKOutputDirectory *dir = RKOutputDirectory::findOutputById(it.value());
 		if (dir) {
-			if (dir->save().failed()) all_ok = false;
+			if (dir->save(dir->filename()).failed()) all_ok = false;
 		}
 		else RK_ASSERT(dir);
 	}
diff --git a/rkward/misc/rkoutputdirectory.cpp b/rkward/misc/rkoutputdirectory.cpp
index 14eb64a3..efc3ccc2 100644
--- a/rkward/misc/rkoutputdirectory.cpp
+++ b/rkward/misc/rkoutputdirectory.cpp
@@ -16,6 +16,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 
 #include "../settings/rksettingsmodulegeneral.h"
 #include "../settings/rksettingsmoduleoutput.h"
+#include "../settings/rkrecenturls.h"
 #include "../rbackend/rcommand.h"
 #include "../rbackend/rkrinterface.h"
 #include "../windows/rkmdiwindow.h"
@@ -113,19 +114,15 @@ RKOutputDirectory* RKOutputDirectory::findOutputByWindow(const RKMDIWindow *wind
 	return nullptr;
 }
 
-GenericRRequestResult RKOutputDirectory::save(const QString& _dest, RKOutputDirectory::OverwriteBehavior overwrite) {
+GenericRRequestResult RKOutputDirectory::save(const QString& dest, RKOutputDirectory::OverwriteBehavior overwrite) {
 	RK_TRACE (APP);
 
-	QString dest = _dest;
-	if (dest.isEmpty()) {
-		dest = filename();  // might still be empty, in which case exportAs will ask for destination
-		if (!dest.isEmpty()) overwrite = Force;  // don't prompt when writing to same file
-	}
 	GenericRRequestResult res = exportAs(dest, overwrite);
 	if (!res.failed()) {
 		save_filename = res.ret.toString();  // might by different from dest, notably, if dest was empty or not yet normalized
 		known_modified = true;  // dirty trick to ensure that updateSavedHash() will trigger a stateChange()->update caption in views, even if using SaveAs on an unmodified directory
 		updateSavedHash();
+		RKRecentUrls::addRecentUrl(RKRecentUrls::outputId(), QUrl::fromLocalFile(save_filename));
 	}
 	return res;
 }
@@ -149,7 +146,7 @@ GenericRRequestResult RKOutputDirectory::exportAs (const QString& _dest, RKOutpu
 	}
 
 	bool exists = QFileInfo::exists(dest);
-	if (exists) {
+	if (exists && (dest != save_filename)) {
 		if (overwrite == Ask) {
 			const QString warning = i18n("Are you sure you want to overwrite the existing file '%1'?", dest);
 			KMessageBox::ButtonCode res = KMessageBox::warningContinueCancel(RKWardMainWindow::getMain(), warning, i18n("Overwrite?"), KStandardGuiItem::overwrite(),
@@ -227,6 +224,7 @@ GenericRRequestResult RKOutputDirectory::import(const QString& _dir) {
 		return GenericRRequestResult::makeError(i18n("Output directory %1 is already in use.", id));
 	}
 
+	RKRecentUrls::addRecentUrl(RKRecentUrls::outputId(), QUrl::fromLocalFile(_dir));
 	return importZipInternal(_dir);
 }
 
@@ -344,7 +342,7 @@ GenericRRequestResult RKOutputDirectory::purge(RKOutputDirectory::OverwriteBehav
 				return GenericRRequestResult::makeError(i18n("User canceled"));
 			}
 			if (res == KMessageBox::No) {
-				auto ret = save();
+				auto ret = save(save_filename);
 				if (ret.failed()) return ret;
 			}
 		}
@@ -577,7 +575,9 @@ GenericRRequestResult RKOutputDirectory::handleRCall(const QStringList& params,
 		} else if (command == QStringLiteral("revert")) {
 			return out->revert(parseOverwrite(params.value(2)));
 		} else if (command == QStringLiteral("save")) {
-			return out->save(params.value(3), parseOverwrite(params.value(2)));
+			QString filename = params.value(3);
+			if (filename.isEmpty()) filename = out->filename();
+			return out->save(filename, parseOverwrite(params.value(2)));
 		} else if (command == QStringLiteral("export")) {
 			return out->exportAs(params.value(3), parseOverwrite(params.value(2)));
 		} else if (command == QStringLiteral("clear")) {
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index 2e84adb4..d0e743b6 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -620,7 +620,6 @@ bool RKHTMLWindow::openURL (const QUrl &url) {
 			}
 
 			current_url = url;	// needs to be set before registering
-			RKRecentUrls::addRecentUrl(RKRecentUrls::outputId(), url);
 			RKOutputWindowManager::self ()->registerWindow (this);
 			dir = RKOutputDirectory::findOutputByWorkPath(url.toLocalFile());
 			part->setOutputDirectoryActionsEnabled(dir != nullptr);
@@ -952,7 +951,7 @@ void RKHTMLWindowPart::initActions () {
 	window->file_save_action = actionCollection()->addAction(KStandardAction::Save, window, SLOT(slotSave()));
 	window->file_save_action->setText(i18n("Save Output"));
 	window->file_save_as_action = actionCollection()->addAction(KStandardAction::SaveAs, window, SLOT(slotSaveAs()));
-	window->file_save_action->setText(i18n("Save Output As"));
+	window->file_save_as_action->setText(i18n("Save Output As"));
 
 	outputFlush = actionCollection ()->addAction ("output_flush", window, SLOT (flushOutput()));
 	outputFlush->setText (i18n ("&Clear Output"));



More information about the rkward-tracker mailing list