2 * geanyobject.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2007 The Geany contributors
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 /* A GObject used for connecting and emitting signals when certain events happen,
22 * e.g. opening a document.
23 * Mainly used for plugins - see the API docs.
27 * signal void save_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
28 * Emitted just before saving main keyfile settings.
30 * signal void load_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
31 * Emitted just after loading main keyfile settings.
38 #include "geanyobject.h"
40 /* extern in geany.h */
41 GObject
*geany_object
;
43 static guint geany_object_signals
[GCB_MAX
] = { 0 };
46 typedef struct _GeanyObjectPrivate GeanyObjectPrivate
;
48 struct _GeanyObjectPrivate
50 /* to avoid warnings (g_type_class_add_private: assertion `private_size > 0' failed) */
55 * Get the GObject-derived GType for GeanyObject
57 * @return GeanyObject type */
59 GType
geany_object_get_type(void);
61 G_DEFINE_TYPE(GeanyObject
, geany_object
, G_TYPE_OBJECT
)
64 static gboolean
boolean_handled_accumulator(GSignalInvocationHint
*ihint
, GValue
*return_accu
,
65 const GValue
*handler_return
, gpointer dummy
)
67 gboolean continue_emission
, signal_handled
;
69 signal_handled
= g_value_get_boolean(handler_return
);
70 g_value_set_boolean(return_accu
, signal_handled
);
71 continue_emission
= !signal_handled
;
73 return continue_emission
;
77 static void create_signals(GObjectClass
*g_object_class
)
79 /* Document signals */
80 geany_object_signals
[GCB_DOCUMENT_NEW
] = g_signal_new (
82 G_OBJECT_CLASS_TYPE (g_object_class
),
84 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
87 geany_object_signals
[GCB_DOCUMENT_OPEN
] = g_signal_new (
89 G_OBJECT_CLASS_TYPE (g_object_class
),
91 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
94 geany_object_signals
[GCB_DOCUMENT_RELOAD
] = g_signal_new (
96 G_OBJECT_CLASS_TYPE (g_object_class
),
98 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
100 GEANY_TYPE_DOCUMENT
);
101 geany_object_signals
[GCB_DOCUMENT_BEFORE_SAVE
] = g_signal_new (
102 "document-before-save",
103 G_OBJECT_CLASS_TYPE (g_object_class
),
105 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
107 GEANY_TYPE_DOCUMENT
);
108 geany_object_signals
[GCB_DOCUMENT_SAVE
] = g_signal_new (
110 G_OBJECT_CLASS_TYPE (g_object_class
),
112 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
114 GEANY_TYPE_DOCUMENT
);
115 geany_object_signals
[GCB_DOCUMENT_FILETYPE_SET
] = g_signal_new (
116 "document-filetype-set",
117 G_OBJECT_CLASS_TYPE (g_object_class
),
121 GEANY_TYPE_DOCUMENT
, GEANY_TYPE_FILETYPE
);
122 geany_object_signals
[GCB_DOCUMENT_ACTIVATE
] = g_signal_new (
124 G_OBJECT_CLASS_TYPE (g_object_class
),
126 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
128 GEANY_TYPE_DOCUMENT
);
129 geany_object_signals
[GCB_DOCUMENT_CLOSE
] = g_signal_new (
131 G_OBJECT_CLASS_TYPE (g_object_class
),
133 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
135 GEANY_TYPE_DOCUMENT
);
137 /* Project signals */
138 geany_object_signals
[GCB_PROJECT_OPEN
] = g_signal_new (
140 G_OBJECT_CLASS_TYPE (g_object_class
),
142 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
145 geany_object_signals
[GCB_PROJECT_SAVE
] = g_signal_new (
147 G_OBJECT_CLASS_TYPE (g_object_class
),
149 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
152 geany_object_signals
[GCB_PROJECT_CLOSE
] = g_signal_new (
154 G_OBJECT_CLASS_TYPE (g_object_class
),
156 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
158 geany_object_signals
[GCB_PROJECT_BEFORE_CLOSE
] = g_signal_new (
159 "project-before-close",
160 G_OBJECT_CLASS_TYPE (g_object_class
),
162 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
164 geany_object_signals
[GCB_PROJECT_DIALOG_OPEN
] = g_signal_new (
165 "project-dialog-open",
166 G_OBJECT_CLASS_TYPE (g_object_class
),
168 0, NULL
, NULL
, g_cclosure_marshal_VOID__OBJECT
,
171 geany_object_signals
[GCB_PROJECT_DIALOG_CONFIRMED
] = g_signal_new (
172 "project-dialog-confirmed",
173 G_OBJECT_CLASS_TYPE (g_object_class
),
175 0, NULL
, NULL
, g_cclosure_marshal_VOID__OBJECT
,
178 geany_object_signals
[GCB_PROJECT_DIALOG_CLOSE
] = g_signal_new (
179 "project-dialog-close",
180 G_OBJECT_CLASS_TYPE (g_object_class
),
182 0, NULL
, NULL
, g_cclosure_marshal_VOID__OBJECT
,
187 geany_object_signals
[GCB_UPDATE_EDITOR_MENU
] = g_signal_new (
188 "update-editor-menu",
189 G_OBJECT_CLASS_TYPE (g_object_class
),
193 G_TYPE_STRING
, G_TYPE_INT
, GEANY_TYPE_DOCUMENT
);
194 geany_object_signals
[GCB_EDITOR_NOTIFY
] = g_signal_new (
196 G_OBJECT_CLASS_TYPE (g_object_class
),
198 0, boolean_handled_accumulator
, NULL
, NULL
,
200 GEANY_TYPE_EDITOR
, SCINTILLA_TYPE_NOTIFICATION
);
202 /* General signals */
203 geany_object_signals
[GCB_GEANY_STARTUP_COMPLETE
] = g_signal_new (
204 "geany-startup-complete",
205 G_OBJECT_CLASS_TYPE (g_object_class
),
207 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
209 geany_object_signals
[GCB_BUILD_START
] = g_signal_new (
211 G_OBJECT_CLASS_TYPE (g_object_class
),
213 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
,
216 /* Core-only signals */
217 geany_object_signals
[GCB_SAVE_SETTINGS
] = g_signal_new (
219 G_OBJECT_CLASS_TYPE (g_object_class
),
221 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
224 geany_object_signals
[GCB_LOAD_SETTINGS
] = g_signal_new (
226 G_OBJECT_CLASS_TYPE (g_object_class
),
228 0, NULL
, NULL
, g_cclosure_marshal_VOID__BOXED
,
232 /* Key press signal */
233 geany_object_signals
[GCB_KEY_PRESS_NOTIFY
] = g_signal_new (
235 G_OBJECT_CLASS_TYPE (g_object_class
),
237 0, boolean_handled_accumulator
, NULL
, NULL
,
239 GDK_TYPE_EVENT
| G_SIGNAL_TYPE_STATIC_SCOPE
);
243 static void geany_object_class_init(GeanyObjectClass
*klass
)
245 GObjectClass
*g_object_class
;
246 g_object_class
= G_OBJECT_CLASS(klass
);
248 g_type_class_add_private(klass
, sizeof(GeanyObjectPrivate
));
250 create_signals(g_object_class
);
254 static void geany_object_init(GeanyObject
*self
)
260 GObject
*geany_object_new(void)
262 return g_object_new(GEANY_OBJECT_TYPE
, NULL
);