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

Provide much more information (context, menu-path, label) in rk.list.plugins()

parent cbfdda9d
......@@ -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 ############################
......
......@@ -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. */
......
......@@ -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");
......
......@@ -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
......
......@@ -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
......
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