[geany/geany] 3ccf95: plugins: introduce probe() for proxy plugins

Thomas Martitz git-noreply at xxxxx
Mon Oct 5 20:11:12 UTC 2015

Branch:      refs/heads/master
Author:      Thomas Martitz <kugel at rockbox.org>
Committer:   Thomas Martitz <kugel at rockbox.org>
Date:        Mon, 05 Oct 2015 20:11:12 UTC
Commit:      3ccf959013edb6744ab58f6953a2b44dfb1abef3

Log Message:
plugins: introduce probe() for proxy plugins

When a file extension alone is ambigious as to whether a potential plugin is
really handled then the proxy should use the probe hook to find out. This can
be especially helpful when two pluxies work on the same file extension.

The proxy's probe() should return PROXY_IGNORED or PROXY_MATCHED accordingly.
A special flag value, PROXY_NOLOAD, can be or'ed into PROXY_MATCHED to say
that the file belongs to the proxy, but isn't directly loaded and should not
be handled by any other proxy or geany itself.

Example for PROXY_IGNORED:
geanypy only supports python2 at the moment. So, scripts written
for python3 aren't handled by it and should be skipped for the PM dialog.
Or perhaps they are handled by another proxy that supports python3.

Example for PROXY_NOLOAD:
A pluxy registers for the metadata file extension (.plugin) where author etc
is in. The actual implmentation is in a python script (.py). The .py file
is tied to the .plugin and should not be processed by other pluxies. Thus,
the pluxy also registers for the .py extension but returns
PROXY_MATCHED|PROXY_NOLOAD for it (if it would return only PROXY_MATCHED
the sub-plugin would show up twice in the PM dialog).

Modified Paths:

Modified: src/plugindata.h
10 lines changed, 10 insertions(+), 0 deletions(-)
@@ -347,9 +347,19 @@ void geany_plugin_set_data(GeanyPlugin *plugin, gpointer data, GDestroyNotify fr
 	geany_plugin_register_full((plugin), GEANY_API_VERSION, \
 	                           (min_api_version), GEANY_ABI_VERSION, (pdata), (free_func))
+typedef enum
+	PROXY_NOLOAD = 0x100,
 /* Hooks that need to be implemented for every proxy */
 typedef struct _GeanyProxyFuncs
+	gint		(*probe)     (GeanyPlugin *proxy, const gchar *filename, gpointer pdata);
 	gpointer	(*load)      (GeanyPlugin *proxy, GeanyPlugin *subplugin, const gchar *filename, gpointer pdata);
 	void		(*unload)    (GeanyPlugin *proxy, GeanyPlugin *subplugin, gpointer load_data, gpointer pdata);

Modified: src/plugins.c
17 lines changed, 16 insertions(+), 1 deletions(-)
@@ -953,7 +953,22 @@ static PluginProxy* is_plugin(const gchar *file)
 		if (utils_str_casecmp(ext, proxy->extension) == 0)
-			return proxy;
+			Plugin *p = proxy->plugin;
+			gint ret = PROXY_MATCHED;
+			if (p->proxy_cbs.probe)
+				ret = p->proxy_cbs.probe(&p->public, file, p->cb_data);
+			switch (ret)
+			{
+				case PROXY_MATCHED:
+					return proxy;
+					return NULL;
+				default:
+					if (ret != PROXY_IGNORED)
+						g_warning("Ignoring bogus return from proxy probe!\n");
+					continue;
+			}
 	return NULL;

This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).

More information about the Commits mailing list