* data/default.proflie, data/Makefile.am, src/anjuta.c,
[anjuta-git-plugin.git] / libanjuta / anjuta-plugin.h
blob7d836b9742d0285d457d8a2a023ef61df3c7b883
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * Anjuta
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #ifndef ANJUTA_PLUGIN_H
23 #define ANJUTA_PLUGIN_H
25 #include <glib.h>
26 #include <glib-object.h>
28 #include <string.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>
33 #include <libanjuta/glue-plugin.h>
35 G_BEGIN_DECLS
37 typedef struct _AnjutaPlugin AnjutaPlugin;
38 typedef struct _AnjutaPluginClass AnjutaPluginClass;
39 typedef struct _AnjutaPluginPrivate AnjutaPluginPrivate;
41 /**
42 * AnjutaPluginValueAdded:
43 * @plugin: The #AnjutaPlugin based plugin
44 * @name: name of value being added.
45 * @value: value of value being added.
46 * @user_data: User data set during anjuta_plugin_add_watch()
48 * The callback to pass to anjuta_plugin_add_watch(). When a @name value
49 * is added to shell by another plugin, this callback will be called.
51 typedef void (*AnjutaPluginValueAdded) (AnjutaPlugin *plugin,
52 const char *name,
53 const GValue *value,
54 gpointer user_data);
56 /**
57 * AnjutaPluginValueRemoved:
58 * @plugin: The #AnjutaPlugin based plugin
59 * @name: name of value being added.
60 * @user_data: User data set during anjuta_plugin_add_watch()
62 * The callback to pass to anjuta_plugin_add_watch(). When the @name value
63 * is removed from the shell (by the plugin exporting this value), this
64 * callback will be called.
66 typedef void (*AnjutaPluginValueRemoved) (AnjutaPlugin *plugin,
67 const char *name,
68 gpointer user_data);
71 #define ANJUTA_TYPE_PLUGIN (anjuta_plugin_get_type ())
72 #define ANJUTA_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ANJUTA_TYPE_PLUGIN, AnjutaPlugin))
73 #define ANJUTA_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), ANJUTA_TYPE_PLUGIN, AnjutaPluginClass))
74 #define ANJUTA_IS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ANJUTA_TYPE_PLUGIN))
75 #define ANJUTA_IS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_PLUGIN))
76 #define ANJUTA_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ANJUTA_TYPE_PLUGIN, AnjutaPluginClass))
78 struct _AnjutaPlugin {
79 GObject parent;
81 /* The shell in which the plugin has been added */
82 AnjutaShell *shell;
84 /*< private >*/
85 AnjutaPluginPrivate *priv;
88 struct _AnjutaPluginClass {
89 GObjectClass parent_class;
91 /* Signals */
92 void (*activated) (AnjutaPlugin *plugin);
93 void (*deactivated) (AnjutaPlugin *plugin);
95 /* Virtual functions */
96 gboolean (*activate) (AnjutaPlugin *plugin);
97 gboolean (*deactivate) (AnjutaPlugin *plugin);
100 GType anjuta_plugin_get_type (void);
102 gboolean anjuta_plugin_activate (AnjutaPlugin *plugin);
104 gboolean anjuta_plugin_deactivate (AnjutaPlugin *plugin);
106 gboolean anjuta_plugin_is_active (AnjutaPlugin *plugin);
108 guint anjuta_plugin_add_watch (AnjutaPlugin *plugin,
109 const gchar *name,
110 AnjutaPluginValueAdded added,
111 AnjutaPluginValueRemoved removed,
112 gpointer user_data);
114 void anjuta_plugin_remove_watch (AnjutaPlugin *plugin, guint id,
115 gboolean send_remove);
118 * ANJUTA_PLUGIN_BEGIN:
119 * @class_name: Name of the class. e.g. EditorPlugin
120 * @prefix: prefix of member function names. e.g. editor_plugin
122 * This is a convienient macro defined to make it easy to write plugin
123 * classes . This macro begins the class type definition. member function
124 * @prefix _class_init and @prefix _instance_init should be statically defined
125 * before using this macro.
127 * The class type definition is finished with ANJUTA_PLUGIN_END() macro. In
128 * between which any number of interface definitions could be added with
129 * ANJUTA_PLUGIN_ADD_INTERFACE() macro.
131 #define ANJUTA_PLUGIN_BEGIN(class_name, prefix) \
132 extern GType \
133 prefix##_get_type (GluePlugin *plugin) \
135 static GType type = 0; \
136 if (G_UNLIKELY (!type)) { \
137 static const GTypeInfo type_info = { \
138 sizeof (class_name##Class), \
139 NULL, \
140 NULL, \
141 (GClassInitFunc)prefix##_class_init, \
142 NULL, \
143 NULL, \
144 sizeof (class_name), \
145 0, \
146 (GInstanceInitFunc)prefix##_instance_init \
147 }; \
148 g_return_val_if_fail (plugin != NULL, 0); \
149 type = g_type_module_register_type (G_TYPE_MODULE (plugin), \
150 ANJUTA_TYPE_PLUGIN, \
151 #class_name, \
152 &type_info, 0);
154 * ANJUTA_PLUGIN_END:
156 * Ends the plugin class type definition started with ANJUTA_PLUGIN_BEGIN()
158 #define ANJUTA_PLUGIN_END \
160 return type; \
164 * ANJUTA_PLUGIN_ADD_INTERFACE:
165 * @interface_type: Interface type. e.g. IANJUTA_TYPE_EDITOR
166 * @prefix: prefix of member function names.
168 * This is a convienient macro defined to make it easy to add interfaces
169 * to a plugin type. @prefix _iface_init should be statically defined
170 * before using this macro. This macro should be called between
171 * ANJUTA_PLUGIN_BEGIN() and ANJUTA_PLUGIN_END() macros.
173 #define ANJUTA_PLUGIN_ADD_INTERFACE(prefix,interface_type) \
175 GInterfaceInfo iface_info = { \
176 (GInterfaceInitFunc)prefix##_iface_init, \
177 NULL, \
178 NULL \
179 }; \
180 g_type_module_add_interface (G_TYPE_MODULE (plugin), \
181 type, interface_type, \
182 &iface_info); \
186 * ANJUTA_PLUGIN_BOILERPLATE:
187 * @class_name: Name of the class. e.g EditorPlugin
188 * @prefix: prefix of member function names. e.g. editor_plugin
190 * This macro is similar to using ANJUTA_PLUGIN_BEGIN() and then immediately
191 * using ANJUTA_PLUGIN_END(). It is basically a plugin type definition macro
192 * that does not have any interface implementation.
194 #define ANJUTA_PLUGIN_BOILERPLATE(class_name, prefix) \
195 ANJUTA_PLUGIN_BEGIN(class_name, prefix); \
196 ANJUTA_PLUGIN_END
199 * ANJUTA_SIMPLE_PLUGIN:
200 * @class_name: Name of the class. e.g. EditorPlugin
201 * @prefix: prefix of member function names. e.g. editor_plugin
203 * Sets up necessary codes for the plugin factory to know the class type of
204 * of the plugin. This macro is generally used at the end of plugin class
205 * and member functions definitions.
207 #define ANJUTA_SIMPLE_PLUGIN(class_name, prefix) \
208 G_MODULE_EXPORT void glue_register_components (GluePlugin *plugin); \
209 G_MODULE_EXPORT GType glue_get_component_type (GluePlugin *plugin, const char *name); \
210 G_MODULE_EXPORT void \
211 glue_register_components (GluePlugin *plugin) \
213 prefix##_get_type (plugin); \
215 G_MODULE_EXPORT GType \
216 glue_get_component_type (GluePlugin *plugin, const char *name) \
218 if (!strcmp (name, #class_name)) { \
219 return prefix##_get_type (plugin); \
220 } else { \
221 return G_TYPE_INVALID; \
225 G_END_DECLS
227 #endif