Don't expose the source file update function to plugins
[geany-mirror.git] / src / plugins.c
blob783a76e4b75e2d840136ee61678f82eee1f4ab89
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 GeanyFunctions geany_functions = {
366 &doc_funcs,
367 &sci_funcs,
368 &template_funcs,
369 &utils_funcs,
370 &uiutils_funcs,
371 &support_funcs,
372 &dialog_funcs,
373 &msgwin_funcs,
374 &encoding_funcs,
375 &keybindings_funcs,
376 &tagmanager_funcs,
377 &search_funcs,
378 &highlighting_funcs,
379 &filetype_funcs,
380 &navqueue_funcs,
381 &editor_funcs,
382 &main_funcs,
383 &plugin_funcs,
384 &scintilla_funcs,
385 &msgwin_funcs,
386 &stash_funcs,
387 &symbols_funcs,
388 &build_funcs
391 static GeanyData geany_data;
394 static void
395 geany_data_init(void)
397 GeanyData gd = {
398 app,
399 &main_widgets,
400 documents_array,
401 filetypes_array,
402 &prefs,
403 &interface_prefs,
404 &toolbar_prefs,
405 &editor_prefs,
406 &file_prefs,
407 &search_prefs,
408 &tool_prefs,
409 &template_prefs,
410 &build_info,
411 filetypes_by_title
414 geany_data = gd;
418 /* Prevent the same plugin filename being loaded more than once.
419 * Note: g_module_name always returns the .so name, even when Plugin::filename is a .la file. */
420 static gboolean
421 plugin_loaded(GModule *module)
423 gchar *basename_module, *basename_loaded;
424 GList *item;
426 basename_module = g_path_get_basename(g_module_name(module));
427 for (item = plugin_list; item != NULL; item = g_list_next(item))
429 basename_loaded = g_path_get_basename(
430 g_module_name(((Plugin*)item->data)->module));
432 if (utils_str_equal(basename_module, basename_loaded))
434 g_free(basename_loaded);
435 g_free(basename_module);
436 return TRUE;
438 g_free(basename_loaded);
440 /* Look also through the list of active plugins. This prevents problems when we have the same
441 * plugin in libdir/geany/ AND in configdir/plugins/ and the one in libdir/geany/ is loaded
442 * as active plugin. The plugin manager list would only take the one in configdir/geany/ and
443 * the plugin manager would list both plugins. Additionally, unloading the active plugin
444 * would cause a crash. */
445 for (item = active_plugin_list; item != NULL; item = g_list_next(item))
447 basename_loaded = g_path_get_basename(g_module_name(((Plugin*)item->data)->module));
449 if (utils_str_equal(basename_module, basename_loaded))
451 g_free(basename_loaded);
452 g_free(basename_module);
453 return TRUE;
455 g_free(basename_loaded);
457 g_free(basename_module);
458 return FALSE;
462 static Plugin *find_active_plugin_by_name(const gchar *filename)
464 GList *item;
466 g_return_val_if_fail(filename, FALSE);
468 for (item = active_plugin_list; item != NULL; item = g_list_next(item))
470 if (utils_str_equal(filename, ((Plugin*)item->data)->filename))
471 return item->data;
474 return NULL;
478 static gboolean
479 plugin_check_version(GModule *module)
481 gint (*version_check)(gint) = NULL;
483 g_module_symbol(module, "plugin_version_check", (void *) &version_check);
485 if (G_UNLIKELY(! version_check))
487 geany_debug("Plugin \"%s\" has no plugin_version_check() function - ignoring plugin!",
488 g_module_name(module));
489 return FALSE;
491 else
493 gint result = version_check(GEANY_ABI_VERSION);
495 if (result < 0)
497 msgwin_status_add(_("The plugin \"%s\" is not binary compatible with this "
498 "release of Geany - please recompile it."), g_module_name(module));
499 geany_debug("Plugin \"%s\" is not binary compatible with this "
500 "release of Geany - recompile it.", g_module_name(module));
501 return FALSE;
503 if (result > GEANY_API_VERSION)
505 geany_debug("Plugin \"%s\" requires a newer version of Geany (API >= v%d).",
506 g_module_name(module), result);
507 return FALSE;
510 return TRUE;
514 static void add_callbacks(Plugin *plugin, PluginCallback *callbacks)
516 PluginCallback *cb;
517 guint i, len = 0;
519 while (TRUE)
521 cb = &callbacks[len];
522 if (!cb->signal_name || !cb->callback)
523 break;
524 len++;
526 if (len == 0)
527 return;
529 for (i = 0; i < len; i++)
531 cb = &callbacks[i];
533 plugin_signal_connect(&plugin->public, NULL, cb->signal_name, cb->after,
534 cb->callback, cb->user_data);
539 static void read_key_group(Plugin *plugin)
541 GeanyKeyGroupInfo *p_key_info;
542 GeanyKeyGroup **p_key_group;
544 g_module_symbol(plugin->module, "plugin_key_group_info", (void *) &p_key_info);
545 g_module_symbol(plugin->module, "plugin_key_group", (void *) &p_key_group);
546 if (p_key_info && p_key_group)
548 GeanyKeyGroupInfo *key_info = p_key_info;
550 if (*p_key_group)
551 geany_debug("Ignoring plugin_key_group symbol for plugin '%s' - "
552 "use plugin_set_key_group() instead to allocate keybindings dynamically.",
553 plugin->info.name);
554 else
556 if (key_info->count)
558 GeanyKeyGroup *key_group =
559 plugin_set_key_group(&plugin->public, key_info->name, key_info->count, NULL);
560 if (key_group)
561 *p_key_group = key_group;
563 else
564 geany_debug("Ignoring plugin_key_group_info symbol for plugin '%s' - "
565 "count field is zero. Maybe use plugin_set_key_group() instead?",
566 plugin->info.name);
569 else if (p_key_info || p_key_group)
570 geany_debug("Ignoring only one of plugin_key_group[_info] symbols defined for plugin '%s'. "
571 "Maybe use plugin_set_key_group() instead?",
572 plugin->info.name);
576 static gint cmp_plugin_names(gconstpointer a, gconstpointer b)
578 const Plugin *pa = a;
579 const Plugin *pb = b;
581 return strcmp(pa->info.name, pb->info.name);
585 static void
586 plugin_init(Plugin *plugin)
588 GeanyPlugin **p_geany_plugin;
589 PluginCallback *callbacks;
590 PluginInfo **p_info;
591 PluginFields **plugin_fields;
593 /* set these symbols before plugin_init() is called
594 * we don't set geany_functions and geany_data since they are set directly by plugin_new() */
595 g_module_symbol(plugin->module, "geany_plugin", (void *) &p_geany_plugin);
596 if (p_geany_plugin)
597 *p_geany_plugin = &plugin->public;
598 g_module_symbol(plugin->module, "plugin_info", (void *) &p_info);
599 if (p_info)
600 *p_info = &plugin->info;
601 g_module_symbol(plugin->module, "plugin_fields", (void *) &plugin_fields);
602 if (plugin_fields)
603 *plugin_fields = &plugin->fields;
604 read_key_group(plugin);
606 /* start the plugin */
607 g_return_if_fail(plugin->init);
608 plugin->init(&geany_data);
610 /* store some function pointers for later use */
611 g_module_symbol(plugin->module, "plugin_configure", (void *) &plugin->configure);
612 g_module_symbol(plugin->module, "plugin_configure_single", (void *) &plugin->configure_single);
613 if (app->debug_mode && plugin->configure && plugin->configure_single)
614 g_warning("Plugin '%s' implements plugin_configure_single() unnecessarily - "
615 "only plugin_configure() will be used!",
616 plugin->info.name);
618 g_module_symbol(plugin->module, "plugin_help", (void *) &plugin->help);
619 g_module_symbol(plugin->module, "plugin_cleanup", (void *) &plugin->cleanup);
620 if (plugin->cleanup == NULL)
622 if (app->debug_mode)
623 g_warning("Plugin '%s' has no plugin_cleanup() function - there may be memory leaks!",
624 plugin->info.name);
627 /* now read any plugin-owned data that might have been set in plugin_init() */
629 if (plugin->fields.flags & PLUGIN_IS_DOCUMENT_SENSITIVE)
631 ui_add_document_sensitive(plugin->fields.menu_item);
634 g_module_symbol(plugin->module, "plugin_callbacks", (void *) &callbacks);
635 if (callbacks)
636 add_callbacks(plugin, callbacks);
638 /* remember which plugins are active.
639 * keep list sorted so tools menu items and plugin preference tabs are
640 * sorted by plugin name */
641 active_plugin_list = g_list_insert_sorted(active_plugin_list, plugin, cmp_plugin_names);
643 geany_debug("Loaded: %s (%s)", plugin->filename,
644 FALLBACK(plugin->info.name, "<Unknown>"));
648 /* Load and optionally init a plugin.
649 * init_plugin decides whether the plugin's plugin_init() function should be called or not. If it is
650 * called, the plugin will be started, if not the plugin will be read only (for the list of
651 * available plugins in the plugin manager).
652 * When add_to_list is set, the plugin will be added to the plugin manager's plugin_list. */
653 static Plugin*
654 plugin_new(const gchar *fname, gboolean init_plugin, gboolean add_to_list)
656 Plugin *plugin;
657 GModule *module;
658 GeanyData **p_geany_data;
659 GeanyFunctions **p_geany_functions;
660 void (*plugin_set_info)(PluginInfo*);
662 g_return_val_if_fail(fname, NULL);
663 g_return_val_if_fail(g_module_supported(), NULL);
665 /* find the plugin in the list of already loaded, active plugins and use it, otherwise
666 * load the module */
667 plugin = find_active_plugin_by_name(fname);
668 if (plugin != NULL)
670 geany_debug("Plugin \"%s\" already loaded.", fname);
671 if (add_to_list)
673 /* do not add to the list twice */
674 if (g_list_find(plugin_list, plugin) != NULL)
675 return NULL;
677 plugin_list = g_list_prepend(plugin_list, plugin);
679 return plugin;
682 /* Don't use G_MODULE_BIND_LAZY otherwise we can get unresolved symbols at runtime,
683 * causing a segfault. Without that flag the module will safely fail to load.
684 * G_MODULE_BIND_LOCAL also helps find undefined symbols e.g. app when it would
685 * otherwise not be detected due to the shadowing of Geany's app variable.
686 * Also without G_MODULE_BIND_LOCAL calling public functions e.g. the old info()
687 * function from a plugin will be shadowed. */
688 module = g_module_open(fname, G_MODULE_BIND_LOCAL);
689 if (! module)
691 geany_debug("Can't load plugin: %s", g_module_error());
692 return NULL;
695 if (plugin_loaded(module))
697 geany_debug("Plugin \"%s\" already loaded.", fname);
699 if (! g_module_close(module))
700 g_warning("%s: %s", fname, g_module_error());
701 return NULL;
704 if (! plugin_check_version(module))
706 if (! g_module_close(module))
707 g_warning("%s: %s", fname, g_module_error());
708 return NULL;
711 g_module_symbol(module, "plugin_set_info", (void *) &plugin_set_info);
712 if (plugin_set_info == NULL)
714 geany_debug("No plugin_set_info() defined for \"%s\" - ignoring plugin!", fname);
716 if (! g_module_close(module))
717 g_warning("%s: %s", fname, g_module_error());
718 return NULL;
721 plugin = g_new0(Plugin, 1);
723 /* set basic fields here to allow plugins to call Geany functions in set_info() */
724 g_module_symbol(module, "geany_data", (void *) &p_geany_data);
725 if (p_geany_data)
726 *p_geany_data = &geany_data;
727 g_module_symbol(module, "geany_functions", (void *) &p_geany_functions);
728 if (p_geany_functions)
729 *p_geany_functions = &geany_functions;
731 /* read plugin name, etc. */
732 plugin_set_info(&plugin->info);
733 if (G_UNLIKELY(EMPTY(plugin->info.name)))
735 geany_debug("No plugin name set in plugin_set_info() for \"%s\" - ignoring plugin!",
736 fname);
738 if (! g_module_close(module))
739 g_warning("%s: %s", fname, g_module_error());
740 g_free(plugin);
741 return NULL;
744 g_module_symbol(module, "plugin_init", (void *) &plugin->init);
745 if (plugin->init == NULL)
747 geany_debug("Plugin '%s' has no plugin_init() function - ignoring plugin!",
748 plugin->info.name);
750 if (! g_module_close(module))
751 g_warning("%s: %s", fname, g_module_error());
752 g_free(plugin);
753 return NULL;
755 /*geany_debug("Initializing plugin '%s'", plugin->info.name);*/
757 plugin->filename = g_strdup(fname);
758 plugin->module = module;
759 plugin->public.info = &plugin->info;
760 plugin->public.priv = plugin;
762 if (init_plugin)
763 plugin_init(plugin);
765 if (add_to_list)
766 plugin_list = g_list_prepend(plugin_list, plugin);
768 return plugin;
772 static void on_object_weak_notify(gpointer data, GObject *old_ptr)
774 Plugin *plugin = data;
775 guint i = 0;
777 g_return_if_fail(plugin && plugin->signal_ids);
779 for (i = 0; i < plugin->signal_ids->len; i++)
781 SignalConnection *sc = &g_array_index(plugin->signal_ids, SignalConnection, i);
783 if (sc->object == old_ptr)
785 g_array_remove_index_fast(plugin->signal_ids, i);
786 /* we can break the loop right after finding the first match,
787 * because we will get one notification per connected signal */
788 break;
794 /* add an object to watch for destruction, and release pointers to it when destroyed.
795 * this should only be used by plugin_signal_connect() to add a watch on
796 * the object lifetime and nuke out references to it in plugin->signal_ids */
797 void plugin_watch_object(Plugin *plugin, gpointer object)
799 g_object_weak_ref(object, on_object_weak_notify, plugin);
803 static void remove_callbacks(Plugin *plugin)
805 GArray *signal_ids = plugin->signal_ids;
806 SignalConnection *sc;
808 if (signal_ids == NULL)
809 return;
811 foreach_array(SignalConnection, sc, signal_ids)
813 g_signal_handler_disconnect(sc->object, sc->handler_id);
814 g_object_weak_unref(sc->object, on_object_weak_notify, plugin);
817 g_array_free(signal_ids, TRUE);
821 static void remove_sources(Plugin *plugin)
823 GList *item;
825 item = plugin->sources;
826 while (item != NULL)
828 GList *next = item->next; /* cache the next pointer because current item will be freed */
830 g_source_destroy(item->data);
831 item = next;
833 /* don't free the list here, it is allocated inside each source's data */
837 static gboolean is_active_plugin(Plugin *plugin)
839 return (g_list_find(active_plugin_list, plugin) != NULL);
843 /* Clean up anything used by an active plugin */
844 static void
845 plugin_cleanup(Plugin *plugin)
847 GtkWidget *widget;
849 if (plugin->cleanup)
850 plugin->cleanup();
852 remove_callbacks(plugin);
853 remove_sources(plugin);
855 if (plugin->key_group)
856 keybindings_free_group(plugin->key_group);
858 widget = plugin->toolbar_separator.widget;
859 if (widget)
860 gtk_widget_destroy(widget);
862 geany_debug("Unloaded: %s", plugin->filename);
866 static void
867 plugin_free(Plugin *plugin)
869 g_return_if_fail(plugin);
870 g_return_if_fail(plugin->module);
872 if (is_active_plugin(plugin))
873 plugin_cleanup(plugin);
875 active_plugin_list = g_list_remove(active_plugin_list, plugin);
877 if (! g_module_close(plugin->module))
878 g_warning("%s: %s", plugin->filename, g_module_error());
880 plugin_list = g_list_remove(plugin_list, plugin);
882 g_free(plugin->filename);
883 g_free(plugin);
884 plugin = NULL;
888 static gchar *get_custom_plugin_path(const gchar *plugin_path_config,
889 const gchar *plugin_path_system)
891 gchar *plugin_path_custom;
893 if (EMPTY(prefs.custom_plugin_path))
894 return NULL;
896 plugin_path_custom = utils_get_locale_from_utf8(prefs.custom_plugin_path);
897 utils_tidy_path(plugin_path_custom);
899 /* check whether the custom plugin path is one of the system or user plugin paths
900 * and abort if so */
901 if (utils_str_equal(plugin_path_custom, plugin_path_config) ||
902 utils_str_equal(plugin_path_custom, plugin_path_system))
904 g_free(plugin_path_custom);
905 return NULL;
907 return plugin_path_custom;
911 /* all 3 paths Geany looks for plugins in can change (even system path on Windows)
912 * so we need to check active plugins are in the right place before loading */
913 static gboolean check_plugin_path(const gchar *fname)
915 gchar *plugin_path_config;
916 gchar *plugin_path_system;
917 gchar *plugin_path_custom;
918 gboolean ret = FALSE;
920 plugin_path_config = g_build_filename(app->configdir, "plugins", NULL);
921 if (g_str_has_prefix(fname, plugin_path_config))
922 ret = TRUE;
924 plugin_path_system = get_plugin_path();
925 if (g_str_has_prefix(fname, plugin_path_system))
926 ret = TRUE;
928 plugin_path_custom = get_custom_plugin_path(plugin_path_config, plugin_path_system);
929 if (plugin_path_custom)
931 if (g_str_has_prefix(fname, plugin_path_custom))
932 ret = TRUE;
934 g_free(plugin_path_custom);
936 g_free(plugin_path_config);
937 g_free(plugin_path_system);
938 return ret;
942 /* load active plugins at startup */
943 static void
944 load_active_plugins(void)
946 guint i, len;
948 if (active_plugins_pref == NULL || (len = g_strv_length(active_plugins_pref)) == 0)
949 return;
951 for (i = 0; i < len; i++)
953 const gchar *fname = active_plugins_pref[i];
955 if (!EMPTY(fname) && g_file_test(fname, G_FILE_TEST_EXISTS))
957 if (!check_plugin_path(fname) || plugin_new(fname, TRUE, FALSE) == NULL)
958 failed_plugins_list = g_list_prepend(failed_plugins_list, g_strdup(fname));
964 static void
965 load_plugins_from_path(const gchar *path)
967 GSList *list, *item;
968 gchar *fname, *tmp;
969 gint count = 0;
971 list = utils_get_file_list(path, NULL, NULL);
973 for (item = list; item != NULL; item = g_slist_next(item))
975 tmp = strrchr(item->data, '.');
976 if (tmp == NULL || utils_str_casecmp(tmp, "." G_MODULE_SUFFIX) != 0)
977 continue;
979 fname = g_build_filename(path, item->data, NULL);
980 if (plugin_new(fname, FALSE, TRUE))
981 count++;
982 g_free(fname);
985 g_slist_foreach(list, (GFunc) g_free, NULL);
986 g_slist_free(list);
988 if (count)
989 geany_debug("Added %d plugin(s) in '%s'.", count, path);
993 static gchar *get_plugin_path(void)
995 #ifdef G_OS_WIN32
996 gchar *path;
997 gchar *install_dir = win32_get_installation_dir();
999 path = g_build_filename(install_dir, "lib", NULL);
1000 g_free(install_dir);
1002 return path;
1003 #else
1004 return g_build_filename(GEANY_LIBDIR, "geany", NULL);
1005 #endif
1009 /* Load (but don't initialize) all plugins for the Plugin Manager dialog */
1010 static void load_all_plugins(void)
1012 gchar *plugin_path_config;
1013 gchar *plugin_path_system;
1014 gchar *plugin_path_custom;
1016 plugin_path_config = g_build_filename(app->configdir, "plugins", NULL);
1017 plugin_path_system = get_plugin_path();
1019 /* first load plugins in ~/.config/geany/plugins/ */
1020 load_plugins_from_path(plugin_path_config);
1022 /* load plugins from a custom path */
1023 plugin_path_custom = get_custom_plugin_path(plugin_path_config, plugin_path_system);
1024 if (plugin_path_custom)
1026 load_plugins_from_path(plugin_path_custom);
1027 g_free(plugin_path_custom);
1030 /* finally load plugins from $prefix/lib/geany */
1031 load_plugins_from_path(plugin_path_system);
1033 g_free(plugin_path_config);
1034 g_free(plugin_path_system);
1038 static void on_tools_menu_show(GtkWidget *menu_item, G_GNUC_UNUSED gpointer user_data)
1040 GList *item, *list = gtk_container_get_children(GTK_CONTAINER(menu_item));
1041 guint i = 0;
1042 gboolean have_plugin_menu_items = FALSE;
1044 for (item = list; item != NULL; item = g_list_next(item))
1046 if (item->data == menu_separator)
1048 if (i < g_list_length(list) - 1)
1050 have_plugin_menu_items = TRUE;
1051 break;
1054 i++;
1056 g_list_free(list);
1058 ui_widget_show_hide(menu_separator, have_plugin_menu_items);
1062 /* Calling this starts up plugin support */
1063 void plugins_load_active(void)
1065 GtkWidget *widget;
1067 want_plugins = TRUE;
1069 geany_data_init();
1071 widget = gtk_separator_menu_item_new();
1072 gtk_widget_show(widget);
1073 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
1075 widget = gtk_menu_item_new_with_mnemonic(_("_Plugin Manager"));
1076 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
1077 gtk_widget_show(widget);
1078 g_signal_connect(widget, "activate", G_CALLBACK(pm_show_dialog), NULL);
1080 menu_separator = gtk_separator_menu_item_new();
1081 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), menu_separator);
1082 g_signal_connect(main_widgets.tools_menu, "show", G_CALLBACK(on_tools_menu_show), NULL);
1084 load_active_plugins();
1088 /* Update the global active plugins list so it's up-to-date when configuration
1089 * is saved. Called in response to GeanyObject's "save-settings" signal. */
1090 static void update_active_plugins_pref(void)
1092 gint i = 0;
1093 GList *list;
1094 gsize count;
1096 /* if plugins are disabled, don't clear list of active plugins */
1097 if (!want_plugins)
1098 return;
1100 count = g_list_length(active_plugin_list) + g_list_length(failed_plugins_list);
1102 g_strfreev(active_plugins_pref);
1104 if (count == 0)
1106 active_plugins_pref = NULL;
1107 return;
1110 active_plugins_pref = g_new0(gchar*, count + 1);
1112 for (list = g_list_first(active_plugin_list); list != NULL; list = list->next)
1114 Plugin *plugin = list->data;
1116 active_plugins_pref[i] = g_strdup(plugin->filename);
1117 i++;
1119 for (list = g_list_first(failed_plugins_list); list != NULL; list = list->next)
1121 const gchar *fname = list->data;
1123 active_plugins_pref[i] = g_strdup(fname);
1124 i++;
1126 active_plugins_pref[i] = NULL;
1130 /* called even if plugin support is disabled */
1131 void plugins_init(void)
1133 StashGroup *group;
1134 gchar *path;
1136 path = get_plugin_path();
1137 geany_debug("System plugin path: %s", path);
1138 g_free(path);
1140 group = stash_group_new("plugins");
1141 configuration_add_pref_group(group, TRUE);
1143 stash_group_add_toggle_button(group, &prefs.load_plugins,
1144 "load_plugins", TRUE, "check_plugins");
1145 stash_group_add_entry(group, &prefs.custom_plugin_path,
1146 "custom_plugin_path", "", "extra_plugin_path_entry");
1148 g_signal_connect(geany_object, "save-settings", G_CALLBACK(update_active_plugins_pref), NULL);
1149 stash_group_add_string_vector(group, &active_plugins_pref, "active_plugins", NULL);
1153 /* called even if plugin support is disabled */
1154 void plugins_finalize(void)
1156 if (failed_plugins_list != NULL)
1158 g_list_foreach(failed_plugins_list, (GFunc) g_free, NULL);
1159 g_list_free(failed_plugins_list);
1161 if (active_plugin_list != NULL)
1163 g_list_foreach(active_plugin_list, (GFunc) plugin_free, NULL);
1164 g_list_free(active_plugin_list);
1166 g_strfreev(active_plugins_pref);
1170 /* Check whether there are any plugins loaded which provide a configure symbol */
1171 gboolean plugins_have_preferences(void)
1173 GList *item;
1175 if (active_plugin_list == NULL)
1176 return FALSE;
1178 foreach_list(item, active_plugin_list)
1180 Plugin *plugin = item->data;
1181 if (plugin->configure != NULL || plugin->configure_single != NULL)
1182 return TRUE;
1185 return FALSE;
1189 /* Plugin Manager */
1191 enum
1193 PLUGIN_COLUMN_CHECK = 0,
1194 PLUGIN_COLUMN_PLUGIN,
1195 PLUGIN_N_COLUMNS,
1196 PM_BUTTON_KEYBINDINGS,
1197 PM_BUTTON_CONFIGURE,
1198 PM_BUTTON_HELP
1201 typedef struct
1203 GtkWidget *dialog;
1204 GtkWidget *tree;
1205 GtkListStore *store;
1206 GtkWidget *configure_button;
1207 GtkWidget *keybindings_button;
1208 GtkWidget *help_button;
1210 PluginManagerWidgets;
1212 static PluginManagerWidgets pm_widgets;
1215 static void pm_update_buttons(Plugin *p)
1217 gboolean is_active;
1219 is_active = is_active_plugin(p);
1220 gtk_widget_set_sensitive(pm_widgets.configure_button,
1221 (p->configure || p->configure_single) && is_active);
1222 gtk_widget_set_sensitive(pm_widgets.help_button, p->help != NULL && is_active);
1223 gtk_widget_set_sensitive(pm_widgets.keybindings_button,
1224 p->key_group && p->key_group->plugin_key_count > 0 && is_active);
1228 static void pm_selection_changed(GtkTreeSelection *selection, gpointer user_data)
1230 GtkTreeIter iter;
1231 GtkTreeModel *model;
1232 Plugin *p;
1234 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1236 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1238 if (p != NULL)
1239 pm_update_buttons(p);
1244 static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data)
1246 gboolean old_state, state;
1247 gchar *file_name;
1248 GtkTreeIter iter;
1249 GtkTreePath *path = gtk_tree_path_new_from_string(pth);
1250 Plugin *p;
1252 gtk_tree_model_get_iter(GTK_TREE_MODEL(pm_widgets.store), &iter, path);
1253 gtk_tree_path_free(path);
1255 gtk_tree_model_get(GTK_TREE_MODEL(pm_widgets.store), &iter,
1256 PLUGIN_COLUMN_CHECK, &old_state, PLUGIN_COLUMN_PLUGIN, &p, -1);
1258 /* no plugins item */
1259 if (p == NULL)
1260 return;
1262 state = ! old_state; /* toggle the state */
1264 /* save the filename of the plugin */
1265 file_name = g_strdup(p->filename);
1267 /* unload plugin module */
1268 if (!state)
1269 /* save shortcuts (only need this group, but it doesn't take long) */
1270 keybindings_write_to_file();
1272 plugin_free(p);
1274 /* reload plugin module and initialize it if item is checked */
1275 p = plugin_new(file_name, state, TRUE);
1276 if (!p)
1278 /* plugin file may no longer be on disk, or is now incompatible */
1279 gtk_list_store_remove(pm_widgets.store, &iter);
1281 else
1283 if (state)
1284 keybindings_load_keyfile(); /* load shortcuts */
1286 /* update model */
1287 gtk_list_store_set(pm_widgets.store, &iter,
1288 PLUGIN_COLUMN_CHECK, state,
1289 PLUGIN_COLUMN_PLUGIN, p, -1);
1291 /* set again the sensitiveness of the configure and help buttons */
1292 pm_update_buttons(p);
1294 g_free(file_name);
1298 static gboolean pm_treeview_query_tooltip(GtkWidget *widget, gint x, gint y,
1299 gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data)
1301 GtkTreeModel *model;
1302 GtkTreeIter iter;
1303 GtkTreePath *path;
1304 Plugin *p = NULL;
1306 if (! gtk_tree_view_get_tooltip_context(GTK_TREE_VIEW(widget), &x, &y, keyboard_mode,
1307 &model, &path, &iter))
1308 return FALSE;
1310 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1311 if (p != NULL)
1313 gchar *markup;
1314 gchar *details;
1316 details = g_strdup_printf(_("Version:\t%s\nAuthor(s):\t%s\nFilename:\t%s"),
1317 p->info.version, p->info.author, p->filename);
1318 markup = g_markup_printf_escaped("<b>%s</b>\n%s\n<small><i>\n%s</i></small>",
1319 p->info.name, p->info.description, details);
1321 gtk_tooltip_set_markup(tooltip, markup);
1322 gtk_tree_view_set_tooltip_row(GTK_TREE_VIEW(widget), tooltip, path);
1324 g_free(details);
1325 g_free(markup);
1327 gtk_tree_path_free(path);
1329 return p != NULL;
1333 static void pm_treeview_text_cell_data_func(GtkTreeViewColumn *column, GtkCellRenderer *cell,
1334 GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1336 Plugin *p;
1338 gtk_tree_model_get(model, iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1340 if (p == NULL)
1341 g_object_set(cell, "text", _("No plugins available."), NULL);
1342 else
1344 gchar *markup = g_markup_printf_escaped("<b>%s</b>\n%s", p->info.name, p->info.description);
1346 g_object_set(cell, "markup", markup, NULL);
1347 g_free(markup);
1352 static gint pm_tree_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
1353 gpointer user_data)
1355 Plugin *pa, *pb;
1357 gtk_tree_model_get(model, a, PLUGIN_COLUMN_PLUGIN, &pa, -1);
1358 gtk_tree_model_get(model, b, PLUGIN_COLUMN_PLUGIN, &pb, -1);
1360 if (pa && pb)
1361 return strcmp(pa->info.name, pb->info.name);
1362 else
1363 return pa - pb;
1367 static void pm_prepare_treeview(GtkWidget *tree, GtkListStore *store)
1369 GtkCellRenderer *text_renderer, *checkbox_renderer;
1370 GtkTreeViewColumn *column;
1371 GtkTreeIter iter;
1372 GList *list;
1373 GtkTreeSelection *sel;
1375 g_signal_connect(tree, "query-tooltip", G_CALLBACK(pm_treeview_query_tooltip), NULL);
1376 gtk_widget_set_has_tooltip(tree, TRUE);
1377 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
1379 checkbox_renderer = gtk_cell_renderer_toggle_new();
1380 column = gtk_tree_view_column_new_with_attributes(
1381 _("Active"), checkbox_renderer, "active", PLUGIN_COLUMN_CHECK, NULL);
1382 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1383 g_signal_connect(checkbox_renderer, "toggled", G_CALLBACK(pm_plugin_toggled), NULL);
1385 text_renderer = gtk_cell_renderer_text_new();
1386 g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1387 column = gtk_tree_view_column_new_with_attributes(_("Plugin"), text_renderer, NULL);
1388 gtk_tree_view_column_set_cell_data_func(column, text_renderer,
1389 pm_treeview_text_cell_data_func, NULL, NULL);
1390 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1392 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
1393 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
1394 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), PLUGIN_COLUMN_PLUGIN,
1395 pm_tree_sort_func, NULL, NULL);
1396 gtk_tree_sortable_set_sort_column_id(
1397 GTK_TREE_SORTABLE(store), PLUGIN_COLUMN_PLUGIN, GTK_SORT_ASCENDING);
1399 /* selection handling */
1400 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
1401 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
1402 g_signal_connect(sel, "changed", G_CALLBACK(pm_selection_changed), NULL);
1404 list = g_list_first(plugin_list);
1405 if (list == NULL)
1407 gtk_list_store_append(store, &iter);
1408 gtk_list_store_set(store, &iter, PLUGIN_COLUMN_CHECK, FALSE,
1409 PLUGIN_COLUMN_PLUGIN, NULL, -1);
1411 else
1413 Plugin *p;
1414 for (; list != NULL; list = list->next)
1416 p = list->data;
1418 gtk_list_store_append(store, &iter);
1419 gtk_list_store_set(store, &iter,
1420 PLUGIN_COLUMN_CHECK, is_active_plugin(p),
1421 PLUGIN_COLUMN_PLUGIN, p,
1422 -1);
1425 gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
1426 g_object_unref(store);
1430 static void pm_on_plugin_button_clicked(GtkButton *button, gpointer user_data)
1432 GtkTreeModel *model;
1433 GtkTreeSelection *selection;
1434 GtkTreeIter iter;
1435 Plugin *p;
1437 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pm_widgets.tree));
1438 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1440 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1442 if (p != NULL)
1444 if (GPOINTER_TO_INT(user_data) == PM_BUTTON_CONFIGURE)
1445 plugin_show_configure(&p->public);
1446 else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_HELP && p->help != NULL)
1447 p->help();
1448 else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_KEYBINDINGS && p->key_group && p->key_group->plugin_key_count > 0)
1449 keybindings_dialog_show_prefs_scroll(p->info.name);
1455 static void
1456 free_non_active_plugin(gpointer data, gpointer user_data)
1458 Plugin *plugin = data;
1460 /* don't do anything when closing the plugin manager and it is an active plugin */
1461 if (is_active_plugin(plugin))
1462 return;
1464 plugin_free(plugin);
1468 /* Callback when plugin manager dialog closes, only ever has response of
1469 * GTK_RESPONSE_OK or GTK_RESPONSE_DELETE_EVENT and both are treated the same. */
1470 static void pm_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
1472 if (plugin_list != NULL)
1474 /* remove all non-active plugins from the list */
1475 g_list_foreach(plugin_list, free_non_active_plugin, NULL);
1476 g_list_free(plugin_list);
1477 plugin_list = NULL;
1479 gtk_widget_destroy(GTK_WIDGET(dialog));
1481 configuration_save();
1485 static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data)
1487 GtkWidget *vbox, *vbox2, *hbox, *swin, *label;
1489 /* before showing the dialog, we need to create the list of available plugins */
1490 load_all_plugins();
1492 pm_widgets.dialog = gtk_dialog_new_with_buttons(_("Plugins"), GTK_WINDOW(main_widgets.window),
1493 GTK_DIALOG_DESTROY_WITH_PARENT,
1494 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
1495 vbox = ui_dialog_vbox_new(GTK_DIALOG(pm_widgets.dialog));
1496 gtk_widget_set_name(pm_widgets.dialog, "GeanyDialog");
1497 gtk_box_set_spacing(GTK_BOX(vbox), 6);
1499 gtk_window_set_default_size(GTK_WINDOW(pm_widgets.dialog), 500, 450);
1501 pm_widgets.tree = gtk_tree_view_new();
1502 pm_widgets.store = gtk_list_store_new(
1503 PLUGIN_N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_POINTER);
1504 pm_prepare_treeview(pm_widgets.tree, pm_widgets.store);
1506 swin = gtk_scrolled_window_new(NULL, NULL);
1507 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
1508 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1509 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin), GTK_SHADOW_IN);
1510 gtk_container_add(GTK_CONTAINER(swin), pm_widgets.tree);
1512 label = geany_wrap_label_new(_("Choose which plugins should be loaded at startup:"));
1514 pm_widgets.keybindings_button = gtk_button_new_with_label(_("Keybindings"));
1515 gtk_widget_set_sensitive(pm_widgets.keybindings_button, FALSE);
1516 g_signal_connect(pm_widgets.keybindings_button, "clicked",
1517 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_KEYBINDINGS));
1519 pm_widgets.configure_button = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
1520 gtk_widget_set_sensitive(pm_widgets.configure_button, FALSE);
1521 g_signal_connect(pm_widgets.configure_button, "clicked",
1522 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_CONFIGURE));
1524 pm_widgets.help_button = gtk_button_new_from_stock(GTK_STOCK_HELP);
1525 gtk_widget_set_sensitive(pm_widgets.help_button, FALSE);
1526 g_signal_connect(pm_widgets.help_button, "clicked",
1527 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_HELP));
1529 hbox = gtk_hbox_new(FALSE, 0);
1530 gtk_box_set_spacing(GTK_BOX(hbox), 6);
1531 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.keybindings_button, FALSE, FALSE, 0);
1532 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.configure_button, FALSE, FALSE, 0);
1533 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.help_button, FALSE, FALSE, 0);
1535 vbox2 = gtk_vbox_new(FALSE, 3);
1536 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 5);
1537 gtk_box_pack_start(GTK_BOX(vbox2), swin, TRUE, TRUE, 0);
1538 gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, TRUE, 0);
1540 g_signal_connect(pm_widgets.dialog, "response", G_CALLBACK(pm_dialog_response), NULL);
1542 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
1543 gtk_widget_show_all(pm_widgets.dialog);
1547 #endif