[rkward-cvs] SF.net SVN: rkward:[3857] trunk/rkward/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Sep 28 17:49:05 UTC 2011


Revision: 3857
          http://rkward.svn.sourceforge.net/rkward/?rev=3857&view=rev
Author:   tfry
Date:     2011-09-28 17:49:04 +0000 (Wed, 28 Sep 2011)
Log Message:
-----------
Add an R function to (re-)load pluginmaps, and change the mechanism of updating the list of installed packages.

Modified Paths:
--------------
    trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
    trunk/rkward/rkward/rbackend/rinterface.cpp
    trunk/rkward/rkward/rbackend/rinterface.h
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.h

Modified: trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp	2011-09-28 15:35:45 UTC (rev 3856)
+++ trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp	2011-09-28 17:49:04 UTC (rev 3857)
@@ -508,9 +508,7 @@
 	installed_view->clear ();
 	loaded_view->clear ();
 
-	RCommand *c = new RCommand (".rk.get.installed.packages ()", RCommand::App | RCommand::Sync | RCommand::GetStructuredData, QString::null, this, GET_INSTALLED_PACKAGES);
-	connect (c->notifier (), SIGNAL (commandFinished(RCommand*)), RKGlobals::rInterface (), SLOT (installedPackagesCommandFinished(RCommand*)));
-	RKGlobals::rInterface ()->issueCommand (c, parent->chain);
+	RKGlobals::rInterface ()->issueCommand (".rk.get.installed.packages ()", RCommand::App | RCommand::Sync | RCommand::GetStructuredData, QString::null, this, GET_INSTALLED_PACKAGES, parent->chain);
 	RKGlobals::rInterface ()->issueCommand (".packages ()", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_LOADED_PACKAGES, parent->chain);
 }
 

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2011-09-28 15:35:45 UTC (rev 3856)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2011-09-28 17:49:04 UTC (rev 3857)
@@ -109,10 +109,9 @@
 	new RKRBackendProtocolFrontend (this);
 	RKRBackendProtocolFrontend::instance ()->setupBackend ();
 
-	// Further initialization commands, which do not necessarily have to run before everything else can be queued, here.
-	RCommand *c = new RCommand (".rk.get.installed.packages()", RCommand::App | RCommand::Sync | RCommand::GetStructuredData);
-	connect (c->notifier (), SIGNAL (commandFinished(RCommand*)), this, SLOT (installedPackagesCommandFinished(RCommand*)));
-	issueCommand (c);
+	/////// Further initialization commands, which do not necessarily have to run before everything else can be queued, here. ///////
+	// NOTE: will receive the list as a call plain generic request from the backend ("updateInstalledPackagesList")
+	issueCommand (".rk.get.installed.packages()", RCommand::App | RCommand::Sync);
 }
 
 void RInterface::issueCommand (const QString &command, int type, const QString &rk_equiv, RCommandReceiver *receiver, int flags, RCommandChain *chain) {
@@ -252,24 +251,6 @@
 	command_requests.pop_back ();
 }
 
-void RInterface::installedPackagesCommandFinished (RCommand *command) {
-	RK_TRACE (RBACKEND);
-
-	if (command->succeeded () && (command->getDataType () == RData::StructureVector) && (command->getDataLength() >= 6)) {
-		RData *dummy = command->getStructureVector ()[0];
-		if (dummy->getDataType () == RData::StringVector) RKSessionVars::instance ()->setInstalledPackages (dummy->getStringVector ());
-		else RK_ASSERT (false);
-
-		dummy = command->getStructureVector ()[5];
-		if (dummy->getDataType () == RData::StringVector) RKSettingsModulePlugins::registerPluginMaps (dummy->getStringVector ());
-		else RK_ASSERT (false);
-
-		return;
-	}
-
-	RK_ASSERT (false);
-}
-
 void RInterface::rCommandDone (RCommand *command) {
 	RK_TRACE (RBACKEND);
 
@@ -535,6 +516,12 @@
 	} else if (call == "listPlugins") {
 		RK_ASSERT (calllist.count () == 1);
 		return RKComponentMap::getMap ()->allComponentIds ();
+	} else if (call == "loadPluginMaps") {
+		bool force = (calllist.value (1) == "force");
+		bool reload = (calllist.value (2) == "reload");
+		RKSettingsModulePlugins::registerPluginMaps (calllist.mid (3), force, reload);
+	} else if (call == "updateInstalledPackagesList") {
+		RKSessionVars::instance ()->setInstalledPackages (calllist.mid (1));
 	} else if (call == "showHTML") {
 		RK_ASSERT (calllist.count () == 2);
 		RKWorkplace::mainWorkplace ()->openHelpWindow (calllist.value (1));

Modified: trunk/rkward/rkward/rbackend/rinterface.h
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.h	2011-09-28 15:35:45 UTC (rev 3856)
+++ trunk/rkward/rkward/rbackend/rinterface.h	2011-09-28 17:49:04 UTC (rev 3857)
@@ -75,9 +75,6 @@
 	bool backendIsIdle ();
 	static bool isNaReal (double value) { return na_real == value; };
 	static bool isNaInt (int value) { return na_int == value; };
-public slots:
-/** Public for hacky reasons. Can be connected to .rk.get.installed.packages() */
-	void installedPackagesCommandFinished (RCommand *command);
 private:
 	void timerEvent (QTimerEvent *);
 	int flush_timer_id;

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2011-09-28 15:35:45 UTC (rev 3856)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2011-09-28 17:49:04 UTC (rev 3857)
@@ -106,6 +106,9 @@
 	oldavail <- match (old$Package, available$Package)	# convert package names to position with in the available packages info
 	new <- match (new, available$Package)	# same for new packages
 
+	# as a side effect, we update the list of known installed packages in the frontend
+	.rk.do.plain.call ("updateInstalledPackagesList", sort (unique (as.character (inst$Package))), synchronous=FALSE)
+
 	list ("available" = list (available$Package, available$Title, available$Version, available$Repository, grepl ("rkward", available$Enhances)),
 		"installed" = list (inst$Package, inst$Title, inst$Version, inst$LibPath, grepl ("rkward", inst$Enhances)),
 		"new" = as.integer (new - 1),
@@ -119,12 +122,15 @@
 	x <- as.data.frame(installed.packages(fields="Title"))
 	# does a package enhance RKWard, i.e. provide plugins?
 	enhance.rk <- ifelse(is.na(x$Enhances), FALSE, grepl("rkward", x$Enhances))
+
+	# as a side effect, we update the list of known installed packages in the frontend
+	.rk.do.plain.call ("updateInstalledPackagesList", sort (unique (as.character (x$Package))), synchronous=FALSE)
 	# check for pluginmaps only in packages which enhance RKWard
-	pluginmaps <- rep("", length(enhance.rk))
-	pluginmaps[enhance.rk] <- .rk.find.package.pluginmaps(x$Package[enhance.rk])
+	rk.load.pluginmaps (.rk.find.package.pluginmaps(x$Package[enhance.rk]), force.add=FALSE, force.reload=FALSE)
+
 	return(list(Package=as.character(x$Package), Title=as.character(x$Title), 
 		Version=as.character(x$Version), LibPath=as.character(x$LibPath),
-		EnhanceRK=as.logical(enhance.rk), Plugins=as.character(pluginmaps)))
+		EnhanceRK=as.logical(enhance.rk)))
 }
 
 # This function works like available.packages (with no arguments), but does simple caching of the result, and of course uses a cache if available. Cache is only used, if it is less than 1 hour old, and options("repos") is unchanged.

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R	2011-09-28 15:35:45 UTC (rev 3856)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R	2011-09-28 17:49:04 UTC (rev 3857)
@@ -99,3 +99,36 @@
 
 	invisible (TRUE)
 }
+
+#' (Re-)load the given pluginmap files into the RKWard GUI
+#'
+#' @param pluginmap.files a character vector of file names to add. This may be left empty,
+#'                        if the only desired effect is to reload all active pluginmaps.
+#' @param force.add logical. Whether the pluginmap files should also be added, if they had
+#'                  been previously de-selected in the settings menu. In scripted usage, this
+#'                  should generally be set to FALSE.
+#' @param force.reload logical. By default the active pluginmaps are reloaded, only if any new ones
+#'                     were added. If set to TRUE, pluginmaps are reloaded in any case. In
+#'                     scripted usage, this should generally be set to FALSE. NOTE: Since
+#'                     a reload always means reloading _all_ active pluginmaps, This may be
+#'                     slow, and should be used with care.
+#'
+#' \bold{Note}: It is not necessary to reload the pluginmap, in order to refresh an individual
+#'              plugin (e.g. after modifying the dialog), as plugins are not kept in memory after closing.
+#'              Any currently opened plugins are not affected by this function. 
+#'
+#' @author Thomas Friedrichsmeier \email{rkward-devel@@lists.sourceforge.net}
+#' @seealso \code{\link{rk.call.plugin}}, @seealso \code{\link{rkwarddev::rk.plugin.skeleton}}
+#' @keywords utilities
+#'
+#' @examples
+#' 
+#' ## NOT RUN
+#'
+#' ## reload all active pluginmaps
+#' rk.load.pluginmaps()
+#'
+#' END NOT RUN
+"rk.load.pluginmaps" <- function (pluginmap.files=NULL, force.add = TRUE, force.reload = TRUE) {
+	.rk.do.plain.call ("loadPluginMaps", c (as.character (isTRUE (force.add)), as.character (isTRUE (force.reload)), as.character (pluginmap.files)), synchronous=FALSE)
+}

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2011-09-28 15:35:45 UTC (rev 3856)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2011-09-28 17:49:04 UTC (rev 3857)
@@ -199,14 +199,17 @@
 }
 
 // static
-void RKSettingsModulePlugins::registerPluginMaps (const QStringList &maps) {
+void RKSettingsModulePlugins::registerPluginMaps (const QStringList &maps, bool force_add, bool force_reload) {
 	RK_TRACE (SETTINGS);
 
 	QStringList added;
 	foreach (const QString &map, maps) {
 		if (map.isEmpty ()) continue;
-		if (known_plugin_maps.contains (map)) continue;
-		known_plugin_maps.append (map);
+		if (known_plugin_maps.contains (map)) {
+			if (!force_add) continue;
+		} else {
+			known_plugin_maps.append (map);
+		}
 
 		if (plugin_maps.contains (map)) continue;
 		plugin_maps.append (map);
@@ -215,8 +218,10 @@
 
 	if (!added.isEmpty ()) {
 		KMessageBox::informationList (RKWardMainWindow::getMain (), i18n ("New RKWard plugin packs (listed below) have been found, and have been activated, automatically. To de-activate selected plugin packs, use Settings->Configure RKWard->Plugins."), added, i18n ("New plugins found"), "new_plugins_found");
-		RKWardMainWindow::getMain ()->initPlugins();
+		force_reload = true;
 	}
+
+	if (force_reload) RKWardMainWindow::getMain ()->initPlugins();
 }
 
 void RKSettingsModulePlugins::fixPluginMapLists () {

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.h	2011-09-28 15:35:45 UTC (rev 3856)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.h	2011-09-28 17:49:04 UTC (rev 3857)
@@ -51,8 +51,12 @@
 	static PluginPrefs getInterfacePreference () { return interface_pref; };
 	static bool showCodeByDefault () { return show_code; };
 	static int defaultCodeHeight () { return code_size; };
-	/** register a list of available plugin-maps (which may or may not already be known). New maps are activated, automatically. */
-	static void registerPluginMaps (const QStringList &maps);
+	/** register a list of available plugin-maps (which may or may not already be known). New maps are activated, automatically.
+	 * @param maps Plugin maps (filenames) to add
+	 * @param force_add If true, maps are added, even if they are not "new", and had previously been disabled by the user
+	 * @param force_reload If true, plugin maps are always reloaded, even if no maps were added
+	 */
+	static void registerPluginMaps (const QStringList &maps, bool force_add, bool force_reload);
 public slots:
 	void settingChanged ();
 	void browseRequest (QStringList* strings);

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the rkward-tracker mailing list