2007-06-26 16:17:16 +00:00
|
|
|
/*
|
|
|
|
* plugins.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2010-01-01 22:55:18 +00:00
|
|
|
* Copyright 2007-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2007-2010 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2007-06-26 16:17:16 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Code to manage, load and unload plugins. */
|
|
|
|
|
|
|
|
#include "geany.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_PLUGINS
|
|
|
|
|
2007-07-28 17:44:02 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2007-08-03 15:05:53 +00:00
|
|
|
#include "Scintilla.h"
|
|
|
|
#include "ScintillaWidget.h"
|
|
|
|
|
2007-12-12 20:04:45 +00:00
|
|
|
#include "prefix.h"
|
2007-06-26 16:17:16 +00:00
|
|
|
#include "plugins.h"
|
|
|
|
#include "plugindata.h"
|
|
|
|
#include "support.h"
|
|
|
|
#include "utils.h"
|
2007-07-04 11:32:33 +00:00
|
|
|
#include "document.h"
|
2007-08-15 15:37:21 +00:00
|
|
|
#include "filetypes.h"
|
2007-07-04 11:32:33 +00:00
|
|
|
#include "templates.h"
|
|
|
|
#include "sciwrappers.h"
|
2007-07-13 14:54:11 +00:00
|
|
|
#include "ui_utils.h"
|
2007-08-03 15:05:53 +00:00
|
|
|
#include "editor.h"
|
2007-08-19 17:40:19 +00:00
|
|
|
#include "dialogs.h"
|
|
|
|
#include "msgwindow.h"
|
2007-08-23 11:34:06 +00:00
|
|
|
#include "prefs.h"
|
2008-01-09 13:24:36 +00:00
|
|
|
#include "geanywraplabel.h"
|
2007-09-17 11:16:48 +00:00
|
|
|
#include "build.h"
|
2007-10-18 18:03:28 +00:00
|
|
|
#include "encodings.h"
|
2007-12-02 10:52:19 +00:00
|
|
|
#include "search.h"
|
2007-12-16 11:27:59 +00:00
|
|
|
#include "highlighting.h"
|
2008-02-29 19:30:28 +00:00
|
|
|
#include "keybindings.h"
|
2008-04-17 17:48:12 +00:00
|
|
|
#include "navqueue.h"
|
2008-07-23 11:46:02 +00:00
|
|
|
#include "main.h"
|
2008-12-06 11:10:06 +00:00
|
|
|
#include "toolbar.h"
|
2008-12-28 13:21:35 +00:00
|
|
|
#include "stash.h"
|
2010-05-05 16:26:25 +00:00
|
|
|
#include "symbols.h"
|
2008-12-28 13:21:35 +00:00
|
|
|
#include "keyfile.h"
|
2009-03-26 20:10:47 +00:00
|
|
|
#include "win32.h"
|
2009-07-28 11:35:33 +00:00
|
|
|
#include "pluginutils.h"
|
|
|
|
#include "pluginprivate.h"
|
2008-10-13 12:38:32 +00:00
|
|
|
|
2009-09-27 14:07:24 +00:00
|
|
|
|
|
|
|
GList *active_plugin_list = NULL; /* list of only actually loaded plugins, always valid */
|
2007-07-04 11:32:33 +00:00
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-12-28 13:21:35 +00:00
|
|
|
static gboolean want_plugins = FALSE;
|
|
|
|
|
2008-03-17 15:48:15 +00:00
|
|
|
/* list of all available, loadable plugins, only valid as long as the plugin manager dialog is
|
|
|
|
* opened, afterwards it will be destroyed */
|
|
|
|
static GList *plugin_list = NULL;
|
2008-04-16 15:44:29 +00:00
|
|
|
static gchar **active_plugins_pref = NULL; /* list of plugin filenames to load at startup */
|
2008-04-16 16:22:28 +00:00
|
|
|
static GList *failed_plugins_list = NULL; /* plugins the user wants active but can't be used */
|
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
static GtkWidget *menu_separator = NULL;
|
2008-04-16 16:22:28 +00:00
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data);
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2008-10-13 12:38:32 +00:00
|
|
|
|
|
|
|
static PluginFuncs plugin_funcs = {
|
2009-02-06 19:05:12 +00:00
|
|
|
&plugin_add_toolbar_item,
|
2009-07-29 17:40:20 +00:00
|
|
|
&plugin_module_make_resident,
|
2009-08-24 11:35:13 +00:00
|
|
|
&plugin_signal_connect,
|
2009-09-27 14:07:24 +00:00
|
|
|
&plugin_set_key_group,
|
|
|
|
&plugin_show_configure
|
2008-10-13 12:38:32 +00:00
|
|
|
};
|
2007-07-04 11:32:33 +00:00
|
|
|
|
2007-07-13 11:22:47 +00:00
|
|
|
static DocumentFuncs doc_funcs = {
|
2008-06-15 13:35:48 +00:00
|
|
|
&document_new_file,
|
2007-08-14 16:29:03 +00:00
|
|
|
&document_get_current,
|
2008-06-12 16:50:01 +00:00
|
|
|
&document_get_from_page,
|
2008-06-15 13:35:48 +00:00
|
|
|
&document_find_by_filename,
|
|
|
|
&document_find_by_real_path,
|
|
|
|
&document_save_file,
|
|
|
|
&document_open_file,
|
2007-08-15 11:52:06 +00:00
|
|
|
&document_open_files,
|
2008-06-12 16:50:01 +00:00
|
|
|
&document_remove_page,
|
2008-06-15 13:35:48 +00:00
|
|
|
&document_reload_file,
|
|
|
|
&document_set_encoding,
|
|
|
|
&document_set_text_changed,
|
2008-07-02 13:40:06 +00:00
|
|
|
&document_set_filetype,
|
2008-12-03 18:03:54 +00:00
|
|
|
&document_close,
|
2009-01-18 18:19:58 +00:00
|
|
|
&document_index,
|
|
|
|
&document_save_file_as,
|
2009-02-08 19:52:21 +00:00
|
|
|
&document_rename_file,
|
2009-04-21 20:53:11 +00:00
|
|
|
&document_get_status_color,
|
2009-10-14 12:21:18 +00:00
|
|
|
&document_get_basename_for_display,
|
|
|
|
&document_get_notebook_page
|
2008-05-14 17:58:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static EditorFuncs editor_funcs = {
|
2008-08-26 15:58:07 +00:00
|
|
|
&editor_get_indent_prefs,
|
2008-10-25 18:57:00 +00:00
|
|
|
&editor_create_widget,
|
2008-11-16 17:54:28 +00:00
|
|
|
&editor_indicator_set_on_range,
|
|
|
|
&editor_indicator_set_on_line,
|
|
|
|
&editor_indicator_clear,
|
2009-02-08 19:52:21 +00:00
|
|
|
&editor_set_indent_type,
|
2009-12-29 18:23:54 +00:00
|
|
|
&editor_get_word_at_pos,
|
|
|
|
&editor_get_eol_char_name,
|
|
|
|
&editor_get_eol_char_len,
|
2010-01-12 18:44:38 +00:00
|
|
|
&editor_get_eol_char,
|
2010-08-01 17:20:50 +00:00
|
|
|
&editor_insert_text_block,
|
2010-08-15 17:44:31 +00:00
|
|
|
&editor_get_eol_char_mode,
|
|
|
|
&editor_goto_pos
|
2007-07-13 14:54:11 +00:00
|
|
|
};
|
2007-07-04 11:32:33 +00:00
|
|
|
|
2008-12-03 13:36:45 +00:00
|
|
|
static ScintillaFuncs scintilla_funcs = {
|
2007-08-03 15:05:53 +00:00
|
|
|
&scintilla_send_message,
|
2008-12-03 13:36:45 +00:00
|
|
|
&scintilla_new
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Macro to prevent a duplicate macro being generated in geanyfunctions.h */
|
2008-12-04 13:55:11 +00:00
|
|
|
#define _scintilla_send_message_macro scintilla_send_message
|
2008-12-03 13:36:45 +00:00
|
|
|
|
|
|
|
static SciFuncs sci_funcs = {
|
2008-12-04 13:55:11 +00:00
|
|
|
&_scintilla_send_message_macro,
|
2008-12-05 12:34:20 +00:00
|
|
|
&sci_send_command,
|
2007-08-03 15:05:53 +00:00
|
|
|
&sci_start_undo_action,
|
|
|
|
&sci_end_undo_action,
|
2007-07-23 15:41:08 +00:00
|
|
|
&sci_set_text,
|
|
|
|
&sci_insert_text,
|
2007-07-24 11:43:46 +00:00
|
|
|
&sci_get_text,
|
|
|
|
&sci_get_length,
|
2007-08-03 15:05:53 +00:00
|
|
|
&sci_get_current_position,
|
|
|
|
&sci_set_current_position,
|
|
|
|
&sci_get_col_from_position,
|
|
|
|
&sci_get_line_from_position,
|
|
|
|
&sci_get_position_from_line,
|
2007-07-24 11:43:46 +00:00
|
|
|
&sci_replace_sel,
|
|
|
|
&sci_get_selected_text,
|
2007-08-03 15:05:53 +00:00
|
|
|
&sci_get_selected_text_length,
|
|
|
|
&sci_get_selection_start,
|
|
|
|
&sci_get_selection_end,
|
|
|
|
&sci_get_selection_mode,
|
|
|
|
&sci_set_selection_mode,
|
|
|
|
&sci_set_selection_start,
|
|
|
|
&sci_set_selection_end,
|
|
|
|
&sci_get_text_range,
|
|
|
|
&sci_get_line,
|
|
|
|
&sci_get_line_length,
|
|
|
|
&sci_get_line_count,
|
|
|
|
&sci_get_line_is_visible,
|
|
|
|
&sci_ensure_line_is_visible,
|
|
|
|
&sci_scroll_caret,
|
2008-09-17 18:02:55 +00:00
|
|
|
&sci_find_matching_brace,
|
2007-08-19 17:40:19 +00:00
|
|
|
&sci_get_style_at,
|
2008-02-04 12:49:14 +00:00
|
|
|
&sci_get_char_at,
|
|
|
|
&sci_get_current_line,
|
2008-09-17 18:02:55 +00:00
|
|
|
&sci_has_selection,
|
2008-09-17 18:05:27 +00:00
|
|
|
&sci_get_tab_width,
|
2008-10-25 18:57:00 +00:00
|
|
|
&sci_indicator_clear,
|
2009-03-24 18:13:28 +00:00
|
|
|
&sci_indicator_set,
|
|
|
|
&sci_get_contents,
|
|
|
|
&sci_get_contents_range,
|
2009-07-14 15:06:20 +00:00
|
|
|
&sci_get_selection_contents,
|
2009-09-06 16:51:11 +00:00
|
|
|
&sci_set_font,
|
|
|
|
&sci_get_line_end_position,
|
|
|
|
&sci_set_target_start,
|
|
|
|
&sci_set_target_end,
|
2009-09-12 17:39:49 +00:00
|
|
|
&sci_replace_target,
|
|
|
|
&sci_set_marker_at_line,
|
|
|
|
&sci_delete_marker_at_line,
|
2009-10-25 22:27:13 +00:00
|
|
|
&sci_is_marker_set_at_line,
|
2009-12-31 15:47:56 +00:00
|
|
|
&sci_goto_line,
|
2010-05-03 14:46:32 +00:00
|
|
|
&sci_find_text,
|
|
|
|
&sci_set_line_indentation,
|
|
|
|
&sci_get_line_indentation
|
2007-07-13 14:54:11 +00:00
|
|
|
};
|
2007-07-04 11:32:33 +00:00
|
|
|
|
2007-07-13 11:22:47 +00:00
|
|
|
static TemplateFuncs template_funcs = {
|
|
|
|
&templates_get_template_fileheader
|
2007-07-13 14:54:11 +00:00
|
|
|
};
|
2007-07-04 11:32:33 +00:00
|
|
|
|
2007-07-13 11:22:47 +00:00
|
|
|
static UtilsFuncs utils_funcs = {
|
|
|
|
&utils_str_equal,
|
2007-09-11 15:21:11 +00:00
|
|
|
&utils_string_replace_all,
|
2007-08-19 17:40:19 +00:00
|
|
|
&utils_get_file_list,
|
|
|
|
&utils_write_file,
|
|
|
|
&utils_get_locale_from_utf8,
|
|
|
|
&utils_get_utf8_from_locale,
|
2007-11-20 18:37:20 +00:00
|
|
|
&utils_remove_ext_from_filename,
|
2008-01-02 21:20:33 +00:00
|
|
|
&utils_mkdir,
|
|
|
|
&utils_get_setting_boolean,
|
|
|
|
&utils_get_setting_integer,
|
2008-02-24 10:27:32 +00:00
|
|
|
&utils_get_setting_string,
|
|
|
|
&utils_spawn_sync,
|
2008-11-11 19:18:51 +00:00
|
|
|
&utils_spawn_async,
|
2008-11-21 17:40:04 +00:00
|
|
|
&utils_str_casecmp,
|
2009-01-28 19:30:18 +00:00
|
|
|
&utils_get_date_time,
|
2009-01-30 16:12:25 +00:00
|
|
|
&utils_open_browser,
|
2009-04-21 20:53:11 +00:00
|
|
|
&utils_string_replace_first,
|
2009-07-20 23:10:46 +00:00
|
|
|
&utils_str_middle_truncate,
|
2009-09-29 13:51:54 +00:00
|
|
|
&utils_str_remove_chars,
|
2010-03-07 19:33:15 +00:00
|
|
|
&utils_get_file_list_full,
|
2010-03-15 14:48:43 +00:00
|
|
|
&utils_copy_environment
|
2007-07-13 14:54:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static UIUtilsFuncs uiutils_funcs = {
|
|
|
|
&ui_dialog_vbox_new,
|
2007-09-25 16:21:35 +00:00
|
|
|
&ui_frame_new_with_alignment,
|
2008-02-04 12:49:14 +00:00
|
|
|
&ui_set_statusbar,
|
|
|
|
&ui_table_add_row,
|
|
|
|
&ui_path_box_new,
|
2008-02-04 13:40:14 +00:00
|
|
|
&ui_button_new_with_image,
|
2008-11-18 20:14:42 +00:00
|
|
|
&ui_add_document_sensitive,
|
2008-11-21 13:34:58 +00:00
|
|
|
&ui_widget_set_tooltip_text,
|
2008-12-02 18:33:41 +00:00
|
|
|
&ui_image_menu_item_new,
|
2009-01-27 20:19:43 +00:00
|
|
|
&ui_lookup_widget,
|
|
|
|
&ui_progress_bar_start,
|
|
|
|
&ui_progress_bar_stop,
|
2009-10-13 17:14:25 +00:00
|
|
|
&ui_entry_add_clear_icon,
|
2009-10-25 12:30:36 +00:00
|
|
|
&ui_menu_add_document_items,
|
2010-03-07 19:33:15 +00:00
|
|
|
&ui_widget_modify_font_from_string,
|
2010-04-11 21:56:08 +00:00
|
|
|
&ui_is_keyval_enter_or_return,
|
2010-06-18 12:20:15 +00:00
|
|
|
&ui_get_gtk_settings_integer,
|
|
|
|
&ui_combo_box_add_to_history
|
2007-07-13 14:54:11 +00:00
|
|
|
};
|
2007-07-04 11:32:33 +00:00
|
|
|
|
2007-08-19 17:40:19 +00:00
|
|
|
static DialogFuncs dialog_funcs = {
|
|
|
|
&dialogs_show_question,
|
2007-10-16 09:01:13 +00:00
|
|
|
&dialogs_show_msgbox,
|
2009-01-21 22:49:47 +00:00
|
|
|
&dialogs_show_save_as,
|
|
|
|
&dialogs_show_input_numeric
|
2007-08-19 17:40:19 +00:00
|
|
|
};
|
|
|
|
|
2008-12-04 13:55:11 +00:00
|
|
|
/* Macro to prevent confusing macro being generated in geanyfunctions.h */
|
2008-12-18 21:21:53 +00:00
|
|
|
#define _lookup_widget_macro ui_lookup_widget
|
2008-12-04 13:55:11 +00:00
|
|
|
|
2008-12-02 18:33:41 +00:00
|
|
|
/* deprecated */
|
2007-08-03 15:05:53 +00:00
|
|
|
static SupportFuncs support_funcs = {
|
2008-12-04 13:55:11 +00:00
|
|
|
&_lookup_widget_macro
|
2007-08-03 15:05:53 +00:00
|
|
|
};
|
|
|
|
|
2007-08-19 17:40:19 +00:00
|
|
|
static MsgWinFuncs msgwin_funcs = {
|
2007-10-24 10:52:48 +00:00
|
|
|
&msgwin_status_add,
|
2008-12-05 17:30:06 +00:00
|
|
|
&msgwin_compiler_add,
|
|
|
|
&msgwin_msg_add,
|
2008-05-14 15:46:48 +00:00
|
|
|
&msgwin_clear_tab,
|
2010-09-16 15:31:23 +00:00
|
|
|
&msgwin_switch_tab,
|
|
|
|
&msgwin_set_messages_dir
|
2007-08-19 17:40:19 +00:00
|
|
|
};
|
|
|
|
|
2007-10-18 18:03:28 +00:00
|
|
|
static EncodingFuncs encoding_funcs = {
|
|
|
|
&encodings_convert_to_utf8,
|
2008-01-16 16:50:10 +00:00
|
|
|
&encodings_convert_to_utf8_from_charset,
|
|
|
|
&encodings_get_charset_from_index
|
2007-10-18 18:03:28 +00:00
|
|
|
};
|
|
|
|
|
2007-10-22 12:42:19 +00:00
|
|
|
static KeybindingFuncs keybindings_funcs = {
|
2008-03-10 13:23:57 +00:00
|
|
|
&keybindings_send_command,
|
2009-08-25 16:55:56 +00:00
|
|
|
&keybindings_set_item,
|
|
|
|
&keybindings_get_item
|
2007-10-22 12:42:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static TagManagerFuncs tagmanager_funcs = {
|
2008-01-02 21:20:33 +00:00
|
|
|
&tm_get_real_path,
|
|
|
|
&tm_source_file_new,
|
|
|
|
&tm_workspace_add_object,
|
|
|
|
&tm_source_file_update,
|
|
|
|
&tm_work_object_free,
|
|
|
|
&tm_workspace_remove_object
|
2007-10-22 12:42:19 +00:00
|
|
|
};
|
|
|
|
|
2007-12-02 10:52:19 +00:00
|
|
|
static SearchFuncs search_funcs = {
|
|
|
|
&search_show_find_in_files_dialog
|
|
|
|
};
|
|
|
|
|
2007-12-16 11:27:59 +00:00
|
|
|
static HighlightingFuncs highlighting_funcs = {
|
2009-10-15 16:54:15 +00:00
|
|
|
&highlighting_get_style,
|
|
|
|
&highlighting_set_styles
|
2007-12-16 11:27:59 +00:00
|
|
|
};
|
|
|
|
|
2008-01-02 21:20:33 +00:00
|
|
|
static FiletypeFuncs filetype_funcs = {
|
2008-07-23 14:44:27 +00:00
|
|
|
&filetypes_detect_from_file,
|
2008-12-03 18:03:54 +00:00
|
|
|
&filetypes_lookup_by_name,
|
|
|
|
&filetypes_index
|
2008-01-02 21:20:33 +00:00
|
|
|
};
|
|
|
|
|
2008-04-17 17:48:12 +00:00
|
|
|
static NavQueueFuncs navqueue_funcs = {
|
2008-06-12 20:45:18 +00:00
|
|
|
&navqueue_goto_line
|
2008-04-17 17:48:12 +00:00
|
|
|
};
|
2008-01-02 21:20:33 +00:00
|
|
|
|
2008-07-23 11:46:02 +00:00
|
|
|
static MainFuncs main_funcs = {
|
2008-10-25 18:56:27 +00:00
|
|
|
&main_reload_configuration,
|
2009-11-29 13:36:26 +00:00
|
|
|
&main_locale_init,
|
|
|
|
&main_is_realized
|
2008-07-23 11:46:02 +00:00
|
|
|
};
|
|
|
|
|
2010-03-30 16:29:38 +00:00
|
|
|
static StashFuncs stash_funcs = {
|
|
|
|
&stash_group_new,
|
|
|
|
&stash_group_add_boolean,
|
|
|
|
&stash_group_add_integer,
|
|
|
|
&stash_group_add_string,
|
|
|
|
&stash_group_add_string_vector,
|
|
|
|
&stash_group_load_from_key_file,
|
|
|
|
&stash_group_save_to_key_file,
|
|
|
|
&stash_group_free,
|
|
|
|
&stash_group_load_from_file,
|
2010-03-31 16:21:28 +00:00
|
|
|
&stash_group_save_to_file,
|
|
|
|
&stash_group_add_toggle_button,
|
|
|
|
&stash_group_add_radio_buttons,
|
|
|
|
&stash_group_add_spin_button_integer,
|
|
|
|
&stash_group_add_combo_box,
|
|
|
|
&stash_group_add_combo_box_entry,
|
|
|
|
&stash_group_add_entry,
|
|
|
|
&stash_group_add_widget_property,
|
|
|
|
&stash_group_display,
|
|
|
|
&stash_group_update
|
2010-03-30 16:29:38 +00:00
|
|
|
};
|
|
|
|
|
2010-05-05 16:26:25 +00:00
|
|
|
static SymbolsFuncs symbols_funcs = {
|
|
|
|
&symbols_get_context_separator
|
|
|
|
};
|
|
|
|
|
2008-05-19 12:35:35 +00:00
|
|
|
static GeanyFunctions geany_functions = {
|
2007-07-26 12:06:12 +00:00
|
|
|
&doc_funcs,
|
|
|
|
&sci_funcs,
|
|
|
|
&template_funcs,
|
|
|
|
&utils_funcs,
|
|
|
|
&uiutils_funcs,
|
2007-08-19 17:40:19 +00:00
|
|
|
&support_funcs,
|
|
|
|
&dialog_funcs,
|
2007-10-18 18:03:28 +00:00
|
|
|
&msgwin_funcs,
|
2007-10-22 12:42:19 +00:00
|
|
|
&encoding_funcs,
|
|
|
|
&keybindings_funcs,
|
|
|
|
&tagmanager_funcs,
|
2007-12-02 10:52:19 +00:00
|
|
|
&search_funcs,
|
2008-01-02 21:20:33 +00:00
|
|
|
&highlighting_funcs,
|
2008-04-17 17:48:12 +00:00
|
|
|
&filetype_funcs,
|
2008-05-14 17:58:56 +00:00
|
|
|
&navqueue_funcs,
|
2008-07-23 11:46:02 +00:00
|
|
|
&editor_funcs,
|
2008-10-13 12:38:32 +00:00
|
|
|
&main_funcs,
|
2008-12-03 13:36:45 +00:00
|
|
|
&plugin_funcs,
|
2008-12-05 16:29:32 +00:00
|
|
|
&scintilla_funcs,
|
2010-03-30 16:29:38 +00:00
|
|
|
&msgwin_funcs,
|
2010-05-05 16:26:25 +00:00
|
|
|
&stash_funcs,
|
|
|
|
&symbols_funcs
|
2007-07-26 12:06:12 +00:00
|
|
|
};
|
|
|
|
|
2008-05-19 12:35:35 +00:00
|
|
|
static GeanyData geany_data;
|
|
|
|
|
2007-07-04 11:32:33 +00:00
|
|
|
|
|
|
|
static void
|
2008-02-20 11:24:23 +00:00
|
|
|
geany_data_init(void)
|
2007-07-04 11:32:33 +00:00
|
|
|
{
|
2008-05-19 12:35:35 +00:00
|
|
|
GeanyData gd = {
|
|
|
|
app,
|
2008-05-22 14:41:28 +00:00
|
|
|
&main_widgets,
|
2008-05-29 17:00:54 +00:00
|
|
|
documents_array,
|
2008-05-19 12:35:35 +00:00
|
|
|
filetypes_array,
|
|
|
|
&prefs,
|
|
|
|
&interface_prefs,
|
|
|
|
&toolbar_prefs,
|
|
|
|
&editor_prefs,
|
|
|
|
&file_prefs,
|
|
|
|
&search_prefs,
|
|
|
|
&tool_prefs,
|
|
|
|
&template_prefs,
|
2009-04-02 15:00:17 +00:00
|
|
|
&build_info,
|
|
|
|
filetypes_by_title
|
2008-05-19 12:35:35 +00:00
|
|
|
};
|
2010-09-17 19:15:13 +00:00
|
|
|
|
|
|
|
geany_data = gd;
|
2007-07-04 11:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
/* Prevent the same plugin filename being loaded more than once.
|
2008-03-17 15:48:15 +00:00
|
|
|
* Note: g_module_name always returns the .so name, even when Plugin::filename is an .la file. */
|
2007-06-26 16:17:16 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_loaded(GModule *module)
|
|
|
|
{
|
2007-08-04 16:25:13 +00:00
|
|
|
gchar *basename_module, *basename_loaded;
|
2007-06-26 16:17:16 +00:00
|
|
|
GList *item;
|
|
|
|
|
2007-08-04 16:25:13 +00:00
|
|
|
basename_module = g_path_get_basename(g_module_name(module));
|
2007-06-26 16:17:16 +00:00
|
|
|
for (item = plugin_list; item != NULL; item = g_list_next(item))
|
|
|
|
{
|
2007-08-04 16:25:13 +00:00
|
|
|
basename_loaded = g_path_get_basename(
|
|
|
|
g_module_name(((Plugin*)item->data)->module));
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2007-08-04 16:25:13 +00:00
|
|
|
if (utils_str_equal(basename_module, basename_loaded))
|
|
|
|
{
|
|
|
|
g_free(basename_loaded);
|
|
|
|
g_free(basename_module);
|
2007-06-26 16:17:16 +00:00
|
|
|
return TRUE;
|
2007-08-04 16:25:13 +00:00
|
|
|
}
|
|
|
|
g_free(basename_loaded);
|
2007-06-26 16:17:16 +00:00
|
|
|
}
|
2008-03-17 15:48:15 +00:00
|
|
|
/* Look also through the list of active plugins. This prevents problems when we have the same
|
|
|
|
* plugin in libdir/geany/ AND in configdir/plugins/ and the one in libdir/geany/ is loaded
|
|
|
|
* as active plugin. The plugin manager list would only take the one in configdir/geany/ and
|
|
|
|
* the plugin manager would list both plugins. Additionally, unloading the active plugin
|
|
|
|
* would cause a crash. */
|
|
|
|
for (item = active_plugin_list; item != NULL; item = g_list_next(item))
|
|
|
|
{
|
|
|
|
basename_loaded = g_path_get_basename(g_module_name(((Plugin*)item->data)->module));
|
|
|
|
|
|
|
|
if (utils_str_equal(basename_module, basename_loaded))
|
|
|
|
{
|
|
|
|
g_free(basename_loaded);
|
|
|
|
g_free(basename_module);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
g_free(basename_loaded);
|
|
|
|
}
|
2007-08-04 16:25:13 +00:00
|
|
|
g_free(basename_module);
|
2007-06-26 16:17:16 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-17 15:48:15 +00:00
|
|
|
static Plugin *find_active_plugin_by_name(const gchar *filename)
|
|
|
|
{
|
|
|
|
GList *item;
|
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
g_return_val_if_fail(filename, FALSE);
|
2008-03-17 15:48:15 +00:00
|
|
|
|
|
|
|
for (item = active_plugin_list; item != NULL; item = g_list_next(item))
|
|
|
|
{
|
|
|
|
if (utils_str_equal(filename, ((Plugin*)item->data)->filename))
|
|
|
|
return item->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
static gboolean
|
|
|
|
plugin_check_version(GModule *module)
|
|
|
|
{
|
|
|
|
gint (*version_check)(gint) = NULL;
|
|
|
|
|
2008-05-26 17:09:43 +00:00
|
|
|
g_module_symbol(module, "plugin_version_check", (void *) &version_check);
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2009-04-05 21:07:40 +00:00
|
|
|
if (G_UNLIKELY(! version_check))
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
2008-05-26 17:09:43 +00:00
|
|
|
geany_debug("Plugin \"%s\" has no plugin_version_check() function - ignoring plugin!",
|
|
|
|
g_module_name(module));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-14 15:50:40 +00:00
|
|
|
gint result = version_check(GEANY_ABI_VERSION);
|
2008-05-26 17:09:43 +00:00
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
if (result < 0)
|
|
|
|
{
|
2009-04-09 12:12:58 +00:00
|
|
|
msgwin_status_add(_("The plugin \"%s\" is not binary compatible with this "
|
2008-04-03 17:24:06 +00:00
|
|
|
"release of Geany - please recompile it."), g_module_name(module));
|
2007-06-26 16:17:16 +00:00
|
|
|
geany_debug("Plugin \"%s\" is not binary compatible with this "
|
|
|
|
"release of Geany - recompile it.", g_module_name(module));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-06-18 15:04:07 +00:00
|
|
|
if (result > GEANY_API_VERSION)
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
|
|
|
geany_debug("Plugin \"%s\" requires a newer version of Geany (API >= v%d).",
|
|
|
|
g_module_name(module), result);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-23 12:29:32 +00:00
|
|
|
static void add_callbacks(Plugin *plugin, PluginCallback *callbacks)
|
2007-08-10 16:11:17 +00:00
|
|
|
{
|
2008-05-23 12:29:32 +00:00
|
|
|
PluginCallback *cb;
|
2007-08-15 12:29:57 +00:00
|
|
|
guint i, len = 0;
|
2007-08-10 16:11:17 +00:00
|
|
|
|
2007-08-15 12:29:57 +00:00
|
|
|
while (TRUE)
|
2007-08-10 16:11:17 +00:00
|
|
|
{
|
2007-08-15 12:29:57 +00:00
|
|
|
cb = &callbacks[len];
|
2007-08-10 16:11:17 +00:00
|
|
|
if (!cb->signal_name || !cb->callback)
|
|
|
|
break;
|
2007-08-15 12:29:57 +00:00
|
|
|
len++;
|
|
|
|
}
|
|
|
|
if (len == 0)
|
|
|
|
return;
|
2007-08-10 16:11:17 +00:00
|
|
|
|
2007-08-15 12:29:57 +00:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
cb = &callbacks[i];
|
|
|
|
|
2009-07-29 17:40:20 +00:00
|
|
|
plugin_signal_connect(&plugin->public, NULL, cb->signal_name, cb->after,
|
|
|
|
cb->callback, cb->user_data);
|
2007-08-15 12:29:57 +00:00
|
|
|
}
|
2007-08-10 16:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-24 11:35:13 +00:00
|
|
|
static void read_key_group(Plugin *plugin)
|
2008-03-07 18:00:22 +00:00
|
|
|
{
|
2009-08-24 11:35:13 +00:00
|
|
|
GeanyKeyGroupInfo *p_key_info;
|
|
|
|
GeanyKeyGroup **p_key_group;
|
2008-05-26 17:09:43 +00:00
|
|
|
|
2009-08-24 11:35:13 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_key_group_info", (void *) &p_key_info);
|
|
|
|
g_module_symbol(plugin->module, "plugin_key_group", (void *) &p_key_group);
|
|
|
|
if (p_key_info && p_key_group)
|
2009-06-23 12:51:16 +00:00
|
|
|
{
|
2009-08-24 11:35:13 +00:00
|
|
|
GeanyKeyGroupInfo *key_info = p_key_info;
|
2008-03-13 17:12:18 +00:00
|
|
|
|
2009-08-24 11:35:13 +00:00
|
|
|
if (*p_key_group)
|
|
|
|
geany_debug("Ignoring plugin_key_group symbol for plugin '%s' - "
|
|
|
|
"use plugin_set_key_group() instead to allocate keybindings dynamically.",
|
|
|
|
plugin->info.name);
|
|
|
|
else
|
2008-05-26 17:09:43 +00:00
|
|
|
{
|
2009-08-24 11:35:13 +00:00
|
|
|
if (key_info->count)
|
|
|
|
{
|
|
|
|
GeanyKeyGroup *key_group =
|
|
|
|
plugin_set_key_group(&plugin->public, key_info->name, key_info->count, NULL);
|
|
|
|
if (key_group)
|
|
|
|
*p_key_group = key_group;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
geany_debug("Ignoring plugin_key_group_info symbol for plugin '%s' - "
|
|
|
|
"count field is zero. Maybe use plugin_set_key_group() instead?",
|
|
|
|
plugin->info.name);
|
2008-05-26 17:09:43 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-31 15:25:35 +00:00
|
|
|
else if (p_key_info || p_key_group)
|
|
|
|
geany_debug("Ignoring only one of plugin_key_group[_info] symbols defined for plugin '%s'. "
|
|
|
|
"Maybe use plugin_set_key_group() instead?",
|
|
|
|
plugin->info.name);
|
2008-03-07 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
static void
|
|
|
|
plugin_init(Plugin *plugin)
|
|
|
|
{
|
2008-10-13 12:38:32 +00:00
|
|
|
GeanyPlugin **p_geany_plugin;
|
2008-05-23 12:29:32 +00:00
|
|
|
PluginCallback *callbacks;
|
2008-05-23 17:08:58 +00:00
|
|
|
PluginInfo **p_info;
|
2008-05-26 14:22:02 +00:00
|
|
|
PluginFields **plugin_fields;
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2010-05-30 18:05:18 +00:00
|
|
|
/* set these symbols before plugin_init() is called
|
|
|
|
* we don't set geany_functions and geany_data since they are set directly by plugin_new() */
|
2008-10-13 12:38:32 +00:00
|
|
|
g_module_symbol(plugin->module, "geany_plugin", (void *) &p_geany_plugin);
|
2009-04-15 22:47:33 +00:00
|
|
|
if (p_geany_plugin)
|
2008-10-13 12:38:32 +00:00
|
|
|
*p_geany_plugin = &plugin->public;
|
2008-05-26 14:17:41 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_info", (void *) &p_info);
|
2009-04-15 22:47:33 +00:00
|
|
|
if (p_info)
|
2008-05-26 14:17:41 +00:00
|
|
|
*p_info = &plugin->info;
|
2008-05-26 14:22:02 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_fields", (void *) &plugin_fields);
|
2008-05-26 14:17:41 +00:00
|
|
|
if (plugin_fields)
|
|
|
|
*plugin_fields = &plugin->fields;
|
2009-08-24 11:35:13 +00:00
|
|
|
read_key_group(plugin);
|
2008-05-26 14:17:41 +00:00
|
|
|
|
|
|
|
/* start the plugin */
|
2009-04-15 22:47:33 +00:00
|
|
|
g_return_if_fail(plugin->init);
|
2008-05-27 14:47:38 +00:00
|
|
|
plugin->init(&geany_data);
|
2008-05-26 14:17:41 +00:00
|
|
|
|
|
|
|
/* store some function pointers for later use */
|
2008-05-28 13:05:09 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_configure", (void *) &plugin->configure);
|
2009-09-24 16:28:59 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_configure_single", (void *) &plugin->configure_single);
|
|
|
|
if (app->debug_mode && plugin->configure && plugin->configure_single)
|
|
|
|
g_warning("Plugin '%s' implements plugin_configure_single() unnecessarily - "
|
|
|
|
"only plugin_configure() will be used!",
|
|
|
|
plugin->info.name);
|
|
|
|
|
2009-01-28 19:30:18 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_help", (void *) &plugin->help);
|
2008-05-26 17:09:43 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_cleanup", (void *) &plugin->cleanup);
|
2009-04-15 22:47:33 +00:00
|
|
|
if (plugin->cleanup == NULL)
|
2008-05-26 14:17:41 +00:00
|
|
|
{
|
|
|
|
if (app->debug_mode)
|
2008-05-26 17:09:43 +00:00
|
|
|
g_warning("Plugin '%s' has no plugin_cleanup() function - there may be memory leaks!",
|
2008-05-26 14:17:41 +00:00
|
|
|
plugin->info.name);
|
|
|
|
}
|
|
|
|
|
2008-05-26 17:09:43 +00:00
|
|
|
/* now read any plugin-owned data that might have been set in plugin_init() */
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
if (plugin->fields.flags & PLUGIN_IS_DOCUMENT_SENSITIVE)
|
|
|
|
{
|
2008-10-15 12:19:24 +00:00
|
|
|
ui_add_document_sensitive(plugin->fields.menu_item);
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
2008-05-23 12:29:32 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_callbacks", (void *) &callbacks);
|
2007-11-20 18:15:46 +00:00
|
|
|
if (callbacks)
|
|
|
|
add_callbacks(plugin, callbacks);
|
|
|
|
|
2008-05-26 14:17:41 +00:00
|
|
|
/* remember which plugins are active */
|
2007-11-20 18:15:46 +00:00
|
|
|
active_plugin_list = g_list_append(active_plugin_list, plugin);
|
|
|
|
|
|
|
|
geany_debug("Loaded: %s (%s)", plugin->filename,
|
2008-05-23 17:08:58 +00:00
|
|
|
NVL(plugin->info.name, "<Unknown>"));
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-27 14:47:38 +00:00
|
|
|
/* Load and optionally init a plugin.
|
2008-05-26 17:09:43 +00:00
|
|
|
* init_plugin decides whether the plugin's plugin_init() function should be called or not. If it is
|
2008-03-13 09:18:41 +00:00
|
|
|
* called, the plugin will be started, if not the plugin will be read only (for the list of
|
2008-03-17 15:48:15 +00:00
|
|
|
* available plugins in the plugin manager).
|
|
|
|
* When add_to_list is set, the plugin will be added to the plugin manager's plugin_list. */
|
2007-06-26 16:17:16 +00:00
|
|
|
static Plugin*
|
2008-03-17 15:48:15 +00:00
|
|
|
plugin_new(const gchar *fname, gboolean init_plugin, gboolean add_to_list)
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
|
|
|
Plugin *plugin;
|
|
|
|
GModule *module;
|
2010-05-30 18:05:18 +00:00
|
|
|
GeanyData **p_geany_data;
|
|
|
|
GeanyFunctions **p_geany_functions;
|
2008-05-23 17:08:58 +00:00
|
|
|
void (*plugin_set_info)(PluginInfo*);
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
g_return_val_if_fail(fname, NULL);
|
2007-06-26 16:17:16 +00:00
|
|
|
g_return_val_if_fail(g_module_supported(), NULL);
|
|
|
|
|
2008-03-17 15:48:15 +00:00
|
|
|
/* find the plugin in the list of already loaded, active plugins and use it, otherwise
|
|
|
|
* load the module */
|
|
|
|
plugin = find_active_plugin_by_name(fname);
|
|
|
|
if (plugin != NULL)
|
|
|
|
{
|
|
|
|
geany_debug("Plugin \"%s\" already loaded.", fname);
|
|
|
|
if (add_to_list)
|
|
|
|
plugin_list = g_list_append(plugin_list, plugin);
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
2007-07-04 11:32:33 +00:00
|
|
|
/* Don't use G_MODULE_BIND_LAZY otherwise we can get unresolved symbols at runtime,
|
2007-07-23 15:41:08 +00:00
|
|
|
* causing a segfault. Without that flag the module will safely fail to load.
|
|
|
|
* G_MODULE_BIND_LOCAL also helps find undefined symbols e.g. app when it would
|
|
|
|
* otherwise not be detected due to the shadowing of Geany's app variable.
|
2008-05-23 17:08:58 +00:00
|
|
|
* Also without G_MODULE_BIND_LOCAL calling public functions e.g. the old info()
|
|
|
|
* function from a plugin will be shadowed. */
|
2007-07-23 15:41:08 +00:00
|
|
|
module = g_module_open(fname, G_MODULE_BIND_LOCAL);
|
2009-04-15 22:47:33 +00:00
|
|
|
if (! module)
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
2008-10-13 15:52:32 +00:00
|
|
|
geany_debug("Can't load plugin: %s", g_module_error());
|
2007-06-26 16:17:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plugin_loaded(module))
|
|
|
|
{
|
|
|
|
geany_debug("Plugin \"%s\" already loaded.", fname);
|
|
|
|
|
|
|
|
if (! g_module_close(module))
|
|
|
|
g_warning("%s: %s", fname, g_module_error());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! plugin_check_version(module))
|
|
|
|
{
|
|
|
|
if (! g_module_close(module))
|
|
|
|
g_warning("%s: %s", fname, g_module_error());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-23 17:08:58 +00:00
|
|
|
g_module_symbol(module, "plugin_set_info", (void *) &plugin_set_info);
|
2009-04-15 22:47:33 +00:00
|
|
|
if (plugin_set_info == NULL)
|
2007-06-27 15:56:42 +00:00
|
|
|
{
|
2008-05-26 17:09:43 +00:00
|
|
|
geany_debug("No plugin_set_info() defined for \"%s\" - ignoring plugin!", fname);
|
2007-06-27 15:56:42 +00:00
|
|
|
|
|
|
|
if (! g_module_close(module))
|
|
|
|
g_warning("%s: %s", fname, g_module_error());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
plugin = g_new0(Plugin, 1);
|
2008-05-23 17:08:58 +00:00
|
|
|
|
2010-05-30 18:05:18 +00:00
|
|
|
/* set basic fields here to allow plugins to call Geany functions in set_info() */
|
|
|
|
g_module_symbol(module, "geany_data", (void *) &p_geany_data);
|
|
|
|
if (p_geany_data)
|
|
|
|
*p_geany_data = &geany_data;
|
|
|
|
g_module_symbol(module, "geany_functions", (void *) &p_geany_functions);
|
|
|
|
if (p_geany_functions)
|
|
|
|
*p_geany_functions = &geany_functions;
|
|
|
|
|
2008-05-23 17:08:58 +00:00
|
|
|
/* read plugin name, etc. */
|
|
|
|
plugin_set_info(&plugin->info);
|
|
|
|
if (!NZV(plugin->info.name))
|
|
|
|
{
|
2008-05-26 17:09:43 +00:00
|
|
|
geany_debug("No plugin name set in plugin_set_info() for \"%s\" - ignoring plugin!",
|
|
|
|
fname);
|
2008-05-23 17:08:58 +00:00
|
|
|
|
|
|
|
if (! g_module_close(module))
|
|
|
|
g_warning("%s: %s", fname, g_module_error());
|
|
|
|
g_free(plugin);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-05-27 14:47:38 +00:00
|
|
|
|
|
|
|
g_module_symbol(module, "plugin_init", (void *) &plugin->init);
|
2009-04-15 22:47:33 +00:00
|
|
|
if (plugin->init == NULL)
|
2008-05-27 14:47:38 +00:00
|
|
|
{
|
|
|
|
geany_debug("Plugin '%s' has no plugin_init() function - ignoring plugin!",
|
|
|
|
plugin->info.name);
|
|
|
|
|
|
|
|
if (! g_module_close(module))
|
|
|
|
g_warning("%s: %s", fname, g_module_error());
|
|
|
|
g_free(plugin);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-04-28 18:20:35 +00:00
|
|
|
/*geany_debug("Initializing plugin '%s'", plugin->info.name);*/
|
2008-05-23 17:08:58 +00:00
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
plugin->filename = g_strdup(fname);
|
|
|
|
plugin->module = module;
|
2008-10-13 12:38:32 +00:00
|
|
|
plugin->public.info = &plugin->info;
|
2009-08-18 15:57:50 +00:00
|
|
|
plugin->public.priv = plugin;
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2008-03-13 09:18:41 +00:00
|
|
|
if (init_plugin)
|
2007-11-20 18:15:46 +00:00
|
|
|
plugin_init(plugin);
|
2008-03-17 15:48:15 +00:00
|
|
|
|
|
|
|
if (add_to_list)
|
|
|
|
plugin_list = g_list_append(plugin_list, plugin);
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-15 12:29:57 +00:00
|
|
|
static void remove_callbacks(Plugin *plugin)
|
|
|
|
{
|
2009-08-18 15:57:50 +00:00
|
|
|
GArray *signal_ids = plugin->signal_ids;
|
2009-07-30 11:56:25 +00:00
|
|
|
SignalConnection *sc;
|
2007-08-15 12:29:57 +00:00
|
|
|
|
2009-07-29 17:40:20 +00:00
|
|
|
if (signal_ids == NULL)
|
2007-08-15 12:29:57 +00:00
|
|
|
return;
|
|
|
|
|
2009-07-30 11:56:25 +00:00
|
|
|
foreach_array(SignalConnection, sc, signal_ids)
|
|
|
|
g_signal_handler_disconnect(sc->object, sc->handler_id);
|
2009-07-29 17:40:20 +00:00
|
|
|
|
|
|
|
g_array_free(signal_ids, TRUE);
|
2007-08-15 12:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-17 15:48:15 +00:00
|
|
|
static gboolean is_active_plugin(Plugin *plugin)
|
|
|
|
{
|
|
|
|
return (g_list_find(active_plugin_list, plugin) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-13 15:40:12 +00:00
|
|
|
/* Clean up anything used by an active plugin */
|
2007-11-20 18:15:46 +00:00
|
|
|
static void
|
2008-10-13 15:40:12 +00:00
|
|
|
plugin_cleanup(Plugin *plugin)
|
2007-11-20 18:15:46 +00:00
|
|
|
{
|
2008-10-13 12:38:32 +00:00
|
|
|
GtkWidget *widget;
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (plugin->cleanup)
|
2008-03-07 18:00:22 +00:00
|
|
|
plugin->cleanup();
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-03-07 18:00:22 +00:00
|
|
|
remove_callbacks(plugin);
|
|
|
|
|
|
|
|
if (plugin->key_group)
|
2009-08-25 16:55:56 +00:00
|
|
|
keybindings_free_group(plugin->key_group);
|
|
|
|
|
2009-08-18 15:57:50 +00:00
|
|
|
widget = plugin->toolbar_separator.widget;
|
2008-10-13 12:38:32 +00:00
|
|
|
if (widget)
|
|
|
|
gtk_widget_destroy(widget);
|
|
|
|
|
2008-03-07 18:00:22 +00:00
|
|
|
geany_debug("Unloaded: %s", plugin->filename);
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
static void
|
2008-05-27 15:10:08 +00:00
|
|
|
plugin_free(Plugin *plugin)
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
2009-04-15 22:47:33 +00:00
|
|
|
g_return_if_fail(plugin);
|
|
|
|
g_return_if_fail(plugin->module);
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2008-10-13 15:40:12 +00:00
|
|
|
if (is_active_plugin(plugin))
|
|
|
|
plugin_cleanup(plugin);
|
|
|
|
|
|
|
|
active_plugin_list = g_list_remove(active_plugin_list, plugin);
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2009-04-05 21:07:40 +00:00
|
|
|
if (! g_module_close(plugin->module))
|
2007-06-26 16:17:16 +00:00
|
|
|
g_warning("%s: %s", plugin->filename, g_module_error());
|
|
|
|
|
2008-03-17 15:48:15 +00:00
|
|
|
plugin_list = g_list_remove(plugin_list, plugin);
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
g_free(plugin->filename);
|
|
|
|
g_free(plugin);
|
2008-03-17 15:48:15 +00:00
|
|
|
plugin = NULL;
|
2007-06-26 16:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-13 09:18:41 +00:00
|
|
|
/* load active plugins at startup */
|
|
|
|
static void
|
2009-01-11 18:29:39 +00:00
|
|
|
load_active_plugins(void)
|
2008-03-13 09:18:41 +00:00
|
|
|
{
|
|
|
|
guint i, len;
|
|
|
|
|
2008-04-22 13:05:31 +00:00
|
|
|
if (active_plugins_pref == NULL || (len = g_strv_length(active_plugins_pref)) == 0)
|
2008-03-13 09:18:41 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
2008-04-16 16:22:28 +00:00
|
|
|
const gchar *fname = active_plugins_pref[i];
|
|
|
|
|
2008-07-15 17:16:28 +00:00
|
|
|
if (NZV(fname) && g_file_test(fname, G_FILE_TEST_EXISTS))
|
2008-04-16 16:22:28 +00:00
|
|
|
{
|
|
|
|
if (plugin_new(fname, TRUE, FALSE) == NULL)
|
|
|
|
failed_plugins_list = g_list_append(failed_plugins_list, g_strdup(fname));
|
|
|
|
}
|
2008-03-13 09:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-26 12:06:12 +00:00
|
|
|
static void
|
2008-03-17 15:48:15 +00:00
|
|
|
load_plugins_from_path(const gchar *path)
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
|
|
|
GSList *list, *item;
|
2007-07-28 17:44:02 +00:00
|
|
|
gchar *fname, *tmp;
|
2007-06-26 16:17:16 +00:00
|
|
|
|
|
|
|
list = utils_get_file_list(path, NULL, NULL);
|
|
|
|
|
|
|
|
for (item = list; item != NULL; item = g_slist_next(item))
|
|
|
|
{
|
2007-07-28 17:44:02 +00:00
|
|
|
tmp = strrchr(item->data, '.');
|
2009-04-27 19:29:33 +00:00
|
|
|
if (tmp == NULL || utils_str_casecmp(tmp, "." G_MODULE_SUFFIX) != 0)
|
2007-07-28 17:44:02 +00:00
|
|
|
continue;
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2007-07-28 17:44:02 +00:00
|
|
|
fname = g_strconcat(path, G_DIR_SEPARATOR_S, item->data, NULL);
|
2008-04-16 16:22:28 +00:00
|
|
|
plugin_new(fname, FALSE, TRUE);
|
2007-06-26 16:17:16 +00:00
|
|
|
g_free(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_foreach(list, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-28 17:44:02 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
static gchar *get_plugin_path()
|
|
|
|
{
|
2009-03-26 20:10:47 +00:00
|
|
|
gchar *install_dir = win32_get_installation_dir();
|
2007-07-28 17:44:02 +00:00
|
|
|
gchar *path;
|
|
|
|
|
2008-06-09 19:29:54 +00:00
|
|
|
path = g_strconcat(install_dir, "\\lib", NULL);
|
2009-03-26 20:10:47 +00:00
|
|
|
g_free(install_dir);
|
2007-07-28 17:44:02 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-03-19 17:42:03 +00:00
|
|
|
/* Load (but don't initialize) all plugins for the Plugin Manager dialog */
|
|
|
|
static void load_all_plugins(void)
|
2007-07-26 12:06:12 +00:00
|
|
|
{
|
2007-07-28 17:44:02 +00:00
|
|
|
gchar *path;
|
2007-07-27 11:34:16 +00:00
|
|
|
|
2007-07-28 17:44:02 +00:00
|
|
|
path = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "plugins", NULL);
|
2009-03-13 10:02:29 +00:00
|
|
|
/* first load plugins in ~/.config/geany/plugins/ */
|
2008-03-17 15:48:15 +00:00
|
|
|
load_plugins_from_path(path);
|
2007-07-28 17:44:02 +00:00
|
|
|
g_free(path);
|
2009-03-13 10:02:29 +00:00
|
|
|
|
|
|
|
/* load plugins from a custom path */
|
|
|
|
if (NZV(prefs.custom_plugin_path))
|
|
|
|
load_plugins_from_path(prefs.custom_plugin_path);
|
|
|
|
|
|
|
|
/* finally load plugins from $prefix/lib/geany */
|
2007-12-12 20:04:45 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2007-07-28 17:44:02 +00:00
|
|
|
path = get_plugin_path();
|
|
|
|
#else
|
2007-12-19 15:37:10 +00:00
|
|
|
path = g_strconcat(GEANY_LIBDIR, G_DIR_SEPARATOR_S "geany", NULL);
|
2007-07-28 17:44:02 +00:00
|
|
|
#endif
|
2008-03-17 15:48:15 +00:00
|
|
|
load_plugins_from_path(path);
|
2007-07-28 17:44:02 +00:00
|
|
|
g_free(path);
|
2007-07-26 12:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-15 11:59:32 +00:00
|
|
|
static void on_tools_menu_show(GtkWidget *menu_item, G_GNUC_UNUSED gpointer user_data)
|
|
|
|
{
|
|
|
|
GList *item, *list = gtk_container_get_children(GTK_CONTAINER(menu_item));
|
|
|
|
guint i = 0;
|
|
|
|
gboolean have_plugin_menu_items = FALSE;
|
|
|
|
|
|
|
|
for (item = list; item != NULL; item = g_list_next(item))
|
|
|
|
{
|
|
|
|
if (item->data == menu_separator)
|
|
|
|
{
|
|
|
|
if (i < g_list_length(list) - 1)
|
|
|
|
{
|
|
|
|
have_plugin_menu_items = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
g_list_free(list);
|
|
|
|
|
|
|
|
ui_widget_show_hide(menu_separator, have_plugin_menu_items);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-28 13:21:35 +00:00
|
|
|
/* Calling this starts up plugin support */
|
|
|
|
void plugins_load_active(void)
|
2007-08-10 16:11:17 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2008-12-28 13:21:35 +00:00
|
|
|
want_plugins = TRUE;
|
|
|
|
|
2007-08-10 16:11:17 +00:00
|
|
|
geany_data_init();
|
|
|
|
|
2008-04-01 12:01:49 +00:00
|
|
|
widget = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(widget);
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
|
2008-04-01 12:01:49 +00:00
|
|
|
|
2008-03-19 17:15:28 +00:00
|
|
|
widget = gtk_menu_item_new_with_mnemonic(_("_Plugin Manager"));
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), widget);
|
2007-11-20 18:15:46 +00:00
|
|
|
gtk_widget_show(widget);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(widget, "activate", G_CALLBACK(pm_show_dialog), NULL);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
menu_separator = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), menu_separator);
|
2008-10-15 11:59:32 +00:00
|
|
|
g_signal_connect(main_widgets.tools_menu, "show", G_CALLBACK(on_tools_menu_show), NULL);
|
2007-11-23 16:37:03 +00:00
|
|
|
|
2008-03-13 09:18:41 +00:00
|
|
|
load_active_plugins();
|
2007-08-10 16:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-18 17:28:11 +00:00
|
|
|
static gint cmp_plugin_names(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
const Plugin *pa = a;
|
|
|
|
const Plugin *pb = b;
|
|
|
|
|
|
|
|
return strcmp(pa->info.name, pb->info.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-16 15:44:29 +00:00
|
|
|
static void update_active_plugins_pref(void)
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
2007-11-20 18:15:46 +00:00
|
|
|
gint i = 0;
|
|
|
|
GList *list;
|
2008-04-16 16:22:28 +00:00
|
|
|
gsize count = g_list_length(active_plugin_list) + g_list_length(failed_plugins_list);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-04-16 15:44:29 +00:00
|
|
|
g_strfreev(active_plugins_pref);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-04-16 16:22:28 +00:00
|
|
|
if (count == 0)
|
2007-11-20 18:15:46 +00:00
|
|
|
{
|
2008-04-16 15:44:29 +00:00
|
|
|
active_plugins_pref = NULL;
|
2007-11-20 18:15:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-18 17:28:11 +00:00
|
|
|
/* sort the list so next time tools menu items are sorted by plugin name
|
|
|
|
* (not ideal to do here, but better than nothing) */
|
|
|
|
active_plugin_list = g_list_sort(active_plugin_list, cmp_plugin_names);
|
|
|
|
|
2008-04-16 16:22:28 +00:00
|
|
|
active_plugins_pref = g_new0(gchar*, count + 1);
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
for (list = g_list_first(active_plugin_list); list != NULL; list = list->next)
|
|
|
|
{
|
2008-04-16 16:22:28 +00:00
|
|
|
Plugin *plugin = list->data;
|
|
|
|
|
|
|
|
active_plugins_pref[i] = g_strdup(plugin->filename);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
for (list = g_list_first(failed_plugins_list); list != NULL; list = list->next)
|
|
|
|
{
|
|
|
|
const gchar *fname = list->data;
|
|
|
|
|
|
|
|
active_plugins_pref[i] = g_strdup(fname);
|
2007-11-20 18:15:46 +00:00
|
|
|
i++;
|
|
|
|
}
|
2008-04-16 15:44:29 +00:00
|
|
|
active_plugins_pref[i] = NULL;
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
2007-08-10 16:11:17 +00:00
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-12-28 13:21:35 +00:00
|
|
|
static void on_save_settings(GKeyFile *config)
|
2008-04-16 15:09:52 +00:00
|
|
|
{
|
2008-12-28 13:21:35 +00:00
|
|
|
/* if plugins are disabled, don't clear list of active plugins */
|
|
|
|
if (want_plugins)
|
|
|
|
update_active_plugins_pref();
|
2008-04-16 15:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-28 13:21:35 +00:00
|
|
|
/* called even if plugin support is disabled */
|
|
|
|
void plugins_init(void)
|
2008-04-16 15:09:52 +00:00
|
|
|
{
|
2010-03-18 17:04:17 +00:00
|
|
|
StashGroup *group;
|
2008-12-28 13:21:35 +00:00
|
|
|
|
|
|
|
group = stash_group_new("plugins");
|
|
|
|
configuration_add_pref_group(group, TRUE);
|
|
|
|
|
|
|
|
stash_group_add_toggle_button(group, &prefs.load_plugins,
|
|
|
|
"load_plugins", TRUE, "check_plugins");
|
2009-03-13 10:02:29 +00:00
|
|
|
stash_group_add_entry(group, &prefs.custom_plugin_path,
|
|
|
|
"custom_plugin_path", "", "extra_plugin_path_entry");
|
2008-12-28 13:21:35 +00:00
|
|
|
|
|
|
|
g_signal_connect(geany_object, "save-settings", G_CALLBACK(on_save_settings), NULL);
|
|
|
|
stash_group_add_string_vector(group, &active_plugins_pref, "active_plugins", NULL);
|
2008-04-16 15:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-28 13:21:35 +00:00
|
|
|
/* called even if plugin support is disabled */
|
|
|
|
void plugins_finalize(void)
|
2007-11-20 18:15:46 +00:00
|
|
|
{
|
2008-04-16 16:22:28 +00:00
|
|
|
if (failed_plugins_list != NULL)
|
|
|
|
{
|
|
|
|
g_list_foreach(failed_plugins_list, (GFunc) g_free, NULL);
|
|
|
|
g_list_free(failed_plugins_list);
|
|
|
|
}
|
2007-11-20 18:15:46 +00:00
|
|
|
if (active_plugin_list != NULL)
|
2008-03-17 15:48:15 +00:00
|
|
|
{
|
2008-05-27 15:10:08 +00:00
|
|
|
g_list_foreach(active_plugin_list, (GFunc) plugin_free, NULL);
|
2007-11-20 18:15:46 +00:00
|
|
|
g_list_free(active_plugin_list);
|
2008-03-17 15:48:15 +00:00
|
|
|
}
|
2008-04-16 15:44:29 +00:00
|
|
|
g_strfreev(active_plugins_pref);
|
2007-06-26 16:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-29 18:35:30 +00:00
|
|
|
/* Check whether there are any plugins loaded which provide a configure symbol */
|
|
|
|
gboolean plugins_have_preferences(void)
|
|
|
|
{
|
|
|
|
GList *item;
|
|
|
|
|
|
|
|
if (active_plugin_list == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
foreach_list(item, active_plugin_list)
|
|
|
|
{
|
|
|
|
Plugin *plugin = item->data;
|
|
|
|
if (plugin->configure != NULL || plugin->configure_single != NULL)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
/* Plugin Manager */
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PLUGIN_COLUMN_CHECK = 0,
|
|
|
|
PLUGIN_COLUMN_NAME,
|
|
|
|
PLUGIN_COLUMN_FILE,
|
|
|
|
PLUGIN_COLUMN_PLUGIN,
|
2009-01-28 19:30:18 +00:00
|
|
|
PLUGIN_N_COLUMNS,
|
|
|
|
PM_BUTTON_CONFIGURE,
|
|
|
|
PM_BUTTON_HELP
|
2007-11-20 18:15:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *tree;
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkWidget *description_label;
|
|
|
|
GtkWidget *configure_button;
|
2009-01-28 19:30:18 +00:00
|
|
|
GtkWidget *help_button;
|
2008-10-15 12:19:24 +00:00
|
|
|
}
|
|
|
|
PluginManagerWidgets;
|
2008-05-28 13:05:09 +00:00
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
static PluginManagerWidgets pm_widgets;
|
|
|
|
|
|
|
|
|
2009-09-24 16:28:59 +00:00
|
|
|
static void pm_update_buttons(Plugin *p)
|
|
|
|
{
|
|
|
|
gboolean is_active;
|
|
|
|
|
|
|
|
is_active = is_active_plugin(p);
|
|
|
|
gtk_widget_set_sensitive(pm_widgets.configure_button,
|
|
|
|
(p->configure || p->configure_single) && is_active);
|
|
|
|
gtk_widget_set_sensitive(pm_widgets.help_button, p->help != NULL && is_active);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pm_selection_changed(GtkTreeSelection *selection, gpointer user_data)
|
2007-11-20 18:15:46 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
Plugin *p;
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected(selection, &model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
|
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (p != NULL)
|
2007-11-20 18:15:46 +00:00
|
|
|
{
|
|
|
|
gchar *text;
|
2008-03-17 15:48:15 +00:00
|
|
|
PluginInfo *pi;
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-05-23 17:08:58 +00:00
|
|
|
pi = &p->info;
|
2007-11-20 18:15:46 +00:00
|
|
|
text = g_strdup_printf(
|
|
|
|
_("Plugin: %s %s\nDescription: %s\nAuthor(s): %s"),
|
|
|
|
pi->name, pi->version, pi->description, pi->author);
|
|
|
|
|
2008-01-09 13:24:36 +00:00
|
|
|
geany_wrap_label_set_text(GTK_LABEL(pm_widgets.description_label), text);
|
2007-11-20 18:15:46 +00:00
|
|
|
g_free(text);
|
|
|
|
|
2009-09-24 16:28:59 +00:00
|
|
|
pm_update_buttons(p);
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data)
|
|
|
|
{
|
|
|
|
gboolean old_state, state;
|
2008-03-17 15:48:15 +00:00
|
|
|
gchar *file_name;
|
2007-11-20 18:15:46 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_string(pth);
|
|
|
|
Plugin *p;
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter(GTK_TREE_MODEL(pm_widgets.store), &iter, path);
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
|
|
|
|
gtk_tree_model_get(GTK_TREE_MODEL(pm_widgets.store), &iter,
|
|
|
|
PLUGIN_COLUMN_CHECK, &old_state, PLUGIN_COLUMN_PLUGIN, &p, -1);
|
2010-02-01 17:45:18 +00:00
|
|
|
|
|
|
|
/* no plugins item */
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
state = ! old_state; /* toggle the state */
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-03-17 15:48:15 +00:00
|
|
|
/* save the filename of the plugin */
|
|
|
|
file_name = g_strdup(p->filename);
|
2008-03-20 16:17:59 +00:00
|
|
|
|
|
|
|
/* unload plugin module */
|
|
|
|
if (!state)
|
2009-01-28 19:30:18 +00:00
|
|
|
/* save shortcuts (only need this group, but it doesn't take long) */
|
|
|
|
keybindings_write_to_file();
|
|
|
|
|
2008-05-27 15:10:08 +00:00
|
|
|
plugin_free(p);
|
2008-03-20 16:17:59 +00:00
|
|
|
|
|
|
|
/* reload plugin module and initialize it if item is checked */
|
2008-03-17 15:48:15 +00:00
|
|
|
p = plugin_new(file_name, state, TRUE);
|
2009-09-01 17:20:34 +00:00
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
/* plugin file may no longer be on disk, or is now incompatible */
|
|
|
|
gtk_list_store_remove(pm_widgets.store, &iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (state)
|
|
|
|
keybindings_load_keyfile(); /* load shortcuts */
|
|
|
|
|
|
|
|
/* update model */
|
|
|
|
gtk_list_store_set(pm_widgets.store, &iter,
|
|
|
|
PLUGIN_COLUMN_CHECK, state,
|
|
|
|
PLUGIN_COLUMN_PLUGIN, p, -1);
|
|
|
|
|
|
|
|
/* set again the sensitiveness of the configure and help buttons */
|
2009-09-24 16:28:59 +00:00
|
|
|
pm_update_buttons(p);
|
2009-09-01 17:20:34 +00:00
|
|
|
}
|
2008-03-17 15:48:15 +00:00
|
|
|
g_free(file_name);
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pm_prepare_treeview(GtkWidget *tree, GtkListStore *store)
|
|
|
|
{
|
|
|
|
GtkCellRenderer *text_renderer, *checkbox_renderer;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GList *list;
|
|
|
|
GtkTreeSelection *sel;
|
|
|
|
|
|
|
|
checkbox_renderer = gtk_cell_renderer_toggle_new();
|
|
|
|
column = gtk_tree_view_column_new_with_attributes(
|
|
|
|
_("Active"), checkbox_renderer, "active", PLUGIN_COLUMN_CHECK, NULL);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(checkbox_renderer, "toggled", G_CALLBACK(pm_plugin_toggled), NULL);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
text_renderer = gtk_cell_renderer_text_new();
|
|
|
|
column = gtk_tree_view_column_new_with_attributes(
|
|
|
|
_("Plugin"), text_renderer, "text", PLUGIN_COLUMN_NAME, NULL);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
|
|
|
|
|
|
|
|
text_renderer = gtk_cell_renderer_text_new();
|
|
|
|
g_object_set(text_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
column = gtk_tree_view_column_new_with_attributes(
|
|
|
|
_("File"), text_renderer, "text", PLUGIN_COLUMN_FILE, NULL);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
|
|
|
|
|
2007-12-12 16:34:02 +00:00
|
|
|
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE);
|
2007-11-20 18:15:46 +00:00
|
|
|
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
|
|
|
|
gtk_tree_sortable_set_sort_column_id(
|
|
|
|
GTK_TREE_SORTABLE(store), PLUGIN_COLUMN_NAME, GTK_SORT_ASCENDING);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* selection handling */
|
2007-11-20 18:15:46 +00:00
|
|
|
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
|
|
|
|
gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(sel, "changed", G_CALLBACK(pm_selection_changed), NULL);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
list = g_list_first(plugin_list);
|
|
|
|
if (list == NULL)
|
|
|
|
{
|
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
gtk_list_store_set(store, &iter, PLUGIN_COLUMN_CHECK, FALSE,
|
|
|
|
PLUGIN_COLUMN_NAME, _("No plugins available."),
|
|
|
|
PLUGIN_COLUMN_FILE, "", PLUGIN_COLUMN_PLUGIN, NULL, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-05 21:07:40 +00:00
|
|
|
Plugin *p;
|
2007-11-20 18:15:46 +00:00
|
|
|
for (; list != NULL; list = list->next)
|
|
|
|
{
|
2009-04-05 21:07:40 +00:00
|
|
|
p = list->data;
|
2008-05-23 17:08:58 +00:00
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
gtk_list_store_set(store, &iter,
|
2008-05-23 17:08:58 +00:00
|
|
|
PLUGIN_COLUMN_CHECK, is_active_plugin(p),
|
|
|
|
PLUGIN_COLUMN_NAME, p->info.name,
|
|
|
|
PLUGIN_COLUMN_FILE, p->filename,
|
|
|
|
PLUGIN_COLUMN_PLUGIN, p,
|
2007-11-20 18:15:46 +00:00
|
|
|
-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
|
2008-10-07 18:51:50 +00:00
|
|
|
g_object_unref(store);
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-24 16:28:59 +00:00
|
|
|
static void pm_on_plugin_button_clicked(GtkButton *button, gpointer user_data)
|
2007-11-20 18:15:46 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
Plugin *p;
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pm_widgets.tree));
|
|
|
|
if (gtk_tree_selection_get_selected(selection, &model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
|
|
|
|
|
2009-04-15 22:47:33 +00:00
|
|
|
if (p != NULL)
|
2007-11-20 18:15:46 +00:00
|
|
|
{
|
2009-01-28 19:30:18 +00:00
|
|
|
if (GPOINTER_TO_INT(user_data) == PM_BUTTON_CONFIGURE)
|
2009-09-27 14:07:24 +00:00
|
|
|
plugin_show_configure(&p->public);
|
2009-01-28 19:30:18 +00:00
|
|
|
else if (GPOINTER_TO_INT(user_data) == PM_BUTTON_HELP && p->help != NULL)
|
|
|
|
p->help();
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-27 15:10:08 +00:00
|
|
|
static void
|
|
|
|
free_non_active_plugin(gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
Plugin *plugin = data;
|
|
|
|
|
|
|
|
/* don't do anything when closing the plugin manager and it is an active plugin */
|
|
|
|
if (is_active_plugin(plugin))
|
|
|
|
return;
|
|
|
|
|
|
|
|
plugin_free(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-17 15:48:15 +00:00
|
|
|
static void pm_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
|
|
|
|
{
|
|
|
|
if (plugin_list != NULL)
|
|
|
|
{
|
|
|
|
/* remove all non-active plugins from the list */
|
2008-05-27 15:10:08 +00:00
|
|
|
g_list_foreach(plugin_list, free_non_active_plugin, NULL);
|
2008-03-17 15:48:15 +00:00
|
|
|
g_list_free(plugin_list);
|
|
|
|
plugin_list = NULL;
|
|
|
|
}
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(dialog));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data)
|
|
|
|
{
|
2008-09-18 11:41:27 +00:00
|
|
|
GtkWidget *vbox, *vbox2, *label_vbox, *hbox, *swin, *label, *label2, *desc_win;
|
2008-03-13 09:18:41 +00:00
|
|
|
|
|
|
|
/* before showing the dialog, we need to create the list of available plugins */
|
2008-03-19 17:42:03 +00:00
|
|
|
load_all_plugins();
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
pm_widgets.dialog = gtk_dialog_new_with_buttons(_("Plugins"), GTK_WINDOW(main_widgets.window),
|
2007-11-20 18:15:46 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
2008-03-19 17:15:28 +00:00
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_CANCEL, NULL);
|
2007-11-20 18:15:46 +00:00
|
|
|
vbox = ui_dialog_vbox_new(GTK_DIALOG(pm_widgets.dialog));
|
|
|
|
gtk_widget_set_name(pm_widgets.dialog, "GeanyDialog");
|
|
|
|
gtk_box_set_spacing(GTK_BOX(vbox), 6);
|
|
|
|
|
2009-07-04 10:47:47 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(pm_widgets.dialog), 500, 450);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
pm_widgets.tree = gtk_tree_view_new();
|
|
|
|
pm_widgets.store = gtk_list_store_new(
|
|
|
|
PLUGIN_N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
|
|
|
|
pm_prepare_treeview(pm_widgets.tree, pm_widgets.store);
|
|
|
|
|
|
|
|
swin = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add(GTK_CONTAINER(swin), pm_widgets.tree);
|
|
|
|
|
2009-09-07 12:10:57 +00:00
|
|
|
label = geany_wrap_label_new(_("Choose which plugins should be loaded at startup:"));
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
pm_widgets.configure_button = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
|
|
|
|
gtk_widget_set_sensitive(pm_widgets.configure_button, FALSE);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(pm_widgets.configure_button, "clicked",
|
2009-01-28 19:30:18 +00:00
|
|
|
G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_CONFIGURE));
|
|
|
|
|
|
|
|
pm_widgets.help_button = gtk_button_new_from_stock(GTK_STOCK_HELP);
|
|
|
|
gtk_widget_set_sensitive(pm_widgets.help_button, FALSE);
|
|
|
|
g_signal_connect(pm_widgets.help_button, "clicked",
|
|
|
|
G_CALLBACK(pm_on_plugin_button_clicked), GINT_TO_POINTER(PM_BUTTON_HELP));
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
label2 = gtk_label_new(_("<b>Plugin details:</b>"));
|
|
|
|
gtk_label_set_use_markup(GTK_LABEL(label2), TRUE);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
|
2008-09-18 11:41:27 +00:00
|
|
|
|
2008-01-09 13:24:36 +00:00
|
|
|
pm_widgets.description_label = geany_wrap_label_new("");
|
2008-09-18 11:41:27 +00:00
|
|
|
desc_win = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(desc_win),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(desc_win),
|
|
|
|
pm_widgets.description_label);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
hbox = gtk_hbox_new(FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), label2, TRUE, TRUE, 0);
|
2009-01-28 19:30:18 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), pm_widgets.help_button, FALSE, FALSE, 4);
|
2007-11-20 18:15:46 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), pm_widgets.configure_button, FALSE, FALSE, 0);
|
|
|
|
|
2009-01-28 19:30:18 +00:00
|
|
|
label_vbox = gtk_vbox_new(FALSE, 3);
|
2007-11-20 18:15:46 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(label_vbox), hbox, FALSE, FALSE, 0);
|
2008-09-18 11:41:27 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(label_vbox), desc_win, FALSE, FALSE, 0);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2009-01-28 19:30:18 +00:00
|
|
|
vbox2 = gtk_vbox_new(FALSE, 3);
|
2007-11-20 18:15:46 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 5);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox2), swin, TRUE, TRUE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox2), label_vbox, FALSE, FALSE, 0);
|
|
|
|
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(pm_widgets.dialog, "response", G_CALLBACK(pm_dialog_response), NULL);
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), vbox2);
|
|
|
|
gtk_widget_show_all(pm_widgets.dialog);
|
|
|
|
}
|
|
|
|
|
2008-10-13 12:38:32 +00:00
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
#endif
|