Update HACKING for changed doc generation instructions
[geany-mirror.git] / src / plugins.c
blobffa5357ea51af62403261d35110b8d85cb421bfc
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_file,
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
117 static EditorFuncs editor_funcs = {
118 &editor_get_indent_prefs,
119 &editor_create_widget,
120 &editor_indicator_set_on_range,
121 &editor_indicator_set_on_line,
122 &editor_indicator_clear,
123 &editor_set_indent_type,
124 &editor_get_word_at_pos,
125 &editor_get_eol_char_name,
126 &editor_get_eol_char_len,
127 &editor_get_eol_char,
128 &editor_insert_text_block,
129 &editor_get_eol_char_mode,
130 &editor_goto_pos,
131 &editor_find_snippet,
132 &editor_insert_snippet
135 static ScintillaFuncs scintilla_funcs = {
136 &scintilla_send_message,
137 &scintilla_new
140 /* Macro to prevent a duplicate macro being generated in geanyfunctions.h */
141 #define _scintilla_send_message_macro scintilla_send_message
143 static SciFuncs sci_funcs = {
144 &_scintilla_send_message_macro,
145 &sci_send_command,
146 &sci_start_undo_action,
147 &sci_end_undo_action,
148 &sci_set_text,
149 &sci_insert_text,
150 &sci_get_text,
151 &sci_get_length,
152 &sci_get_current_position,
153 &sci_set_current_position,
154 &sci_get_col_from_position,
155 &sci_get_line_from_position,
156 &sci_get_position_from_line,
157 &sci_replace_sel,
158 &sci_get_selected_text,
159 &sci_get_selected_text_length,
160 &sci_get_selection_start,
161 &sci_get_selection_end,
162 &sci_get_selection_mode,
163 &sci_set_selection_mode,
164 &sci_set_selection_start,
165 &sci_set_selection_end,
166 &sci_get_text_range,
167 &sci_get_line,
168 &sci_get_line_length,
169 &sci_get_line_count,
170 &sci_get_line_is_visible,
171 &sci_ensure_line_is_visible,
172 &sci_scroll_caret,
173 &sci_find_matching_brace,
174 &sci_get_style_at,
175 &sci_get_char_at,
176 &sci_get_current_line,
177 &sci_has_selection,
178 &sci_get_tab_width,
179 &sci_indicator_clear,
180 &sci_indicator_set,
181 &sci_get_contents,
182 &sci_get_contents_range,
183 &sci_get_selection_contents,
184 &sci_set_font,
185 &sci_get_line_end_position,
186 &sci_set_target_start,
187 &sci_set_target_end,
188 &sci_replace_target,
189 &sci_set_marker_at_line,
190 &sci_delete_marker_at_line,
191 &sci_is_marker_set_at_line,
192 &sci_goto_line,
193 &sci_find_text,
194 &sci_set_line_indentation,
195 &sci_get_line_indentation,
196 &sci_get_lexer
199 static TemplateFuncs template_funcs = {
200 &templates_get_template_fileheader
203 static UtilsFuncs utils_funcs = {
204 &utils_str_equal,
205 &utils_string_replace_all,
206 &utils_get_file_list,
207 &utils_write_file,
208 &utils_get_locale_from_utf8,
209 &utils_get_utf8_from_locale,
210 &utils_remove_ext_from_filename,
211 &utils_mkdir,
212 &utils_get_setting_boolean,
213 &utils_get_setting_integer,
214 &utils_get_setting_string,
215 &utils_spawn_sync,
216 &utils_spawn_async,
217 &utils_str_casecmp,
218 &utils_get_date_time,
219 &utils_open_browser,
220 &utils_string_replace_first,
221 &utils_str_middle_truncate,
222 &utils_str_remove_chars,
223 &utils_get_file_list_full,
224 &utils_copy_environment,
225 &utils_find_open_xml_tag,
226 &utils_find_open_xml_tag_pos
229 static UIUtilsFuncs uiutils_funcs = {
230 &ui_dialog_vbox_new,
231 &ui_frame_new_with_alignment,
232 &ui_set_statusbar,
233 &ui_table_add_row,
234 &ui_path_box_new,
235 &ui_button_new_with_image,
236 &ui_add_document_sensitive,
237 &ui_widget_set_tooltip_text,
238 &ui_image_menu_item_new,
239 &ui_lookup_widget,
240 &ui_progress_bar_start,
241 &ui_progress_bar_stop,
242 &ui_entry_add_clear_icon,
243 &ui_menu_add_document_items,
244 &ui_widget_modify_font_from_string,
245 &ui_is_keyval_enter_or_return,
246 &ui_get_gtk_settings_integer,
247 &ui_combo_box_add_to_history,
248 &ui_menu_add_document_items_sorted,
249 &ui_lookup_stock_label
252 static DialogFuncs dialog_funcs = {
253 &dialogs_show_question,
254 &dialogs_show_msgbox,
255 &dialogs_show_save_as,
256 &dialogs_show_input_numeric,
257 &dialogs_show_input
260 /* Macro to prevent confusing macro being generated in geanyfunctions.h */
261 #define _lookup_widget_macro ui_lookup_widget
263 /* deprecated */
264 static SupportFuncs support_funcs = {
265 &_lookup_widget_macro
268 static MsgWinFuncs msgwin_funcs = {
269 &msgwin_status_add,
270 &msgwin_compiler_add,
271 &msgwin_msg_add,
272 &msgwin_clear_tab,
273 &msgwin_switch_tab,
274 &msgwin_set_messages_dir
277 static EncodingFuncs encoding_funcs = {
278 &encodings_convert_to_utf8,
279 &encodings_convert_to_utf8_from_charset,
280 &encodings_get_charset_from_index
283 static KeybindingFuncs keybindings_funcs = {
284 &keybindings_send_command,
285 &keybindings_set_item,
286 &keybindings_get_item
289 static TagManagerFuncs tagmanager_funcs = {
290 &tm_get_real_path,
291 &tm_source_file_new,
292 &tm_workspace_add_object,
293 &tm_source_file_update,
294 &tm_work_object_free,
295 &tm_workspace_remove_object
298 static SearchFuncs search_funcs = {
299 &search_show_find_in_files_dialog
302 static HighlightingFuncs highlighting_funcs = {
303 &highlighting_get_style,
304 &highlighting_set_styles,
305 &highlighting_is_string_style,
306 &highlighting_is_comment_style,
307 &highlighting_is_code_style
310 static FiletypeFuncs filetype_funcs = {
311 &filetypes_detect_from_file,
312 &filetypes_lookup_by_name,
313 &filetypes_index,
314 &filetypes_get_display_name,
315 &filetypes_get_sorted_by_name
318 static NavQueueFuncs navqueue_funcs = {
319 &navqueue_goto_line
322 static MainFuncs main_funcs = {
323 &main_reload_configuration,
324 &main_locale_init,
325 &main_is_realized
328 static StashFuncs stash_funcs = {
329 &stash_group_new,
330 &stash_group_add_boolean,
331 &stash_group_add_integer,
332 &stash_group_add_string,
333 &stash_group_add_string_vector,
334 &stash_group_load_from_key_file,
335 &stash_group_save_to_key_file,
336 &stash_group_free,
337 &stash_group_load_from_file,
338 &stash_group_save_to_file,
339 &stash_group_add_toggle_button,
340 &stash_group_add_radio_buttons,
341 &stash_group_add_spin_button_integer,
342 &stash_group_add_combo_box,
343 &stash_group_add_combo_box_entry,
344 &stash_group_add_entry,
345 &stash_group_add_widget_property,
346 &stash_group_display,
347 &stash_group_update,
348 &stash_group_free_settings
351 static SymbolsFuncs symbols_funcs = {
352 &symbols_get_context_separator
355 static BuildFuncs build_funcs = {
356 &build_activate_menu_item,
357 &build_get_current_menu_item,
358 &build_remove_menu_item,
359 &build_set_menu_item,
360 &build_get_group_count
363 static GeanyFunctions geany_functions = {
364 &doc_funcs,
365 &sci_funcs,
366 &template_funcs,
367 &utils_funcs,
368 &uiutils_funcs,
369 &support_funcs,
370 &dialog_funcs,
371 &msgwin_funcs,
372 &encoding_funcs,
373 &keybindings_funcs,
374 &tagmanager_funcs,
375 &search_funcs,
376 &highlighting_funcs,
377 &filetype_funcs,
378 &navqueue_funcs,
379 &editor_funcs,
380 &main_funcs,
381 &plugin_funcs,
382 &scintilla_funcs,
383 &msgwin_funcs,
384 &stash_funcs,
385 &symbols_funcs,
386 &build_funcs
389 static GeanyData geany_data;
392 static void
393 geany_data_init(void)
395 GeanyData gd = {
396 app,
397 &main_widgets,
398 documents_array,
399 filetypes_array,
400 &prefs,
401 &interface_prefs,
402 &toolbar_prefs,
403 &editor_prefs,
404 &file_prefs,
405 &search_prefs,
406 &tool_prefs,
407 &template_prefs,
408 &build_info,
409 filetypes_by_title
412 geany_data = gd;
416 /* Prevent the same plugin filename being loaded more than once.
417 * Note: g_module_name always returns the .so name, even when Plugin::filename is a .la file. */
418 static gboolean
419 plugin_loaded(GModule *module)
421 gchar *basename_module, *basename_loaded;
422 GList *item;
424 basename_module = g_path_get_basename(g_module_name(module));
425 for (item = plugin_list; item != NULL; item = g_list_next(item))
427 basename_loaded = g_path_get_basename(
428 g_module_name(((Plugin*)item->data)->module));
430 if (utils_str_equal(basename_module, basename_loaded))
432 g_free(basename_loaded);
433 g_free(basename_module);
434 return TRUE;
436 g_free(basename_loaded);
438 /* Look also through the list of active plugins. This prevents problems when we have the same
439 * plugin in libdir/geany/ AND in configdir/plugins/ and the one in libdir/geany/ is loaded
440 * as active plugin. The plugin manager list would only take the one in configdir/geany/ and
441 * the plugin manager would list both plugins. Additionally, unloading the active plugin
442 * would cause a crash. */
443 for (item = active_plugin_list; item != NULL; item = g_list_next(item))
445 basename_loaded = g_path_get_basename(g_module_name(((Plugin*)item->data)->module));
447 if (utils_str_equal(basename_module, basename_loaded))
449 g_free(basename_loaded);
450 g_free(basename_module);
451 return TRUE;
453 g_free(basename_loaded);
455 g_free(basename_module);
456 return FALSE;
460 static Plugin *find_active_plugin_by_name(const gchar *filename)
462 GList *item;
464 g_return_val_if_fail(filename, FALSE);
466 for (item = active_plugin_list; item != NULL; item = g_list_next(item))
468 if (utils_str_equal(filename, ((Plugin*)item->data)->filename))
469 return item->data;
472 return NULL;
476 static gboolean
477 plugin_check_version(GModule *module)
479 gint (*version_check)(gint) = NULL;
481 g_module_symbol(module, "plugin_version_check", (void *) &version_check);
483 if (G_UNLIKELY(! version_check))
485 geany_debug("Plugin \"%s\" has no plugin_version_check() function - ignoring plugin!",
486 g_module_name(module));
487 return FALSE;
489 else
491 gint result = version_check(GEANY_ABI_VERSION);
493 if (result < 0)
495 msgwin_status_add(_("The plugin \"%s\" is not binary compatible with this "
496 "release of Geany - please recompile it."), g_module_name(module));
497 geany_debug("Plugin \"%s\" is not binary compatible with this "
498 "release of Geany - recompile it.", g_module_name(module));
499 return FALSE;
501 if (result > GEANY_API_VERSION)
503 geany_debug("Plugin \"%s\" requires a newer version of Geany (API >= v%d).",
504 g_module_name(module), result);
505 return FALSE;
508 return TRUE;
512 static void add_callbacks(Plugin *plugin, PluginCallback *callbacks)
514 PluginCallback *cb;
515 guint i, len = 0;
517 while (TRUE)
519 cb = &callbacks[len];
520 if (!cb->signal_name || !cb->callback)
521 break;
522 len++;
524 if (len == 0)
525 return;
527 for (i = 0; i < len; i++)
529 cb = &callbacks[i];
531 plugin_signal_connect(&plugin->public, NULL, cb->signal_name, cb->after,
532 cb->callback, cb->user_data);
537 static void read_key_group(Plugin *plugin)
539 GeanyKeyGroupInfo *p_key_info;
540 GeanyKeyGroup **p_key_group;
542 g_module_symbol(plugin->module, "plugin_key_group_info", (void *) &p_key_info);
543 g_module_symbol(plugin->module, "plugin_key_group", (void *) &p_key_group);
544 if (p_key_info && p_key_group)
546 GeanyKeyGroupInfo *key_info = p_key_info;
548 if (*p_key_group)
549 geany_debug("Ignoring plugin_key_group symbol for plugin '%s' - "
550 "use plugin_set_key_group() instead to allocate keybindings dynamically.",
551 plugin->info.name);
552 else
554 if (key_info->count)
556 GeanyKeyGroup *key_group =
557 plugin_set_key_group(&plugin->public, key_info->name, key_info->count, NULL);
558 if (key_group)
559 *p_key_group = key_group;
561 else
562 geany_debug("Ignoring plugin_key_group_info symbol for plugin '%s' - "
563 "count field is zero. Maybe use plugin_set_key_group() instead?",
564 plugin->info.name);
567 else if (p_key_info || p_key_group)
568 geany_debug("Ignoring only one of plugin_key_group[_info] symbols defined for plugin '%s'. "
569 "Maybe use plugin_set_key_group() instead?",
570 plugin->info.name);
574 static gint cmp_plugin_names(gconstpointer a, gconstpointer b)
576 const Plugin *pa = a;
577 const Plugin *pb = b;
579 return strcmp(pa->info.name, pb->info.name);
583 static void
584 plugin_init(Plugin *plugin)
586 GeanyPlugin **p_geany_plugin;
587 PluginCallback *callbacks;
588 PluginInfo **p_info;
589 PluginFields **plugin_fields;
591 /* set these symbols before plugin_init() is called
592 * we don't set geany_functions and geany_data since they are set directly by plugin_new() */
593 g_module_symbol(plugin->module, "geany_plugin", (void *) &p_geany_plugin);
594 if (p_geany_plugin)
595 *p_geany_plugin = &plugin->public;
596 g_module_symbol(plugin->module, "plugin_info", (void *) &p_info);
597 if (p_info)
598 *p_info = &plugin->info;
599 g_module_symbol(plugin->module, "plugin_fields", (void *) &plugin_fields);
600 if (plugin_fields)
601 *plugin_fields = &plugin->fields;
602 read_key_group(plugin);
604 /* start the plugin */
605 g_return_if_fail(plugin->init);
606 plugin->init(&geany_data);
608 /* store some function pointers for later use */
609 g_module_symbol(plugin->module, "plugin_configure", (void *) &plugin->configure);
610 g_module_symbol(plugin->module, "plugin_configure_single", (void *) &plugin->configure_single);
611 if (app->debug_mode && plugin->configure && plugin->configure_single)
612 g_warning("Plugin '%s' implements plugin_configure_single() unnecessarily - "
613 "only plugin_configure() will be used!",
614 plugin->info.name);
616 g_module_symbol(plugin->module, "plugin_help", (void *) &plugin->help);
617 g_module_symbol(plugin->module, "plugin_cleanup", (void *) &plugin->cleanup);
618 if (plugin->cleanup == NULL)
620 if (app->debug_mode)
621 g_warning("Plugin '%s' has no plugin_cleanup() function - there may be memory leaks!",
622 plugin->info.name);
625 /* now read any plugin-owned data that might have been set in plugin_init() */
627 if (plugin->fields.flags & PLUGIN_IS_DOCUMENT_SENSITIVE)
629 ui_add_document_sensitive(plugin->fields.menu_item);
632 g_module_symbol(plugin->module, "plugin_callbacks", (void *) &callbacks);
633 if (callbacks)
634 add_callbacks(plugin, callbacks);
636 /* remember which plugins are active.
637 * keep list sorted so tools menu items and plugin preference tabs are
638 * sorted by plugin name */
639 active_plugin_list = g_list_insert_sorted(active_plugin_list, plugin, cmp_plugin_names);
641 geany_debug("Loaded: %s (%s)", plugin->filename,
642 FALLBACK(plugin->info.name, "<Unknown>"));
646 /* Load and optionally init a plugin.
647 * init_plugin decides whether the plugin's plugin_init() function should be called or not. If it is
648 * called, the plugin will be started, if not the plugin will be read only (for the list of
649 * available plugins in the plugin manager).
650 * When add_to_list is set, the plugin will be added to the plugin manager's plugin_list. */
651 static Plugin*
652 plugin_new(const gchar *fname, gboolean init_plugin, gboolean add_to_list)
654 Plugin *plugin;
655 GModule *module;
656 GeanyData **p_geany_data;
657 GeanyFunctions **p_geany_functions;
658 void (*plugin_set_info)(PluginInfo*);
660 g_return_val_if_fail(fname, NULL);
661 g_return_val_if_fail(g_module_supported(), NULL);
663 /* find the plugin in the list of already loaded, active plugins and use it, otherwise
664 * load the module */
665 plugin = find_active_plugin_by_name(fname);
666 if (plugin != NULL)
668 geany_debug("Plugin \"%s\" already loaded.", fname);
669 if (add_to_list)
671 /* do not add to the list twice */
672 if (g_list_find(plugin_list, plugin) != NULL)
673 return NULL;
675 plugin_list = g_list_prepend(plugin_list, plugin);
677 return plugin;
680 /* Don't use G_MODULE_BIND_LAZY otherwise we can get unresolved symbols at runtime,
681 * causing a segfault. Without that flag the module will safely fail to load.
682 * G_MODULE_BIND_LOCAL also helps find undefined symbols e.g. app when it would
683 * otherwise not be detected due to the shadowing of Geany's app variable.
684 * Also without G_MODULE_BIND_LOCAL calling public functions e.g. the old info()
685 * function from a plugin will be shadowed. */
686 module = g_module_open(fname, G_MODULE_BIND_LOCAL);
687 if (! module)
689 geany_debug("Can't load plugin: %s", g_module_error());
690 return NULL;
693 if (plugin_loaded(module))
695 geany_debug("Plugin \"%s\" already loaded.", fname);
697 if (! g_module_close(module))
698 g_warning("%s: %s", fname, g_module_error());
699 return NULL;
702 if (! plugin_check_version(module))
704 if (! g_module_close(module))
705 g_warning("%s: %s", fname, g_module_error());
706 return NULL;
709 g_module_symbol(module, "plugin_set_info", (void *) &plugin_set_info);
710 if (plugin_set_info == NULL)
712 geany_debug("No plugin_set_info() defined for \"%s\" - ignoring plugin!", fname);
714 if (! g_module_close(module))
715 g_warning("%s: %s", fname, g_module_error());
716 return NULL;
719 plugin = g_new0(Plugin, 1);
721 /* set basic fields here to allow plugins to call Geany functions in set_info() */
722 g_module_symbol(module, "geany_data", (void *) &p_geany_data);
723 if (p_geany_data)
724 *p_geany_data = &geany_data;
725 g_module_symbol(module, "geany_functions", (void *) &p_geany_functions);
726 if (p_geany_functions)
727 *p_geany_functions = &geany_functions;
729 /* read plugin name, etc. */
730 plugin_set_info(&plugin->info);
731 if (G_UNLIKELY(EMPTY(plugin->info.name)))
733 geany_debug("No plugin name set in plugin_set_info() for \"%s\" - ignoring plugin!",
734 fname);
736 if (! g_module_close(module))
737 g_warning("%s: %s", fname, g_module_error());
738 g_free(plugin);
739 return NULL;
742 g_module_symbol(module, "plugin_init", (void *) &plugin->init);
743 if (plugin->init == NULL)
745 geany_debug("Plugin '%s' has no plugin_init() function - ignoring plugin!",
746 plugin->info.name);
748 if (! g_module_close(module))
749 g_warning("%s: %s", fname, g_module_error());
750 g_free(plugin);
751 return NULL;
753 /*geany_debug("Initializing plugin '%s'", plugin->info.name);*/
755 plugin->filename = g_strdup(fname);
756 plugin->module = module;
757 plugin->public.info = &plugin->info;
758 plugin->public.priv = plugin;
760 if (init_plugin)
761 plugin_init(plugin);
763 if (add_to_list)
764 plugin_list = g_list_prepend(plugin_list, plugin);
766 return plugin;
770 static void on_object_weak_notify(gpointer data, GObject *old_ptr)
772 Plugin *plugin = data;
773 guint i = 0;
775 g_return_if_fail(plugin && plugin->signal_ids);
777 for (i = 0; i < plugin->signal_ids->len; i++)
779 SignalConnection *sc = &g_array_index(plugin->signal_ids, SignalConnection, i);
781 if (sc->object == old_ptr)
783 g_array_remove_index_fast(plugin->signal_ids, i);
784 /* we can break the loop right after finding the first match,
785 * because we will get one notification per connected signal */
786 break;
792 /* add an object to watch for destruction, and release pointers to it when destroyed.
793 * this should only be used by plugin_signal_connect() to add a watch on
794 * the object lifetime and nuke out references to it in plugin->signal_ids */
795 void plugin_watch_object(Plugin *plugin, gpointer object)
797 g_object_weak_ref(object, on_object_weak_notify, plugin);
801 static void remove_callbacks(Plugin *plugin)
803 GArray *signal_ids = plugin->signal_ids;
804 SignalConnection *sc;
806 if (signal_ids == NULL)
807 return;
809 foreach_array(SignalConnection, sc, signal_ids)
811 g_signal_handler_disconnect(sc->object, sc->handler_id);
812 g_object_weak_unref(sc->object, on_object_weak_notify, plugin);
815 g_array_free(signal_ids, TRUE);
819 static void remove_sources(Plugin *plugin)
821 GList *item;
823 item = plugin->sources;
824 while (item != NULL)
826 GList *next = item->next; /* cache the next pointer because current item will be freed */
828 g_source_destroy(item->data);
829 item = next;
831 /* don't free the list here, it is allocated inside each source's data */
835 static gboolean is_active_plugin(Plugin *plugin)
837 return (g_list_find(active_plugin_list, plugin) != NULL);
841 /* Clean up anything used by an active plugin */
842 static void
843 plugin_cleanup(Plugin *plugin)
845 GtkWidget *widget;
847 if (plugin->cleanup)
848 plugin->cleanup();
850 remove_callbacks(plugin);
851 remove_sources(plugin);
853 if (plugin->key_group)
854 keybindings_free_group(plugin->key_group);
856 widget = plugin->toolbar_separator.widget;
857 if (widget)
858 gtk_widget_destroy(widget);
860 geany_debug("Unloaded: %s", plugin->filename);
864 static void
865 plugin_free(Plugin *plugin)
867 g_return_if_fail(plugin);
868 g_return_if_fail(plugin->module);
870 if (is_active_plugin(plugin))
871 plugin_cleanup(plugin);
873 active_plugin_list = g_list_remove(active_plugin_list, plugin);
875 if (! g_module_close(plugin->module))
876 g_warning("%s: %s", plugin->filename, g_module_error());
878 plugin_list = g_list_remove(plugin_list, plugin);
880 g_free(plugin->filename);
881 g_free(plugin);
882 plugin = NULL;
886 static gchar *get_custom_plugin_path(const gchar *plugin_path_config,
887 const gchar *plugin_path_system)
889 gchar *plugin_path_custom;
891 if (EMPTY(prefs.custom_plugin_path))
892 return NULL;
894 plugin_path_custom = utils_get_locale_from_utf8(prefs.custom_plugin_path);
895 utils_tidy_path(plugin_path_custom);
897 /* check whether the custom plugin path is one of the system or user plugin paths
898 * and abort if so */
899 if (utils_str_equal(plugin_path_custom, plugin_path_config) ||
900 utils_str_equal(plugin_path_custom, plugin_path_system))
902 g_free(plugin_path_custom);
903 return NULL;
905 return plugin_path_custom;
909 /* all 3 paths Geany looks for plugins in can change (even system path on Windows)
910 * so we need to check active plugins are in the right place before loading */
911 static gboolean check_plugin_path(const gchar *fname)
913 gchar *plugin_path_config;
914 gchar *plugin_path_system;
915 gchar *plugin_path_custom;
916 gboolean ret = FALSE;
918 plugin_path_config = g_build_filename(app->configdir, "plugins", NULL);
919 if (g_str_has_prefix(fname, plugin_path_config))
920 ret = TRUE;
922 plugin_path_system = get_plugin_path();
923 if (g_str_has_prefix(fname, plugin_path_system))
924 ret = TRUE;
926 plugin_path_custom = get_custom_plugin_path(plugin_path_config, plugin_path_system);
927 if (plugin_path_custom)
929 if (g_str_has_prefix(fname, plugin_path_custom))
930 ret = TRUE;
932 g_free(plugin_path_custom);
934 g_free(plugin_path_config);
935 g_free(plugin_path_system);
936 return ret;
940 /* load active plugins at startup */
941 static void
942 load_active_plugins(void)
944 guint i, len;
946 if (active_plugins_pref == NULL || (len = g_strv_length(active_plugins_pref)) == 0)
947 return;
949 for (i = 0; i < len; i++)
951 const gchar *fname = active_plugins_pref[i];
953 if (!EMPTY(fname) && g_file_test(fname, G_FILE_TEST_EXISTS))
955 if (!check_plugin_path(fname) || plugin_new(fname, TRUE, FALSE) == NULL)
956 failed_plugins_list = g_list_prepend(failed_plugins_list, g_strdup(fname));
962 static void
963 load_plugins_from_path(const gchar *path)
965 GSList *list, *item;
966 gchar *fname, *tmp;
967 gint count = 0;
969 list = utils_get_file_list(path, NULL, NULL);
971 for (item = list; item != NULL; item = g_slist_next(item))
973 tmp = strrchr(item->data, '.');
974 if (tmp == NULL || utils_str_casecmp(tmp, "." G_MODULE_SUFFIX) != 0)
975 continue;
977 fname = g_build_filename(path, item->data, NULL);
978 if (plugin_new(fname, FALSE, TRUE))
979 count++;
980 g_free(fname);
983 g_slist_foreach(list, (GFunc) g_free, NULL);
984 g_slist_free(list);
986 if (count)
987 geany_debug("Added %d plugin(s) in '%s'.", count, path);
991 static gchar *get_plugin_path(void)
993 #ifdef G_OS_WIN32
994 gchar *path;
995 gchar *install_dir = win32_get_installation_dir();
997 path = g_build_filename(install_dir, "lib", NULL);
998 g_free(install_dir);
1000 return path;
1001 #else
1002 return g_build_filename(GEANY_LIBDIR, "geany", NULL);
1003 #endif
1007 /* Load (but don't initialize) all plugins for the Plugin Manager dialog */
1008 static void load_all_plugins(void)
1010 gchar *plugin_path_config;
1011 gchar *plugin_path_system;
1012 gchar *plugin_path_custom;
1014 plugin_path_config = g_build_filename(app->configdir, "plugins", NULL);
1015 plugin_path_system = get_plugin_path();
1017 /* first load plugins in ~/.config/geany/plugins/ */
1018 load_plugins_from_path(plugin_path_config);
1020 /* load plugins from a custom path */
1021 plugin_path_custom = get_custom_plugin_path(plugin_path_config, plugin_path_system);
1022 if (plugin_path_custom)
1024 load_plugins_from_path(plugin_path_custom);
1025 g_free(plugin_path_custom);
1028 /* finally load plugins from $prefix/lib/geany */
1029 load_plugins_from_path(plugin_path_system);
1031 g_free(plugin_path_config);
1032 g_free(plugin_path_system);
1036 static void on_tools_menu_show(GtkWidget *menu_item, G_GNUC_UNUSED gpointer user_data)
1038 GList *item, *list = gtk_container_get_children(GTK_CONTAINER(menu_item));
1039 guint i = 0;
1040 gboolean have_plugin_menu_items = FALSE;
1042 for (item = list; item != NULL; item = g_list_next(item))
1044 if (item->data == menu_separator)
1046 if (i < g_list_length(list) - 1)
1048 have_plugin_menu_items = TRUE;
1049 break;
1052 i++;
1054 g_list_free(list);
1056 ui_widget_show_hide(menu_separator, have_plugin_menu_items);
1060 /* Calling this starts up plugin support */
1061 void plugins_load_active(void)
1063 GtkWidget *widget;
1065 want_plugins = TRUE;
1067 geany_data_init();
1069 widget = gtk_separator_menu_item_new();
1070 gtk_widget_show(widget);
1071 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
1073 widget = gtk_menu_item_new_with_mnemonic(_("_Plugin Manager"));
1074 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
1075 gtk_widget_show(widget);
1076 g_signal_connect(widget, "activate", G_CALLBACK(pm_show_dialog), NULL);
1078 menu_separator = gtk_separator_menu_item_new();
1079 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), menu_separator);
1080 g_signal_connect(main_widgets.tools_menu, "show", G_CALLBACK(on_tools_menu_show), NULL);
1082 load_active_plugins();
1086 /* Update the global active plugins list so it's up-to-date when configuration
1087 * is saved. Called in response to GeanyObject's "save-settings" signal. */
1088 static void update_active_plugins_pref(void)
1090 gint i = 0;
1091 GList *list;
1092 gsize count;
1094 /* if plugins are disabled, don't clear list of active plugins */
1095 if (!want_plugins)
1096 return;
1098 count = g_list_length(active_plugin_list) + g_list_length(failed_plugins_list);
1100 g_strfreev(active_plugins_pref);
1102 if (count == 0)
1104 active_plugins_pref = NULL;
1105 return;
1108 active_plugins_pref = g_new0(gchar*, count + 1);
1110 for (list = g_list_first(active_plugin_list); list != NULL; list = list->next)
1112 Plugin *plugin = list->data;
1114 active_plugins_pref[i] = g_strdup(plugin->filename);
1115 i++;
1117 for (list = g_list_first(failed_plugins_list); list != NULL; list = list->next)
1119 const gchar *fname = list->data;
1121 active_plugins_pref[i] = g_strdup(fname);
1122 i++;
1124 active_plugins_pref[i] = NULL;
1128 /* called even if plugin support is disabled */
1129 void plugins_init(void)
1131 StashGroup *group;
1132 gchar *path;
1134 path = get_plugin_path();
1135 geany_debug("System plugin path: %s", path);
1136 g_free(path);
1138 group = stash_group_new("plugins");
1139 configuration_add_pref_group(group, TRUE);
1141 stash_group_add_toggle_button(group, &prefs.load_plugins,
1142 "load_plugins", TRUE, "check_plugins");
1143 stash_group_add_entry(group, &prefs.custom_plugin_path,
1144 "custom_plugin_path", "", "extra_plugin_path_entry");
1146 g_signal_connect(geany_object, "save-settings", G_CALLBACK(update_active_plugins_pref), NULL);
1147 stash_group_add_string_vector(group, &active_plugins_pref, "active_plugins", NULL);
1151 /* called even if plugin support is disabled */
1152 void plugins_finalize(void)
1154 if (failed_plugins_list != NULL)
1156 g_list_foreach(failed_plugins_list, (GFunc) g_free, NULL);
1157 g_list_free(failed_plugins_list);
1159 if (active_plugin_list != NULL)
1161 g_list_foreach(active_plugin_list, (GFunc) plugin_free, NULL);
1162 g_list_free(active_plugin_list);
1164 g_strfreev(active_plugins_pref);
1168 /* Check whether there are any plugins loaded which provide a configure symbol */
1169 gboolean plugins_have_preferences(void)
1171 GList *item;
1173 if (active_plugin_list == NULL)
1174 return FALSE;
1176 foreach_list(item, active_plugin_list)
1178 Plugin *plugin = item->data;
1179 if (plugin->configure != NULL || plugin->configure_single != NULL)
1180 return TRUE;
1183 return FALSE;
1187 /* Plugin Manager */
1189 enum
1191 PLUGIN_COLUMN_CHECK = 0,
1192 PLUGIN_COLUMN_PLUGIN,
1193 PLUGIN_N_COLUMNS,
1194 PM_BUTTON_KEYBINDINGS,
1195 PM_BUTTON_CONFIGURE,
1196 PM_BUTTON_HELP
1199 typedef struct
1201 GtkWidget *dialog;
1202 GtkWidget *tree;
1203 GtkListStore *store;
1204 GtkWidget *configure_button;
1205 GtkWidget *keybindings_button;
1206 GtkWidget *help_button;
1208 PluginManagerWidgets;
1210 static PluginManagerWidgets pm_widgets;
1213 static void pm_update_buttons(Plugin *p)
1215 gboolean is_active;
1217 is_active = is_active_plugin(p);
1218 gtk_widget_set_sensitive(pm_widgets.configure_button,
1219 (p->configure || p->configure_single) && is_active);
1220 gtk_widget_set_sensitive(pm_widgets.help_button, p->help != NULL && is_active);
1221 gtk_widget_set_sensitive(pm_widgets.keybindings_button,
1222 p->key_group && p->key_group->plugin_key_count > 0 && is_active);
1226 static void pm_selection_changed(GtkTreeSelection *selection, gpointer user_data)
1228 GtkTreeIter iter;
1229 GtkTreeModel *model;
1230 Plugin *p;
1232 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1234 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1236 if (p != NULL)
1237 pm_update_buttons(p);
1242 static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data)
1244 gboolean old_state, state;
1245 gchar *file_name;
1246 GtkTreeIter iter;
1247 GtkTreePath *path = gtk_tree_path_new_from_string(pth);
1248 Plugin *p;
1250 gtk_tree_model_get_iter(GTK_TREE_MODEL(pm_widgets.store), &iter, path);
1251 gtk_tree_path_free(path);
1253 gtk_tree_model_get(GTK_TREE_MODEL(pm_widgets.store), &iter,
1254 PLUGIN_COLUMN_CHECK, &old_state, PLUGIN_COLUMN_PLUGIN, &p, -1);
1256 /* no plugins item */
1257 if (p == NULL)
1258 return;
1260 state = ! old_state; /* toggle the state */
1262 /* save the filename of the plugin */
1263 file_name = g_strdup(p->filename);
1265 /* unload plugin module */
1266 if (!state)
1267 /* save shortcuts (only need this group, but it doesn't take long) */
1268 keybindings_write_to_file();
1270 plugin_free(p);
1272 /* reload plugin module and initialize it if item is checked */
1273 p = plugin_new(file_name, state, TRUE);
1274 if (!p)
1276 /* plugin file may no longer be on disk, or is now incompatible */
1277 gtk_list_store_remove(pm_widgets.store, &iter);
1279 else
1281 if (state)
1282 keybindings_load_keyfile(); /* load shortcuts */
1284 /* update model */
1285 gtk_list_store_set(pm_widgets.store, &iter,
1286 PLUGIN_COLUMN_CHECK, state,
1287 PLUGIN_COLUMN_PLUGIN, p, -1);
1289 /* set again the sensitiveness of the configure and help buttons */
1290 pm_update_buttons(p);
1292 g_free(file_name);
1296 static gboolean pm_treeview_query_tooltip(GtkWidget *widget, gint x, gint y,
1297 gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data)
1299 GtkTreeModel *model;
1300 GtkTreeIter iter;
1301 GtkTreePath *path;
1302 Plugin *p = NULL;
1304 if (! gtk_tree_view_get_tooltip_context(GTK_TREE_VIEW(widget), &x, &y, keyboard_mode,
1305 &model, &path, &iter))
1306 return FALSE;
1308 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1309 if (p != NULL)
1311 gchar *markup;
1312 gchar *details;
1314 details = g_strdup_printf(_("Version:\t%s\nAuthor(s):\t%s\nFilename:\t%s"),
1315 p->info.version, p->info.author, p->filename);
1316 markup = g_markup_printf_escaped("<b>%s</b>\n%s\n<small><i>\n%s</i></small>",
1317 p->info.name, p->info.description, details);
1319 gtk_tooltip_set_markup(tooltip, markup);
1320 gtk_tree_view_set_tooltip_row(GTK_TREE_VIEW(widget), tooltip, path);
1322 g_free(details);
1323 g_free(markup);
1325 gtk_tree_path_free(path);
1327 return p != NULL;
1331 static void pm_treeview_text_cell_data_func(GtkTreeViewColumn *column, GtkCellRenderer *cell,
1332 GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
1334 Plugin *p;
1336 gtk_tree_model_get(model, iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1338 if (p == NULL)
1339 g_object_set(cell, "text", _("No plugins available."), NULL);
1340 else
1342 gchar *markup = g_markup_printf_escaped("<b>%s</b>\n%s", p->info.name, p->info.description);
1344 g_object_set(cell, "markup", markup, NULL);
1345 g_free(markup);
1350 static gint pm_tree_sort_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
1351 gpointer user_data)
1353 Plugin *pa, *pb;
1355 gtk_tree_model_get(model, a, PLUGIN_COLUMN_PLUGIN, &pa, -1);
1356 gtk_tree_model_get(model, b, PLUGIN_COLUMN_PLUGIN, &pb, -1);
1358 if (pa && pb)
1359 return strcmp(pa->info.name, pb->info.name);
1360 else
1361 return pa - pb;
1365 static void pm_prepare_treeview(GtkWidget *tree, GtkListStore *store)
1367 GtkCellRenderer *text_renderer, *checkbox_renderer;
1368 GtkTreeViewColumn *column;
1369 GtkTreeIter iter;
1370 GList *list;
1371 GtkTreeSelection *sel;
1373 g_signal_connect(tree, "query-tooltip", G_CALLBACK(pm_treeview_query_tooltip), NULL);
1374 gtk_widget_set_has_tooltip(tree, TRUE);
1375 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
1377 checkbox_renderer = gtk_cell_renderer_toggle_new();
1378 column = gtk_tree_view_column_new_with_attributes(
1379 _("Active"), checkbox_renderer, "active", PLUGIN_COLUMN_CHECK, NULL);
1380 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1381 g_signal_connect(checkbox_renderer, "toggled", G_CALLBACK(pm_plugin_toggled), NULL);
1383 text_renderer = gtk_cell_renderer_text_new();
1384 g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1385 column = gtk_tree_view_column_new_with_attributes(_("Plugin"), text_renderer, NULL);
1386 gtk_tree_view_column_set_cell_data_func(column, text_renderer,
1387 pm_treeview_text_cell_data_func, NULL, NULL);
1388 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1390 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
1391 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
1392 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), PLUGIN_COLUMN_PLUGIN,
1393 pm_tree_sort_func, NULL, NULL);
1394 gtk_tree_sortable_set_sort_column_id(
1395 GTK_TREE_SORTABLE(store), PLUGIN_COLUMN_PLUGIN, GTK_SORT_ASCENDING);
1397 /* selection handling */
1398 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
1399 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
1400 g_signal_connect(sel, "changed", G_CALLBACK(pm_selection_changed), NULL);
1402 list = g_list_first(plugin_list);
1403 if (list == NULL)
1405 gtk_list_store_append(store, &iter);
1406 gtk_list_store_set(store, &iter, PLUGIN_COLUMN_CHECK, FALSE,
1407 PLUGIN_COLUMN_PLUGIN, NULL, -1);
1409 else
1411 Plugin *p;
1412 for (; list != NULL; list = list->next)
1414 p = list->data;
1416 gtk_list_store_append(store, &iter);
1417 gtk_list_store_set(store, &iter,
1418 PLUGIN_COLUMN_CHECK, is_active_plugin(p),
1419 PLUGIN_COLUMN_PLUGIN, p,
1420 -1);
1423 gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
1424 g_object_unref(store);
1428 static void pm_on_plugin_button_clicked(GtkButton *button, gpointer user_data)
1430 GtkTreeModel *model;
1431 GtkTreeSelection *selection;
1432 GtkTreeIter iter;
1433 Plugin *p;
1435 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pm_widgets.tree));
1436 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1438 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1440 if (p != NULL)
1442 if (GPOINTER_TO_INT(user_data) == PM_BUTTON_CONFIGURE)
1443 plugin_show_configure(&p->public);
1444 else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_HELP && p->help != NULL)
1445 p->help();
1446 else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_KEYBINDINGS && p->key_group && p->key_group->plugin_key_count > 0)
1447 keybindings_dialog_show_prefs_scroll(p->info.name);
1453 static void
1454 free_non_active_plugin(gpointer data, gpointer user_data)
1456 Plugin *plugin = data;
1458 /* don't do anything when closing the plugin manager and it is an active plugin */
1459 if (is_active_plugin(plugin))
1460 return;
1462 plugin_free(plugin);
1466 /* Callback when plugin manager dialog closes, only ever has response of
1467 * GTK_RESPONSE_OK or GTK_RESPONSE_DELETE_EVENT and both are treated the same. */
1468 static void pm_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
1470 if (plugin_list != NULL)
1472 /* remove all non-active plugins from the list */
1473 g_list_foreach(plugin_list, free_non_active_plugin, NULL);
1474 g_list_free(plugin_list);
1475 plugin_list = NULL;
1477 gtk_widget_destroy(GTK_WIDGET(dialog));
1479 configuration_save();
1483 static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data)
1485 GtkWidget *vbox, *vbox2, *hbox, *swin, *label;
1487 /* before showing the dialog, we need to create the list of available plugins */
1488 load_all_plugins();
1490 pm_widgets.dialog = gtk_dialog_new_with_buttons(_("Plugins"), GTK_WINDOW(main_widgets.window),
1491 GTK_DIALOG_DESTROY_WITH_PARENT,
1492 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
1493 vbox = ui_dialog_vbox_new(GTK_DIALOG(pm_widgets.dialog));
1494 gtk_widget_set_name(pm_widgets.dialog, "GeanyDialog");
1495 gtk_box_set_spacing(GTK_BOX(vbox), 6);
1497 gtk_window_set_default_size(GTK_WINDOW(pm_widgets.dialog), 500, 450);
1499 pm_widgets.tree = gtk_tree_view_new();
1500 pm_widgets.store = gtk_list_store_new(
1501 PLUGIN_N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_POINTER);
1502 pm_prepare_treeview(pm_widgets.tree, pm_widgets.store);
1504 swin = gtk_scrolled_window_new(NULL, NULL);
1505 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
1506 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1507 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin), GTK_SHADOW_IN);
1508 gtk_container_add(GTK_CONTAINER(swin), pm_widgets.tree);
1510 label = geany_wrap_label_new(_("Choose which plugins should be loaded at startup:"));
1512 pm_widgets.keybindings_button = gtk_button_new_with_label(_("Keybindings"));
1513 gtk_widget_set_sensitive(pm_widgets.keybindings_button, FALSE);
1514 g_signal_connect(pm_widgets.keybindings_button, "clicked",
1515 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_KEYBINDINGS));
1517 pm_widgets.configure_button = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
1518 gtk_widget_set_sensitive(pm_widgets.configure_button, FALSE);
1519 g_signal_connect(pm_widgets.configure_button, "clicked",
1520 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_CONFIGURE));
1522 pm_widgets.help_button = gtk_button_new_from_stock(GTK_STOCK_HELP);
1523 gtk_widget_set_sensitive(pm_widgets.help_button, FALSE);
1524 g_signal_connect(pm_widgets.help_button, "clicked",
1525 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_HELP));
1527 hbox = gtk_hbox_new(FALSE, 0);
1528 gtk_box_set_spacing(GTK_BOX(hbox), 6);
1529 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.keybindings_button, FALSE, FALSE, 0);
1530 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.configure_button, FALSE, FALSE, 0);
1531 gtk_box_pack_end(GTK_BOX(hbox), pm_widgets.help_button, FALSE, FALSE, 0);
1533 vbox2 = gtk_vbox_new(FALSE, 3);
1534 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 5);
1535 gtk_box_pack_start(GTK_BOX(vbox2), swin, TRUE, TRUE, 0);
1536 gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, TRUE, 0);
1538 g_signal_connect(pm_widgets.dialog, "response", G_CALLBACK(pm_dialog_response), NULL);
1540 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
1541 gtk_widget_show_all(pm_widgets.dialog);
1545 #endif