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.
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.
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) */
56 * Get the GObject-derived GType for GeanyObject
58 * @return GeanyObject type */
60 GType
geany_object_get_type(void);
62 G_DEFINE_TYPE(GeanyObject
, geany_object
, G_TYPE_OBJECT
)
65 static gboolean
boolean_handled_accumulator(GSignalInvocationHint
*ihint
, GValue
*return_accu
,
66 const GValue
*handler_return
, gpointer dummy
)
68 gboolean continue_emission
, signal_handled
;
70 signal_handled
= g_value_get_boolean(handler_return
);
71 g_value_set_boolean(return_accu
, signal_handled
);
72 continue_emission
= !signal_handled
;
74 return continue_emission
;
78 static void create_signals(GObjectClass
*g_object_class
)
80 /* Document signals */
81 geany_object_signals
[GCB_DOCUMENT_NEW
] = g_signal_new (
83 G_OBJECT_CLASS_TYPE (g_object_class
),
85 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
88 geany_object_signals
[GCB_DOCUMENT_OPEN
] = g_signal_new (
90 G_OBJECT_CLASS_TYPE (g_object_class
),
92 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
95 geany_object_signals
[GCB_DOCUMENT_RELOAD
] = g_signal_new (
97 G_OBJECT_CLASS_TYPE (g_object_class
),
99 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
101 GEANY_TYPE_DOCUMENT
);
102 geany_object_signals
[GCB_DOCUMENT_BEFORE_SAVE
] = g_signal_new (
103 "document-before-save",
104 G_OBJECT_CLASS_TYPE (g_object_class
),
106 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
108 GEANY_TYPE_DOCUMENT
);
109 geany_object_signals
[GCB_DOCUMENT_SAVE
] = g_signal_new (
111 G_OBJECT_CLASS_TYPE (g_object_class
),
113 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
115 GEANY_TYPE_DOCUMENT
);
116 geany_object_signals
[GCB_DOCUMENT_FILETYPE_SET
] = g_signal_new (
117 "document-filetype-set",
118 G_OBJECT_CLASS_TYPE (g_object_class
),
122 GEANY_TYPE_DOCUMENT
, GEANY_TYPE_FILETYPE
);
123 geany_object_signals
[GCB_DOCUMENT_ACTIVATE
] = g_signal_new (
125 G_OBJECT_CLASS_TYPE (g_object_class
),
127 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
129 GEANY_TYPE_DOCUMENT
);
130 geany_object_signals
[GCB_DOCUMENT_CLOSE
] = g_signal_new (
132 G_OBJECT_CLASS_TYPE (g_object_class
),
134 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
136 GEANY_TYPE_DOCUMENT
);
138 /* Project signals */
139 geany_object_signals
[GCB_PROJECT_OPEN
] = g_signal_new (
141 G_OBJECT_CLASS_TYPE (g_object_class
),
143 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
146 geany_object_signals
[GCB_PROJECT_SAVE
] = g_signal_new (
148 G_OBJECT_CLASS_TYPE (g_object_class
),
150 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
153 geany_object_signals
[GCB_PROJECT_CLOSE
] = g_signal_new (
155 G_OBJECT_CLASS_TYPE (g_object_class
),
157 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
159 geany_object_signals
[GCB_PROJECT_BEFORE_CLOSE
] = g_signal_new (
160 "project-before-close",
161 G_OBJECT_CLASS_TYPE (g_object_class
),
163 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
165 geany_object_signals
[GCB_PROJECT_DIALOG_OPEN
] = g_signal_new (
166 "project-dialog-open",
167 G_OBJECT_CLASS_TYPE (g_object_class
),
169 0, NULL
, NULL
, g_cclosure_marshal_VOID__OBJECT
,
172 geany_object_signals
[GCB_PROJECT_DIALOG_CONFIRMED
] = g_signal_new (
173 "project-dialog-confirmed",
174 G_OBJECT_CLASS_TYPE (g_object_class
),
176 0, NULL
, NULL
, g_cclosure_marshal_VOID__OBJECT
,
179 geany_object_signals
[GCB_PROJECT_DIALOG_CLOSE
] = g_signal_new (
180 "project-dialog-close",
181 G_OBJECT_CLASS_TYPE (g_object_class
),
183 0, NULL
, NULL
, g_cclosure_marshal_VOID__OBJECT
,
188 geany_object_signals
[GCB_UPDATE_EDITOR_MENU
] = g_signal_new (
189 "update-editor-menu",
190 G_OBJECT_CLASS_TYPE (g_object_class
),
194 G_TYPE_STRING
, G_TYPE_INT
, GEANY_TYPE_DOCUMENT
);
195 geany_object_signals
[GCB_EDITOR_NOTIFY
] = g_signal_new (
197 G_OBJECT_CLASS_TYPE (g_object_class
),
199 0, boolean_handled_accumulator
, NULL
, NULL
,
201 GEANY_TYPE_EDITOR
, SCINTILLA_TYPE_NOTIFICATION
);
203 /* General signals */
204 geany_object_signals
[GCB_GEANY_STARTUP_COMPLETE
] = g_signal_new (
205 "geany-startup-complete",
206 G_OBJECT_CLASS_TYPE (g_object_class
),
208 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
210 geany_object_signals
[GCB_BUILD_START
] = g_signal_new (
212 G_OBJECT_CLASS_TYPE (g_object_class
),
214 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
217 /* Core-only signals */
218 geany_object_signals
[GCB_SAVE_SETTINGS
] = g_signal_new (
220 G_OBJECT_CLASS_TYPE (g_object_class
),
222 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
225 geany_object_signals
[GCB_LOAD_SETTINGS
] = g_signal_new (
227 G_OBJECT_CLASS_TYPE (g_object_class
),
229 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
235 static void geany_object_class_init(GeanyObjectClass
*klass
)
237 GObjectClass
*g_object_class
;
238 g_object_class
= G_OBJECT_CLASS(klass
);
240 g_type_class_add_private(klass
, sizeof(GeanyObjectPrivate
));
242 create_signals(g_object_class
);
246 static void geany_object_init(GeanyObject
*self
)
252 GObject
*geany_object_new(void)
254 return g_object_new(GEANY_OBJECT_TYPE
, NULL
);