[rkward-cvs] [rkward] /: Finish implementing rk.set.plugin.status().
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Mon Jan 5 19:49:51 UTC 2015
Git commit e816e415e77d6548f6bbbc5e5ae9b0669f5de352 by Thomas Friedrichsmeier.
Committed on 05/01/2015 at 19:49.
Pushed by tfry into branch 'master'.
Finish implementing rk.set.plugin.status().
M +1 -0 ChangeLog
M +28 -0 rkward/plugin/rkcomponentmap.cpp
M +2 -1 rkward/plugin/rkcomponentmap.h
M +11 -3 rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
A +58 -0 rkward/rbackend/rpackages/rkward/man/rk.list.plugins.Rd
M +1 -0 rkward/rkward.h
http://commits.kde.org/rkward/e816e415e77d6548f6bbbc5e5ae9b0669f5de352
diff --git a/ChangeLog b/ChangeLog
index 136df96..250d3c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Add R function rk.set.plugin.status() to allow further customization of loaded plugins (hiding of individual menu entries)
- TODO: With the improved interface to plugins from R, make sure plugins can actually be modified at runtime without crashing (close and re-open them)
- Pluginmap-management was reworked, partially, and moved to Settings->Manage R packages and plugins
- Provide more detailed information on loaded plugins in rk.list.plugins()
diff --git a/rkward/plugin/rkcomponentmap.cpp b/rkward/plugin/rkcomponentmap.cpp
index 5594cd5..982e24e 100644
--- a/rkward/plugin/rkcomponentmap.cpp
+++ b/rkward/plugin/rkcomponentmap.cpp
@@ -279,6 +279,21 @@ int RKComponentGUIXML::addEntries (RKComponentGUIXML::Menu *menu, XMLHelper &xml
continue;
}
+ // check if there is an override hiding this plugin (TODO: what if there is more than one override?)
+ bool hidden = false;
+ OverrideMap::const_iterator ov = overrides.constFind (id);
+ while (ov != overrides.constEnd () && ov.key () == id) {
+ const ComponentOverride &over = ov.value ();
+ if (over.context.isEmpty () || over.context == context) {
+ if (over.hidden) {
+ hidden = true;
+ break;
+ }
+ }
+ ++ov;
+ }
+ if (hidden) continue;
+
Entry *plug = new Entry ();
plug->id = id;
insertEntry (menu, plug, add_to);
@@ -295,6 +310,17 @@ int RKComponentGUIXML::addEntries (RKComponentGUIXML::Menu *menu, XMLHelper &xml
// static
QMultiMap<QString, RKComponentGUIXML::ComponentOverride> RKComponentGUIXML::overrides;
void RKComponentGUIXML::addOverride (const QString& id, const QString& context, bool visible) {
+
+ OverrideMap::iterator ov = overrides.find (id);
+ while (ov != overrides.end () && ov.key () == id) {
+ const ComponentOverride &over = ov.value ();
+ if (over.context == context) {
+ overrides.erase (ov);
+ break;
+ }
+ ++ov;
+ }
+
ComponentOverride over;
over.context = context;
over.hidden = !visible;
@@ -742,6 +768,8 @@ void RKComponentMap::setPluginStatus (const QStringList& ids, const QStringList&
for (int i = 0; i < ids.size (); ++i) {
addOverride (ids[i], _contexts[i], (_visible[i] == "1"));
}
+
+ RKWardMainWindow::getMain ()->initPlugins ();
}
diff --git a/rkward/plugin/rkcomponentmap.h b/rkward/plugin/rkcomponentmap.h
index 6ade57b..8bb9bf1 100644
--- a/rkward/plugin/rkcomponentmap.h
+++ b/rkward/plugin/rkcomponentmap.h
@@ -183,7 +183,8 @@ private:
QString context;
bool hidden;
};
- static QMultiMap<QString, ComponentOverride> overrides;
+ typedef QMultiMap<QString, ComponentOverride> OverrideMap;
+ static OverrideMap overrides;
QString context;
void appendPluginToList (const QString &id, QStringList *list);
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
index 6a0387a..eaef8d4 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
@@ -133,13 +133,21 @@
#' meaning the plugin will be affected in all contexts it occurs in, or a character vector
#' of the same length as id.
#' @param visible logical, controlling whether the plugin should be shown (\code{TRUE}) or
-#' hidden (\code{FALSE}).
+#' hidden (\code{FALSE}). Hidden plugins are essentially removed from the menu. They may still
+#' be accessible embedded into other plugins.
#'
#' @return \code{rk.list.plugins} returns a data.frame listing plugin ids, context, menu path
#' (tab-separated), and label of the plugin. If a plugin is available in more
#' than one context, it will be listed several times. The exact layout (number and order of columns)
#' of this data.frame might be subject to change. However, the \bold{names} of the columns in the
-#' returned data.frame are expected to remain stable. \code {rk.set.plugin.status} returns \code{NULL}, invisibly
+#' returned data.frame are expected to remain stable.
+#' \code{rk.set.plugin.status} returns \code{NULL}, invisibly
+#'
+#' \bold{Note}: Each call to \code{rk.set.plugin.status} will result in a complete rebuild of the
+#' menu (in the current implementation). While this should be hardly noticeable in interactive
+#' use, it could be an issue when changing the status of many plugins, programatically.
+#' In this case, make sure to do all changes in \bold{one} call to \code{rk.set.plugin.status},
+#' rather than many separate calls.
#'
#' @author Thomas Friedrichsmeier \email{rkward-devel@@lists.sourceforge.net}
#' @keywords utilities
@@ -152,7 +160,7 @@
#'
#' ## NOT RUN
#' ## hide t.test plugin
-#' rk.set.plugin.status ("t_test", visible=FALSE)
+#' rk.set.plugin.status ("rkward::t_test", visible=FALSE)
#' ## END NOT RUN
#'
#' @export
diff --git a/rkward/rbackend/rpackages/rkward/man/rk.list.plugins.Rd b/rkward/rbackend/rpackages/rkward/man/rk.list.plugins.Rd
new file mode 100644
index 0000000..363bd0b
--- /dev/null
+++ b/rkward/rbackend/rpackages/rkward/man/rk.list.plugins.Rd
@@ -0,0 +1,58 @@
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{rk.list.plugins}
+\alias{rk.list.plugins}
+\alias{rk.set.plugin.status}
+\title{List of modify loaded plugins}
+\usage{
+rk.list.plugins()
+
+rk.set.plugin.status(id, context = "", visible = TRUE)
+}
+\arguments{
+\item{id}{vector of ids (character) of the plugins to modify}
+
+\item{context}{in which the plugin should be shown / hidden. This can either be "",
+meaning the plugin will be affected in all contexts it occurs in, or a character vector
+of the same length as id.}
+
+\item{visible}{logical, controlling whether the plugin should be shown (\code{TRUE}) or
+ hidden (\code{FALSE}). Hidden plugins are essentially removed from the menu. They may still
+ be accessible embedded into other plugins.}
+}
+\value{
+\code{rk.list.plugins} returns a data.frame listing plugin ids, context, menu path
+ (tab-separated), and label of the plugin. If a plugin is available in more
+ than one context, it will be listed several times. The exact layout (number and order of columns)
+ of this data.frame might be subject to change. However, the \bold{names} of the columns in the
+ returned data.frame are expected to remain stable.
+ \code{rk.set.plugin.status} returns \code{NULL}, invisibly
+
+\bold{Note}: Each call to \code{rk.set.plugin.status} will result in a complete rebuild of the
+ menu (in the current implementation). While this should be hardly noticeable in interactive
+ use, it could be an issue when changing the status of many plugins, programatically.
+ In this case, make sure to do all changes in \bold{one} call to \code{rk.set.plugin.status},
+ rather than many separate calls.
+}
+\description{
+\code{rk.list.plugins} returns the a list of all currently
+registered plugins (in loaded pluginmaps).
+\code{rk.set.plugin.status} allows to control the status of the given plugin(s). Currently,
+ only visibility can be controlled.
+}
+\examples{
+## list all current plugins
+rk.list.plugins ()
+
+## NOT RUN
+## hide t.test plugin
+rk.set.plugin.status ("rkward::t_test", visible=FALSE)
+## END NOT RUN
+}
+\author{
+Thomas Friedrichsmeier \email{rkward-devel at lists.sourceforge.net}
+}
+\seealso{
+\code{\link{rk.call.plugin}} for invoking a plugin, programatically
+}
+\keyword{utilities}
+
diff --git a/rkward/rkward.h b/rkward/rkward.h
index 2edb558..5ba9701 100644
--- a/rkward/rkward.h
+++ b/rkward/rkward.h
@@ -176,6 +176,7 @@ private:
friend class RKSettingsModule;
friend class RKSettingsModulePlugins;
friend class RKSettings;
+ friend class RKComponentMap;
/** Finds plugins and inserts them into the menu-structure */
void initPlugins (const QStringList &automatically_added = QStringList ());
More information about the rkward-tracker
mailing list