Update of Russian translation
[geany-mirror.git] / src / plugins.c
blob08523d8907332e34eed99c44ea8981f5d8dce6b9
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 #include "geany.h"
26 #ifdef HAVE_PLUGINS
28 #include <string.h>
30 #include "Scintilla.h"
31 #include "ScintillaWidget.h"
33 #include "prefix.h"
34 #include "plugins.h"
35 #include "plugindata.h"
36 #include "support.h"
37 #include "utils.h"
38 #include "document.h"
39 #include "filetypes.h"
40 #include "templates.h"
41 #include "sciwrappers.h"
42 #include "ui_utils.h"
43 #include "editor.h"
44 #include "dialogs.h"
45 #include "msgwindow.h"
46 #include "prefs.h"
47 #include "geanywraplabel.h"
48 /* #include "build.h" included in plugindata.h so it can use enums */
49 #include "encodings.h"
50 #include "search.h"
51 #include "highlighting.h"
52 #include "keybindings.h"
53 #include "navqueue.h"
54 #include "main.h"
55 #include "toolbar.h"
56 #include "stash.h"
57 #include "symbols.h"
58 #include "keyfile.h"
59 #include "win32.h"
60 #include "pluginutils.h"
61 #include "pluginprivate.h"
64 GList *active_plugin_list = NULL; /* list of only actually loaded plugins, always valid */
67 static gboolean want_plugins = FALSE;
69 /* list of all available, loadable plugins, only valid as long as the plugin manager dialog is
70 * opened, afterwards it will be destroyed */
71 static GList *plugin_list = NULL;
72 static gchar **active_plugins_pref = NULL; /* list of plugin filenames to load at startup */
73 static GList *failed_plugins_list = NULL; /* plugins the user wants active but can't be used */
75 static GtkWidget *menu_separator = NULL;
77 static gchar *get_plugin_path(void);
78 static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data);
81 static PluginFuncs plugin_funcs = {
82 &plugin_add_toolbar_item,
83 &plugin_module_make_resident,
84 &plugin_signal_connect,
85 &plugin_set_key_group,
86 &plugin_show_configure,
87 &plugin_timeout_add,
88 &plugin_timeout_add_seconds,
89 &plugin_idle_add,
90 &plugin_builder_connect_signals
93 static DocumentFuncs doc_funcs = {
94 &document_new_file,
95 &document_get_current,
96 &document_get_from_page,
97 &document_find_by_filename,
98 &document_find_by_real_path,
99 &document_save_file,
100 &document_open_file,
101 &document_open_files,
102 &document_remove_page,
103 &document_reload_file,
104 &document_set_encoding,
105 &document_set_text_changed,
106 &document_set_filetype,
107 &document_close,
108 &document_index,
109 &document_save_file_as,
110 &document_rename_file,
111 &document_get_status_color,
112 &document_get_basename_for_display,
113 &document_get_notebook_page,
114 &document_compare_by_display_name,
115 &document_compare_by_tab_order,
116 &document_compare_by_tab_order_reverse
119 static EditorFuncs editor_funcs = {
120 &editor_get_indent_prefs,
121 &editor_create_widget,
122 &editor_indicator_set_on_range,
123 &editor_indicator_set_on_line,
124 &editor_indicator_clear,
125 &editor_set_indent_type,
126 &editor_get_word_at_pos,
127 &editor_get_eol_char_name,
128 &editor_get_eol_char_len,
129 &editor_get_eol_char,
130 &editor_insert_text_block,
131 &editor_get_eol_char_mode,
132 &editor_goto_pos,
133 &editor_find_snippet,
134 &editor_insert_snippet
137 static ScintillaFuncs scintilla_funcs = {
138 &scintilla_send_message,
139 &scintilla_new
142 /* Macro to prevent a duplicate macro being generated in geanyfunctions.h */
143 #define _scintilla_send_message_macro scintilla_send_message
145 static SciFuncs sci_funcs = {
146 &_scintilla_send_message_macro,
147 &sci_send_command,
148 &sci_start_undo_action,
149 &sci_end_undo_action,
150 &sci_set_text,
151 &sci_insert_text,
152 &sci_get_text,
153 &sci_get_length,
154 &sci_get_current_position,
155 &sci_set_current_position,
156 &sci_get_col_from_position,
157 &sci_get_line_from_position,
158 &sci_get_position_from_line,
159 &sci_replace_sel,
160 &sci_get_selected_text,
161 &sci_get_selected_text_length,
162 &sci_get_selection_start,
163 &sci_get_selection_end,
164 &sci_get_selection_mode,
165 &sci_set_selection_mode,
166 &sci_set_selection_start,
167 &sci_set_selection_end,
168 &sci_get_text_range,
169 &sci_get_line,
170 &sci_get_line_length,
171 &sci_get_line_count,
172 &sci_get_line_is_visible,
173 &sci_ensure_line_is_visible,
174 &sci_scroll_caret,
175 &sci_find_matching_brace,
176 &sci_get_style_at,
177 &sci_get_char_at,
178 &sci_get_current_line,
179 &sci_has_selection,
180 &sci_get_tab_width,
181 &sci_indicator_clear,
182 &sci_indicator_set,
183 &sci_get_contents,
184 &sci_get_contents_range,
185 &sci_get_selection_contents,
186 &sci_set_font,
187 &sci_get_line_end_position,
188 &sci_set_target_start,
189 &sci_set_target_end,
190 &sci_replace_target,
191 &sci_set_marker_at_line,
192 &sci_delete_marker_at_line,
193 &sci_is_marker_set_at_line,
194 &sci_goto_line,
195 &sci_find_text,
196 &sci_set_line_indentation,
197 &sci_get_line_indentation,
198 &sci_get_lexer
201 static TemplateFuncs template_funcs = {
202 &templates_get_template_fileheader
205 static UtilsFuncs utils_funcs = {
206 &utils_str_equal,
207 &utils_string_replace_all,
208 &utils_get_file_list,
209 &utils_write_file,
210 &utils_get_locale_from_utf8,
211 &utils_get_utf8_from_locale,
212 &utils_remove_ext_from_filename,
213 &utils_mkdir,
214 &utils_get_setting_boolean,
215 &utils_get_setting_integer,
216 &utils_get_setting_string,
217 &utils_spawn_sync,
218 &utils_spawn_async,
219 &utils_str_casecmp,
220 &utils_get_date_time,
221 &utils_open_browser,
222 &utils_string_replace_first,
223 &utils_str_middle_truncate,
224 &utils_str_remove_chars,
225 &utils_get_file_list_full,
226 &utils_copy_environment,
227 &utils_find_open_xml_tag,
228 &utils_find_open_xml_tag_pos
231 static UIUtilsFuncs uiutils_funcs = {
232 &ui_dialog_vbox_new,
233 &ui_frame_new_with_alignment,
234 &ui_set_statusbar,
235 &ui_table_add_row,
236 &ui_path_box_new,
237 &ui_button_new_with_image,
238 &ui_add_document_sensitive,
239 &ui_widget_set_tooltip_text,
240 &ui_image_menu_item_new,
241 &ui_lookup_widget,
242 &ui_progress_bar_start,
243 &ui_progress_bar_stop,
244 &ui_entry_add_clear_icon,
245 &ui_menu_add_document_items,
246 &ui_widget_modify_font_from_string,
247 &ui_is_keyval_enter_or_return,
248 &ui_get_gtk_settings_integer,
249 &ui_combo_box_add_to_history,
250 &ui_menu_add_document_items_sorted,
251 &ui_lookup_stock_label
254 static DialogFuncs dialog_funcs = {
255 &dialogs_show_question,
256 &dialogs_show_msgbox,
257 &dialogs_show_save_as,
258 &dialogs_show_input_numeric,
259 &dialogs_show_input
262 /* Macro to prevent confusing macro being generated in geanyfunctions.h */
263 #define _lookup_widget_macro ui_lookup_widget
265 /* deprecated */
266 static SupportFuncs support_funcs = {
267 &_lookup_widget_macro
270 static MsgWinFuncs msgwin_funcs = {
271 &msgwin_status_add,
272 &msgwin_compiler_add,
273 &msgwin_msg_add,
274 &msgwin_clear_tab,
275 &msgwin_switch_tab,
276 &msgwin_set_messages_dir
279 static EncodingFuncs encoding_funcs = {
280 &encodings_convert_to_utf8,
281 &encodings_convert_to_utf8_from_charset,
282 &encodings_get_charset_from_index
285 static KeybindingFuncs keybindings_funcs = {
286 &keybindings_send_command,
287 &keybindings_set_item,
288 &keybindings_get_item
291 static TagManagerFuncs tagmanager_funcs = {
292 &tm_get_real_path,
293 &tm_source_file_new,
294 &tm_workspace_add_object,
295 &tm_source_file_update,
296 &tm_work_object_free,
297 &tm_workspace_remove_object
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 remove_callbacks(Plugin *plugin)
774 GArray *signal_ids = plugin->signal_ids;
775 SignalConnection *sc;
777 if (signal_ids == NULL)
778 return;
780 foreach_array(SignalConnection, sc, signal_ids)
781 g_signal_handler_disconnect(sc->object, sc->handler_id);
783 g_array_free(signal_ids, TRUE);
787 static void remove_sources(Plugin *plugin)
789 GList *item;
791 item = plugin->sources;
792 while (item != NULL)
794 GList *next = item->next; /* cache the next pointer because current item will be freed */
796 g_source_destroy(item->data);
797 item = next;
799 /* don't free the list here, it is allocated inside each source's data */
803 static gboolean is_active_plugin(Plugin *plugin)
805 return (g_list_find(active_plugin_list, plugin) != NULL);
809 /* Clean up anything used by an active plugin */
810 static void
811 plugin_cleanup(Plugin *plugin)
813 GtkWidget *widget;
815 if (plugin->cleanup)
816 plugin->cleanup();
818 remove_callbacks(plugin);
819 remove_sources(plugin);
821 if (plugin->key_group)
822 keybindings_free_group(plugin->key_group);
824 widget = plugin->toolbar_separator.widget;
825 if (widget)
826 gtk_widget_destroy(widget);
828 geany_debug("Unloaded: %s", plugin->filename);
832 static void
833 plugin_free(Plugin *plugin)
835 g_return_if_fail(plugin);
836 g_return_if_fail(plugin->module);
838 if (is_active_plugin(plugin))
839 plugin_cleanup(plugin);
841 active_plugin_list = g_list_remove(active_plugin_list, plugin);
843 if (! g_module_close(plugin->module))
844 g_warning("%s: %s", plugin->filename, g_module_error());
846 plugin_list = g_list_remove(plugin_list, plugin);
848 g_free(plugin->filename);
849 g_free(plugin);
850 plugin = NULL;
854 static gchar *get_custom_plugin_path(const gchar *plugin_path_config,
855 const gchar *plugin_path_system)
857 gchar *plugin_path_custom;
859 if (EMPTY(prefs.custom_plugin_path))
860 return NULL;
862 plugin_path_custom = utils_get_locale_from_utf8(prefs.custom_plugin_path);
863 utils_tidy_path(plugin_path_custom);
865 /* check whether the custom plugin path is one of the system or user plugin paths
866 * and abort if so */
867 if (utils_str_equal(plugin_path_custom, plugin_path_config) ||
868 utils_str_equal(plugin_path_custom, plugin_path_system))
870 g_free(plugin_path_custom);
871 return NULL;
873 return plugin_path_custom;
877 /* all 3 paths Geany looks for plugins in can change (even system path on Windows)
878 * so we need to check active plugins are in the right place before loading */
879 static gboolean check_plugin_path(const gchar *fname)
881 gchar *plugin_path_config;
882 gchar *plugin_path_system;
883 gchar *plugin_path_custom;
884 gboolean ret = FALSE;
886 plugin_path_config = g_build_filename(app->configdir, "plugins", NULL);
887 if (g_str_has_prefix(fname, plugin_path_config))
888 ret = TRUE;
890 plugin_path_system = get_plugin_path();
891 if (g_str_has_prefix(fname, plugin_path_system))
892 ret = TRUE;
894 plugin_path_custom = get_custom_plugin_path(plugin_path_config, plugin_path_system);
895 if (plugin_path_custom)
897 if (g_str_has_prefix(fname, plugin_path_custom))
898 ret = TRUE;
900 g_free(plugin_path_custom);
902 g_free(plugin_path_config);
903 g_free(plugin_path_system);
904 return ret;
908 /* load active plugins at startup */
909 static void
910 load_active_plugins(void)
912 guint i, len;
914 if (active_plugins_pref == NULL || (len = g_strv_length(active_plugins_pref)) == 0)
915 return;
917 for (i = 0; i < len; i++)
919 const gchar *fname = active_plugins_pref[i];
921 if (!EMPTY(fname) && g_file_test(fname, G_FILE_TEST_EXISTS))
923 if (!check_plugin_path(fname) || plugin_new(fname, TRUE, FALSE) == NULL)
924 failed_plugins_list = g_list_prepend(failed_plugins_list, g_strdup(fname));
930 static void
931 load_plugins_from_path(const gchar *path)
933 GSList *list, *item;
934 gchar *fname, *tmp;
935 gint count = 0;
937 list = utils_get_file_list(path, NULL, NULL);
939 for (item = list; item != NULL; item = g_slist_next(item))
941 tmp = strrchr(item->data, '.');
942 if (tmp == NULL || utils_str_casecmp(tmp, "." G_MODULE_SUFFIX) != 0)
943 continue;
945 fname = g_build_filename(path, item->data, NULL);
946 if (plugin_new(fname, FALSE, TRUE))
947 count++;
948 g_free(fname);
951 g_slist_foreach(list, (GFunc) g_free, NULL);
952 g_slist_free(list);
954 if (count)
955 geany_debug("Added %d plugin(s) in '%s'.", count, path);
959 static gchar *get_plugin_path(void)
961 #ifdef G_OS_WIN32
962 gchar *path;
963 gchar *install_dir = win32_get_installation_dir();
965 path = g_build_filename(install_dir, "lib", NULL);
966 g_free(install_dir);
968 return path;
969 #else
970 return g_build_filename(GEANY_LIBDIR, "geany", NULL);
971 #endif
975 /* Load (but don't initialize) all plugins for the Plugin Manager dialog */
976 static void load_all_plugins(void)
978 gchar *plugin_path_config;
979 gchar *plugin_path_system;
980 gchar *plugin_path_custom;
982 plugin_path_config = g_build_filename(app->configdir, "plugins", NULL);
983 plugin_path_system = get_plugin_path();
985 /* first load plugins in ~/.config/geany/plugins/ */
986 load_plugins_from_path(plugin_path_config);
988 /* load plugins from a custom path */
989 plugin_path_custom = get_custom_plugin_path(plugin_path_config, plugin_path_system);
990 if (plugin_path_custom)
992 load_plugins_from_path(plugin_path_custom);
993 g_free(plugin_path_custom);
996 /* finally load plugins from $prefix/lib/geany */
997 load_plugins_from_path(plugin_path_system);
999 g_free(plugin_path_config);
1000 g_free(plugin_path_system);
1004 static void on_tools_menu_show(GtkWidget *menu_item, G_GNUC_UNUSED gpointer user_data)
1006 GList *item, *list = gtk_container_get_children(GTK_CONTAINER(menu_item));
1007 guint i = 0;
1008 gboolean have_plugin_menu_items = FALSE;
1010 for (item = list; item != NULL; item = g_list_next(item))
1012 if (item->data == menu_separator)
1014 if (i < g_list_length(list) - 1)
1016 have_plugin_menu_items = TRUE;
1017 break;
1020 i++;
1022 g_list_free(list);
1024 ui_widget_show_hide(menu_separator, have_plugin_menu_items);
1028 /* Calling this starts up plugin support */
1029 void plugins_load_active(void)
1031 GtkWidget *widget;
1033 want_plugins = TRUE;
1035 geany_data_init();
1037 widget = gtk_separator_menu_item_new();
1038 gtk_widget_show(widget);
1039 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
1041 widget = gtk_menu_item_new_with_mnemonic(_("_Plugin Manager"));
1042 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
1043 gtk_widget_show(widget);
1044 g_signal_connect(widget, "activate", G_CALLBACK(pm_show_dialog), NULL);
1046 menu_separator = gtk_separator_menu_item_new();
1047 gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), menu_separator);
1048 g_signal_connect(main_widgets.tools_menu, "show", G_CALLBACK(on_tools_menu_show), NULL);
1050 load_active_plugins();
1054 /* Update the global active plugins list so it's up-to-date when configuration
1055 * is saved. Called in response to GeanyObject's "save-settings" signal. */
1056 static void update_active_plugins_pref(void)
1058 gint i = 0;
1059 GList *list;
1060 gsize count;
1062 /* if plugins are disabled, don't clear list of active plugins */
1063 if (!want_plugins)
1064 return;
1066 count = g_list_length(active_plugin_list) + g_list_length(failed_plugins_list);
1068 g_strfreev(active_plugins_pref);
1070 if (count == 0)
1072 active_plugins_pref = NULL;
1073 return;
1076 active_plugins_pref = g_new0(gchar*, count + 1);
1078 for (list = g_list_first(active_plugin_list); list != NULL; list = list->next)
1080 Plugin *plugin = list->data;
1082 active_plugins_pref[i] = g_strdup(plugin->filename);
1083 i++;
1085 for (list = g_list_first(failed_plugins_list); list != NULL; list = list->next)
1087 const gchar *fname = list->data;
1089 active_plugins_pref[i] = g_strdup(fname);
1090 i++;
1092 active_plugins_pref[i] = NULL;
1096 /* called even if plugin support is disabled */
1097 void plugins_init(void)
1099 StashGroup *group;
1100 gchar *path;
1102 path = get_plugin_path();
1103 geany_debug("System plugin path: %s", path);
1104 g_free(path);
1106 group = stash_group_new("plugins");
1107 configuration_add_pref_group(group, TRUE);
1109 stash_group_add_toggle_button(group, &prefs.load_plugins,
1110 "load_plugins", TRUE, "check_plugins");
1111 stash_group_add_entry(group, &prefs.custom_plugin_path,
1112 "custom_plugin_path", "", "extra_plugin_path_entry");
1114 g_signal_connect(geany_object, "save-settings", G_CALLBACK(update_active_plugins_pref), NULL);
1115 stash_group_add_string_vector(group, &active_plugins_pref, "active_plugins", NULL);
1119 /* called even if plugin support is disabled */
1120 void plugins_finalize(void)
1122 if (failed_plugins_list != NULL)
1124 g_list_foreach(failed_plugins_list, (GFunc) g_free, NULL);
1125 g_list_free(failed_plugins_list);
1127 if (active_plugin_list != NULL)
1129 g_list_foreach(active_plugin_list, (GFunc) plugin_free, NULL);
1130 g_list_free(active_plugin_list);
1132 g_strfreev(active_plugins_pref);
1136 /* Check whether there are any plugins loaded which provide a configure symbol */
1137 gboolean plugins_have_preferences(void)
1139 GList *item;
1141 if (active_plugin_list == NULL)
1142 return FALSE;
1144 foreach_list(item, active_plugin_list)
1146 Plugin *plugin = item->data;
1147 if (plugin->configure != NULL || plugin->configure_single != NULL)
1148 return TRUE;
1151 return FALSE;
1155 /* Plugin Manager */
1157 enum
1159 PLUGIN_COLUMN_CHECK = 0,
1160 PLUGIN_COLUMN_NAME,
1161 PLUGIN_COLUMN_DESCRIPTION,
1162 PLUGIN_COLUMN_PLUGIN,
1163 PLUGIN_N_COLUMNS,
1164 PM_BUTTON_KEYBINDINGS,
1165 PM_BUTTON_CONFIGURE,
1166 PM_BUTTON_HELP
1169 typedef struct
1171 GtkWidget *dialog;
1172 GtkWidget *tree;
1173 GtkListStore *store;
1174 GtkWidget *plugin_label;
1175 GtkWidget *filename_label;
1176 GtkWidget *author_label;
1177 GtkWidget *configure_button;
1178 GtkWidget *keybindings_button;
1179 GtkWidget *help_button;
1181 PluginManagerWidgets;
1183 static PluginManagerWidgets pm_widgets;
1186 static void pm_update_buttons(Plugin *p)
1188 gboolean is_active;
1190 is_active = is_active_plugin(p);
1191 gtk_widget_set_sensitive(pm_widgets.configure_button,
1192 (p->configure || p->configure_single) && is_active);
1193 gtk_widget_set_sensitive(pm_widgets.help_button, p->help != NULL && is_active);
1194 gtk_widget_set_sensitive(pm_widgets.keybindings_button,
1195 p->key_group && p->key_group->plugin_key_count > 0 && is_active);
1199 static void pm_selection_changed(GtkTreeSelection *selection, gpointer user_data)
1201 GtkTreeIter iter;
1202 GtkTreeModel *model;
1203 Plugin *p;
1205 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1207 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1209 if (p != NULL)
1211 gchar *text;
1212 PluginInfo *pi;
1214 pi = &p->info;
1215 /* Translators: <plugin name> <plugin version> */
1216 text = g_strdup_printf(_("%s %s"), pi->name, pi->version);
1217 gtk_label_set_text(GTK_LABEL(pm_widgets.plugin_label), text);
1218 gtk_label_set_text(GTK_LABEL(pm_widgets.filename_label), p->filename);
1219 gtk_label_set_text(GTK_LABEL(pm_widgets.author_label), pi->author);
1220 g_free(text);
1222 pm_update_buttons(p);
1228 static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data)
1230 gboolean old_state, state;
1231 gchar *file_name;
1232 GtkTreeIter iter;
1233 GtkTreePath *path = gtk_tree_path_new_from_string(pth);
1234 Plugin *p;
1236 gtk_tree_model_get_iter(GTK_TREE_MODEL(pm_widgets.store), &iter, path);
1237 gtk_tree_path_free(path);
1239 gtk_tree_model_get(GTK_TREE_MODEL(pm_widgets.store), &iter,
1240 PLUGIN_COLUMN_CHECK, &old_state, PLUGIN_COLUMN_PLUGIN, &p, -1);
1242 /* no plugins item */
1243 if (p == NULL)
1244 return;
1246 state = ! old_state; /* toggle the state */
1248 /* save the filename of the plugin */
1249 file_name = g_strdup(p->filename);
1251 /* unload plugin module */
1252 if (!state)
1253 /* save shortcuts (only need this group, but it doesn't take long) */
1254 keybindings_write_to_file();
1256 plugin_free(p);
1258 /* reload plugin module and initialize it if item is checked */
1259 p = plugin_new(file_name, state, TRUE);
1260 if (!p)
1262 /* plugin file may no longer be on disk, or is now incompatible */
1263 gtk_list_store_remove(pm_widgets.store, &iter);
1265 else
1267 if (state)
1268 keybindings_load_keyfile(); /* load shortcuts */
1270 /* update model */
1271 gtk_list_store_set(pm_widgets.store, &iter,
1272 PLUGIN_COLUMN_CHECK, state,
1273 PLUGIN_COLUMN_PLUGIN, p, -1);
1275 /* set again the sensitiveness of the configure and help buttons */
1276 pm_update_buttons(p);
1278 g_free(file_name);
1282 static void pm_prepare_treeview(GtkWidget *tree, GtkListStore *store)
1284 GtkCellRenderer *text_renderer, *checkbox_renderer;
1285 GtkTreeViewColumn *column;
1286 GtkTreeIter iter;
1287 GList *list;
1288 GtkTreeSelection *sel;
1290 checkbox_renderer = gtk_cell_renderer_toggle_new();
1291 column = gtk_tree_view_column_new_with_attributes(
1292 _("Active"), checkbox_renderer, "active", PLUGIN_COLUMN_CHECK, NULL);
1293 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1294 g_signal_connect(checkbox_renderer, "toggled", G_CALLBACK(pm_plugin_toggled), NULL);
1296 text_renderer = gtk_cell_renderer_text_new();
1297 column = gtk_tree_view_column_new_with_attributes(
1298 _("Plugin"), text_renderer, "text", PLUGIN_COLUMN_NAME, NULL);
1299 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1301 text_renderer = gtk_cell_renderer_text_new();
1302 g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1303 column = gtk_tree_view_column_new_with_attributes(
1304 _("Description"), text_renderer, "text", PLUGIN_COLUMN_DESCRIPTION, NULL);
1305 gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
1307 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
1308 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
1309 gtk_tree_sortable_set_sort_column_id(
1310 GTK_TREE_SORTABLE(store), PLUGIN_COLUMN_NAME, GTK_SORT_ASCENDING);
1312 /* selection handling */
1313 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
1314 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
1315 g_signal_connect(sel, "changed", G_CALLBACK(pm_selection_changed), NULL);
1317 list = g_list_first(plugin_list);
1318 if (list == NULL)
1320 gtk_list_store_append(store, &iter);
1321 gtk_list_store_set(store, &iter, PLUGIN_COLUMN_CHECK, FALSE,
1322 PLUGIN_COLUMN_NAME, _("No plugins available."),
1323 PLUGIN_COLUMN_DESCRIPTION, "", PLUGIN_COLUMN_PLUGIN, NULL, -1);
1325 else
1327 Plugin *p;
1328 for (; list != NULL; list = list->next)
1330 p = list->data;
1332 gtk_list_store_append(store, &iter);
1333 gtk_list_store_set(store, &iter,
1334 PLUGIN_COLUMN_CHECK, is_active_plugin(p),
1335 PLUGIN_COLUMN_NAME, p->info.name,
1336 PLUGIN_COLUMN_DESCRIPTION, p->info.description,
1337 PLUGIN_COLUMN_PLUGIN, p,
1338 -1);
1341 gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
1342 g_object_unref(store);
1346 static void pm_on_plugin_button_clicked(GtkButton *button, gpointer user_data)
1348 GtkTreeModel *model;
1349 GtkTreeSelection *selection;
1350 GtkTreeIter iter;
1351 Plugin *p;
1353 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pm_widgets.tree));
1354 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1356 gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
1358 if (p != NULL)
1360 if (GPOINTER_TO_INT(user_data) == PM_BUTTON_CONFIGURE)
1361 plugin_show_configure(&p->public);
1362 else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_HELP && p->help != NULL)
1363 p->help();
1364 else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_KEYBINDINGS && p->key_group && p->key_group->plugin_key_count > 0)
1365 keybindings_dialog_show_prefs_scroll(p->info.name);
1371 static void
1372 free_non_active_plugin(gpointer data, gpointer user_data)
1374 Plugin *plugin = data;
1376 /* don't do anything when closing the plugin manager and it is an active plugin */
1377 if (is_active_plugin(plugin))
1378 return;
1380 plugin_free(plugin);
1384 /* Callback when plugin manager dialog closes, only ever has response of
1385 * GTK_RESPONSE_OK or GTK_RESPONSE_DELETE_EVENT and both are treated the same. */
1386 static void pm_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
1388 if (plugin_list != NULL)
1390 /* remove all non-active plugins from the list */
1391 g_list_foreach(plugin_list, free_non_active_plugin, NULL);
1392 g_list_free(plugin_list);
1393 plugin_list = NULL;
1395 gtk_widget_destroy(GTK_WIDGET(dialog));
1397 configuration_save();
1401 static GtkWidget *create_table_label(const gchar *text)
1403 GtkWidget *label;
1404 PangoAttrList *attrs;
1406 attrs = pango_attr_list_new();
1407 pango_attr_list_insert(attrs, pango_attr_weight_new(PANGO_WEIGHT_BOLD));
1408 label = gtk_label_new(text);
1409 gtk_label_set_attributes(GTK_LABEL(label), attrs);
1410 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
1411 pango_attr_list_unref(attrs);
1413 return label;
1417 static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data)
1419 GtkWidget *vbox, *vbox2, *label_vbox, *hbox, *swin, *label, *label2, *desc_win, *table, *paned;
1421 /* before showing the dialog, we need to create the list of available plugins */
1422 load_all_plugins();
1424 pm_widgets.dialog = gtk_dialog_new_with_buttons(_("Plugins"), GTK_WINDOW(main_widgets.window),
1425 GTK_DIALOG_DESTROY_WITH_PARENT,
1426 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
1427 vbox = ui_dialog_vbox_new(GTK_DIALOG(pm_widgets.dialog));
1428 gtk_widget_set_name(pm_widgets.dialog, "GeanyDialog");
1429 gtk_box_set_spacing(GTK_BOX(vbox), 6);
1431 gtk_window_set_default_size(GTK_WINDOW(pm_widgets.dialog), 500, 450);
1433 pm_widgets.tree = gtk_tree_view_new();
1434 pm_widgets.store = gtk_list_store_new(
1435 PLUGIN_N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
1436 pm_prepare_treeview(pm_widgets.tree, pm_widgets.store);
1438 swin = gtk_scrolled_window_new(NULL, NULL);
1439 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
1440 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1441 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin), GTK_SHADOW_IN);
1442 gtk_container_add(GTK_CONTAINER(swin), pm_widgets.tree);
1444 label = geany_wrap_label_new(_("Choose which plugins should be loaded at startup:"));
1446 pm_widgets.keybindings_button = gtk_button_new_with_label(_("Keybindings"));
1447 gtk_widget_set_sensitive(pm_widgets.keybindings_button, FALSE);
1448 g_signal_connect(pm_widgets.keybindings_button, "clicked",
1449 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_KEYBINDINGS));
1451 pm_widgets.configure_button = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
1452 gtk_widget_set_sensitive(pm_widgets.configure_button, FALSE);
1453 g_signal_connect(pm_widgets.configure_button, "clicked",
1454 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_CONFIGURE));
1456 pm_widgets.help_button = gtk_button_new_from_stock(GTK_STOCK_HELP);
1457 gtk_widget_set_sensitive(pm_widgets.help_button, FALSE);
1458 g_signal_connect(pm_widgets.help_button, "clicked",
1459 G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_HELP));
1461 label2 = gtk_label_new(_("<b>Plugin details:</b>"));
1462 gtk_label_set_use_markup(GTK_LABEL(label2), TRUE);
1463 gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
1465 table = gtk_table_new(3, 2, FALSE);
1466 gtk_table_set_col_spacings(GTK_TABLE(table), 6);
1467 pm_widgets.plugin_label = geany_wrap_label_new(NULL);
1468 pm_widgets.filename_label = geany_wrap_label_new(NULL);
1469 pm_widgets.author_label = geany_wrap_label_new(NULL);
1470 gtk_table_attach(GTK_TABLE(table), create_table_label(_("Plugin:")), 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
1471 gtk_table_attach(GTK_TABLE(table), create_table_label(_("Author(s):")), 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
1472 gtk_table_attach(GTK_TABLE(table), create_table_label(_("Filename:")), 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
1473 gtk_table_attach(GTK_TABLE(table), pm_widgets.plugin_label, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1474 gtk_table_attach(GTK_TABLE(table), pm_widgets.author_label, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1475 gtk_table_attach(GTK_TABLE(table), pm_widgets.filename_label, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
1477 desc_win = gtk_scrolled_window_new(NULL, NULL);
1478 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(desc_win),
1479 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1480 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(desc_win), table);
1482 hbox = gtk_hbox_new(FALSE, 0);
1483 gtk_box_set_spacing(GTK_BOX(hbox), 6);
1484 gtk_box_pack_start(GTK_BOX(hbox), label2, TRUE, TRUE, 0);
1485 gtk_box_pack_start(GTK_BOX(hbox), pm_widgets.help_button, FALSE, FALSE, 0);
1486 gtk_box_pack_start(GTK_BOX(hbox), pm_widgets.configure_button, FALSE, FALSE, 0);
1487 gtk_box_pack_start(GTK_BOX(hbox), pm_widgets.keybindings_button, FALSE, FALSE, 0);
1489 label_vbox = gtk_vbox_new(FALSE, 3);
1490 gtk_box_pack_start(GTK_BOX(label_vbox), hbox, FALSE, FALSE, 0);
1491 gtk_box_pack_start(GTK_BOX(label_vbox), desc_win, TRUE, TRUE, 0);
1493 paned = gtk_vpaned_new();
1494 gtk_paned_pack1(GTK_PANED(paned), swin, TRUE, FALSE);
1495 gtk_paned_pack2(GTK_PANED(paned), label_vbox, FALSE, FALSE);
1497 vbox2 = gtk_vbox_new(FALSE, 3);
1498 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 5);
1499 gtk_box_pack_start(GTK_BOX(vbox2), paned, TRUE, TRUE, 0);
1501 g_signal_connect(pm_widgets.dialog, "response", G_CALLBACK(pm_dialog_response), NULL);
1503 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
1504 gtk_widget_show_all(pm_widgets.dialog);
1508 #endif