Merge pull request #890 from kugel-/gtkdoc-hdr
[geany-mirror.git] / src / plugindata.h
blob1758eac44766e49ac8eecbe309fed62927eed8e7
1 /*
2 * plugindata.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2007-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2007-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /**
23 * @file plugindata.h
24 * This file defines the plugin API, the interface between Geany and its plugins.
25 * For detailed documentation of the plugin system please read the plugin
26 * API documentation.
27 **/
28 /* Note: Remember to increment GEANY_API_VERSION (and GEANY_ABI_VERSION if necessary)
29 * when making changes (see 'Keeping the plugin ABI stable' in the HACKING file). */
32 #ifndef GEANY_PLUGIN_DATA_H
33 #define GEANY_PLUGIN_DATA_H 1
35 #include "build.h" /* GeanyBuildGroup, GeanyBuildSource, GeanyBuildCmdEntries enums */
36 #include "document.h" /* GeanyDocument */
37 #include "editor.h" /* GeanyEditor, GeanyIndentType */
38 #include "filetypes.h" /* GeanyFiletype */
40 #include "gtkcompat.h"
42 G_BEGIN_DECLS
44 /* Compatibility for sharing macros between API and core.
45 * First include geany.h, then plugindata.h, then other API headers. */
46 #undef GEANY
47 #define GEANY(symbol_name) geany->symbol_name
50 /** The Application Programming Interface (API) version, incremented
51 * whenever any plugin data types are modified or appended to.
53 * You can protect code that needs a higher API than e.g. 200 with:
54 * @code #if GEANY_API_VERSION >= 200
55 * some_newer_function();
56 * #endif @endcode
58 * @warning You should not test for values below 200 as previously
59 * @c GEANY_API_VERSION was defined as an enum value, not a macro.
61 #define GEANY_API_VERSION 227
63 /* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins
64 * with GTK3-linked Geany leads to crash */
65 #if GTK_CHECK_VERSION(3, 0, 0)
66 # define GEANY_ABI_SHIFT 8
67 #else
68 # define GEANY_ABI_SHIFT 0
69 #endif
70 /** The Application Binary Interface (ABI) version, incremented whenever
71 * existing fields in the plugin data types have to be changed or reordered.
72 * Changing this forces all plugins to be recompiled before Geany can load them. */
73 /* This should usually stay the same if fields are only appended, assuming only pointers to
74 * structs and not structs themselves are declared by plugins. */
75 #define GEANY_ABI_VERSION (71 << GEANY_ABI_SHIFT)
78 /** Defines a function to check the plugin is safe to load.
79 * This performs runtime checks that try to ensure:
80 * - Geany ABI data types are compatible with this plugin.
81 * - Geany sources provide the required API for this plugin.
82 * @param api_required The minimum API number your plugin requires.
83 * Look at the source for the value of @c GEANY_API_VERSION to use if you
84 * want your plugin to require the current Geany version on your machine.
85 * You should update this value when using any new API features. */
86 #define PLUGIN_VERSION_CHECK(api_required) \
87 gint plugin_version_check(gint abi_ver) \
88 { \
89 if (abi_ver != GEANY_ABI_VERSION) \
90 return -1; \
91 return (api_required); \
95 /** Basic information about a plugin available to Geany without loading the plugin.
96 * The fields are set in plugin_set_info(), usually with the PLUGIN_SET_INFO() macro. */
97 typedef struct PluginInfo
99 /** The name of the plugin. */
100 const gchar *name;
101 /** The description of the plugin. */
102 const gchar *description;
103 /** The version of the plugin. */
104 const gchar *version;
105 /** The author of the plugin. */
106 const gchar *author;
108 PluginInfo;
111 /** Sets the plugin name and some other basic information about a plugin.
113 * @note If you want some of the arguments to be translated, see @ref PLUGIN_SET_TRANSLATABLE_INFO()
115 * Example:
116 * @code PLUGIN_SET_INFO("Cool Feature", "Adds cool feature support.", "0.1", "Joe Author") @endcode */
117 /* plugin_set_info() could be written manually for plugins if we want to add any
118 * extra PluginInfo features (such as an icon), so we don't need to break API
119 * compatibility. Alternatively just add a new macro, PLUGIN_SET_INFO_FULL(). -ntrel */
120 #define PLUGIN_SET_INFO(p_name, p_description, p_version, p_author) \
121 void plugin_set_info(PluginInfo *info) \
123 info->name = (p_name); \
124 info->description = (p_description); \
125 info->version = (p_version); \
126 info->author = (p_author); \
129 /** Sets the plugin name and some other basic information about a plugin.
130 * This macro is like @ref PLUGIN_SET_INFO() but allows the passed information to be translated
131 * by setting up the translation mechanism with @ref main_locale_init().
132 * You therefore don't need to call it manually in plugin_init().
134 * Example:
135 * @code PLUGIN_SET_TRANSLATABLE_INFO(LOCALEDIR, GETTEXT_PACKAGE, _("Cool Feature"), _("Adds a cool feature."), "0.1", "John Doe") @endcode
137 * @since 0.19 */
138 #define PLUGIN_SET_TRANSLATABLE_INFO(localedir, package, p_name, p_description, p_version, p_author) \
139 void plugin_set_info(PluginInfo *info) \
141 main_locale_init((localedir), (package)); \
142 info->name = (p_name); \
143 info->description = (p_description); \
144 info->version = (p_version); \
145 info->author = (p_author); \
149 /** @deprecated - use plugin_set_key_group() instead.
150 * @see PLUGIN_KEY_GROUP() macro. */
151 typedef struct GeanyKeyGroupInfo
153 const gchar *name; /**< Group name used in the configuration file, such as @c "html_chars" */
154 gsize count; /**< The number of keybindings the group will hold */
156 GeanyKeyGroupInfo;
158 /** @deprecated - use plugin_set_key_group() instead.
159 * Declare and initialise a keybinding group.
160 * @code GeanyKeyGroup *plugin_key_group; @endcode
161 * You must then set the @c plugin_key_group::keys[] entries for the group in plugin_init(),
162 * normally using keybindings_set_item().
163 * The @c plugin_key_group::label field is set by Geany after @c plugin_init()
164 * is called, to the name of the plugin.
165 * @param group_name A unique group name (without quotes) to be used in the
166 * configuration file, such as @c html_chars.
167 * @param key_count The number of keybindings the group will hold. */
168 #define PLUGIN_KEY_GROUP(group_name, key_count) \
169 /* We have to declare this as a single element array.
170 * Declaring as a pointer to a struct doesn't work with g_module_symbol(). */ \
171 GeanyKeyGroupInfo plugin_key_group_info[1] = \
173 {G_STRINGIFY(group_name), key_count} \
175 GeanyKeyGroup *plugin_key_group = NULL;
178 /** Callback array entry type used with the @ref plugin_callbacks symbol. */
179 typedef struct PluginCallback
181 /** The name of signal, must be an existing signal. For a list of available signals,
182 * please see the @link pluginsignals.c Signal documentation @endlink. */
183 const gchar *signal_name;
184 /** A callback function which is called when the signal is emitted. */
185 GCallback callback;
186 /** Set to TRUE to connect your handler with g_signal_connect_after(). */
187 gboolean after;
188 /** The user data passed to the signal handler. If set to NULL then the signal
189 * handler will receive the data set with geany_plugin_register_full() or
190 * geany_plugin_set_data() */
191 gpointer user_data;
193 PluginCallback;
196 /** @deprecated Use @ref ui_add_document_sensitive() instead.
197 * Flags to be set by plugins in PluginFields struct. */
198 typedef enum
200 /** Whether a plugin's menu item should be disabled when there are no open documents */
201 PLUGIN_IS_DOCUMENT_SENSITIVE = 1 << 0
203 PluginFlags;
205 /** @deprecated Use @ref ui_add_document_sensitive() instead.
206 * Fields set and owned by the plugin. */
207 typedef struct PluginFields
209 /** Bitmask of @c PluginFlags. */
210 PluginFlags flags;
211 /** Pointer to a plugin's menu item which will be automatically enabled/disabled when there
212 * are no open documents and @c PLUGIN_IS_DOCUMENT_SENSITIVE is set.
213 * This is required if using @c PLUGIN_IS_DOCUMENT_SENSITIVE, ignored otherwise */
214 GtkWidget *menu_item;
216 PluginFields;
219 /** This contains pointers to global variables owned by Geany for plugins to use.
220 * Core variable pointers can be appended when needed by plugin authors, if appropriate. */
221 typedef struct GeanyData
223 struct GeanyApp *app; /**< Geany application data fields */
224 struct GeanyMainWidgets *main_widgets; /**< Important widgets in the main window */
225 GPtrArray *documents_array; /**< See document.h#documents_array. @elementtype{GeanyDocument} */
226 GPtrArray *filetypes_array; /**< Dynamic array of GeanyFiletype pointers. @elementtype{GeanyFiletype} */
227 struct GeanyPrefs *prefs; /**< General settings */
228 struct GeanyInterfacePrefs *interface_prefs; /**< Interface settings */
229 struct GeanyToolbarPrefs *toolbar_prefs; /**< Toolbar settings */
230 struct GeanyEditorPrefs *editor_prefs; /**< Editor settings */
231 struct GeanyFilePrefs *file_prefs; /**< File-related settings */
232 struct GeanySearchPrefs *search_prefs; /**< Search-related settings */
233 struct GeanyToolPrefs *tool_prefs; /**< Tool settings */
234 struct GeanyTemplatePrefs *template_prefs; /**< Template settings */
235 gpointer *_compat; /* Remove field on next ABI break (abi-todo) */
236 GSList *filetypes_by_title; /**< See filetypes.h#filetypes_by_title. */
238 GeanyData;
240 #define geany geany_data /**< Simple macro for @c geany_data that reduces typing. */
242 typedef struct GeanyPluginFuncs GeanyPluginFuncs;
243 typedef struct GeanyProxyFuncs GeanyProxyFuncs;
245 /** Basic information for the plugin and identification.
246 * @see geany_plugin. */
247 typedef struct GeanyPlugin
249 PluginInfo *info; /**< Fields set in plugin_set_info(). */
250 GeanyData *geany_data; /**< Pointer to global GeanyData intance */
251 GeanyPluginFuncs *funcs; /**< Functions implemented by the plugin, set in geany_load_module() */
252 GeanyProxyFuncs *proxy_funcs; /**< Hooks implemented by the plugin if it wants to act as a proxy
253 Must be set prior to calling geany_plugin_register_proxy() */
254 struct GeanyPluginPrivate *priv; /* private */
256 GeanyPlugin;
258 #ifndef GEANY_PRIVATE
260 /* Prototypes for building plugins with -Wmissing-prototypes
261 * Also allows the compiler to check if the signature of the plugin's
262 * symbol properly matches what we expect. */
263 gint plugin_version_check(gint abi_ver);
264 void plugin_set_info(PluginInfo *info);
266 void plugin_init(GeanyData *data);
267 GtkWidget *plugin_configure(GtkDialog *dialog);
268 void plugin_configure_single(GtkWidget *parent);
269 void plugin_help(void);
270 void plugin_cleanup(void);
272 /** Called by Geany when a plugin library is loaded.
274 * This is the original entry point. Implement and export this function to be loadable at all.
275 * Then fill in GeanyPlugin::info and GeanyPlugin::funcs of the passed @p plugin. Finally
276 * GEANY_PLUGIN_REGISTER() and specify a minimum supported API version.
278 * For all glory details please read @ref howto.
280 * Because the plugin is not yet enabled by the user you may not call plugin API functions inside
281 * this function, except for the API functions below which are required for proper registration.
283 * API functions which are allowed to be called within this function:
284 * - main_locale_init()
285 * - geany_plugin_register() (and GEANY_PLUGIN_REGISTER())
286 * - geany_plugin_register_full() (and GEANY_PLUGIN_REGISTER_FULL())
287 * - plugin_module_make_resident()
289 * @param plugin The unique plugin handle to your plugin. You must set some fields here.
291 * @since 1.26 (API 225)
292 * @see @ref howto
294 void geany_load_module(GeanyPlugin *plugin);
296 #endif
298 /** Callback functions that need to be implemented for every plugin.
300 * These callbacks should be registered by the plugin within Geany's call to
301 * geany_load_module() by calling geany_plugin_register() with an instance of this type.
303 * Geany will then call the callbacks at appropriate times. Each gets passed the
304 * plugin-defined data pointer as well as the corresponding GeanyPlugin instance
305 * pointer.
307 * @since 1.26 (API 225)
308 * @see @ref howto
310 struct GeanyPluginFuncs
312 /** Array of plugin-provided signal handlers @see PluginCallback */
313 PluginCallback *callbacks;
314 /** Called to initialize the plugin, when the user activates it (must not be @c NULL) */
315 gboolean (*init) (GeanyPlugin *plugin, gpointer pdata);
316 /** plugins configure dialog, optional (can be @c NULL) */
317 GtkWidget* (*configure) (GeanyPlugin *plugin, GtkDialog *dialog, gpointer pdata);
318 /** Called when the plugin should show some help, optional (can be @c NULL) */
319 void (*help) (GeanyPlugin *plugin, gpointer pdata);
320 /** Called when the plugin is disabled or when Geany exits (must not be @c NULL) */
321 void (*cleanup) (GeanyPlugin *plugin, gpointer pdata);
324 gboolean geany_plugin_register(GeanyPlugin *plugin, gint api_version,
325 gint min_api_version, gint abi_version);
326 gboolean geany_plugin_register_full(GeanyPlugin *plugin, gint api_version,
327 gint min_api_version, gint abi_version,
328 gpointer data, GDestroyNotify free_func);
329 void geany_plugin_set_data(GeanyPlugin *plugin, gpointer data, GDestroyNotify free_func);
331 /** Convenience macro to register a plugin.
333 * It simply calls geany_plugin_register() with GEANY_API_VERSION and GEANY_ABI_VERSION.
335 * @since 1.26 (API 225)
336 * @see @ref howto
338 #define GEANY_PLUGIN_REGISTER(plugin, min_api_version) \
339 geany_plugin_register((plugin), GEANY_API_VERSION, \
340 (min_api_version), GEANY_ABI_VERSION)
342 /** Convenience macro to register a plugin with data.
344 * It simply calls geany_plugin_register_full() with GEANY_API_VERSION and GEANY_ABI_VERSION.
346 * @since 1.26 (API 225)
347 * @see @ref howto
349 #define GEANY_PLUGIN_REGISTER_FULL(plugin, min_api_version, pdata, free_func) \
350 geany_plugin_register_full((plugin), GEANY_API_VERSION, \
351 (min_api_version), GEANY_ABI_VERSION, (pdata), (free_func))
353 /** Return values for GeanyProxyHooks::probe()
355 * Only @c PROXY_IGNORED, @c PROXY_MATCHED or @c PROXY_MATCHED|PROXY_NOLOAD
356 * are valid return values.
358 * @see geany_plugin_register_proxy() for a full description of the proxy plugin mechanisms.
360 * @since 1.26 (API 226)
362 typedef enum
364 /** The proxy is not responsible at all, and Geany or other plugins are free
365 * to probe it.
367 PROXY_IGNORED,
368 /** The proxy is responsible for this file, and creates a plugin for it */
369 PROXY_MATCHED,
371 /** The proxy is does not directly load it, but it's still tied to the proxy
373 * This is for plugins that come in multiple files where only one of these
374 * files is relevant for the plugin creation (for the PM dialog). The other
375 * files should be ignored by Geany and other proxies. Example: libpeas has
376 * a .plugin and a .so per plugin. Geany should not process the .so file
377 * if there is a corresponding .plugin.
379 PROXY_NOLOAD = 0x100,
381 GeanyProxyProbeResults;
384 /** Hooks that need to be implemented by every proxy
386 * @see geany_plugin_register_proxy() for a full description of the proxy mechanism.
388 * @since 1.26 (API 226)
390 struct GeanyProxyFuncs
392 /** Called to determine whether the proxy is truly responsible for the requested plugin.
393 * A NULL pointer assumes the probe() function would always return @ref PROXY_MATCHED */
394 gint (*probe) (GeanyPlugin *proxy, const gchar *filename, gpointer pdata);
395 /** Called after probe(), to perform the actual job of loading the plugin */
396 gpointer (*load) (GeanyPlugin *proxy, GeanyPlugin *subplugin, const gchar *filename, gpointer pdata);
397 /** Called when the user initiates unloading of a plugin, e.g. on Geany exit */
398 void (*unload) (GeanyPlugin *proxy, GeanyPlugin *subplugin, gpointer load_data, gpointer pdata);
401 gint geany_plugin_register_proxy(GeanyPlugin *plugin, const gchar **extensions);
403 /* Deprecated aliases */
404 #ifndef GEANY_DISABLE_DEPRECATED
406 /* This remains so that older plugins that contain a `GeanyFunctions *geany_functions;`
407 * variable in their plugin - as was previously required - will still compile
408 * without changes. */
409 typedef struct GeanyFunctionsUndefined GeanyFunctions;
411 #define document_reload_file document_reload_force
413 /** @deprecated - copy into your plugin code if needed.
414 * @c NULL-safe way to get the index of @a doc_ptr in the documents array. */
415 #define DOC_IDX(doc_ptr) \
416 (doc_ptr ? doc_ptr->index : -1)
417 #define DOC_IDX_VALID(doc_idx) \
418 ((doc_idx) >= 0 && (guint)(doc_idx) < documents_array->len && documents[doc_idx]->is_valid)
420 #define GEANY_WINDOW_MINIMAL_WIDTH 550
421 #define GEANY_WINDOW_MINIMAL_HEIGHT GEANY_DEFAULT_DIALOG_HEIGHT
423 #endif /* GEANY_DISABLE_DEPRECATED */
425 G_END_DECLS
427 #endif /* GEANY_PLUGIN_DATA_H */