2 * pluginsignals.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2008-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2008-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 /* Note: this file is for Doxygen only. */
25 * @file pluginsignals.c
31 * To use plugin signals in Geany, you have two options:
33 * -# Create a PluginCallback array with the @ref plugin_callbacks symbol. List the signals
34 * you want to listen to and create the appropriate signal callbacks for each signal.
35 * The callback array is read @a after plugin_init() has been called.
36 * -# Use plugin_signal_connect(), which can be called at any time and can also connect
37 * to non-Geany signals (such as GTK widget signals).
39 * This page lists the signal prototypes, but you connect to them using the
40 * string name (which by convention uses @c - hyphens instead of @c _ underscores).
42 * E.g. @c "document-open" for @ref document_open.
44 * The following code demonstrates how to use signals in Geany plugins. The code can be inserted
45 * in your plugin code at any desired position.
48 static void on_document_open(GObject *obj, GeanyDocument *doc, gpointer user_data)
50 printf("Example: %s was opened\n", DOC_FILENAME(doc));
53 PluginCallback plugin_callbacks[] =
55 { "document-open", (GCallback) &on_document_open, FALSE, NULL },
56 { NULL, NULL, FALSE, NULL }
59 * @note The PluginCallback array has to be ended with a final @c NULL entry.
62 /** Sent when a new document is created.
64 * @param obj a GeanyObject instance, should be ignored.
65 * @param doc the new document.
66 * @param user_data user data.
68 signal
void (*document_new
)(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
);
70 /** Sent when a new document is opened.
72 * @param obj a GeanyObject instance, should be ignored.
73 * @param doc the opened document.
74 * @param user_data user data.
76 signal
void (*document_open
)(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
);
78 /** Sent when an existing document is reloaded.
80 * @param obj a GeanyObject instance, should be ignored.
81 * @param doc the re-opened document.
82 * @param user_data user data.
86 signal
void (*document_reload
)(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
);
88 /** Sent before a document is saved.
90 * @param obj a GeanyObject instance, should be ignored.
91 * @param doc the document to be saved.
92 * @param user_data user data.
94 signal
void (*document_before_save
)(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
);
96 /** Sent when a new document is saved.
98 * @param obj a GeanyObject instance, should be ignored.
99 * @param doc the saved document.
100 * @param user_data user data.
102 signal
void (*document_save
)(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
);
105 /** Sent after the filetype of a document has been changed.
107 * The previous filetype object is passed but it can be NULL (e.g. at startup).
108 * The new filetype can be read with: @code
109 * GeanyFiletype *ft = doc->file_type;
112 * @param obj a GeanyObject instance, should be ignored.
113 * @param doc the saved document.
114 * @param filetype_old the previous filetype of the document.
115 * @param user_data user data.
117 signal
void (*document_filetype_set
)(GObject
*obj
, GeanyDocument
*doc
, GeanyFiletype
*filetype_old
, gpointer user_data
);
119 /** Sent when switching notebook pages.
121 * @param obj a GeanyObject instance, should be ignored.
122 * @param doc the current document.
123 * @param user_data user data.
125 signal
void (*document_activate
)(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
);
127 /** Sent before closing a document.
129 * @param obj a GeanyObject instance, should be ignored.
130 * @param doc the document about to be closed.
131 * @param user_data user data.
133 signal
void (*document_close
)(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
);
135 /** Sent after a project is opened but before session files are loaded.
137 * @param obj a GeanyObject instance, should be ignored.
138 * @param config an existing GKeyFile object which can be used to read and write data.
139 * It must not be closed or freed.
140 * @param user_data user data.
142 signal
void (*project_open
)(GObject
*obj
, GKeyFile
*config
, gpointer user_data
);
144 /** Sent when a project is saved (happens when the project is created, the properties
145 * dialog is closed, before the project is closed, or when Geany is exited).
146 * This signal is emitted shortly before Geany will write the contents of the
147 * GKeyFile to the disc.
149 * @param obj a GeanyObject instance, should be ignored.
150 * @param config an existing GKeyFile object which can be used to read and write data.
151 * It must not be closed or freed.
152 * @param user_data user data.
154 signal
void (*project_save
)(GObject
*obj
, GKeyFile
*config
, gpointer user_data
);
156 /** Sent after a project is closed.
158 * @param obj a GeanyObject instance, should be ignored.
159 * @param user_data user data.
161 signal
void (*project_close
)(GObject
*obj
, gpointer user_data
);
163 /** Sent before a project is closed.
165 * @param obj a GeanyObject instance, should be ignored.
166 * @param user_data user data.
168 * @since 1.29 (API 230)
170 signal
void (*project_before_close
)(GObject
*obj
, gpointer user_data
);
172 /** Sent after a project dialog is opened but before it is displayed. Plugins
173 * can append their own project settings tabs by using this signal.
175 * @param obj a GeanyObject instance, should be ignored.
176 * @param notebook a GtkNotebook instance that can be used by plugins to append their
178 * @param user_data user data.
180 signal
void (*project_dialog_open
)(GObject
*obj
, GtkWidget
*notebook
, gpointer user_data
);
182 /** Sent when the settings dialog is confirmed by the user. Plugins can use
183 * this signal to read the settings widgets previously added by using the
184 * @c project-dialog-open signal.
186 * @warning The dialog will still be running afterwards if the user chose 'Apply'.
187 * @param obj a GeanyObject instance, should be ignored.
188 * @param notebook a GtkNotebook instance that can be used by plugins to read their
190 * @param user_data user data.
192 signal
void (*project_dialog_confirmed
)(GObject
*obj
, GtkWidget
*notebook
, gpointer user_data
);
194 /** Sent before project dialog is closed. By using this signal, plugins can remove
195 * tabs previously added in project-dialog-open signal handler.
197 * @param obj a GeanyObject instance, should be ignored.
198 * @param notebook a GtkNotebook instance that can be used by plugins to remove
199 * settings tabs previously added in the project-dialog-open signal handler.
200 * @param user_data user data.
202 signal
void (*project_dialog_close
)(GObject
*obj
, GtkWidget
*notebook
, gpointer user_data
);
204 /** Sent once Geany has finished all initialization and startup tasks and the GUI has been
205 * realized. This signal is the very last step in the startup process and is sent once
206 * the GTK main event loop has been entered.
208 * @param obj a GeanyObject instance, should be ignored.
209 * @param user_data user data.
211 signal
void (*geany_startup_complete
)(GObject
*obj
, gpointer user_data
);
213 /** Sent before build is started. A plugin could use this signal e.g. to save all unsaved documents
214 * before the build starts.
216 * @param obj a GeanyObject instance, should be ignored.
217 * @param user_data user data.
219 signal
void (*build_start
)(GObject
*obj
, gpointer user_data
);
221 /** Sent before the popup menu of the editing widget is shown. This can be used to modify or extend
224 * @note You can add menu items from @c plugin_init() using @c geany->main_widgets->editor_menu,
225 * remembering to destroy them in @c plugin_cleanup().
227 * @param obj a GeanyObject instance, should be ignored.
228 * @param word the current word (in UTF-8 encoding) below the cursor position
229 * where the popup menu will be opened.
230 * @param click_pos the cursor position where the popup will be opened.
231 * @param doc the current document.
232 * @param user_data user data.
234 signal
void (*update_editor_menu
)(GObject
*obj
, const gchar
*word
, gint pos
, GeanyDocument
*doc
,
237 /** Sent whenever something in the editor widget changes.
239 * E.g. Character added, fold level changes, clicks to the line number margin.
240 * A detailed description of possible notifications and the SCNotification can be found at
241 * http://www.scintilla.org/ScintillaDoc.html#Notifications.
243 * If you connect to this signal, you must check @c nt->nmhdr.code for the notification type
244 * to prevent handling unwanted notifications. This is important because for instance SCN_UPDATEUI
245 * is sent very often whereas you probably don't want to handle this notification.
247 * By default, the signal is sent before Geany's default handler is processing the event.
248 * Your callback function should return FALSE to allow Geany processing the event as well. If you
249 * want to prevent this for some reason, return TRUE.
250 * Please use this with care as it can break basic functionality of Geany.
252 * The signal can be sent after Geany's default handler has been run when you set
253 * PluginCallback::after field to TRUE.
255 * An example callback implementation of this signal can be found in the Demo plugin.
257 * @warning This signal has much power and should be used carefully. You should especially
258 * care about the return value; make sure to return TRUE only if it is necessary
259 * and in the correct situations.
261 * @param obj a GeanyObject instance, should be ignored.
262 * @param editor The current GeanyEditor.
263 * @param nt A pointer to the SCNotification struct which holds additional information for
265 * @param user_data user data.
266 * @return @c TRUE to stop other handlers from being invoked for the event.
267 * @c FALSE to propagate the event further.
271 signal
gboolean (*editor_notify
)(GObject
*obj
, GeanyEditor
*editor
, SCNotification
*nt
,