info bars: Explicitely move focus back to the editor when closing
[geany-mirror.git] / src / geanyobject.c
blobd523b4e1648dd69ddcfb91f0112fa83e948fccc1
1 /*
2 * geanyobject.c - 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 /* A GObject used for connecting and emitting signals when certain events happen,
23 * e.g. opening a document.
24 * Mainly used for plugins - see the API docs.
26 * Core-only signals:
28 * signal void save_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
29 * Emitted just before saving main keyfile settings.
31 * signal void load_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
32 * Emitted just after loading main keyfile settings.
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
39 #include "geanyobject.h"
41 /* extern in geany.h */
42 GObject *geany_object;
44 static guint geany_object_signals[GCB_MAX] = { 0 };
47 typedef struct _GeanyObjectPrivate GeanyObjectPrivate;
49 struct _GeanyObjectPrivate
51 /* to avoid warnings (g_type_class_add_private: assertion `private_size > 0' failed) */
52 gchar dummy;
56 G_DEFINE_TYPE(GeanyObject, geany_object, G_TYPE_OBJECT)
60 static void geany_cclosure_marshal_VOID__STRING_INT_POINTER(GClosure *closure, GValue *ret_val,
61 guint n_param_vals, const GValue *param_values, gpointer hint, gpointer mdata)
63 typedef gboolean (*GeanyMarshalFunc_VOID__STRING_INT_POINTER)
64 (gpointer data1, gconstpointer arg_1, gint arg_2, gpointer arg_3, gpointer data2);
66 register GeanyMarshalFunc_VOID__STRING_INT_POINTER callback;
67 register GCClosure* cc = (GCClosure*) closure;
68 register gpointer data1, data2;
70 g_return_if_fail(n_param_vals == 4);
72 if (G_CCLOSURE_SWAP_DATA(closure))
74 data1 = closure->data;
75 data2 = g_value_peek_pointer(param_values + 0);
77 else
79 data1 = g_value_peek_pointer(param_values + 0);
80 data2 = closure->data;
82 callback = (GeanyMarshalFunc_VOID__STRING_INT_POINTER) (mdata ? mdata : cc->callback);
83 callback(data1,
84 g_value_get_string(param_values + 1),
85 g_value_get_int(param_values + 2),
86 g_value_get_pointer(param_values + 3),
87 data2);
91 static void geany_cclosure_marshal_VOID__POINTER_POINTER(GClosure *closure, GValue *ret_val,
92 guint n_param_vals, const GValue *param_values, gpointer hint, gpointer mdata)
94 typedef gboolean (*GeanyMarshalFunc_VOID__POINTER_POINTER)
95 (gpointer data1, gconstpointer arg_1, gconstpointer arg_2, gpointer data2);
97 register GeanyMarshalFunc_VOID__POINTER_POINTER callback;
98 register GCClosure* cc = (GCClosure*) closure;
99 register gpointer data1, data2;
101 g_return_if_fail(n_param_vals == 3);
103 if (G_CCLOSURE_SWAP_DATA(closure))
105 data1 = closure->data;
106 data2 = g_value_peek_pointer(param_values + 0);
108 else
110 data1 = g_value_peek_pointer(param_values + 0);
111 data2 = closure->data;
113 callback = (GeanyMarshalFunc_VOID__POINTER_POINTER) (mdata ? mdata : cc->callback);
114 callback(data1,
115 g_value_get_pointer(param_values + 1),
116 g_value_get_pointer(param_values + 2),
117 data2);
121 static gboolean boolean_handled_accumulator(GSignalInvocationHint *ihint, GValue *return_accu,
122 const GValue *handler_return, gpointer dummy)
124 gboolean continue_emission, signal_handled;
126 signal_handled = g_value_get_boolean(handler_return);
127 g_value_set_boolean(return_accu, signal_handled);
128 continue_emission = !signal_handled;
130 return continue_emission;
134 static void geany_cclosure_marshal_BOOL__POINTER_POINTER(GClosure *closure, GValue *return_value,
135 guint n_param_values, const GValue *param_values,
136 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
138 typedef gboolean (*GeanyMarshalFunc_BOOLEAN__POINTER_POINTER)
139 (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
141 register GeanyMarshalFunc_BOOLEAN__POINTER_POINTER callback;
142 register GCClosure *cc = (GCClosure*) closure;
143 register gpointer data1, data2;
144 gboolean v_return;
146 g_return_if_fail(return_value != NULL);
147 g_return_if_fail(n_param_values == 3);
149 if (G_CCLOSURE_SWAP_DATA(closure))
151 data1 = closure->data;
152 data2 = g_value_peek_pointer(param_values + 0);
154 else
156 data1 = g_value_peek_pointer(param_values + 0);
157 data2 = closure->data;
159 callback = (GeanyMarshalFunc_BOOLEAN__POINTER_POINTER)
160 (marshal_data ? marshal_data : cc->callback);
162 v_return = callback(data1,
163 g_value_get_pointer(param_values + 1),
164 g_value_get_pointer(param_values + 2),
165 data2);
167 g_value_set_boolean(return_value, v_return);
171 static void create_signals(GObjectClass *g_object_class)
173 /* Document signals */
174 geany_object_signals[GCB_DOCUMENT_NEW] = g_signal_new (
175 "document-new",
176 G_OBJECT_CLASS_TYPE (g_object_class),
177 G_SIGNAL_RUN_FIRST,
178 G_STRUCT_OFFSET (GeanyObjectClass, document_new),
179 NULL, NULL,
180 g_cclosure_marshal_VOID__POINTER,
181 G_TYPE_NONE, 1,
182 G_TYPE_POINTER);
183 geany_object_signals[GCB_DOCUMENT_OPEN] = g_signal_new (
184 "document-open",
185 G_OBJECT_CLASS_TYPE (g_object_class),
186 G_SIGNAL_RUN_FIRST,
187 G_STRUCT_OFFSET (GeanyObjectClass, document_open),
188 NULL, NULL,
189 g_cclosure_marshal_VOID__POINTER,
190 G_TYPE_NONE, 1,
191 G_TYPE_POINTER);
192 geany_object_signals[GCB_DOCUMENT_RELOAD] = g_signal_new (
193 "document-reload",
194 G_OBJECT_CLASS_TYPE (g_object_class),
195 G_SIGNAL_RUN_FIRST,
196 G_STRUCT_OFFSET (GeanyObjectClass, document_reload),
197 NULL, NULL,
198 g_cclosure_marshal_VOID__POINTER,
199 G_TYPE_NONE, 1,
200 G_TYPE_POINTER);
201 geany_object_signals[GCB_DOCUMENT_BEFORE_SAVE] = g_signal_new (
202 "document-before-save",
203 G_OBJECT_CLASS_TYPE (g_object_class),
204 G_SIGNAL_RUN_FIRST,
205 G_STRUCT_OFFSET (GeanyObjectClass, document_before_save),
206 NULL, NULL,
207 g_cclosure_marshal_VOID__POINTER,
208 G_TYPE_NONE, 1,
209 G_TYPE_POINTER);
210 geany_object_signals[GCB_DOCUMENT_SAVE] = g_signal_new (
211 "document-save",
212 G_OBJECT_CLASS_TYPE (g_object_class),
213 G_SIGNAL_RUN_FIRST,
214 G_STRUCT_OFFSET (GeanyObjectClass, document_save),
215 NULL, NULL,
216 g_cclosure_marshal_VOID__POINTER,
217 G_TYPE_NONE, 1,
218 G_TYPE_POINTER);
219 geany_object_signals[GCB_DOCUMENT_FILETYPE_SET] = g_signal_new (
220 "document-filetype-set",
221 G_OBJECT_CLASS_TYPE (g_object_class),
222 G_SIGNAL_RUN_FIRST,
223 G_STRUCT_OFFSET (GeanyObjectClass, document_filetype_set),
224 NULL, NULL,
225 geany_cclosure_marshal_VOID__POINTER_POINTER,
226 G_TYPE_NONE, 2,
227 G_TYPE_POINTER, G_TYPE_POINTER);
228 geany_object_signals[GCB_DOCUMENT_ACTIVATE] = g_signal_new (
229 "document-activate",
230 G_OBJECT_CLASS_TYPE (g_object_class),
231 G_SIGNAL_RUN_FIRST,
232 G_STRUCT_OFFSET (GeanyObjectClass, document_activate),
233 NULL, NULL,
234 g_cclosure_marshal_VOID__POINTER,
235 G_TYPE_NONE, 1,
236 G_TYPE_POINTER);
237 geany_object_signals[GCB_DOCUMENT_CLOSE] = g_signal_new (
238 "document-close",
239 G_OBJECT_CLASS_TYPE (g_object_class),
240 G_SIGNAL_RUN_FIRST,
241 G_STRUCT_OFFSET (GeanyObjectClass, document_close),
242 NULL, NULL,
243 g_cclosure_marshal_VOID__POINTER,
244 G_TYPE_NONE, 1,
245 G_TYPE_POINTER);
247 /* Project signals */
248 geany_object_signals[GCB_PROJECT_OPEN] = g_signal_new (
249 "project-open",
250 G_OBJECT_CLASS_TYPE (g_object_class),
251 G_SIGNAL_RUN_FIRST,
252 G_STRUCT_OFFSET (GeanyObjectClass, project_open),
253 NULL, NULL,
254 g_cclosure_marshal_VOID__POINTER,
255 G_TYPE_NONE, 1,
256 G_TYPE_POINTER);
257 geany_object_signals[GCB_PROJECT_SAVE] = g_signal_new (
258 "project-save",
259 G_OBJECT_CLASS_TYPE (g_object_class),
260 G_SIGNAL_RUN_FIRST,
261 G_STRUCT_OFFSET (GeanyObjectClass, project_save),
262 NULL, NULL,
263 g_cclosure_marshal_VOID__POINTER,
264 G_TYPE_NONE, 1,
265 G_TYPE_POINTER);
266 geany_object_signals[GCB_PROJECT_CLOSE] = g_signal_new (
267 "project-close",
268 G_OBJECT_CLASS_TYPE (g_object_class),
269 G_SIGNAL_RUN_FIRST,
270 G_STRUCT_OFFSET (GeanyObjectClass, project_close),
271 NULL, NULL,
272 g_cclosure_marshal_VOID__VOID,
273 G_TYPE_NONE, 0);
274 geany_object_signals[GCB_PROJECT_DIALOG_OPEN] = g_signal_new (
275 "project-dialog-open",
276 G_OBJECT_CLASS_TYPE (g_object_class),
277 G_SIGNAL_RUN_FIRST,
278 G_STRUCT_OFFSET (GeanyObjectClass, project_dialog_open),
279 NULL, NULL,
280 g_cclosure_marshal_VOID__POINTER,
281 G_TYPE_NONE, 1,
282 G_TYPE_POINTER);
283 geany_object_signals[GCB_PROJECT_DIALOG_CONFIRMED] = g_signal_new (
284 "project-dialog-confirmed",
285 G_OBJECT_CLASS_TYPE (g_object_class),
286 G_SIGNAL_RUN_FIRST,
287 G_STRUCT_OFFSET (GeanyObjectClass, project_dialog_confirmed),
288 NULL, NULL,
289 g_cclosure_marshal_VOID__POINTER,
290 G_TYPE_NONE, 1,
291 G_TYPE_POINTER);
292 geany_object_signals[GCB_PROJECT_DIALOG_CLOSE] = g_signal_new (
293 "project-dialog-close",
294 G_OBJECT_CLASS_TYPE (g_object_class),
295 G_SIGNAL_RUN_FIRST,
296 G_STRUCT_OFFSET (GeanyObjectClass, project_dialog_close),
297 NULL, NULL,
298 g_cclosure_marshal_VOID__POINTER,
299 G_TYPE_NONE, 1,
300 G_TYPE_POINTER);
302 /* Editor signals */
303 geany_object_signals[GCB_UPDATE_EDITOR_MENU] = g_signal_new (
304 "update-editor-menu",
305 G_OBJECT_CLASS_TYPE (g_object_class),
306 G_SIGNAL_RUN_FIRST,
307 G_STRUCT_OFFSET (GeanyObjectClass, update_editor_menu),
308 NULL, NULL,
309 geany_cclosure_marshal_VOID__STRING_INT_POINTER,
310 G_TYPE_NONE, 3,
311 G_TYPE_STRING, G_TYPE_INT, G_TYPE_POINTER);
312 geany_object_signals[GCB_EDITOR_NOTIFY] = g_signal_new (
313 "editor-notify",
314 G_OBJECT_CLASS_TYPE (g_object_class),
315 G_SIGNAL_RUN_LAST,
316 G_STRUCT_OFFSET (GeanyObjectClass, update_editor_menu),
317 boolean_handled_accumulator, NULL,
318 geany_cclosure_marshal_BOOL__POINTER_POINTER,
319 G_TYPE_BOOLEAN, 2,
320 G_TYPE_POINTER, G_TYPE_POINTER);
322 /* General signals */
323 geany_object_signals[GCB_GEANY_STARTUP_COMPLETE] = g_signal_new (
324 "geany-startup-complete",
325 G_OBJECT_CLASS_TYPE (g_object_class),
326 G_SIGNAL_RUN_FIRST,
327 G_STRUCT_OFFSET (GeanyObjectClass, geany_startup_complete),
328 NULL, NULL,
329 g_cclosure_marshal_VOID__VOID,
330 G_TYPE_NONE, 0);
331 geany_object_signals[GCB_BUILD_START] = g_signal_new (
332 "build-start",
333 G_OBJECT_CLASS_TYPE (g_object_class),
334 G_SIGNAL_RUN_FIRST,
335 G_STRUCT_OFFSET (GeanyObjectClass, build_start),
336 NULL, NULL,
337 g_cclosure_marshal_VOID__VOID,
338 G_TYPE_NONE, 0);
340 /* Core-only signals */
341 geany_object_signals[GCB_SAVE_SETTINGS] = g_signal_new (
342 "save-settings",
343 G_OBJECT_CLASS_TYPE (g_object_class),
344 G_SIGNAL_RUN_FIRST,
345 G_STRUCT_OFFSET (GeanyObjectClass, save_settings),
346 NULL, NULL,
347 g_cclosure_marshal_VOID__POINTER,
348 G_TYPE_NONE, 1,
349 G_TYPE_POINTER);
350 geany_object_signals[GCB_LOAD_SETTINGS] = g_signal_new (
351 "load-settings",
352 G_OBJECT_CLASS_TYPE (g_object_class),
353 G_SIGNAL_RUN_FIRST,
354 G_STRUCT_OFFSET (GeanyObjectClass, load_settings),
355 NULL, NULL,
356 g_cclosure_marshal_VOID__POINTER,
357 G_TYPE_NONE, 1,
358 G_TYPE_POINTER);
362 static void geany_object_class_init(GeanyObjectClass *klass)
364 GObjectClass *g_object_class;
365 g_object_class = G_OBJECT_CLASS(klass);
367 g_type_class_add_private(klass, sizeof(GeanyObjectPrivate));
369 create_signals(g_object_class);
373 static void geany_object_init(GeanyObject *self)
375 /* nothing to do */
379 GObject *geany_object_new(void)
381 return g_object_new(GEANY_OBJECT_TYPE, NULL);