Use pre-compiled 'grep' binary from MSYS2 on Windows
[geany-mirror.git] / src / plugindata.h
blob1413450853e9dae0e0844aea4114ddbcb88e31ee
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 "geany.h" /* for GEANY_DEPRECATED */
36 #include "build.h" /* GeanyBuildGroup, GeanyBuildSource, GeanyBuildCmdEntries enums */
37 #include "document.h" /* GeanyDocument */
38 #include "editor.h" /* GeanyEditor, GeanyIndentType */
39 #include "filetypes.h" /* GeanyFiletype */
41 #include "gtkcompat.h"
43 G_BEGIN_DECLS
45 /* Compatibility for sharing macros between API and core.
46 * First include geany.h, then plugindata.h, then other API headers. */
47 #undef GEANY
48 #define GEANY(symbol_name) geany->symbol_name
51 /** The Application Programming Interface (API) version, incremented
52 * whenever any plugin data types are modified or appended to.
54 * You can protect code that needs a higher API than e.g. 200 with:
55 * @code #if GEANY_API_VERSION >= 200
56 * some_newer_function();
57 * #endif @endcode
59 * @warning You should not test for values below 200 as previously
60 * @c GEANY_API_VERSION was defined as an enum value, not a macro.
62 #define GEANY_API_VERSION 230
64 /* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins
65 * with GTK3-linked Geany leads to crash */
66 #if GTK_CHECK_VERSION(3, 0, 0)
67 # define GEANY_ABI_SHIFT 8
68 #else
69 # define GEANY_ABI_SHIFT 0
70 #endif
71 /** The Application Binary Interface (ABI) version, incremented whenever
72 * existing fields in the plugin data types have to be changed or reordered.
73 * Changing this forces all plugins to be recompiled before Geany can load them. */
74 /* This should usually stay the same if fields are only appended, assuming only pointers to
75 * structs and not structs themselves are declared by plugins. */
76 #define GEANY_ABI_VERSION (71 << GEANY_ABI_SHIFT)
79 /** Defines a function to check the plugin is safe to load.
80 * This performs runtime checks that try to ensure:
81 * - Geany ABI data types are compatible with this plugin.
82 * - Geany sources provide the required API for this plugin.
83 * @param api_required The minimum API number your plugin requires.
84 * Look at the source for the value of @c GEANY_API_VERSION to use if you
85 * want your plugin to require the current Geany version on your machine.
86 * You should update this value when using any new API features. */
87 #define PLUGIN_VERSION_CHECK(api_required) \
88 gint plugin_version_check(gint abi_ver) \
89 { \
90 if (abi_ver != GEANY_ABI_VERSION) \
91 return -1; \
92 return (api_required); \
96 /** Basic information about a plugin available to Geany without loading the plugin.
97 * The fields are set in plugin_set_info(), usually with the PLUGIN_SET_INFO() macro. */
98 typedef struct PluginInfo
100 /** The name of the plugin. */
101 const gchar *name;
102 /** The description of the plugin. */
103 const gchar *description;
104 /** The version of the plugin. */
105 const gchar *version;
106 /** The author of the plugin. */
107 const gchar *author;
109 PluginInfo;
112 /** Sets the plugin name and some other basic information about a plugin.
114 * @note If you want some of the arguments to be translated, see @ref PLUGIN_SET_TRANSLATABLE_INFO()
116 * Example:
117 * @code PLUGIN_SET_INFO("Cool Feature", "Adds cool feature support.", "0.1", "Joe Author") @endcode */
118 /* plugin_set_info() could be written manually for plugins if we want to add any
119 * extra PluginInfo features (such as an icon), so we don't need to break API
120 * compatibility. Alternatively just add a new macro, PLUGIN_SET_INFO_FULL(). -ntrel */
121 #define PLUGIN_SET_INFO(p_name, p_description, p_version, p_author) \
122 void plugin_set_info(PluginInfo *info) \
124 info->name = (p_name); \
125 info->description = (p_description); \
126 info->version = (p_version); \
127 info->author = (p_author); \
130 /** Sets the plugin name and some other basic information about a plugin.
131 * This macro is like @ref PLUGIN_SET_INFO() but allows the passed information to be translated
132 * by setting up the translation mechanism with @ref main_locale_init().
133 * You therefore don't need to call it manually in plugin_init().
135 * Example:
136 * @code PLUGIN_SET_TRANSLATABLE_INFO(LOCALEDIR, GETTEXT_PACKAGE, _("Cool Feature"), _("Adds a cool feature."), "0.1", "John Doe") @endcode
138 * @since 0.19 */
139 #define PLUGIN_SET_TRANSLATABLE_INFO(localedir, package, p_name, p_description, p_version, p_author) \
140 void plugin_set_info(PluginInfo *info) \
142 main_locale_init((localedir), (package)); \
143 info->name = (p_name); \
144 info->description = (p_description); \
145 info->version = (p_version); \
146 info->author = (p_author); \
150 /** Callback array entry type used with the @ref plugin_callbacks symbol. */
151 typedef struct PluginCallback
153 /** The name of signal, must be an existing signal. For a list of available signals,
154 * please see the @link pluginsignals.c Signal documentation @endlink. */
155 const gchar *signal_name;
156 /** A callback function which is called when the signal is emitted. */
157 GCallback callback;
158 /** Set to TRUE to connect your handler with g_signal_connect_after(). */
159 gboolean after;
160 /** The user data passed to the signal handler. If set to NULL then the signal
161 * handler will receive the data set with geany_plugin_register_full() or
162 * geany_plugin_set_data() */
163 gpointer user_data;
165 PluginCallback;
168 /** This contains pointers to global variables owned by Geany for plugins to use.
169 * Core variable pointers can be appended when needed by plugin authors, if appropriate. */
170 typedef struct GeanyData
172 struct GeanyApp *app; /**< Geany application data fields */
173 struct GeanyMainWidgets *main_widgets; /**< Important widgets in the main window */
174 /** Dynamic array of GeanyDocument pointers.
175 * Once a pointer is added to this, it is never freed. This means the same document pointer
176 * can represent a different document later on, or it may have been closed and become invalid.
177 * For this reason, you should use document_find_by_id() instead of storing
178 * document pointers over time if there is a chance the user can close the
179 * document.
181 * @warning You must check @c GeanyDocument::is_valid when iterating over this array.
182 * This is done automatically if you use the foreach_document() macro.
184 * @note
185 * Never assume that the order of document pointers is the same as the order of notebook tabs.
186 * One reason is that notebook tabs can be reordered.
187 * Use @c document_get_from_page() to lookup a document from a notebook tab number.
189 * @see documents.
191 * @elementtype{GeanyDocument}
193 GPtrArray *documents_array;
194 /** Dynamic array of filetype pointers
196 * List the list is dynamically expanded for custom filetypes filetypes so don't expect
197 * the list of known filetypes to be a constant.
199 * @elementtype{GeanyFiletype}
201 GPtrArray *filetypes_array;
202 struct GeanyPrefs *prefs; /**< General settings */
203 struct GeanyInterfacePrefs *interface_prefs; /**< Interface settings */
204 struct GeanyToolbarPrefs *toolbar_prefs; /**< Toolbar settings */
205 struct GeanyEditorPrefs *editor_prefs; /**< Editor settings */
206 struct GeanyFilePrefs *file_prefs; /**< File-related settings */
207 struct GeanySearchPrefs *search_prefs; /**< Search-related settings */
208 struct GeanyToolPrefs *tool_prefs; /**< Tool settings */
209 struct GeanyTemplatePrefs *template_prefs; /**< Template settings */
210 gpointer *_compat; /* Remove field on next ABI break (abi-todo) */
211 /** List of filetype pointers sorted by name, but with @c filetypes_index(GEANY_FILETYPES_NONE)
212 * first, as this is usually treated specially.
213 * The list does not change (after filetypes have been initialized), so you can use
214 * @code g_slist_nth_data(filetypes_by_title, n) @endcode and expect the same result at different times.
215 * @see filetypes_get_sorted_by_name().
217 * @elementtype{GeanyFiletype}
219 GSList *filetypes_by_title;
220 /** @gironly
221 * Global object signalling events via signals
223 * This is mostly for language bindings. Otherwise prefer to use
224 * plugin_signal_connect() instead this which adds automatic cleanup. */
225 GObject *object;
227 GeanyData;
229 #define geany geany_data /**< Simple macro for @c geany_data that reduces typing. */
231 typedef struct GeanyPluginFuncs GeanyPluginFuncs;
232 typedef struct GeanyProxyFuncs GeanyProxyFuncs;
234 /** Basic information for the plugin and identification.
235 * @see geany_plugin. */
236 typedef struct GeanyPlugin
238 PluginInfo *info; /**< Fields set in plugin_set_info(). */
239 GeanyData *geany_data; /**< Pointer to global GeanyData intance */
240 GeanyPluginFuncs *funcs; /**< Functions implemented by the plugin, set in geany_load_module() */
241 GeanyProxyFuncs *proxy_funcs; /**< Hooks implemented by the plugin if it wants to act as a proxy
242 Must be set prior to calling geany_plugin_register_proxy() */
243 struct GeanyPluginPrivate *priv; /* private */
245 GeanyPlugin;
247 #ifndef GEANY_PRIVATE
249 /* Prototypes for building plugins with -Wmissing-prototypes
250 * Also allows the compiler to check if the signature of the plugin's
251 * symbol properly matches what we expect. */
252 gint plugin_version_check(gint abi_ver);
253 void plugin_set_info(PluginInfo *info);
255 void plugin_init(GeanyData *data);
256 GtkWidget *plugin_configure(GtkDialog *dialog);
257 void plugin_configure_single(GtkWidget *parent);
258 void plugin_help(void);
259 void plugin_cleanup(void);
261 /** Called by Geany when a plugin library is loaded.
263 * This is the original entry point. Implement and export this function to be loadable at all.
264 * Then fill in GeanyPlugin::info and GeanyPlugin::funcs of the passed @p plugin. Finally
265 * GEANY_PLUGIN_REGISTER() and specify a minimum supported API version.
267 * For all glory details please read @ref howto.
269 * Because the plugin is not yet enabled by the user you may not call plugin API functions inside
270 * this function, except for the API functions below which are required for proper registration.
272 * API functions which are allowed to be called within this function:
273 * - main_locale_init()
274 * - geany_plugin_register() (and GEANY_PLUGIN_REGISTER())
275 * - geany_plugin_register_full() (and GEANY_PLUGIN_REGISTER_FULL())
276 * - plugin_module_make_resident()
278 * @param plugin The unique plugin handle to your plugin. You must set some fields here.
280 * @since 1.26 (API 225)
281 * @see @ref howto
283 void geany_load_module(GeanyPlugin *plugin);
285 #endif
287 /** Callback functions that need to be implemented for every plugin.
289 * These callbacks should be registered by the plugin within Geany's call to
290 * geany_load_module() by calling geany_plugin_register() with an instance of this type.
292 * Geany will then call the callbacks at appropriate times. Each gets passed the
293 * plugin-defined data pointer as well as the corresponding GeanyPlugin instance
294 * pointer.
296 * @since 1.26 (API 225)
297 * @see @ref howto
299 struct GeanyPluginFuncs
301 /** Array of plugin-provided signal handlers @see PluginCallback */
302 PluginCallback *callbacks;
303 /** Called to initialize the plugin, when the user activates it (must not be @c NULL) */
304 gboolean (*init) (GeanyPlugin *plugin, gpointer pdata);
305 /** plugins configure dialog, optional (can be @c NULL) */
306 GtkWidget* (*configure) (GeanyPlugin *plugin, GtkDialog *dialog, gpointer pdata);
307 /** Called when the plugin should show some help, optional (can be @c NULL) */
308 void (*help) (GeanyPlugin *plugin, gpointer pdata);
309 /** Called when the plugin is disabled or when Geany exits (must not be @c NULL) */
310 void (*cleanup) (GeanyPlugin *plugin, gpointer pdata);
313 gboolean geany_plugin_register(GeanyPlugin *plugin, gint api_version,
314 gint min_api_version, gint abi_version);
315 gboolean geany_plugin_register_full(GeanyPlugin *plugin, gint api_version,
316 gint min_api_version, gint abi_version,
317 gpointer data, GDestroyNotify free_func);
318 void geany_plugin_set_data(GeanyPlugin *plugin, gpointer data, GDestroyNotify free_func);
320 /** Convenience macro to register a plugin.
322 * It simply calls geany_plugin_register() with GEANY_API_VERSION and GEANY_ABI_VERSION.
324 * @since 1.26 (API 225)
325 * @see @ref howto
327 #define GEANY_PLUGIN_REGISTER(plugin, min_api_version) \
328 geany_plugin_register((plugin), GEANY_API_VERSION, \
329 (min_api_version), GEANY_ABI_VERSION)
331 /** Convenience macro to register a plugin with data.
333 * It simply calls geany_plugin_register_full() with GEANY_API_VERSION and GEANY_ABI_VERSION.
335 * @since 1.26 (API 225)
336 * @see @ref howto
338 #define GEANY_PLUGIN_REGISTER_FULL(plugin, min_api_version, pdata, free_func) \
339 geany_plugin_register_full((plugin), GEANY_API_VERSION, \
340 (min_api_version), GEANY_ABI_VERSION, (pdata), (free_func))
342 /** Return values for GeanyProxyHooks::probe()
344 * @see geany_plugin_register_proxy() for a full description of the proxy plugin mechanisms.
346 typedef enum
348 /** @deprecated Use GEANY_PROXY_IGNORE instead.
349 * @since 1.26 (API 226)
351 PROXY_IGNORED,
352 /** @deprecated Use GEANY_PROXY_MATCH instead.
353 * @since 1.26 (API 226)
355 PROXY_MATCHED,
356 /** @deprecated Use GEANY_PROXY_RELATED instead.
357 * @since 1.26 (API 226)
359 PROXY_NOLOAD = 0x100,
360 /** The proxy is not responsible at all, and Geany or other plugins are free
361 * to probe it.
363 * @since 1.29 (API 229)
365 GEANY_PROXY_IGNORE = PROXY_IGNORED,
366 /** The proxy is responsible for this file, and creates a plugin for it.
368 * @since 1.29 (API 229)
370 GEANY_PROXY_MATCH = 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 * @since 1.29 (API 229)
381 GEANY_PROXY_RELATED = PROXY_MATCHED | PROXY_NOLOAD
383 GeanyProxyProbeResults;
386 /** Hooks that need to be implemented by every proxy
388 * @see geany_plugin_register_proxy() for a full description of the proxy mechanism.
390 * @since 1.26 (API 226)
392 struct GeanyProxyFuncs
394 /** Called to determine whether the proxy is truly responsible for the requested plugin.
395 * A NULL pointer assumes the probe() function would always return @ref GEANY_PROXY_MATCH */
396 gint (*probe) (GeanyPlugin *proxy, const gchar *filename, gpointer pdata);
397 /** Called after probe(), to perform the actual job of loading the plugin */
398 gpointer (*load) (GeanyPlugin *proxy, GeanyPlugin *subplugin, const gchar *filename, gpointer pdata);
399 /** Called when the user initiates unloading of a plugin, e.g. on Geany exit */
400 void (*unload) (GeanyPlugin *proxy, GeanyPlugin *subplugin, gpointer load_data, gpointer pdata);
403 gint geany_plugin_register_proxy(GeanyPlugin *plugin, const gchar **extensions);
405 /* Deprecated aliases */
406 #ifndef GEANY_DISABLE_DEPRECATED
408 /* This remains so that older plugins that contain a `GeanyFunctions *geany_functions;`
409 * variable in their plugin - as was previously required - will still compile
410 * without changes. */
411 typedef struct GeanyFunctionsUndefined GeanyFunctions GEANY_DEPRECATED;
413 /** @deprecated - use plugin_set_key_group() instead.
414 * @see PLUGIN_KEY_GROUP() macro. */
415 typedef struct GeanyKeyGroupInfo
417 const gchar *name; /**< Group name used in the configuration file, such as @c "html_chars" */
418 gsize count; /**< The number of keybindings the group will hold */
420 GeanyKeyGroupInfo GEANY_DEPRECATED_FOR(plugin_set_key_group);
422 /** @deprecated - use plugin_set_key_group() instead.
423 * Declare and initialise a keybinding group.
424 * @code GeanyKeyGroup *plugin_key_group; @endcode
425 * You must then set the @c plugin_key_group::keys[] entries for the group in plugin_init(),
426 * normally using keybindings_set_item().
427 * The @c plugin_key_group::label field is set by Geany after @c plugin_init()
428 * is called, to the name of the plugin.
429 * @param group_name A unique group name (without quotes) to be used in the
430 * configuration file, such as @c html_chars.
431 * @param key_count The number of keybindings the group will hold. */
432 #define PLUGIN_KEY_GROUP(group_name, key_count) \
433 /* We have to declare this as a single element array.
434 * Declaring as a pointer to a struct doesn't work with g_module_symbol(). */ \
435 GeanyKeyGroupInfo plugin_key_group_info[1] = \
437 {G_STRINGIFY(group_name), key_count} \
439 GeanyKeyGroup *plugin_key_group = NULL;
441 /** @deprecated Use @ref ui_add_document_sensitive() instead.
442 * Flags to be set by plugins in PluginFields struct. */
443 typedef enum
445 /** Whether a plugin's menu item should be disabled when there are no open documents */
446 PLUGIN_IS_DOCUMENT_SENSITIVE = 1 << 0
448 PluginFlags;
450 /** @deprecated Use @ref ui_add_document_sensitive() instead.
451 * Fields set and owned by the plugin. */
452 typedef struct PluginFields
454 /** Bitmask of @c PluginFlags. */
455 PluginFlags flags;
456 /** Pointer to a plugin's menu item which will be automatically enabled/disabled when there
457 * are no open documents and @c PLUGIN_IS_DOCUMENT_SENSITIVE is set.
458 * This is required if using @c PLUGIN_IS_DOCUMENT_SENSITIVE, ignored otherwise */
459 GtkWidget *menu_item;
461 PluginFields GEANY_DEPRECATED_FOR(ui_add_document_sensitive);
463 #define document_reload_file document_reload_force
465 /** @deprecated - copy into your plugin code if needed.
466 * @c NULL-safe way to get the index of @a doc_ptr in the documents array. */
467 #define DOC_IDX(doc_ptr) \
468 (doc_ptr ? doc_ptr->index : -1)
469 #define DOC_IDX_VALID(doc_idx) \
470 ((doc_idx) >= 0 && (guint)(doc_idx) < documents_array->len && documents[doc_idx]->is_valid)
472 #define GEANY_WINDOW_MINIMAL_WIDTH 550
473 #define GEANY_WINDOW_MINIMAL_HEIGHT GEANY_DEFAULT_DIALOG_HEIGHT
475 #endif /* GEANY_DISABLE_DEPRECATED */
477 G_END_DECLS
479 #endif /* GEANY_PLUGIN_DATA_H */