Merge pull request #404 from ntrel/enum-base
[geany-mirror.git] / src / plugins.c
blobaeeca293b7e56dea9d7d42912a319b3765ef7430
1 /*
2 * plugins.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 /* Code to manage, load and unload plugins. */
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #ifdef HAVE_PLUGINS
30 #include "plugins.h"
32 #include "app.h"
33 #include "dialogs.h"
34 #include "encodings.h"
35 #include "geanyobject.h"
36 #include "geanywraplabel.h"
37 #include "highlighting.h"
38 #include "keybindingsprivate.h"
39 #include "keyfile.h"
40 #include "main.h"
41 #include "msgwindow.h"
42 #include "navqueue.h"
43 #include "plugindata.h"
44 #include "pluginprivate.h"
45 #include "pluginutils.h"
46 #include "prefs.h"
47 #include "sciwrappers.h"
48 #include "stash.h"
49 #include "support.h"
50 #include "symbols.h"
51 #include "templates.h"
52 #include "toolbar.h"
53 #include "ui_utils.h"
54 #include "utils.h"
55 #include "win32.h"
57 #include "gtkcompat.h"
59 #include <string.h>
62 GList *active_plugin_list = NULL; /* list of only actually loaded plugins, always valid */
65 static gboolean want_plugins = FALSE;
67 /* list of all available, loadable plugins, only valid as long as the plugin manager dialog is
68 * opened, afterwards it will be destroyed */
69 static GList *plugin_list = NULL;
70 static gchar **active_plugins_pref = NULL; /* list of plugin filenames to load at startup */
71 static GList *failed_plugins_list = NULL; /* plugins the user wants active but can't be used */
73 static GtkWidget *menu_separator = NULL;
75 static gchar *get_plugin_path(void);
76 static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data);
79 static PluginFuncs plugin_funcs = {
80 &plugin_add_toolbar_item,
81 &plugin_module_make_resident,
82 &plugin_signal_connect,
83 &plugin_set_key_group,
84 &plugin_show_configure,
85 &plugin_timeout_add,
86 &plugin_timeout_add_seconds,
87 &plugin_idle_add,
88 &plugin_builder_connect_signals
91 static DocumentFuncs doc_funcs = {
92 &document_new_file,
93 &document_get_current,
94 &document_get_from_page,
95 &document_find_by_filename,
96 &document_find_by_real_path,
97 &document_save_file,
98 &document_open_file,
99 &document_open_files,
100 &document_remove_page,
101 &document_reload_force,
102 &document_set_encoding,
103 &document_set_text_changed,
104 &document_set_filetype,
105 &document_close,
106 &document_index,
107 &document_save_file_as,
108 &document_rename_file,
109 &document_get_status_color,
110 &document_get_basename_for_display,
111 &document_get_notebook_page,
112 &document_compare_by_display_name,
113 &document_compare_by_tab_order,
114 &document_compare_by_tab_order_reverse,
115 &document_find_by_id
118 static EditorFuncs editor_funcs = {
119 &editor_get_indent_prefs,
120 &editor_create_widget,
121 &editor_indicator_set_on_range,
122 &editor_indicator_set_on_line,
123 &editor_indicator_clear,
124 &editor_set_indent_type,
125 &editor_get_word_at_pos,
126 &editor_get_eol_char_name,
127 &editor_get_eol_char_len,
128 &editor_get_eol_char,
129 &editor_insert_text_block,
130 &editor_get_eol_char_mode,
131 &editor_goto_pos,
132 &editor_find_snippet,
133 &editor_insert_snippet
136 static ScintillaFuncs scintilla_funcs = {
137 &scintilla_send_message,
138 &scintilla_new
141 /* Macro to prevent a duplicate macro being generated in geanyfunctions.h */
142 #define _scintilla_send_message_macro scintilla_send_message
144 static SciFuncs sci_funcs = {
145 &_scintilla_send_message_macro,
146 &sci_send_command,
147 &sci_start_undo_action,
148 &sci_end_undo_action,
149 &sci_set_text,
150 &sci_insert_text,
151 &sci_get_text,
152 &sci_get_length,
153 &sci_get_current_position,
154 &sci_set_current_position,
155 &sci_get_col_from_position,
156 &sci_get_line_from_position,
157 &sci_get_position_from_line,
158 &sci_replace_sel,
159 &sci_get_selected_text,
160 &sci_get_selected_text_length,
161 &sci_get_selection_start,
162 &sci_get_selection_end,
163 &sci_get_selection_mode,
164 &sci_set_selection_mode,
165 &sci_set_selection_start,
166 &sci_set_selection_end,
167 &sci_get_text_range,
168 &sci_get_line,
169 &sci_get_line_length,
170 &sci_get_line_count,
171 &sci_get_line_is_visible,
172 &sci_ensure_line_is_visible,
173 &sci_scroll_caret,
174 &sci_find_matching_brace,
175 &sci_get_style_at,
176 &sci_get_char_at,
177 &sci_get_current_line,
178 &sci_has_selection,
179 &sci_get_tab_width,
180 &sci_indicator_clear,
181 &sci_indicator_set,
182 &sci_get_contents,
183 &sci_get_contents_range,
184 &sci_get_selection_contents,
185 &sci_set_font,
186 &sci_get_line_end_position,
187 &sci_set_target_start,
188 &sci_set_target_end,
189 &sci_replace_target,
190 &sci_set_marker_at_line,
191 &sci_delete_marker_at_line,
192 &sci_is_marker_set_at_line,
193 &sci_goto_line,
194 &sci_find_text,
195 &sci_set_line_indentation,
196 &sci_get_line_indentation,
197 &sci_get_lexer
200 static TemplateFuncs template_funcs = {
201 &templates_get_template_fileheader
204 static UtilsFuncs utils_funcs = {
205 &utils_str_equal,
206 &utils_string_replace_all,
207 &utils_get_file_list,
208 &utils_write_file,
209 &utils_get_locale_from_utf8,
210 &utils_get_utf8_from_locale,
211 &utils_remove_ext_from_filename,
212 &utils_mkdir,
213 &utils_get_setting_boolean,
214 &utils_get_setting_integer,
215 &utils_get_setting_string,
216 &utils_spawn_sync,
217 &utils_spawn_async,
218 &utils_str_casecmp,
219 &utils_get_date_time,
220 &utils_open_browser,
221 &utils_string_replace_first,
222 &utils_str_middle_truncate,
223 &utils_str_remove_chars,
224 &utils_get_file_list_full,
225 &utils_copy_environment,
226 &utils_find_open_xml_tag,
227 &utils_find_open_xml_tag_pos
230 static UIUtilsFuncs uiutils_funcs = {
231 &ui_dialog_vbox_new,
232 &ui_frame_new_with_alignment,
233 &ui_set_statusbar,
234 &ui_table_add_row,
235 &ui_path_box_new,
236 &ui_button_new_with_image,
237 &ui_add_document_sensitive,
238 &ui_widget_set_tooltip_text,
239 &ui_image_menu_item_new,
240 &ui_lookup_widget,
241 &ui_progress_bar_start,
242 &ui_progress_bar_stop,
243 &ui_entry_add_clear_icon,
244 &ui_menu_add_document_items,
245 &ui_widget_modify_font_from_string,
246 &ui_is_keyval_enter_or_return,
247 &ui_get_gtk_settings_integer,
248 &ui_combo_box_add_to_history,
249 &ui_menu_add_document_items_sorted,
250 &ui_lookup_stock_label
253 static DialogFuncs dialog_funcs = {
254 &dialogs_show_question,
255 &dialogs_show_msgbox,
256 &dialogs_show_save_as,
257 &dialogs_show_input_numeric,
258 &dialogs_show_input
261 /* Macro to prevent confusing macro being generated in geanyfunctions.h */
262 #define _lookup_widget_macro ui_lookup_widget
264 /* deprecated */
265 static SupportFuncs support_funcs = {
266 &_lookup_widget_macro
269 static MsgWinFuncs msgwin_funcs = {
270 &msgwin_status_add,
271 &msgwin_compiler_add,
272 &msgwin_msg_add,
273 &msgwin_clear_tab,
274 &msgwin_switch_tab,
275 &msgwin_set_messages_dir
278 static EncodingFuncs encoding_funcs = {
279 &encodings_convert_to_utf8,
280 &encodings_convert_to_utf8_from_charset,
281 &encodings_get_charset_from_index
284 static KeybindingFuncs keybindings_funcs = {
285 &keybindings_send_command,
286 &keybindings_set_item,
287 &keybindings_get_item
290 static TagManagerFuncs tagmanager_funcs = {
291 &tm_get_real_path,
292 &tm_source_file_new,
293 &tm_source_file_free,
294 &tm_workspace_add_source_file,
295 &tm_workspace_remove_source_file,
296 &tm_workspace_add_source_files,
297 &tm_workspace_remove_source_files
300 static SearchFuncs search_funcs = {
301 &search_show_find_in_files_dialog
304 static HighlightingFuncs highlighting_funcs = {
305 &highlighting_get_style,
306 &highlighting_set_styles,
307 &highlighting_is_string_style,
308 &highlighting_is_comment_style,
309 &highlighting_is_code_style
312 static FiletypeFuncs filetype_funcs = {
313 &filetypes_detect_from_file,
314 &filetypes_lookup_by_name,
315 &filetypes_index,
316 &filetypes_get_display_name,
317 &filetypes_get_sorted_by_name
320 static NavQueueFuncs navqueue_funcs = {
321 &navqueue_goto_line
324 static MainFuncs main_funcs = {
325 &main_reload_configuration,
326 &main_locale_init,
327 &main_is_realized
330 static StashFuncs stash_funcs = {
331 &stash_group_new,
332 &stash_group_add_boolean,
333 &stash_group_add_integer,
334 &stash_group_add_string,
335 &stash_group_add_string_vector,
336 &stash_group_load_from_key_file,
337 &stash_group_save_to_key_file,
338 &stash_group_free,
339 &stash_group_load_from_file,
340 &stash_group_save_to_file,
341 &stash_group_add_toggle_button,
342 &stash_group_add_radio_buttons,
343 &stash_group_add_spin_button_integer,
344 &stash_group_add_combo_box,
345 &stash_group_add_combo_box_entry,
346 &stash_group_add_entry,
347 &stash_group_add_widget_property,
348 &stash_group_display,
349 &stash_group_update,
350 &stash_group_free_settings
353 static SymbolsFuncs symbols_funcs = {
354 &symbols_get_context_separator
357 static BuildFuncs build_funcs = {
358 &build_activate_menu_item,
359 &build_get_current_menu_item,
360 &build_remove_menu_item,
361 &build_set_menu_item,
362 &build_get_group_count
365 static ProjectFuncs project_funcs = {
366 &project_write_config
369 static GeanyFunctions geany_functions = {
370 &doc_funcs,
371 &sci_funcs,
372 &template_funcs,
373 &utils_funcs,
374 &uiutils_funcs,
375 &support_funcs,
376 &dialog_funcs,
377 &msgwin_funcs,
378 &encoding_funcs,
379 &keybindings_funcs,
380 &tagmanager_funcs,
381 &search_funcs,
382 &highlighting_funcs,
383 &filetype_funcs,
384 &navqueue_funcs,
385 &editor_funcs,
386 &main_funcs,
387 &plugin_funcs,
388 &scintilla_funcs,
389 &msgwin_funcs,
390 &stash_funcs,
391 &symbols_funcs,
392 &build_funcs,
393 &project_funcs
396 static GeanyData geany_data;
399 static void
400 geany_data_init(void)
402 GeanyData gd = {
403 app,
404 &main_widgets,
405 documents_array,
406 filetypes_array,
407 &prefs,
408 &interface_prefs,
409 &toolbar_prefs,
410 &editor_prefs,
411 &file_prefs,
412 &search_prefs,
413 &tool_prefs,
414 &template_prefs,
415 &build_info,
416 filetypes_by_title
419 geany_data = gd;
423 /* Prevent the same plugin filename being loaded more than once.
424 * Note: g_module_name always returns the .so name, even when Plugin::filename is a .la file. */
425 static gboolean
426 plugin_loaded(GModule *module)
428 gchar *basename_module, *basename_loaded;
429 GList *item;
431 basename_module = g_path_get_basename(g_module_name(module));
432 for (item = plugin_list; item != NULL; item = g_list_next(item))
434 basename_loaded = g_path_get_basename(
435 g_module_name(((Plugin*)item->data)->module));
437 if (utils_str_equal(basename_module, basename_loaded))
439 g_free(basename_loaded);
440 g_free(basename_module);
441 return TRUE;
443 g_free(basename_loaded);
445 /* Look also through the list of active plugins. This prevents problems when we have the same
446 * plugin in libdir/geany/ AND in configdir/plugins/ and the one in libdir/geany/ is loaded
447 * as active plugin. The plugin manager list would only take the one in configdir/geany/ and
448 * the plugin manager would list both plugins. Additionally, unloading the active plugin
449 * would cause a crash. */
450 for (item = active_plugin_list; item != NULL; item = g_list_next(item))
452 basename_loaded = g_path_get_basename(g_module_name(((Plugin*)item->data)->module));
454 if (utils_str_equal(basename_module, basename_loaded))
456 g_free(basename_loaded);
457 g_free(basename_module);
458 return TRUE;
460 g_free(basename_loaded);
462 g_free(basename_module);
463 return FALSE;
467 static Plugin *find_active_plugin_by_name(const gchar *filename)
469 GList *item;
471 g_return_val_if_fail(filename, FALSE);
473 for (item = active_plugin_list; item != NULL; item = g_list_next(item))
475 if (utils_str_equal(filename, ((Plugin*)item->data)->filename))
476 return item->data;
479 return NULL;
483 static gboolean
484 plugin_check_version(GModule *module)
486 gint (*version_check)(gint) = NULL;
488 g_module_symbol(module, "plugin_version_check", (void *) &version_check);
490 if (G_UNLIKELY(! version_check))
492 geany_debug("Plugin \"%s\" has no plugin_version_check() function - ignoring plugin!",
493 g_module_name(module));
494 return FALSE;
496 else
498 gint result = version_check(GEANY_ABI_VERSION);
500 if (result < 0)
502 msgwin_status_add(_("The plugin \"%s\" is not binary compatible with this "
503 "release of Geany - please recompile it."), g_module_name(module));
504 geany_debug("Plugin \"%s\" is not binary compatible with this "
505 "release of Geany - recompile it.", g_module_name(module));
506 return FALSE;
508 if (result > GEANY_API_VERSION)
510 geany_debug("Plugin \"%s\" requires a newer version of Geany (API >= v%d).",
511 g_module_name(module), result);
512 return FALSE;
515 return TRUE;
519 static void add_callbacks(Plugin *plugin, PluginCallback *callbacks)
521 PluginCallback *cb;
522 guint i, len = 0;
524 while (TRUE)
526 cb = &callbacks[len];
527 if (!cb->signal_name || !cb->callback)
528 break;
529 len++;
531 if (len == 0)
532 return;
534 for (i = 0; i < len; i++)
536 cb = &callbacks[i];
538 plugin_signal_connect(&plugin->public, NULL, cb->signal_name, cb->after,
539 cb->callback, cb->user_data);
544 static void read_key_group(Plugin *plugin)
546 GeanyKeyGroupInfo *p_key_info;
547 GeanyKeyGroup **p_key_group;
549 g_module_symbol(plugin->module, "plugin_key_group_info", (void *) &p_key_info);
550 g_module_symbol(plugin->module, "plugin_key_group", (void *) &p_key_group);
551 if (p_key_info && p_key_group)
553 GeanyKeyGroupInfo *key_info = p_key_info;
555 if (*p_key_group)
556 geany_debug("Ignoring plugin_key_group symbol for plugin '%s' - "
557 "use plugin_set_key_group() instead to allocate keybindings dynamically.",
558 plugin->info.name);
559 else
561 if (key_info->count)
563 GeanyKeyGroup *key_group =
564 plugin_set_key_group(&plugin->public, key_info->name, key_info->count, NULL);
565 if (key_group)
566 *p_key_group = key_group;
568 else
569 geany_debug("Ignoring plugin_key_group_info symbol for plugin '%s' - "
570 "count field is zero. Maybe use plugin_set_key_group() instead?",
571 plugin->info.name);
574 else if (p_key_info || p_key_group)
575 geany_debug("Ignoring only one of plugin_key_group[_info] symbols defined for plugin '%s'. "
576 "Maybe use plugin_set_key_group() instead?",
577 plugin->info.name);
581 static gint cmp_plugin_names(gconstpointer a, gconstpointer b)
583 const Plugin *pa = a;
584 const Plugin *pb = b;
586 return strcmp(pa->info.name, pb->info.name);
590 static void
591 plugin_load(Plugin *plugin)
593 GeanyPlugin **p_geany_plugin;
594 PluginCallback *callbacks;
595 PluginInfo **p_info;
596 PluginFields **plugin_fields;
598 /* set these symbols before plugin_init() is called
599 * we don't set geany_functions and geany_data since they are set directly by plugin_new() */
600 g_module_symbol(plugin->module, "geany_plugin", (void *) &p_geany_plugin);
601 if (p_geany_plugin)
602 *p_geany_plugin = &plugin->public;
603 g_module_symbol(plugin->module, "plugin_info", (void *) &p_info);
604 if (p_info)
605 *p_info = &plugin->info;
606 g_module_symbol(plugin->module, "plugin_fields", (void *) &plugin_fields);
607 if (plugin_fields)
608 *plugin_fields = &plugin->fields;
609 read_key_group(plugin);
611 /* start the plugin */
612 g_return_if_fail(plugin->init);
613 plugin->init(&geany_data);
615 /* store some function pointers for later use */
616 g_module_symbol(plugin->module, "plugin_configure", (void *) &plugin->configure);
617 g_module_symbol(plugin->module, "plugin_configure_single", (void *) &plugin->configure_single);
618 if (app->debug_mode && plugin->configure && plugin->configure_single)
619 g_warning("Plugin '%s' implements plugin_configure_single() unnecessarily - "
620 "only plugin_configure() will be used!",
621 plugin->info.name);
623 g_module_symbol(plugin->module, "plugin_help", (void *) &plugin->help);
624 g_module_symbol(plugin->module, "plugin_cleanup", (void *) &plugin->cleanup);
625 if (plugin->cleanup == NULL)
627 if (app->debug_mode)
628 g_warning("Plugin '%s' has no plugin_cleanup() function - there may be memory leaks!",
629 plugin->info.name);
632 /* now read any plugin-owned data that might have been set in plugin_init() */
634 if (plugin->fields.flags & PLUGIN_IS_DOCUMENT_SENSITIVE)
636 ui_add_document_sensitive(plugin->fields.menu_item);
639 g_module_symbol(plugin->module, "plugin_callbacks", (void *) &callbacks);
640 if (callbacks)
641 add_callbacks(plugin, callbacks);
643 /* remember which plugins are active.
644 * keep list sorted so tools menu items and plugin preference tabs are
645 * sorted by plugin name */
646 active_plugin_list = g_list_insert_sorted(active_plugin_list, plugin, cmp_plugin_names);
648 geany_debug("Loaded: %s (%s)", plugin->filename,
649 FALLBACK(plugin->info.name, "<Unknown>"));
653 /* Load and optionally init a plugin.
654 * load_plugin decides whether the plugin's plugin_init() function should be called or not. If it is
655 * called, the plugin will be started, if not the plugin will be read only (for the list of
656 * available plugins in the plugin manager).
657 * When add_to_list is set, the plugin will be added to the plugin manager's plugin_list. */
658 static Plugin*
659 plugin_new(const gchar *fname, gboolean load_plugin, gboolean add_to_list)
661 Plugin *plugin;
662 GModule *module;
663 GeanyData **p_geany_data;
664 GeanyFunctions **p_geany_functions;
665 void (*plugin_set_info)(PluginInfo*);
667 g_return_val_if_fail(fname, NULL);
668 g_return_val_if_fail(g_module_supported(), NULL);
670 /* find the plugin in the list of already loaded, active plugins and use it, otherwise
671 * load the module */
672 plugin = find_active_plugin_by_name(fname);
673 if (plugin != NULL)
675 geany_debug("Plugin \"%s\" already loaded.", fname);
676 if (add_to_list)
678 /* do not add to the list twice */
679 if (g_list_find(plugin_list, plugin) != NULL)
680 return NULL;
682 plugin_list = g_list_prepend(plugin_list, plugin);
684 return plugin;
687 /* Don't use G_MODULE_BIND_LAZY otherwise we can get unresolved symbols at runtime,
688 * causing a segfault. Without that flag the module will safely fail to load.
689 * G_MODULE_BIND_LOCAL also helps find undefined symbols e.g. app when it would
690 * otherwise not be detected due to the shadowing of Geany's app variable.
691 * Also without G_MODULE_BIND_LOCAL calling public functions e.g. the old info()
692 * function from a plugin will be shadowed. */
693 module = g_module_open(fname, G_MODULE_BIND_LOCAL);
694 if (! module)
696 geany_debug("Can't load plugin: %s", g_module_error());
697 return NULL;
700 if (plugin_loaded(module))
702 geany_debug("Plugin \"%s\" already loaded.", fname);
704 if (! g_module_close(module))
705 g_warning("%s: %s", fname, g_module_error());
706 return NULL;
709 if (! plugin_check_version(module))
711 if (! g_module_close(module))
712 g_warning("%s: %s", fname, g_module_error());
713 return NULL;
716 g_module_symbol(module, "plugin_set_info", (void *) &plugin_set_info);
717 if (plugin_set_info == NULL)
719 geany_debug("No plugin_set_info() defined for \"%s\" - ignoring plugin!", fname);
721 if (! g_module_close(module))
722 g_warning("%s: %s", fname, g_module_error());
723 return NULL;
726 plugin = g_new0(Plugin, 1);
728 /* set basic fields here to allow plugins to call Geany functions in set_info() */
729 g_module_symbol(module, "geany_data", (void *) &p_geany_data);
730 if (p_geany_data)
731 *p_geany_data = &geany_data;
732 g_module_symbol(module, "geany_functions", (void *) &p_geany_functions);
733 if (p_geany_functions)
734 *p_geany_functions = &geany_functions;
736 /* read plugin name, etc. */
737 plugin_set_info(&plugin->info);
738 if (G_UNLIKELY(EMPTY(plugin->info.name)))
740 geany_debug("No plugin name set in plugin_set_info() for \"%s\" - ignoring plugin!",
741 fname);
743 if (! g_module_close(module))
744 g_warning("%s: %s", fname, g_module_error());
745 g_free(plugin);
746 return NULL;
749 g_module_symbol(module, "plugin_init", (void *) &plugin->init);
750 if (plugin->init == NULL)
752 geany_debug("Plugin '%s' has no plugin_init() function - ignoring plugin!",
753 plugin->info.name);
755 if (! g_module_close(module))
756 g_warning("%s: %s", fname, g_module_error());
757 g_free(plugin);
758 return NULL;
760 /*geany_debug("Initializing plugin '%s'", plugin->info.name);*/
762 plugin->filename = g_strdup(fname);
763 plugin->module = module;
764 plugin->public.info = &plugin->info;
765 plugin->public.priv = plugin;
767 if (load_plugin)
768 plugin_load(plugin);
770 if (add_to_list)
771 plugin_list = g_list_prepend(plugin_list, plugin);
773 return plugin;
777 static void on_object_weak_notify(gpointer data, GObject *old_ptr)
779 Plugin *plugin = data;
780 guint i = 0;
782 g_return_if_fail(plugin && plugin->signal_ids);
784 for (i = 0; i < plugin->signal_ids->len; i++)
786 SignalConnection *sc = &g_array_index(plugin->signal_ids, SignalConnection, i);
788 if (sc->object == old_ptr)
790 g_array_remove_index_fast(plugin->signal_ids, i);
791 /* we can break the loop right after finding the first match,
792 * because we will get one notification per connected signal */
793 break;
799 /* add an object to watch for destruction, and release pointers to it when destroyed.
800 * this should only be used by plugin_signal_connect() to add a watch on
801 * the object lifetime and nuke out references to it in plugin->signal_ids */
802 void plugin_watch_object(Plugin *plugin, gpointer object)
804 g_object_weak_ref(object, on_object_weak_notify, plugin);
808 static void remove_callbacks(Plugin *plugin)
810 GArray *signal_ids = plugin->signal_ids;
811 SignalConnection *sc;
813 if (signal_ids == NULL)
814 return;
816 foreach_array(SignalConnection, sc, signal_ids)
818 g_signal_handler_disconnect(sc->object, sc->handler_id);
819 g_object_weak_unref(sc->object, on_object_weak_notify, plugin);
822 g_array_free(signal_ids, TRUE);
826 static void remove_sources(Plugin *plugin)
828 GList *item;
830 item = plugin->sources;
831 while (item != NULL)
833 GList *next = item->next; /* cache the next pointer because current item will be freed */
835 g_source_destroy(item->data);
836 item = next;
838 /* don't free the list here, it is allocated inside each source's data */
842 static gboolean is_active_plugin(Plugin *plugin)
844 return (g_list_find(active_plugin_list, plugin) != NULL);
848 /* Clean up anything used by an active plugin */
849 static void
850 plugin_cleanup(Plugin *plugin)
852 GtkWidget *widget;
854 if (plugin->cleanup)
855 plugin->cleanup();
857 remove_callbacks(plugin);
858 remove_sources(plugin);
860 if (plugin->key_group)
861 keybindings_free_group(plugin->key_group);
863 widget = plugin->toolbar_separator.widget;
864 if (widget)
865 gtk_widget_destroy(widget);
867 geany_debug("Unloaded: %s", plugin->filename);
871 static void
872 plugin_free(Plugin *plugin)
874 g_return_if_fail(plugin);
875 g_return_if_fail(plugin->module);
877 if (is_active_plugin(plugin))
878 plugin_cleanup(plugin);
880 active_plugin_list = g_list_remove(active_plugin_list, plugin);
882 if (! g_module_close(plugin->module))
883 g_warning("%s: %s", plugin->filename, g_module_error());
885 plugin_list = g_list_remove(plugin_list, plugin);
887 g_free(plugin->filename);
888 g_free(plugin);
889 plugin = NULL;
893 static gchar *get_custom_plugin_path(const gchar *plugin_path_config,
894 const gchar *plugin_path_system)
896 gchar *plugin_path_custom;
898 if (EMPTY(prefs.custom_plugin_path))
899 return NULL;
901 plugin_path_custom = utils_get_locale_from_utf8(prefs.custom_plugin_path);
902 utils_tidy_path(plugin_path_custom);
904 /* check whether the custom plugin path is one of the system or user plugin paths
905 * and abort if so */
906 if (utils_str_equal(plugin_path_custom, plugin_path_config) ||
907 utils_str_equal(plugin_path_custom, plugin_path_system))
909 g_free(plugin_path_custom);
910 return NULL;
912 return plugin_path_custom;
916 /* all 3 paths Geany looks for plugins in can change (even system path on Windows)
917 * so we need to check active plugins are in the right place before loading */
918 static gboolean check_plugin_path(const gchar *fname)
920 gchar *plugin_path_config;
921 gchar *plugin_path_system;
922 gchar *plugin_path_custom;
923 gboolean ret = FALSE;
925 plugin_path_config = g_build_filename(app->configdir, "plugins", NULL);
926 if (g_str_has_prefix(fname, plugin_path_config))
927 ret = TRUE;
929 plugin_path_system = get_plugin_path();
930 if (g_str_has_prefix(fname, plugin_path_system))
931 ret = TRUE;
933 plugin_path_custom = get_custom_plugin_path(plugin_path_config, plugin_path_system);
934 if (plugin_path_custom)
936 if (g_str_has_prefix(fname, plugin_path_custom))
937 ret = TRUE;
939 g_free(plugin_path_custom);
941 g_free(plugin_path_config);
942 g_free(plugin_path_system);
943 return ret;
947 /* load active plugins at startup */
948 static void
949 load_active_plugins(void)
951 guint i, len;
953 if (active_plugins_pref == NULL || (len = g_strv_length(active_plugins_pref)) == 0)
954 return;
956 for (i = 0; i < len; i++)
958 const gchar *fname = active_plugins_pref[i];
960 if (!EMPTY(fname) && g_file_test(fname, G_FILE_TEST_EXISTS))
962 if (!check_plugin_path(fname) || plugin_new(fname, TRUE, FALSE) == NULL)
963 failed_plugins_list = g_list_prepend(failed_plugins_list, g_strdup(fname));
969 static void
970 load_plugins_from_path(const gchar *path)
972 GSList *list, *item;
973 gchar *fname, *tmp;
974 gint count = 0;
976 list = utils_get_file_list(path, NULL, NULL);
978 for (item = list; item != NULL; item = g_slist_next(item))
980 tmp = strrchr(item->data, '.');
981 if (tmp == NULL || utils_str_casecmp(tmp, "." G_MODULE_SUFFIX) != 0)
982 continue;
984 fname = g_build_filename(path, item->data, NULL);
985 if (plugin_new(fname, FALSE, TRUE))
986 count++;
987 g_free(fname);
990 g_slist_foreach(list, (GFunc) g_free, NULL);
991 g_slist_free(list);
993 if (count)
994 geany_debug("Added %d plugin(s) in '%s'.", count, path);
998 static gchar *get_plugin_path(void)
1000 #ifdef G_OS_WIN32
1001 gchar *path;
1002 gchar *install_dir = win32_get_installation_dir();
1004 path = g_build_filename(install_dir, "lib", NULL);
1005 g_free(install_dir);
1007 return path;
1008 #else
1009 return g_build_filename(GEANY_LIBDIR, "geany", NULL);
1010 #endif
1014 /* Load (but don't initialize) all plugins for the Plugin Manager dialog */
1015 static void load_all_plugins(void)
1017 gchar *plugin_path_config;
1018 gchar *plugin_path_system;
1019 gchar *plugin_path_custom;
1021 plugin_path_config = g_build_filename(app->configdir, "plugins", NULL);
1022 plugin_path_system = get_plugin_path();
1024 /* first load plugins in ~/.config/geany/plugins/ */
1025 load_plugins_from_path(plugin_path_config);
1027 /* load plugins from a custom path */
1028 plugin_path_custom = get_custom_plugin_path(plugin_path_config, plugin_path_system);
1029 if (plugin_path_custom)
1031 load_plugins_from_path(plugin_path_custom);
1032 g_free(plugin_path_custom);
1035 /* finally load plugins from $prefix/lib/geany */
1036 load_plugins_from_path(plugin_path_system);
1038 g_free(plugin_path_config);
1039 g_free(plugin_path_system);
1043 static void on_tools_menu_show(GtkWidget *menu_item, G_GNUC_UNUSED gpointer user_data)
1045 GList *item, *list = gtk_container_get_children(GTK_CONTAINER(menu_item));
1046 guint i = 0;
1047 gboolean have_plugin_menu_items = FALSE;
1049 for (item = list; item != NULL; item = g_list_next(item))
1051 if (item->data == menu_separator)
1053 if (i < g_list_length(list) - 1)
1055 have_plugin_menu_items = TRUE;
1056 break;
1059 i++;
1061 g_list_free(list);
1063 ui_widget_show_hide(menu_separator, have_plugin_menu_items);
1067 /* Calling this starts up plugin support */
1068 void plugins_load_active(void)
1070 GtkWidget *widget;
1072 want_plugins = TRUE;
1074 geany_data_init();
1076 widget = gtk_separator_menu_item_new();
1077 gtk_widget_show(widget);
1078 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
1080 widget = gtk_menu_item_new_with_mnemonic(_("_Plugin Manager"));
1081 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
1082 gtk_widget_show(widget);
1083 g_signal_connect(widget, "activate", G_CALLBACK(pm_show_dialog), NULL);
1085 menu_separator = gtk_separator_menu_item_new();
1086 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), menu_separator);
1087 g_signal_connect(main_widgets.tools_menu, "show", G_CALLBACK(on_tools_menu_show), NULL);
1089 load_active_plugins();
1093 /* Update the global active plugins list so it's up-to-date when configuration
1094 * is saved. Called in response to GeanyObject's "save-settings" signal. */
1095 static void update_active_plugins_pref(void)
1097 gint i = 0;
1098 GList *list;
1099 gsize count;
1101 /* if plugins are disabled, don't clear list of active plugins */
1102 if (!want_plugins)
1103 return;
1105 count = g_list_length(active_plugin_list) + g_list_length(failed_plugins_list);
1107 g_strfreev(active_plugins_pref);
1109 if (count == 0)
1111 active_plugins_pref = NULL;
1112 return;
1115 active_plugins_pref = g_new0(gchar*, count + 1);
1117 for (list = g_list_first(active_plugin_list); list != NULL; list = list->next)
1119 Plugin *plugin = list->data;
1121 active_plugins_pref[i] = g_strdup(plugin->filename);
1122 i++;
1124 for (list = g_list_first(failed_plugins_list); list != NULL; list = list->next)
1126 const gchar *fname = list->data;
1128 active_plugins_pref[i] = g_strdup(fname);
1129 i++;
1131 active_plugins_pref[i] = NULL;
1135 /* called even if plugin support is disabled */
1136 void plugins_init(void)
1138 StashGroup *group;
1139 gchar *path;
1141 path = get_plugin_path();
1142 geany_debug("System plugin path: %s", path);
1143 g_free(path);
1145 group = stash_group_new("plugins");
1146 configuration_add_pref_group(group, TRUE);
1148 stash_group_add_toggle_button(group, &prefs.load_plugins,
1149 "load_plugins", TRUE, "check_plugins");
1150 stash_group_add_entry(group, &prefs.custom_plugin_path,
1151 "custom_plugin_path", "", "extra_plugin_path_entry");
1153 g_signal_connect(geany_object, "save-settings", G_CALLBACK(update_active_plugins_pref), NULL);
1154 stash_group_add_string_vector(group, &active_plugins_pref, "active_plugins", NULL);
1158 /* called even if plugin support is disabled */
1159 void plugins_finalize(void)
1161 if (failed_plugins_list != NULL)
1163 g_list_foreach(failed_plugins_list, (GFunc) g_free, NULL);
1164 g_list_free(failed_plugins_list);
1166 if (active_plugin_list != NULL)
1168 g_list_foreach(active_plugin_list, (GFunc) plugin_free, NULL);
1169 g_list_free(active_plugin_list);
1171 g_strfreev(active_plugins_pref);
1175 /* Check whether there are any plugins loaded which provide a configure symbol */
1176 gboolean plugins_have_preferences(void)
1178 GList *item;
1180 if (active_plugin_list == NULL)
1181 return FALSE;
1183 foreach_list(item, active_plugin_list)
1185 Plugin *plugin = item->data;
1186 if (plugin->configure != NULL || plugin->configure_single != NULL)
1187 return TRUE;
1190 return FALSE;
1194 /* Plugin Manager */
1196 enum
1198 PLUGIN_COLUMN_CHECK = 0,
1199 PLUGIN_COLUMN_PLUGIN,
1200 PLUGIN_N_COLUMNS,
1201 PM_BUTTON_KEYBINDINGS,
1202 PM_BUTTON_CONFIGURE,
1203 PM_BUTTON_HELP
1206 typedef struct
1208 GtkWidget *dialog;
1209 GtkWidget *tree;
1210 GtkListStore *store;
1211 GtkWidget *configure_button;
1212 GtkWidget *keybindings_button;
1213 GtkWidget *help_button;
1215 PluginManagerWidgets;
1217 static PluginManagerWidgets pm_widgets;
1220 static void pm_update_buttons(Plugin *p)
1222 gboolean is_active;
1224 is_active = is_active_plugin(p);
1225 gtk_widget_set_sensitive(pm_widgets.configure_button,
1226 (p->configure || p->configure_single) && is_active);
1227 gtk_widget_set_sensitive(pm_widgets.help_button, p->help != NULL && is_active);
1228 gtk_widget_set_sensitive(pm_widgets.keybindings_button,
1229 p->key_group && p->key_group->plugin_key_count > 0 && is_active);
1233 static void pm_selection_changed(GtkTreeSelection *selection, gpointer user_data)
1235 GtkTreeIter iter;
1236 GtkTreeModel *model;
1237 Plugin *p;
1239 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1241 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1243 if (p != NULL)
1244 pm_update_buttons(p);
1249 static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data)
1251 gboolean old_state, state;
1252 gchar *file_name;
1253 GtkTreeIter iter;
1254 GtkTreePath *path = gtk_tree_path_new_from_string(pth);
1255 Plugin *p;
1257 gtk_tree_model_get_iter(GTK_TREE_MODEL(pm_widgets.store), &iter, path);
1258 gtk_tree_path_free(path);
1260 gtk_tree_model_get(GTK_TREE_MODEL(pm_widgets.store), &iter,
1261 PLUGIN_COLUMN_CHECK, &old_state, PLUGIN_COLUMN_PLUGIN, &p, -1);
1263 /* no plugins item */
1264 if (p == NULL)
1265 return;
1267 state = ! old_state; /* toggle the state */
1269 /* save the filename of the plugin */
1270 file_name = g_strdup(p->filename);
1272 /* unload plugin module */
1273 if (!state)
1274 /* save shortcuts (only need this group, but it doesn't take long) */
1275 keybindings_write_to_file();
1277 plugin_free(p);
1279 /* reload plugin module and initialize it if item is checked */
1280 p = plugin_new(file_name, state, TRUE);
1281 if (!p)
1283 /* plugin file may no longer be on disk, or is now incompatible */
1284 gtk_list_store_remove(pm_widgets.store, &iter);
1286 else
1288 if (state)
1289 keybindings_load_keyfile(); /* load shortcuts */
1291 /* update model */
1292 gtk_list_store_set(pm_widgets.store, &iter,
1293 PLUGIN_COLUMN_CHECK, state,
1294 PLUGIN_COLUMN_PLUGIN, p, -1);
1296 /* set again the sensitiveness of the configure and help buttons */
1297 pm_update_buttons(p);
1299 g_free(file_name);
1303 static gboolean pm_treeview_query_tooltip(GtkWidget *widget, gint x, gint y,
1304 gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data)
1306 GtkTreeModel *model;
1307 GtkTreeIter iter;
1308 GtkTreePath *path;
1309 Plugin *p = NULL;
1311 if (! gtk_tree_view_get_tooltip_context(GTK_TREE_VIEW(widget), &x, &y, keyboard_mode,
1312 &model, &path, &iter))
1313 return FALSE;
1315 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1316 if (p != NULL)
1318 gchar *markup;
1319 gchar *details;
1321 details = g_strdup_printf(_("Version:\t%s\nAuthor(s):\t%s\nFilename:\t%s"),
1322 p->info.version, p->info.author, p->filename);
1323 markup = g_markup_printf_escaped("<b>%s</b>\n%s\n<small><i>\n%s</i></small>",
1324 p->info.name, p->info.description, details);
1326 gtk_tooltip_set_markup(tooltip, markup);
1327 gtk_tree_view_set_tooltip_row(GTK_TREE_VIEW(widget), tooltip, path);
1329 g_free(details);
1330 g_free(markup);
1332 gtk_tree_path_free(path);
1334 return p != NULL;
1338 static void pm_treeview_text_cell_data_func(GtkTreeViewColumn *column, GtkCellRenderer *cell,
1339 GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1341 Plugin *p;
1343 gtk_tree_model_get(model, iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1345 if (p == NULL)
1346 g_object_set(cell, "text", _("No plugins available."), NULL);
1347 else
1349 gchar *markup = g_markup_printf_escaped("<b>%s</b>\n%s", p->info.name, p->info.description);
1351 g_object_set(cell, "markup", markup, NULL);
1352 g_free(markup);
1357 static gint pm_tree_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
1358 gpointer user_data)
1360 Plugin *pa, *pb;
1362 gtk_tree_model_get(model, a, PLUGIN_COLUMN_PLUGIN, &pa, -1);
1363 gtk_tree_model_get(model, b, PLUGIN_COLUMN_PLUGIN, &pb, -1);
1365 if (pa && pb)
1366 return strcmp(pa->info.name, pb->info.name);
1367 else
1368 return pa - pb;
1372 static void pm_prepare_treeview(GtkWidget *tree, GtkListStore *store)
1374 GtkCellRenderer *text_renderer, *checkbox_renderer;
1375 GtkTreeViewColumn *column;
1376 GtkTreeIter iter;
1377 GList *list;
1378 GtkTreeSelection *sel;
1380 g_signal_connect(tree, "query-tooltip", G_CALLBACK(pm_treeview_query_tooltip), NULL);
1381 gtk_widget_set_has_tooltip(tree, TRUE);
1382 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
1384 checkbox_renderer = gtk_cell_renderer_toggle_new();
1385 column = gtk_tree_view_column_new_with_attributes(
1386 _("Active"), checkbox_renderer, "active", PLUGIN_COLUMN_CHECK, NULL);
1387 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1388 g_signal_connect(checkbox_renderer, "toggled", G_CALLBACK(pm_plugin_toggled), NULL);
1390 text_renderer = gtk_cell_renderer_text_new();
1391 g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1392 column = gtk_tree_view_column_new_with_attributes(_("Plugin"), text_renderer, NULL);
1393 gtk_tree_view_column_set_cell_data_func(column, text_renderer,
1394 pm_treeview_text_cell_data_func, NULL, NULL);
1395 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1397 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
1398 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
1399 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), PLUGIN_COLUMN_PLUGIN,
1400 pm_tree_sort_func, NULL, NULL);
1401 gtk_tree_sortable_set_sort_column_id(
1402 GTK_TREE_SORTABLE(store), PLUGIN_COLUMN_PLUGIN, GTK_SORT_ASCENDING);
1404 /* selection handling */
1405 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
1406 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
1407 g_signal_connect(sel, "changed", G_CALLBACK(pm_selection_changed), NULL);
1409 list = g_list_first(plugin_list);
1410 if (list == NULL)
1412 gtk_list_store_append(store, &iter);
1413 gtk_list_store_set(store, &iter, PLUGIN_COLUMN_CHECK, FALSE,
1414 PLUGIN_COLUMN_PLUGIN, NULL, -1);
1416 else
1418 Plugin *p;
1419 for (; list != NULL; list = list->next)
1421 p = list->data;
1423 gtk_list_store_append(store, &iter);
1424 gtk_list_store_set(store, &iter,
1425 PLUGIN_COLUMN_CHECK, is_active_plugin(p),
1426 PLUGIN_COLUMN_PLUGIN, p,
1427 -1);
1430 gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
1431 g_object_unref(store);
1435 static void pm_on_plugin_button_clicked(GtkButton *button, gpointer user_data)
1437 GtkTreeModel *model;
1438 GtkTreeSelection *selection;
1439 GtkTreeIter iter;
1440 Plugin *p;
1442 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pm_widgets.tree));
1443 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1445 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1447 if (p != NULL)
1449 if (GPOINTER_TO_INT(user_data) == PM_BUTTON_CONFIGURE)
1450 plugin_show_configure(&p->public);
1451 else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_HELP && p->help != NULL)
1452 p->help();
1453 else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_KEYBINDINGS && p->key_group && p->key_group->plugin_key_count > 0)
1454 keybindings_dialog_show_prefs_scroll(p->info.name);
1460 static void
1461 free_non_active_plugin(gpointer data, gpointer user_data)
1463 Plugin *plugin = data;
1465 /* don't do anything when closing the plugin manager and it is an active plugin */
1466 if (is_active_plugin(plugin))
1467 return;
1469 plugin_free(plugin);
1473 /* Callback when plugin manager dialog closes, only ever has response of
1474 * GTK_RESPONSE_OK or GTK_RESPONSE_DELETE_EVENT and both are treated the same. */
1475 static void pm_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
1477 if (plugin_list != NULL)
1479 /* remove all non-active plugins from the list */
1480 g_list_foreach(plugin_list, free_non_active_plugin, NULL);
1481 g_list_free(plugin_list);
1482 plugin_list = NULL;
1484 gtk_widget_destroy(GTK_WIDGET(dialog));
1486 configuration_save();
1490 static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data)
1492 GtkWidget *vbox, *vbox2, *hbox, *swin, *label;
1494 /* before showing the dialog, we need to create the list of available plugins */
1495 load_all_plugins();
1497 pm_widgets.dialog = gtk_dialog_new_with_buttons(_("Plugins"), GTK_WINDOW(main_widgets.window),
1498 GTK_DIALOG_DESTROY_WITH_PARENT,
1499 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
1500 vbox = ui_dialog_vbox_new(GTK_DIALOG(pm_widgets.dialog));
1501 gtk_widget_set_name(pm_widgets.dialog, "GeanyDialog");
1502 gtk_box_set_spacing(GTK_BOX(vbox), 6);
1504 gtk_window_set_default_size(GTK_WINDOW(pm_widgets.dialog), 500, 450);
1506 pm_widgets.tree = gtk_tree_view_new();
1507 pm_widgets.store = gtk_list_store_new(
1508 PLUGIN_N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_POINTER);
1509 pm_prepare_treeview(pm_widgets.tree, pm_widgets.store);
1511 swin = gtk_scrolled_window_new(NULL, NULL);
1512 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
1513 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1514 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin), GTK_SHADOW_IN);
1515 gtk_container_add(GTK_CONTAINER(swin), pm_widgets.tree);
1517 label = geany_wrap_label_new(_("Choose which plugins should be loaded at startup:"));
1519 pm_widgets.keybindings_button = gtk_button_new_with_label(_("Keybindings"));
1520 gtk_widget_set_sensitive(pm_widgets.keybindings_button, FALSE);
1521 g_signal_connect(pm_widgets.keybindings_button, "clicked",
1522 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_KEYBINDINGS));
1524 pm_widgets.configure_button = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
1525 gtk_widget_set_sensitive(pm_widgets.configure_button, FALSE);
1526 g_signal_connect(pm_widgets.configure_button, "clicked",
1527 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_CONFIGURE));
1529 pm_widgets.help_button = gtk_button_new_from_stock(GTK_STOCK_HELP);
1530 gtk_widget_set_sensitive(pm_widgets.help_button, FALSE);
1531 g_signal_connect(pm_widgets.help_button, "clicked",
1532 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_HELP));
1534 hbox = gtk_hbox_new(FALSE, 0);
1535 gtk_box_set_spacing(GTK_BOX(hbox), 6);
1536 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.keybindings_button, FALSE, FALSE, 0);
1537 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.configure_button, FALSE, FALSE, 0);
1538 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.help_button, FALSE, FALSE, 0);
1540 vbox2 = gtk_vbox_new(FALSE, 3);
1541 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 5);
1542 gtk_box_pack_start(GTK_BOX(vbox2), swin, TRUE, TRUE, 0);
1543 gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, TRUE, 0);
1545 g_signal_connect(pm_widgets.dialog, "response", G_CALLBACK(pm_dialog_response), NULL);
1547 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
1548 gtk_widget_show_all(pm_widgets.dialog);
1552 #endif