[education/rkward] rkward: Allow direct display of HTML content
Thomas Friedrichsmeier
null at kde.org
Sun Jul 7 17:33:10 BST 2024
Git commit 901402312c9621e2498f90f7430229ffd1ac8dc9 by Thomas Friedrichsmeier.
Committed on 07/07/2024 at 16:32.
Pushed by tfry into branch 'master'.
Allow direct display of HTML content
M +1 -1 rkward/main.cpp
M +6 -2 rkward/rbackend/rkrinterface.cpp
M +9 -2 rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R
M +5 -0 rkward/windows/rkhtmlwindow.cpp
M +2 -0 rkward/windows/rkhtmlwindow.h
M +3 -7 rkward/windows/rkworkplace.cpp
https://invent.kde.org/education/rkward/-/commit/901402312c9621e2498f90f7430229ffd1ac8dc9
diff --git a/rkward/main.cpp b/rkward/main.cpp
index 6223e1649..ced1b8d63 100644
--- a/rkward/main.cpp
+++ b/rkward/main.cpp
@@ -173,7 +173,7 @@ int main (int argc, char *argv[]) {
KUrlAuthorized::allowUrlAction ("redirect", QUrl("rkward://"), QUrl ("help:"));
KLocalizedString::setApplicationDomain ("rkward");
- KAboutData aboutData ("rkward", i18n ("RKWard"), RKWARD_VERSION, i18n ("Frontend to the R statistics language"), KAboutLicense::GPL, i18n ("(c) 2002 - 2022"), QString (), "https://rkward.kde.org");
+ KAboutData aboutData ("rkward", i18n ("RKWard"), RKWARD_VERSION, i18n ("Frontend to the R statistics language"), KAboutLicense::GPL, i18n ("(c) 2002 - 2024"), QString (), "https://rkward.kde.org");
aboutData.addAuthor (i18n ("Thomas Friedrichsmeier"), i18n ("Project leader / main developer"));
aboutData.addAuthor (i18n ("Pierre Ecochard"), i18n ("C++ developer between 2004 and 2007"));
aboutData.addAuthor (i18n ("Prasenjit Kapat"), i18n ("Many plugins, suggestions, plot history feature"));
diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index 0503ba8c5..9302567a1 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -700,8 +700,12 @@ GenericRRequestResult RInterface::processRCallRequest (const QString &call, cons
} else if (call == "updateInstalledPackagesList") {
RKSessionVars::instance ()->setInstalledPackages(arglist);
} else if (call == "showHTML") {
- RK_ASSERT(arglist.size() == 1);
- RKWorkplace::mainWorkplace()->openHelpWindow(QUrl::fromUserInput(arglist.value(0), QDir::currentPath (), QUrl::AssumeLocalFile));
+ if (arglist.size() == 1) RKWorkplace::mainWorkplace()->openHelpWindow(QUrl::fromUserInput(arglist.value(0), QDir::currentPath(), QUrl::AssumeLocalFile));
+ else {
+ auto win = qobject_cast<RKHTMLWindow*>(RKWorkplace::mainWorkplace()->openHelpWindow(QUrl()));
+ RK_ASSERT(win);
+ win->setContent(arglist.value(1));
+ }
} else if (call == "showPDF") {
RK_ASSERT(arglist.size() == 1);
RKWorkplace::mainWorkplace()->openPDFWindow(QUrl::fromUserInput(arglist.value(0), QDir::currentPath (), QUrl::AssumeLocalFile));
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R
index 3e382385a..3d38cf68c 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.edit-functions.R
@@ -17,6 +17,11 @@
#' by default, when run inside an RKWard session. (via \code{getOption("editor")},
#' and \code{getOption("browser")}.
#'
+#' \code{rk.show.html} with \code{content}-argument, insed of \code{url}-argument, will
+#' show the given HTML string. This is mostly useful for plugins, where it may be
+#' desirable to show an error-message at the place where usually an HTML-file would
+#' be shown.
+#'
#' \code{rk.show.pdf} opens a PDF (or postscript) document in a viewer window inside RKWard.
#'
#' @param x an object to edit.
@@ -95,8 +100,10 @@
#' @param url a URL to show.
#' @export
#' @rdname rk.edit
-"rk.show.html" <- function (url) {
- .rk.call.async("showHTML", as.character(url));
+"rk.show.html" <- function(url, content) {
+ if (missing(url) == missing(content)) stop("Exactly one of 'url' or 'content' must be specified.")
+ if (missing(url)) .rk.call.async("showHTML", c("", as.character(content)))
+ else .rk.call.async("showHTML", as.character(url))
}
#' @param url a URL to show.
diff --git a/rkward/windows/rkhtmlwindow.cpp b/rkward/windows/rkhtmlwindow.cpp
index 170ad6008..b44bee4d7 100644
--- a/rkward/windows/rkhtmlwindow.cpp
+++ b/rkward/windows/rkhtmlwindow.cpp
@@ -551,6 +551,11 @@ bool RKHTMLWindow::handleRKWardURL (const QUrl &url, RKHTMLWindow *window) {
return false;
}
+void RKHTMLWindow::setContent(const QString &content) {
+ RK_TRACE(APP);
+ page->setHtmlWrapper(content, QUrl());
+}
+
bool RKHTMLWindow::openURL (const QUrl &url) {
RK_TRACE (APP);
diff --git a/rkward/windows/rkhtmlwindow.h b/rkward/windows/rkhtmlwindow.h
index c341095b1..e09da7007 100644
--- a/rkward/windows/rkhtmlwindow.h
+++ b/rkward/windows/rkhtmlwindow.h
@@ -59,6 +59,8 @@ public:
~RKHTMLWindow ();
/** open given URL. Returns false, if the URL is not an existing local file. Loading a non-local URL may succeed, even if this returns false! */
bool openURL (const QUrl &url);
+/** Show the given content, assuming HTML mimetype. */
+ void setContent(const QString &content);
/** takes care of special handling, if the url is an rkward://-url. Does nothing and returns false, otherwise.
* If window is not 0, and the url is a help window, open it, there (otherwise in a new window).
* TODO: move to RKWorkplace? As this can really open a bunch of different things, although generally _from_ an html window.
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index c49cc8080..020fbf197 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -489,11 +489,6 @@ RKMDIWindow* RKWorkplace::openPDFWindow(const QUrl &url) {
RKMDIWindow* RKWorkplace::openHelpWindow (const QUrl &url, bool only_once) {
RK_TRACE (APP);
- if (url.isEmpty ()) {
- RK_ASSERT (false);
- return nullptr;
- }
-
if (only_once) {
RKWorkplaceObjectList help_windows = getObjectList (RKMDIWindow::HelpWindow, RKMDIWindow::AnyWindowState);
for (int i = 0; i < help_windows.size (); ++i) {
@@ -514,7 +509,7 @@ RKMDIWindow* RKWorkplace::openHelpWindow (const QUrl &url, bool only_once) {
}
RKHTMLWindow *hw = new RKHTMLWindow (view (), RKHTMLWindow::HTMLHelpWindow);
- hw->openURL (url);
+ if (!url.isEmpty()) hw->openURL (url);
addWindow (hw);
return (hw);
}
@@ -929,7 +924,8 @@ RKMDIWindow* restoreDocumentWindowInternal (RKWorkplace* wp, const ItemSpecifica
if (spec.type.endsWith(".active")) dir->activate();
win = RKWorkplace::mainWorkplace()->openOutputWindow(QUrl::fromLocalFile(dir->workPath()));
} else if (spec.type == "help") {
- win = wp->openHelpWindow (checkAdjustRestoredUrl (spec.specification, base), true);
+ auto url = checkAdjustRestoredUrl (spec.specification, base);
+ if (!url.isEmpty()) win = wp->openHelpWindow(url, true);
} else if (spec.type == "pdf") {
win = wp->openPDFWindow(checkAdjustRestoredUrl(spec.specification, base));
} else if (spec.type == "object") {
More information about the rkward-tracker
mailing list