Skip to content

Commit

Permalink
plugins: introduce probe() for proxy plugins
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
kugel- committed Aug 26, 2015
1 parent 7acda46 commit 533c4d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/plugindata.h
Expand Up @@ -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_IGNORED,
PROXY_MATCHED,

PROXY_NOLOAD = 0x100,
}
GeanyProxyProbeResults;

/* 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 *inferior, const gchar *filename, gpointer pdata);
void (*unload) (GeanyPlugin *proxy, GeanyPlugin *inferior, gpointer load_data, gpointer pdata);
}
Expand Down
18 changes: 17 additions & 1 deletion src/plugins.c
Expand Up @@ -948,7 +948,23 @@ static PluginProxy* is_plugin(const gchar *file)
{
if (utils_str_equal(tmp, proxy->extension))
{
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;
case PROXY_MATCHED|PROXY_NOLOAD:
return NULL;
default:
if (ret != PROXY_IGNORED)
g_warning("Ignoring bogus return from proxy probe!\n");
continue;
}

}
}
return NULL;
Expand Down

0 comments on commit 533c4d6

Please sign in to comment.