[rkward-cvs] [rkward] rkward: Provide much more information (context, menu-path, label) in rk.list.plugins()
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Jan 1 21:12:14 UTC 2015
Git commit d64697b36e050caf11b8d3f72b28e13ddd688b29 by Thomas Friedrichsmeier.
Committed on 01/01/2015 at 21:06.
Pushed by tfry into branch 'master'.
Provide much more information (context, menu-path, label) in rk.list.plugins()
M +31 -2 rkward/plugin/rkcomponentmap.cpp
M +5 -3 rkward/plugin/rkcomponentmap.h
M +1 -1 rkward/rbackend/rinterface.cpp
M +7 -7 rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
M +5 -4 rkward/rbackend/rpackages/rkward/man/rk.call.plugin.Rd
http://commits.kde.org/rkward/d64697b36e050caf11b8d3f72b28e13ddd688b29
diff --git a/rkward/plugin/rkcomponentmap.cpp b/rkward/plugin/rkcomponentmap.cpp
index 4dc1cf2..014327a 100644
--- a/rkward/plugin/rkcomponentmap.cpp
+++ b/rkward/plugin/rkcomponentmap.cpp
@@ -78,7 +78,7 @@ bool compareMenuEntries (const RKComponentGUIXML::Entry *a, const RKComponentGUI
return (QString::localeAwareCompare (a->label, b->label) < 0);
}
-void RKComponentGUIXML::resolveComponentLabelsAndSortMenu (Menu *menu) {
+void RKComponentGUIXML::resolveComponentLabelsAndSortMenu (Menu *menu, const QString &menu_path) {
RK_TRACE (PLUGIN);
for (int i = 0; i < menu->groups.size (); ++i) {
@@ -96,9 +96,10 @@ void RKComponentGUIXML::resolveComponentLabelsAndSortMenu (Menu *menu) {
// The reason that handling of label is delayed to this point is that if a plugin is overridden, we want to use the label specified for the effective plugin (which might have changed WRT the overridden plugin, too).
entry->label = handle->getLabel ();
addedEntry (entry->id, handle);
+ component_menus.insert (handle, menu_path);
}
} else {
- resolveComponentLabelsAndSortMenu (static_cast<Menu*> (entry));
+ resolveComponentLabelsAndSortMenu (static_cast<Menu*> (entry), menu_path.isEmpty () ? entry->label : menu_path + "\t" + entry->label);
}
}
qSort (group->entries.begin (), group->entries.end (), compareMenuEntries);
@@ -149,6 +150,7 @@ void RKComponentGUIXML::finalize () {
QDomElement xmlgui_menubar_element = gui_xml.documentElement ().firstChildElement ("MenuBar");
resolveComponentLabelsAndSortMenu (&toplevel_menu);
menuItemsToXml (&toplevel_menu, xmlgui_menubar_element);
+ toplevel_menu.clear (); // no longer needed
}
RKComponentGUIXML::Group::~Group () {
@@ -686,6 +688,33 @@ void RKComponentMap::addedEntry (const QString &id, RKComponentHandle *handle) {
}
}
+QStringList RKComponentMap::listPlugins () {
+ RK_TRACE (PLUGIN);
+
+ QStringList ret;
+#if QT_VERSION >= 0x040500
+ ret.reserve (components.size () * 4);
+#endif
+ for (ComponentMap::const_iterator it = components.constBegin (); it != components.constEnd (); ++it) {
+ ret.append (it.key ());
+ ret.append ("global"); // context
+ ret.append (component_menus.value (it.value ()));
+ ret.append (it.value ()->getLabel ());
+ }
+ for (RKComponentContextMap::const_iterator ctx = contexts.constBegin (); ctx != contexts.constEnd (); ++ctx) {
+ QStringList ids = ctx.value ()->components ();
+ for (int i = 0; i < ids.size (); ++i) {
+ ret.append (ids[i]);
+ ret.append (ctx.key ());
+ RKComponentHandle *handle = getComponentHandle (ids[i]);
+ ret.append (ctx.value ()->component_menus.value (handle));
+ ret.append (handle->getLabel ());
+ }
+ }
+ return ret;
+}
+
+
///########################### END RKComponentMap ###############################
///########################### BEGIN RKComponentHandle ############################
diff --git a/rkward/plugin/rkcomponentmap.h b/rkward/plugin/rkcomponentmap.h
index 1c3f0d1..df53ae6 100644
--- a/rkward/plugin/rkcomponentmap.h
+++ b/rkward/plugin/rkcomponentmap.h
@@ -163,10 +163,12 @@ protected:
/** The generated XML GUI description in KDEs ui.rc format */
QDomDocument gui_xml;
+friend class RKComponentMap;
+ QMap<RKComponentHandle*, QString> component_menus;
private:
int addEntries (RKComponentGUIXML::Menu *menu, XMLHelper &xml, const QDomElement description, const QString& cnamespace);
void menuItemsToXml (const RKComponentGUIXML::Menu *menu, QDomElement &xml);
- void resolveComponentLabelsAndSortMenu (Menu *menu);
+ void resolveComponentLabelsAndSortMenu (Menu *menu, const QString &menu_path=QString ());
};
@@ -226,8 +228,8 @@ public:
/** invokes the specified component as toplevel
@param message If a non-null pointer to QString is given, error messages are written into this string *instead* of being displayed */
static bool invokeComponent (const QString &component_id, const QStringList &serialized_settings, ComponentInvocationMode submit_mode = ManualSubmit, QString *message=0, RCommandChain *in_chain = 0);
-/** @returns a list of all currently registered component ids */
- QStringList allComponentIds () { return components.keys(); };
+/** @returns for rk.list.plugins(): Return a list of all currently registered component ids, their context, menu, and label (i.e. current four strings per component) */
+ QStringList listPlugins ();
bool isPluginMapLoaded (const QString& abs_filename) const;
public slots:
/** Slot called, when a menu-item for a component is selected. Responsible for creating the GUI. */
diff --git a/rkward/rbackend/rinterface.cpp b/rkward/rbackend/rinterface.cpp
index 009b57a..3021e37 100644
--- a/rkward/rbackend/rinterface.cpp
+++ b/rkward/rbackend/rinterface.cpp
@@ -579,7 +579,7 @@ QStringList RInterface::processPlainGenericRequest (const QStringList &calllist)
if (res != KMessageBox::Continue) return (QStringList ("FALSE"));
} else if (call == "listPlugins") {
RK_ASSERT (calllist.count () == 1);
- return RKComponentMap::getMap ()->allComponentIds ();
+ return RKComponentMap::getMap ()->listPlugins ();
} else if (call == "loadPluginMaps") {
bool force = (calllist.value (1) == "force");
bool reload = (calllist.value (2) == "reload");
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
index db928fa..4fb9dc9 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.plugin-functions.R
@@ -20,8 +20,8 @@
#' run in the global context. Any local variables of the calling context are
#' not available to the plugin.
#'
-#' \code{rk.list.plugins} returns the list of the names of all currently
-#' registered plugins.
+#' \code{rk.list.plugins} returns the a list of all currently
+#' registered plugins (in loaded pluginmaps).
#'
#' @aliases rk.call.plugin rk.list.plugins
#' @param plugin character string, giving the name of the plugin to call. See
@@ -40,8 +40,9 @@
#' an error.
#' @return \code{rk.call.plugin} returns \code{TRUE} invisibly.
#'
-#' \code{rk.list.plugins} returns a character vector of plugin names. If none
-#' found, \code{NULL} is returned.
+#' \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.
#' @author Thomas Friedrichsmeier \email{rkward-devel@@lists.sourceforge.net}
#' @seealso \code{\link{rk.results}}, \url{rkward://page/rkward_output}
#' @keywords utilities
@@ -63,11 +64,10 @@
#' submit.mode="submit")
#' })
#'
-# list all available plugins in RKWard; this is a companion function for rk.call.plugin:
-# the output provides possible strings for "plugin" argument in rk.call.plugin
#' @export
rk.list.plugins <- function () {
- .rk.do.plain.call ("listPlugins")
+ plugs <- .rk.do.plain.call("listPlugins")
+ as.data.frame (matrix (plugs, ncol=4, byrow=TRUE, dimnames=list (1:(length (plugs) / 4), c ("ID", "Context", "Menupath", "Label"))), stringsAsFactors=FALSE)
}
#' @export
diff --git a/rkward/rbackend/rpackages/rkward/man/rk.call.plugin.Rd b/rkward/rbackend/rpackages/rkward/man/rk.call.plugin.Rd
index 01e0916..9e7225c 100644
--- a/rkward/rbackend/rpackages/rkward/man/rk.call.plugin.Rd
+++ b/rkward/rbackend/rpackages/rkward/man/rk.call.plugin.Rd
@@ -29,8 +29,9 @@ an error.}
\value{
\code{rk.call.plugin} returns \code{TRUE} invisibly.
-\code{rk.list.plugins} returns a character vector of plugin names. If none
- found, \code{NULL} is returned.
+\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.
}
\description{
\code{rk.call.plugin} provides a high level wrapper to call any plugin
@@ -54,8 +55,8 @@ tests, cross-references, and scripted tutorials.
run in the global context. Any local variables of the calling context are
not available to the plugin.
-\code{rk.list.plugins} returns the list of the names of all currently
-registered plugins.
+\code{rk.list.plugins} returns the a list of all currently
+registered plugins (in loaded pluginmaps).
}
\examples{
## list all current plugins
More information about the rkward-tracker
mailing list