[rkward] /: Add option to override CSS file used for the output window.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Fri Mar 11 20:17:34 UTC 2016


Git commit 4c6b577cbc900805348cf7d398ccbb9419875cff by Thomas Friedrichsmeier.
Committed on 11/03/2016 at 20:16.
Pushed by tfry into branch 'master'.

Add option to override CSS file used for the output window.

Also copy the system-wide CSS file to a sibling of the output html file.

M  +1    -0    ChangeLog
M  +0    -2    rkward/rbackend/rinterface.cpp
M  +13   -2    rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
M  +11   -1    rkward/settings/rksettingsmoduleoutput.cpp
M  +3    -0    rkward/settings/rksettingsmoduleoutput.h

http://commits.kde.org/rkward/4c6b577cbc900805348cf7d398ccbb9419875cff

diff --git a/ChangeLog b/ChangeLog
index a9a66aa..03f290d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Add option to override CSS file used for the output window
 - When manually adding pluginmaps, load these after, not before other pluginmaps, by default
 - Added context menu option to search for information on current symbol online
 - Fixed: Wizard plugins would be too small, initially
diff --git a/rkward/rbackend/rinterface.cpp b/rkward/rbackend/rinterface.cpp
index ef4d19e..f385dd4 100644
--- a/rkward/rbackend/rinterface.cpp
+++ b/rkward/rbackend/rinterface.cpp
@@ -562,8 +562,6 @@ QStringList RInterface::processPlainGenericRequest (const QStringList &calllist)
 	} else if (call == "set.output.file") {
 		RK_ASSERT (calllist.count () == 2);
 		RKOutputWindowManager::self ()->setCurrentOutputPath (calllist.value (1));
-	} else if (call == "getCSSlink") {
-		return (QStringList (QString ("<link rel=\"StyleSheet\" type=\"text/css\" href=\"" + KUrl::fromLocalFile (RKCommonFunctions::getRKWardDataDir () + "pages/rkward_output.css").toString () + "\"/>\n")));
 	} else if (call == "wdChange") {
 		// in case of separate processes, apply new working directory in frontend, too.
 		QDir::setCurrent (calllist.value (1));
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
index d62cb5d..472dd8e 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
@@ -30,6 +30,9 @@
 #'        This could be scripts or additional CSS definitions, for example. Note that
 #'        \emph{nothing} will be added to the header, if the file already exists.
 #' @param style Currently either "regular" or "preview". The latter omits table of contents and date.
+#' @param css Local file name of CSS file to use, or NULL for no CSS file. The CSS file will be
+#'            placed next to x, with file name extension ".css". Only effective when initializing a
+#'            (non-existing) output file.
 #' @param flush.images. If true, any images used in the output file will be deleted as well.
 #' @param ask Logical: Whether to ask before flushing the output file.
 #' @param ... Further parameters passed to rk.set.output.html.file()
@@ -79,7 +82,7 @@
 
 #' @export
 #' @rdname rk.get.tempfile.name
-"rk.set.output.html.file" <- function (x, additional.header.contents = getOption ("rk.html.header.additions"), style=c ("regular", "preview")) {
+"rk.set.output.html.file" <- function (x, additional.header.contents = getOption ("rk.html.header.additions"), style=c ("regular", "preview"), css = getOption ("rk.output.css.file")) {
 	stopifnot (is.character (x))
 	style <- match.arg (style)
 	oldfile <- rk.get.output.html.file ()
@@ -87,7 +90,15 @@
 
 	if (!file.exists (x)) {
 		.rk.cat.output (paste ("<?xml version=\"1.0\" encoding=\"", .Call ("rk.locale.name", PACKAGE="(embedding)"), "\"?>\n", sep=""))
-		.rk.cat.output (paste ("<html><head>\n<title>RKWard Output</title>\n", .rk.do.plain.call ("getCSSlink"), sep=""))
+		.rk.cat.output ("<html><head>\n<title>RKWard Output</title>\n")
+		if (!is.null (css)) {
+			cssfilename <- paste (sub ("\\.[^.]*$", "", basename (x)), ".css", sep="")
+			.rk.cat.output (paste ("<link rel=\"StyleSheet\" type=\"text/css\" href=\"", cssfilename, "\"/>\n", sep=""))
+			cssfile <- file.path (dirname (x), cssfilename)
+			if (!file.copy (css, cssfile, overwrite=TRUE)) {
+				warning ("Failed to copy CSS file ", css, " to ", cssfile)
+			}
+		}
 		# the next part defines a JavaScript function to add individual results to a global table of contents menu in the document
 		if (style != "preview") {
 			.rk.cat.output (paste ("\t<script type=\"text/javascript\">
diff --git a/rkward/settings/rksettingsmoduleoutput.cpp b/rkward/settings/rksettingsmoduleoutput.cpp
index 0bb39fa..c57acb6 100644
--- a/rkward/settings/rksettingsmoduleoutput.cpp
+++ b/rkward/settings/rksettingsmoduleoutput.cpp
@@ -29,6 +29,8 @@
 #include <QComboBox>
 
 #include "../rkglobals.h"
+#include "../misc/getfilenamewidget.h"
+#include "../misc/rkcommonfunctions.h"
 #include "../rbackend/rinterface.h"
 #include "../debug.h"
 
@@ -146,6 +148,7 @@ QString RKSettingsModuleOutput::graphics_type;
 int RKSettingsModuleOutput::graphics_width;
 int RKSettingsModuleOutput::graphics_height;
 int RKSettingsModuleOutput::graphics_jpg_quality;
+QString RKSettingsModuleOutput::custom_css_file;
 
 RKSettingsModuleOutput::RKSettingsModuleOutput (RKSettings *gui, QWidget *parent) : RKSettingsModule(gui, parent) {
 	RK_TRACE (SETTINGS);
@@ -164,6 +167,10 @@ RKSettingsModuleOutput::RKSettingsModuleOutput (RKSettings *gui, QWidget *parent
 
 	main_vbox->addWidget (group);
 
+	custom_css_file_box = new GetFileNameWidget (this, GetFileNameWidget::ExistingFile, true, i18n ("CSS file to use for output (leave empty for default)"), i18n ("Select CSS file"), QString ());
+	connect (custom_css_file_box, SIGNAL (locationChanged()), this, SLOT (boxChanged()));  // KF5 TODO new syntax
+	main_vbox->addWidget (custom_css_file_box);
+
 	group = new QGroupBox (i18n ("Graphics"), this);
 	group_layout = new QVBoxLayout (group);
 	QHBoxLayout *h_layout = new QHBoxLayout ();
@@ -255,6 +262,7 @@ void RKSettingsModuleOutput::saveSettings (KConfig *config) {
 	cg.writeEntry ("graphics_width", graphics_width);
 	cg.writeEntry ("graphics_height", graphics_height);
 	cg.writeEntry ("graphics_jpg_quality", graphics_jpg_quality);
+	cg.writeEntry ("custom css file", custom_css_file);
 
 	RKCarbonCopySettings::saveSettings (config);
 }
@@ -269,6 +277,7 @@ void RKSettingsModuleOutput::loadSettings (KConfig *config) {
 	graphics_width = cg.readEntry ("graphics_width", 480);
 	graphics_height = cg.readEntry ("graphics_height", 480);
 	graphics_jpg_quality = cg.readEntry ("graphics_jpg_quality", 75);
+	custom_css_file = cg.readEntry ("custom css file", QString ());
 
 	RKCarbonCopySettings::loadSettings (config);
 }
@@ -283,8 +292,9 @@ QStringList RKSettingsModuleOutput::makeRRunTimeOptionCommands () {
 	command.append (", \"rk.graphics.width\"=" + QString::number (graphics_width));
 	command.append (", \"rk.graphics.height\"=" + QString::number (graphics_height));
 	if (graphics_type == "\"JPG\"") command.append (", \"rk.graphics.jpg.quality\"=" + QString::number (graphics_jpg_quality));
+	command.append (", \"rk.output.css.file\"=\"" + (custom_css_file.isEmpty () ? RKCommonFunctions::getRKWardDataDir () + "pages/rkward_output.css" : custom_css_file) + '\"');
 	list.append (command + ")\n");
-	
+
 	return (list);
 }
 
diff --git a/rkward/settings/rksettingsmoduleoutput.h b/rkward/settings/rksettingsmoduleoutput.h
index 784e1ee..8e110ac 100644
--- a/rkward/settings/rksettingsmoduleoutput.h
+++ b/rkward/settings/rksettingsmoduleoutput.h
@@ -26,6 +26,7 @@ class QGroupBox;
 class QComboBox;
 class KIntSpinBox;
 class RCommand;
+class GetFileNameWidget;
 
 /**
 Allows to configure which types of commands should be "carbon copied" to the output window. Like the RKSettingsModules classes, this class encapsulates both, the setting itself,
@@ -99,6 +100,7 @@ private:
 	KIntSpinBox *graphics_height_box;
 	KIntSpinBox *graphics_jpg_quality_box;
 	RKCarbonCopySettings *cc_settings;
+	GetFileNameWidget *custom_css_file_box;
 
 	static bool auto_show;
 	static bool auto_raise;
@@ -106,6 +108,7 @@ private:
 	static int graphics_width;
 	static int graphics_height;
 	static int graphics_jpg_quality;
+	static QString custom_css_file;
 };
 
 #endif



More information about the rkward-tracker mailing list