2007-06-26 16:17:16 +00:00
|
|
|
/*
|
|
|
|
* plugins.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2007-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2007-2008 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"
|
2007-08-10 16:11:17 +00:00
|
|
|
#include "geanyobject.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"
|
2007-10-22 12:42:19 +00:00
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2007-07-28 17:44:02 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
# define PLUGIN_EXT "dll"
|
|
|
|
#else
|
|
|
|
# define PLUGIN_EXT "so"
|
|
|
|
#endif
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2007-07-04 11:32:33 +00:00
|
|
|
typedef struct Plugin
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
2007-07-23 15:41:08 +00:00
|
|
|
GModule *module;
|
2008-03-07 18:00:22 +00:00
|
|
|
gchar *filename; /* plugin filename (/path/libname.so) */
|
2007-07-23 15:41:08 +00:00
|
|
|
PluginFields fields;
|
2008-03-07 18:00:22 +00:00
|
|
|
gulong *signal_ids; /* signal IDs to disconnect when unloading */
|
2007-08-15 12:29:57 +00:00
|
|
|
gsize signal_ids_len;
|
2008-03-07 18:00:22 +00:00
|
|
|
KeyBindingGroup *key_group;
|
2007-07-23 15:41:08 +00:00
|
|
|
|
2008-03-07 18:00:22 +00:00
|
|
|
PluginInfo* (*info) (void); /* Returns plugin name, description */
|
2007-07-27 10:37:22 +00:00
|
|
|
void (*init) (GeanyData *data); /* Called when the plugin is enabled */
|
2007-11-20 18:15:46 +00:00
|
|
|
void (*configure) (GtkWidget *parent); /* plugin configure dialog, optionally */
|
2008-03-07 18:00:22 +00:00
|
|
|
void (*cleanup) (void); /* Called when the plugin is disabled or when Geany exits */
|
2007-07-04 11:32:33 +00:00
|
|
|
}
|
|
|
|
Plugin;
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-03-07 18:00:22 +00:00
|
|
|
static GList *plugin_list = NULL; /* list of all available, loadable plugins */
|
2008-02-27 13:17:29 +00:00
|
|
|
static GList *active_plugin_list = NULL; /* list of only actually loaded plugins */
|
2007-11-23 16:37:03 +00:00
|
|
|
static GtkWidget *separator = NULL;
|
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
|
|
|
|
2007-07-04 11:32:33 +00:00
|
|
|
|
2007-07-13 11:22:47 +00:00
|
|
|
static DocumentFuncs doc_funcs = {
|
2007-07-23 15:41:08 +00:00
|
|
|
&document_new_file,
|
2007-07-24 11:43:46 +00:00
|
|
|
&document_get_cur_idx,
|
2007-11-21 18:54:12 +00:00
|
|
|
&document_get_n_idx,
|
2007-12-01 17:53:36 +00:00
|
|
|
&document_find_by_filename,
|
2007-08-14 16:29:03 +00:00
|
|
|
&document_get_current,
|
|
|
|
&document_save_file,
|
2007-08-15 11:52:06 +00:00
|
|
|
&document_open_file,
|
|
|
|
&document_open_files,
|
2007-09-11 16:05:03 +00:00
|
|
|
&document_remove,
|
2007-10-18 18:03:28 +00:00
|
|
|
&document_reload_file,
|
2007-11-04 10:12:15 +00:00
|
|
|
&document_set_encoding,
|
|
|
|
&document_set_text_changed
|
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 ScintillaFuncs sci_funcs = {
|
2007-08-03 15:05:53 +00:00
|
|
|
&scintilla_send_message,
|
|
|
|
&sci_cmd,
|
|
|
|
&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,
|
2007-08-19 17:40:19 +00:00
|
|
|
&sci_find_bracematch,
|
|
|
|
&sci_get_style_at,
|
2008-02-04 12:49:14 +00:00
|
|
|
&sci_get_char_at,
|
|
|
|
&sci_get_current_line,
|
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,
|
|
|
|
&utils_spawn_async
|
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,
|
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,
|
|
|
|
&dialogs_show_save_as
|
2007-08-19 17:40:19 +00:00
|
|
|
};
|
|
|
|
|
2007-08-03 15:05:53 +00:00
|
|
|
static SupportFuncs support_funcs = {
|
|
|
|
&lookup_widget
|
|
|
|
};
|
|
|
|
|
2007-08-19 17:40:19 +00:00
|
|
|
static MsgWinFuncs msgwin_funcs = {
|
2007-10-24 10:52:48 +00:00
|
|
|
&msgwin_status_add,
|
2007-09-17 11:16:48 +00:00
|
|
|
&msgwin_compiler_add_fmt
|
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,
|
|
|
|
&keybindings_set_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 = {
|
|
|
|
&highlighting_get_style
|
|
|
|
};
|
|
|
|
|
2007-10-18 18:03:28 +00:00
|
|
|
|
2008-01-02 21:20:33 +00:00
|
|
|
static FiletypeFuncs filetype_funcs = {
|
|
|
|
&filetypes_detect_from_filename
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-07-27 10:37:22 +00:00
|
|
|
static GeanyData geany_data = {
|
2007-07-26 12:06:12 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-08-03 15:05:53 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-08-23 11:34:06 +00:00
|
|
|
NULL,
|
2007-09-17 11:16:48 +00:00
|
|
|
NULL,
|
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,
|
|
|
|
&filetype_funcs
|
2007-07-26 12:06:12 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2007-07-26 12:06:12 +00:00
|
|
|
geany_data.app = app;
|
|
|
|
geany_data.tools_menu = lookup_widget(app->window, "tools1_menu");
|
|
|
|
geany_data.doc_array = doc_array;
|
2007-08-03 15:05:53 +00:00
|
|
|
geany_data.filetypes = filetypes;
|
2007-08-23 11:34:06 +00:00
|
|
|
geany_data.prefs = &prefs;
|
2007-08-03 15:05:53 +00:00
|
|
|
geany_data.editor_prefs = &editor_prefs;
|
2007-09-17 11:16:48 +00:00
|
|
|
geany_data.build_info = &build_info;
|
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.
|
|
|
|
* Note: g_module_name always returns the .so name, even when Plugin::filename
|
|
|
|
* is an .la file. */
|
|
|
|
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
|
|
|
}
|
2007-08-04 16:25:13 +00:00
|
|
|
g_free(basename_module);
|
2007-06-26 16:17:16 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_check_version(GModule *module)
|
|
|
|
{
|
|
|
|
gint (*version_check)(gint) = NULL;
|
|
|
|
gint result;
|
|
|
|
|
|
|
|
g_module_symbol(module, "version_check", (void *) &version_check);
|
|
|
|
|
|
|
|
if (version_check)
|
|
|
|
{
|
|
|
|
result = version_check(abi_version);
|
|
|
|
if (result < 0)
|
|
|
|
{
|
|
|
|
geany_debug("Plugin \"%s\" is not binary compatible with this "
|
|
|
|
"release of Geany - recompile it.", g_module_name(module));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (result > 0)
|
|
|
|
{
|
|
|
|
geany_debug("Plugin \"%s\" requires a newer version of Geany (API >= v%d).",
|
|
|
|
g_module_name(module), result);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-15 12:29:57 +00:00
|
|
|
static void add_callbacks(Plugin *plugin, GeanyCallback *callbacks)
|
2007-08-10 16:11:17 +00:00
|
|
|
{
|
|
|
|
GeanyCallback *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
|
|
|
plugin->signal_ids_len = len;
|
|
|
|
plugin->signal_ids = g_new(gulong, len);
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
cb = &callbacks[i];
|
|
|
|
|
|
|
|
plugin->signal_ids[i] = (cb->after) ?
|
|
|
|
g_signal_connect_after(geany_object, cb->signal_name, cb->callback, cb->user_data) :
|
2007-08-10 16:11:17 +00:00
|
|
|
g_signal_connect(geany_object, cb->signal_name, cb->callback, cb->user_data);
|
2007-08-15 12:29:57 +00:00
|
|
|
}
|
2007-08-10 16:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
static gboolean
|
|
|
|
is_active_plugin(const gchar *name)
|
|
|
|
{
|
|
|
|
gint i, len;
|
|
|
|
|
|
|
|
g_return_val_if_fail(name, FALSE);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* if app->active_plugins is NULL, guess it was not yet set and don't load any plugins */
|
2007-11-20 18:15:46 +00:00
|
|
|
if (app->active_plugins == NULL || (len = g_strv_length(app->active_plugins)) == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (utils_str_equal(name, app->active_plugins[i]))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-07 18:00:22 +00:00
|
|
|
static void
|
|
|
|
add_kb_group(Plugin *plugin)
|
|
|
|
{
|
|
|
|
g_ptr_array_add(keybinding_groups, plugin->key_group);
|
|
|
|
|
|
|
|
plugin->key_group->label = plugin->info()->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
static void
|
|
|
|
plugin_init(Plugin *plugin)
|
|
|
|
{
|
|
|
|
GeanyCallback *callbacks;
|
|
|
|
|
|
|
|
if (plugin->init)
|
|
|
|
plugin->init(&geany_data);
|
|
|
|
|
|
|
|
if (plugin->fields.flags & PLUGIN_IS_DOCUMENT_SENSITIVE)
|
|
|
|
{
|
|
|
|
gboolean enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) ? TRUE : FALSE;
|
|
|
|
gtk_widget_set_sensitive(plugin->fields.menu_item, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_module_symbol(plugin->module, "geany_callbacks", (void *) &callbacks);
|
|
|
|
if (callbacks)
|
|
|
|
add_callbacks(plugin, callbacks);
|
|
|
|
|
2008-03-07 18:00:22 +00:00
|
|
|
g_module_symbol(plugin->module, "plugin_key_group",
|
|
|
|
(void *) &plugin->key_group);
|
|
|
|
if (plugin->key_group)
|
|
|
|
add_kb_group(plugin);
|
|
|
|
|
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,
|
|
|
|
NVL(plugin->info()->name, "<Unknown>"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
static Plugin*
|
|
|
|
plugin_new(const gchar *fname)
|
|
|
|
{
|
|
|
|
Plugin *plugin;
|
|
|
|
GModule *module;
|
2008-02-20 11:24:23 +00:00
|
|
|
PluginInfo* (*info)(void);
|
2007-07-23 15:41:08 +00:00
|
|
|
PluginFields **plugin_fields;
|
2007-07-27 10:37:22 +00:00
|
|
|
GeanyData **p_geany_data;
|
2007-06-26 16:17:16 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail(fname, NULL);
|
|
|
|
g_return_val_if_fail(g_module_supported(), NULL);
|
|
|
|
|
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.
|
|
|
|
* Also without G_MODULE_BIND_LOCAL calling info() in a plugin will be shadowed. */
|
|
|
|
module = g_module_open(fname, G_MODULE_BIND_LOCAL);
|
2007-06-26 16:17:16 +00:00
|
|
|
if (! module)
|
|
|
|
{
|
|
|
|
g_warning("%s", g_module_error());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-06-27 15:56:42 +00:00
|
|
|
g_module_symbol(module, "info", (void *) &info);
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
geany_debug("Unknown plugin info for \"%s\"!", fname);
|
|
|
|
|
|
|
|
if (! g_module_close(module))
|
|
|
|
g_warning("%s: %s", fname, g_module_error());
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-20 18:15:46 +00:00
|
|
|
geany_debug("Initializing plugin '%s'", info()->name);
|
2007-06-27 15:56:42 +00:00
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
plugin = g_new0(Plugin, 1);
|
2007-06-27 15:56:42 +00:00
|
|
|
plugin->info = info;
|
2007-06-26 16:17:16 +00:00
|
|
|
plugin->filename = g_strdup(fname);
|
|
|
|
plugin->module = module;
|
|
|
|
|
2007-07-27 10:37:22 +00:00
|
|
|
g_module_symbol(module, "geany_data", (void *) &p_geany_data);
|
|
|
|
if (p_geany_data)
|
|
|
|
*p_geany_data = &geany_data;
|
2007-07-23 15:41:08 +00:00
|
|
|
g_module_symbol(module, "plugin_fields", (void *) &plugin_fields);
|
|
|
|
if (plugin_fields)
|
|
|
|
*plugin_fields = &plugin->fields;
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
g_module_symbol(module, "init", (void *) &plugin->init);
|
2007-11-20 18:15:46 +00:00
|
|
|
g_module_symbol(module, "configure", (void *) &plugin->configure);
|
2007-06-26 16:17:16 +00:00
|
|
|
g_module_symbol(module, "cleanup", (void *) &plugin->cleanup);
|
2007-07-25 11:59:34 +00:00
|
|
|
if (plugin->init != NULL && plugin->cleanup == NULL)
|
|
|
|
{
|
|
|
|
if (app->debug_mode)
|
|
|
|
g_warning("Plugin '%s' has no cleanup() function - there may be memory leaks!",
|
|
|
|
info()->name);
|
|
|
|
}
|
2007-06-26 16:17:16 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* only initialise the plugin if it should be loaded */
|
2007-11-20 18:15:46 +00:00
|
|
|
if (is_active_plugin(fname))
|
2007-07-23 15:41:08 +00:00
|
|
|
{
|
2007-11-20 18:15:46 +00:00
|
|
|
plugin_init(plugin);
|
2007-07-23 15:41:08 +00:00
|
|
|
}
|
2007-06-26 16:17:16 +00:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-15 12:29:57 +00:00
|
|
|
static void remove_callbacks(Plugin *plugin)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (plugin->signal_ids == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < plugin->signal_ids_len; i++)
|
|
|
|
g_signal_handler_disconnect(geany_object, plugin->signal_ids[i]);
|
|
|
|
g_free(plugin->signal_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
static void
|
|
|
|
plugin_unload(Plugin *plugin)
|
|
|
|
{
|
|
|
|
g_return_if_fail(plugin);
|
|
|
|
g_return_if_fail(plugin->module);
|
|
|
|
|
2008-03-07 18:00:22 +00:00
|
|
|
/* only do cleanup if the plugin was actually loaded */
|
|
|
|
if (! g_list_find(active_plugin_list, plugin))
|
|
|
|
return;
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-03-07 18:00:22 +00:00
|
|
|
if (plugin->cleanup)
|
|
|
|
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)
|
|
|
|
g_ptr_array_remove_fast(keybinding_groups, plugin->key_group);
|
|
|
|
|
|
|
|
active_plugin_list = g_list_remove(active_plugin_list, plugin);
|
|
|
|
geany_debug("Unloaded: %s", plugin->filename);
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
static void
|
|
|
|
plugin_free(Plugin *plugin)
|
|
|
|
{
|
|
|
|
g_return_if_fail(plugin);
|
|
|
|
g_return_if_fail(plugin->module);
|
|
|
|
|
2007-11-21 18:54:12 +00:00
|
|
|
plugin_unload(plugin);
|
2007-06-26 16:17:16 +00:00
|
|
|
|
|
|
|
if (! g_module_close(plugin->module))
|
|
|
|
g_warning("%s: %s", plugin->filename, g_module_error());
|
|
|
|
|
|
|
|
g_free(plugin->filename);
|
|
|
|
g_free(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-26 12:06:12 +00:00
|
|
|
static void
|
2007-07-28 11:47:56 +00:00
|
|
|
load_plugins(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;
|
|
|
|
Plugin *plugin;
|
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, '.');
|
|
|
|
if (tmp == NULL || strcasecmp(tmp, "." PLUGIN_EXT) != 0)
|
|
|
|
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);
|
2007-06-26 16:17:16 +00:00
|
|
|
plugin = plugin_new(fname);
|
|
|
|
if (plugin != NULL)
|
|
|
|
{
|
|
|
|
plugin_list = g_list_append(plugin_list, plugin);
|
|
|
|
}
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
gchar *install_dir = g_win32_get_package_installation_directory("geany", NULL);
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
path = g_strconcat(install_dir, "\\plugins", NULL);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void load_plugin_paths(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);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* first load plugins in ~/.geany/plugins/, then in $prefix/lib/geany */
|
2007-07-28 17:44:02 +00:00
|
|
|
load_plugins(path);
|
|
|
|
g_free(path);
|
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
|
2007-12-12 20:04:45 +00:00
|
|
|
load_plugins(path);
|
2007-07-28 11:47:56 +00:00
|
|
|
|
2007-07-28 17:44:02 +00:00
|
|
|
g_free(path);
|
2007-07-26 12:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-10 16:11:17 +00:00
|
|
|
void plugins_init()
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
geany_data_init();
|
|
|
|
geany_object = geany_object_new();
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
widget = gtk_menu_item_new_with_mnemonic(_("Plugin Manager"));
|
|
|
|
gtk_container_add(GTK_CONTAINER (geany_data.tools_menu), widget);
|
|
|
|
gtk_widget_show(widget);
|
|
|
|
g_signal_connect((gpointer) widget, "activate", G_CALLBACK(pm_show_dialog), NULL);
|
|
|
|
|
2007-11-23 16:37:03 +00:00
|
|
|
separator = gtk_separator_menu_item_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(geany_data.tools_menu), separator);
|
|
|
|
|
2007-08-10 16:11:17 +00:00
|
|
|
load_plugin_paths();
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
plugins_update_tools_menu();
|
2007-08-10 16:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
void plugins_create_active_list()
|
2007-06-26 16:17:16 +00:00
|
|
|
{
|
2007-11-20 18:15:46 +00:00
|
|
|
gint i = 0;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_strfreev(app->active_plugins);
|
|
|
|
|
|
|
|
if (active_plugin_list == NULL)
|
|
|
|
{
|
|
|
|
app->active_plugins = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
app->active_plugins = g_new0(gchar*, g_list_length(active_plugin_list) + 1);
|
|
|
|
for (list = g_list_first(active_plugin_list); list != NULL; list = list->next)
|
|
|
|
{
|
|
|
|
app->active_plugins[i] = g_strdup(((Plugin*)list->data)->filename);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
app->active_plugins[i] = NULL;
|
|
|
|
}
|
2007-08-10 16:11:17 +00:00
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
|
|
|
|
void plugins_free()
|
|
|
|
{
|
2007-06-26 16:17:16 +00:00
|
|
|
if (plugin_list != NULL)
|
|
|
|
{
|
|
|
|
g_list_foreach(plugin_list, (GFunc) plugin_free, NULL);
|
|
|
|
g_list_free(plugin_list);
|
|
|
|
}
|
2007-11-20 18:15:46 +00:00
|
|
|
if (active_plugin_list != NULL)
|
2008-02-27 13:17:29 +00:00
|
|
|
/* no need to do more here, active_plugin_list holds the same pointer as plugin_list */
|
2007-11-20 18:15:46 +00:00
|
|
|
g_list_free(active_plugin_list);
|
|
|
|
|
2007-08-17 11:48:30 +00:00
|
|
|
g_object_unref(geany_object);
|
2008-02-27 13:17:29 +00:00
|
|
|
geany_object = NULL; /* to mark the object as invalid for any code which tries to emit signals */
|
2007-06-26 16:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-23 15:41:08 +00:00
|
|
|
void plugins_update_document_sensitive(gboolean enabled)
|
|
|
|
{
|
|
|
|
GList *item;
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
for (item = active_plugin_list; item != NULL; item = g_list_next(item))
|
2007-07-23 15:41:08 +00:00
|
|
|
{
|
|
|
|
Plugin *plugin = item->data;
|
|
|
|
|
|
|
|
if (plugin->fields.flags & PLUGIN_IS_DOCUMENT_SENSITIVE)
|
|
|
|
gtk_widget_set_sensitive(plugin->fields.menu_item, enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2007-11-21 18:54:12 +00:00
|
|
|
static gint
|
|
|
|
plugin_has_menu(Plugin *a, Plugin *b)
|
|
|
|
{
|
2008-02-20 11:24:23 +00:00
|
|
|
if (a->fields.menu_item != NULL)
|
2007-11-21 18:54:12 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
void plugins_update_tools_menu()
|
|
|
|
{
|
2007-11-21 18:54:12 +00:00
|
|
|
gboolean found;
|
|
|
|
|
2007-11-20 18:15:46 +00:00
|
|
|
if (separator == NULL)
|
2007-11-23 16:37:03 +00:00
|
|
|
return;
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2007-11-21 18:54:12 +00:00
|
|
|
found = (g_list_find_custom(active_plugin_list, NULL, (GCompareFunc) plugin_has_menu) != NULL);
|
|
|
|
ui_widget_show_hide(separator, found);
|
2007-11-20 18:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Plugin Manager */
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PLUGIN_COLUMN_CHECK = 0,
|
|
|
|
PLUGIN_COLUMN_NAME,
|
|
|
|
PLUGIN_COLUMN_FILE,
|
|
|
|
PLUGIN_COLUMN_PLUGIN,
|
|
|
|
PLUGIN_N_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *tree;
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkWidget *description_label;
|
|
|
|
GtkWidget *configure_button;
|
|
|
|
} PluginManagerWidgets;
|
|
|
|
static PluginManagerWidgets pm_widgets;
|
|
|
|
|
|
|
|
|
|
|
|
void pm_selection_changed(GtkTreeSelection *selection, gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
Plugin *p;
|
|
|
|
PluginInfo *pi;
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected(selection, &model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, &iter, PLUGIN_COLUMN_PLUGIN, &p, -1);
|
|
|
|
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
pi = p->info();
|
|
|
|
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);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive(pm_widgets.configure_button,
|
|
|
|
p->configure != NULL && g_list_find(active_plugin_list, p) != NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pm_plugin_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data)
|
|
|
|
{
|
|
|
|
gboolean old_state, state;
|
|
|
|
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);
|
|
|
|
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
|
|
|
gtk_list_store_set(pm_widgets.store, &iter, PLUGIN_COLUMN_CHECK, state, -1);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* load/unload the plugin once it was toggled for correct behaviour of the preferences button
|
|
|
|
* we want to call plugin's configure() only after init() has been called */
|
2007-11-20 18:15:46 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* plugin should be loaded, so load it if it is not already */
|
2007-11-20 18:15:46 +00:00
|
|
|
if (state && g_list_find(active_plugin_list, p) == NULL)
|
|
|
|
{
|
|
|
|
plugin_init(p);
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* plugin should be unloaded, so unload it if it is loaded */
|
2007-11-20 18:15:46 +00:00
|
|
|
if (! state && g_list_find(active_plugin_list, p) != NULL)
|
|
|
|
{
|
|
|
|
plugin_unload(p);
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* set again the sensitiveness of the configure button */
|
2007-11-20 18:15:46 +00:00
|
|
|
gtk_widget_set_sensitive(pm_widgets.configure_button,
|
|
|
|
p->configure != NULL && g_list_find(active_plugin_list, p) != NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_signal_connect((gpointer) checkbox_renderer, "toggled", G_CALLBACK(pm_plugin_toggled), NULL);
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_signal_connect((gpointer) sel, "changed", G_CALLBACK(pm_selection_changed), NULL);
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
for (; list != NULL; list = list->next)
|
|
|
|
{
|
|
|
|
gboolean active = (g_list_find(active_plugin_list, list->data) != NULL) ? TRUE : FALSE;
|
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
gtk_list_store_set(store, &iter,
|
|
|
|
PLUGIN_COLUMN_CHECK, active,
|
|
|
|
PLUGIN_COLUMN_NAME, ((Plugin*)list->data)->info()->name,
|
|
|
|
PLUGIN_COLUMN_FILE, ((Plugin*)list->data)->filename,
|
|
|
|
PLUGIN_COLUMN_PLUGIN, list->data,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void pm_on_configure_button_clicked(GtkButton *button, gpointer user_data)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
p->configure(pm_widgets.dialog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pm_show_dialog(GtkMenuItem *menuitem, gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox, *vbox2, *label_vbox, *hbox, *swin, *label, *label2;
|
|
|
|
|
|
|
|
pm_widgets.dialog = gtk_dialog_new_with_buttons(_("Plugins"), GTK_WINDOW(app->window),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
|
|
|
|
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);
|
|
|
|
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(pm_widgets.dialog), 400, 350);
|
|
|
|
gtk_dialog_set_default_response(GTK_DIALOG(pm_widgets.dialog), GTK_RESPONSE_CANCEL);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
label = gtk_label_new(_("Below is a list of available plugins. "
|
|
|
|
"Select the plugins which should be loaded when Geany is started."));
|
|
|
|
|
|
|
|
pm_widgets.configure_button = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
|
|
|
|
gtk_widget_set_sensitive(pm_widgets.configure_button, FALSE);
|
|
|
|
g_signal_connect((gpointer) pm_widgets.configure_button, "clicked",
|
|
|
|
G_CALLBACK(pm_on_configure_button_clicked), NULL);
|
|
|
|
|
|
|
|
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-01-09 13:24:36 +00:00
|
|
|
pm_widgets.description_label = geany_wrap_label_new("");
|
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);
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), pm_widgets.configure_button, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
label_vbox = gtk_vbox_new(FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(label_vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(label_vbox), pm_widgets.description_label, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
vbox2 = gtk_vbox_new(FALSE, 6);
|
|
|
|
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);
|
|
|
|
|
|
|
|
g_signal_connect_swapped((gpointer) pm_widgets.dialog, "response",
|
|
|
|
G_CALLBACK(gtk_widget_destroy), pm_widgets.dialog);
|
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), vbox2);
|
|
|
|
gtk_widget_show_all(pm_widgets.dialog);
|
|
|
|
}
|
|
|
|
|
2007-06-26 16:17:16 +00:00
|
|
|
#endif
|