[education/rkward/devel/workspace_output] rkward: Save (but do not load yet) workplace item for opened output windows
Thomas Friedrichsmeier
null at kde.org
Fri Feb 18 20:39:06 GMT 2022
Git commit f7adcb22d6475d9812de5d8c635f6a2b7c24820a by Thomas Friedrichsmeier.
Committed on 18/02/2022 at 20:38.
Pushed by tfry into branch 'devel/workspace_output'.
Save (but do not load yet) workplace item for opened output windows
M +14 -1 rkward/misc/rkoutputdirectory.cpp
M +1 -1 rkward/misc/rkoutputdirectory.h
M +5 -1 rkward/rbackend/rpackages/rkward/R/rk.output.R
M +0 -4 rkward/windows/rkhtmlwindow.cpp
M +1 -1 rkward/windows/rkhtmlwindow.h
M +9 -2 rkward/windows/rkworkplace.cpp
https://invent.kde.org/education/rkward/commit/f7adcb22d6475d9812de5d8c635f6a2b7c24820a
diff --git a/rkward/misc/rkoutputdirectory.cpp b/rkward/misc/rkoutputdirectory.cpp
index 7b8beb9e..a28d6f89 100644
--- a/rkward/misc/rkoutputdirectory.cpp
+++ b/rkward/misc/rkoutputdirectory.cpp
@@ -65,7 +65,7 @@ QString hashDirectoryState(const QString& dir) {
QMap<QString, RKOutputDirectory*> RKOutputDirectory::outputs;
-RKOutputDirectory::RKOutputDirectory() : initialized(false), window(nullptr) {
+RKOutputDirectory::RKOutputDirectory() : initialized(false) {
RK_TRACE(APP);
}
@@ -91,6 +91,19 @@ RKOutputDirectory* RKOutputDirectory::getOutputBySaveUrl(const QString& _dest) {
return nullptr;
}
+RKOutputDirectory* RKOutputDirectory::getOutputByWindow(const RKMDIWindow *window) {
+ RK_TRACE (APP);
+
+ if (!window) return nullptr;
+ if (!window->isType(RKMDIWindow::OutputWindow)) return nullptr;
+ for (auto it = outputs.constBegin(); it != outputs.constEnd(); ++it) {
+ if (it.value()->workPath() == static_cast<const RKHTMLWindow*>(window)->url().toLocalFile()) {
+ return(it.value());
+ }
+ }
+ return nullptr;
+}
+
GenericRRequestResult RKOutputDirectory::save(const QString& _dest, RKOutputDirectory::OverwriteBehavior overwrite) {
RK_TRACE (APP);
diff --git a/rkward/misc/rkoutputdirectory.h b/rkward/misc/rkoutputdirectory.h
index 6e558927..82224191 100644
--- a/rkward/misc/rkoutputdirectory.h
+++ b/rkward/misc/rkoutputdirectory.h
@@ -56,6 +56,7 @@ public:
static GenericRRequestResult handleRCall(const QStringList& params, RCommandChain *chain);
static RKOutputDirectory* getOutputById(const QString& id);
static RKOutputDirectory* getOutputBySaveUrl(const QString& dest);
+ static RKOutputDirectory* getOutputByWindow(const RKMDIWindow* window);
/** Return a list of all current output directories that have been modified. Used for asking for save during shutdown. */
static QList<RKOutputDirectory*> modifiedOutputDirectories();
@@ -79,7 +80,6 @@ private:
QString id;
bool initialized;
- QPointer<RKMDIWindow> window;
/** map of outputs. */
static QMap<QString, RKOutputDirectory*> outputs;
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.output.R b/rkward/rbackend/rpackages/rkward/R/rk.output.R
index 66abf2cf..c603b9cf 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.output.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.output.R
@@ -9,7 +9,11 @@
#' an instance of the \code{RK.Output} reference class, which has methods for subsequent manipulation. Two instances of this class may be pointing to the same
#' logical output file/directory (e.g. when loading the same output file, twice), in which case any operation will affect both instances the same.
#'
-#' Internally, outputs are managed by the RKWard frontend. The frontend will ask to save any unsaved modified output pages on exit.
+#' Internally, outputs are managed by the RKWard frontend. The frontend will ask to save any unsaved modified output pages on exit, even if those are not currently shown.
+#'
+#' Output references can be assigned to a symbol, which may be useful when writing to several output files in turn. However, such references should be considered
+#' short-lived. Importantly, they will not currently remain valid across sessions. Where this may be a concern, code should obtain a new reference using
+#' rk.output(filename="something") at relevant entry points to subsequent code.
#'
#' At the time of this writing, output is stored in directories containing an HTML index file, and, usually, several image files, and possibly more.
#' However other types of output may be supported in the future, and therefore assumptions about the details of the output storage should be avoided.
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index 1b15d133..364f34fb 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -593,10 +593,6 @@ bool RKHTMLWindow::openURL (const QUrl &url) {
return true;
}
-QUrl RKHTMLWindow::url () {
- return current_url;
-}
-
void RKHTMLWindow::mimeTypeJobFail (KJob* job) {
RK_TRACE (APP);
diff --git a/rkward/windows/rkhtmlwindow.h b/rkward/windows/rkhtmlwindow.h
index d109eb3c..56879d0b 100644
--- a/rkward/windows/rkhtmlwindow.h
+++ b/rkward/windows/rkhtmlwindow.h
@@ -74,7 +74,7 @@ public:
bool isModified () override;
/** Return current url */
- QUrl url ();
+ QUrl url () const { return current_url; };
/** Return current url in a restorable way, i.e. for help pages, abstract the session specific part of the path */
QUrl restorableUrl ();
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index 9de9de9b..a8995a63 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -800,8 +800,15 @@ QString RKWorkplace::makeItemDescription (RKMDIWindow *win) const {
specification = static_cast<RKCommandEditorWindow*> (win)->url ().url ();
if (specification.isEmpty ()) specification = static_cast<RKCommandEditorWindow*> (win)->id ();
} else if (win->isType (RKMDIWindow::OutputWindow)) {
- type = "output";
- specification = static_cast<RKHTMLWindow*> (win)->url ().url ();
+ RKOutputDirectory *dir = RKOutputDirectory::getOutputByWindow(win);
+ if (dir) {
+ type = "rkoutput";
+ specification = dir->filename();
+ } else {
+ // legacy support for rk.set.html.output.file()
+ type = "output";
+ specification = static_cast<RKHTMLWindow*> (win)->url ().url ();
+ }
} else if (win->isType (RKMDIWindow::HelpWindow)) {
type = "help";
specification = static_cast<RKHTMLWindow*> (win)->restorableUrl ().url ();
More information about the rkward-tracker
mailing list