1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) 2000 Dave Camp, Naba Kumar <naba@gnome.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #ifndef ANJUTA_PLUGIN_H
23 #define ANJUTA_PLUGIN_H
26 #include <glib-object.h>
29 #include <libanjuta/anjuta-shell.h>
30 #include <libanjuta/anjuta-ui.h>
31 #include <libanjuta/anjuta-preferences.h>
32 #include <libanjuta/anjuta-utils.h>
36 /* Add this alias in case some plugin outside Anjuta tree still uses it */
37 typedef GTypeModule AnjutaGluePlugin
;
39 typedef struct _AnjutaPlugin AnjutaPlugin
;
40 typedef struct _AnjutaPluginClass AnjutaPluginClass
;
41 typedef struct _AnjutaPluginPrivate AnjutaPluginPrivate
;
44 * AnjutaPluginValueAdded:
45 * @plugin: The #AnjutaPlugin based plugin
46 * @name: name of value being added.
47 * @value: value of value being added.
48 * @user_data: User data set during anjuta_plugin_add_watch()
50 * The callback to pass to anjuta_plugin_add_watch(). When a @name value
51 * is added to shell by another plugin, this callback will be called.
53 typedef void (*AnjutaPluginValueAdded
) (AnjutaPlugin
*plugin
,
59 * AnjutaPluginValueRemoved:
60 * @plugin: The #AnjutaPlugin based plugin
61 * @name: name of value being added.
62 * @user_data: User data set during anjuta_plugin_add_watch()
64 * The callback to pass to anjuta_plugin_add_watch(). When the @name value
65 * is removed from the shell (by the plugin exporting this value), this
66 * callback will be called.
68 typedef void (*AnjutaPluginValueRemoved
) (AnjutaPlugin
*plugin
,
73 #define ANJUTA_TYPE_PLUGIN (anjuta_plugin_get_type ())
74 #define ANJUTA_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ANJUTA_TYPE_PLUGIN, AnjutaPlugin))
75 #define ANJUTA_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), ANJUTA_TYPE_PLUGIN, AnjutaPluginClass))
76 #define ANJUTA_IS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ANJUTA_TYPE_PLUGIN))
77 #define ANJUTA_IS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_PLUGIN))
78 #define ANJUTA_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ANJUTA_TYPE_PLUGIN, AnjutaPluginClass))
80 struct _AnjutaPlugin
{
83 /* The shell in which the plugin has been added */
87 AnjutaPluginPrivate
*priv
;
90 struct _AnjutaPluginClass
{
91 GObjectClass parent_class
;
94 void (*activated
) (AnjutaPlugin
*plugin
);
95 void (*deactivated
) (AnjutaPlugin
*plugin
);
97 /* Virtual functions */
98 gboolean (*activate
) (AnjutaPlugin
*plugin
);
99 gboolean (*deactivate
) (AnjutaPlugin
*plugin
);
102 GType
anjuta_plugin_get_type (void);
104 gboolean
anjuta_plugin_activate (AnjutaPlugin
*plugin
);
106 gboolean
anjuta_plugin_deactivate (AnjutaPlugin
*plugin
);
108 gboolean
anjuta_plugin_is_active (AnjutaPlugin
*plugin
);
110 guint
anjuta_plugin_add_watch (AnjutaPlugin
*plugin
,
112 AnjutaPluginValueAdded added
,
113 AnjutaPluginValueRemoved removed
,
116 void anjuta_plugin_remove_watch (AnjutaPlugin
*plugin
, guint id
,
117 gboolean send_remove
);
119 AnjutaShell
*anjuta_plugin_get_shell (AnjutaPlugin
* plugin
);
122 * ANJUTA_PLUGIN_BEGIN:
123 * @class_name: Name of the class. e.g. EditorPlugin
124 * @prefix: prefix of member function names. e.g. editor_plugin
126 * This is a convienient macro defined to make it easy to write plugin
127 * classes . This macro begins the class type definition. member function
128 * @prefix _class_init and @prefix _instance_init should be statically defined
129 * before using this macro.
131 * The class type definition is finished with ANJUTA_PLUGIN_END() macro. In
132 * between which any number of interface definitions could be added with
133 * ANJUTA_PLUGIN_ADD_INTERFACE() macro.
135 #define ANJUTA_PLUGIN_BEGIN(class_name, prefix) \
137 prefix##_get_type (GTypeModule *module) \
139 static GType type = 0; \
140 if (G_UNLIKELY (!type)) { \
141 static const GTypeInfo type_info = { \
142 sizeof (class_name##Class), \
145 (GClassInitFunc)prefix##_class_init, \
148 sizeof (class_name), \
150 (GInstanceInitFunc)prefix##_instance_init \
152 g_return_val_if_fail (module != NULL, 0); \
153 type = g_type_module_register_type (module, \
154 ANJUTA_TYPE_PLUGIN, \
160 * Ends the plugin class type definition started with ANJUTA_PLUGIN_BEGIN()
162 #define ANJUTA_PLUGIN_END \
168 * ANJUTA_PLUGIN_ADD_INTERFACE:
169 * @interface_type: Interface type. e.g. IANJUTA_TYPE_EDITOR
170 * @prefix: prefix of member function names.
172 * This is a convienient macro defined to make it easy to add interfaces
173 * to a plugin type. @prefix _iface_init should be statically defined
174 * before using this macro. This macro should be called between
175 * ANJUTA_PLUGIN_BEGIN() and ANJUTA_PLUGIN_END() macros.
177 #define ANJUTA_PLUGIN_ADD_INTERFACE(prefix,interface_type) \
179 GInterfaceInfo iface_info = { \
180 (GInterfaceInitFunc)prefix##_iface_init, \
184 g_type_module_add_interface (module, \
185 type, interface_type, \
190 * ANJUTA_PLUGIN_BOILERPLATE:
191 * @class_name: Name of the class. e.g EditorPlugin
192 * @prefix: prefix of member function names. e.g. editor_plugin
194 * This macro is similar to using ANJUTA_PLUGIN_BEGIN() and then immediately
195 * using ANJUTA_PLUGIN_END(). It is basically a plugin type definition macro
196 * that does not have any interface implementation.
198 #define ANJUTA_PLUGIN_BOILERPLATE(class_name, prefix) \
199 ANJUTA_PLUGIN_BEGIN(class_name, prefix); \
203 * ANJUTA_SIMPLE_PLUGIN:
204 * @class_name: Name of the class. e.g. EditorPlugin
205 * @prefix: prefix of member function names. e.g. editor_plugin
207 * Sets up necessary codes for the plugin factory to know the class type of
208 * of the plugin. This macro is generally used at the end of plugin class
209 * and member functions definitions.
211 #define ANJUTA_SIMPLE_PLUGIN(class_name, prefix) \
212 G_MODULE_EXPORT void anjuta_glue_register_components (GTypeModule *module); \
213 G_MODULE_EXPORT void \
214 anjuta_glue_register_components (GTypeModule *module) \
216 prefix##_get_type (module); \