Commit e816e415 authored by Thomas Friedrichsmeier's avatar Thomas Friedrichsmeier
Browse files

Finish implementing rk.set.plugin.status().

parent 10667466
- 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()
......
......@@ -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 ();
}
......
......@@ -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);
......
......@@ -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
......
% 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@lists.sourceforge.net}
}
\seealso{
\code{\link{rk.call.plugin}} for invoking a plugin, programatically
}
\keyword{utilities}
......@@ -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 ());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment