Port plugin system to libpeas

Adapted from:
52fd78ddfc
This commit is contained in:
JosephMcc 2016-12-26 12:53:23 -08:00
parent 29f0acc0d6
commit b52cc3f037
11 changed files with 267 additions and 1025 deletions

View File

@ -157,6 +157,8 @@ PKG_CHECK_MODULES(XED, [
gio-2.0 >= 2.26.0 gio-2.0 >= 2.26.0
gtk+-3.0 >= 3.10.0 gtk+-3.0 >= 3.10.0
gtksourceview-3.0 >= 2.9.7 gtksourceview-3.0 >= 2.9.7
libpeas-1.0 >= 1.12.0
libpeas-gtk-1.0 >= 1.12.0
]) ])
PKG_CHECK_MODULES(X11, [x11]) PKG_CHECK_MODULES(X11, [x11])

View File

@ -6,7 +6,7 @@ pluginsdir=@libdir@/xed/plugins
Name: xed Name: xed
Description: xed Description: xed
Requires: gtksourceview-3.0 Requires: gtksourceview-3.0 libpeas-1.0 libpeas-gtk-1.0
Version: @VERSION@ Version: @VERSION@
Cflags: -I${includedir}/xed Cflags: -I${includedir}/xed
Libs: -L${libdir} Libs: -L${libdir}

View File

@ -52,11 +52,6 @@ NOINST_H_FILES = \
xed-history-entry.h \ xed-history-entry.h \
xed-io-error-message-area.h \ xed-io-error-message-area.h \
xed-language-manager.h \ xed-language-manager.h \
xed-object-module.h \
xed-plugin-info.h \
xed-plugin-info-priv.h \
xed-plugin-loader.h \
xed-plugin-manager.h \
xed-plugins-engine.h \ xed-plugins-engine.h \
xed-prefs-manager-private.h \ xed-prefs-manager-private.h \
xed-print-job.h \ xed-print-job.h \
@ -83,7 +78,6 @@ INST_H_FILES = \
xed-message.h \ xed-message.h \
xed-notebook.h \ xed-notebook.h \
xed-panel.h \ xed-panel.h \
xed-plugin.h \
xed-prefs-manager-app.h \ xed-prefs-manager-app.h \
xed-prefs-manager.h \ xed-prefs-manager.h \
xed-progress-message-area.h \ xed-progress-message-area.h \
@ -135,13 +129,8 @@ libxed_c_files = \
xed-message-bus.c \ xed-message-bus.c \
xed-message-type.c \ xed-message-type.c \
xed-message.c \ xed-message.c \
xed-object-module.c \
xed-notebook.c \ xed-notebook.c \
xed-panel.c \ xed-panel.c \
xed-plugin-info.c \
xed-plugin.c \
xed-plugin-loader.c \
xed-plugin-manager.c \
xed-plugins-engine.c \ xed-plugins-engine.c \
xed-prefs-manager-app.c \ xed-prefs-manager-app.c \
xed-prefs-manager.c \ xed-prefs-manager.c \

View File

@ -3,7 +3,7 @@
* xed-preferences-dialog.c * xed-preferences-dialog.c
* This file is part of xed * This file is part of xed
* *
* Copyright (C) 2001-2005 Paolo Maggi * Copyright (C) 2001-2005 Paolo Maggi
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -17,14 +17,14 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, * Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
/* /*
* Modified by the xed Team, 2001-2003. See the AUTHORS file for a * Modified by the xed Team, 2001-2003. See the AUTHORS file for a
* list of people on the xed Team. * list of people on the xed Team.
* See the ChangeLog files for a list of changes. * See the ChangeLog files for a list of changes.
* *
* $Id$ * $Id$
*/ */
@ -39,6 +39,7 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gtksourceview/gtksource.h> #include <gtksourceview/gtksource.h>
#include <libpeas-gtk/peas-gtk-plugin-manager.h>
#include <xed/xed-prefs-manager.h> #include <xed/xed-prefs-manager.h>
@ -47,7 +48,6 @@
#include "xed-debug.h" #include "xed-debug.h"
#include "xed-document.h" #include "xed-document.h"
#include "xed-style-scheme-manager.h" #include "xed-style-scheme-manager.h"
#include "xed-plugin-manager.h"
#include "xed-help.h" #include "xed-help.h"
#include "xed-dirs.h" #include "xed-dirs.h"
@ -90,7 +90,7 @@ struct _XedPreferencesDialogPrivate
GtkWidget *schemes_treeview; GtkWidget *schemes_treeview;
GtkWidget *install_scheme_button; GtkWidget *install_scheme_button;
GtkWidget *uninstall_scheme_button; GtkWidget *uninstall_scheme_button;
GtkWidget *install_scheme_file_schooser; GtkWidget *install_scheme_file_schooser;
/* Tabs */ /* Tabs */
@ -110,16 +110,16 @@ struct _XedPreferencesDialogPrivate
GtkWidget *auto_save_checkbutton; GtkWidget *auto_save_checkbutton;
GtkWidget *auto_save_spinbutton; GtkWidget *auto_save_spinbutton;
GtkWidget *autosave_hbox; GtkWidget *autosave_hbox;
/* Line numbers */ /* Line numbers */
GtkWidget *display_line_numbers_checkbutton; GtkWidget *display_line_numbers_checkbutton;
/* Highlight current line */ /* Highlight current line */
GtkWidget *highlight_current_line_checkbutton; GtkWidget *highlight_current_line_checkbutton;
/* Highlight matching bracket */ /* Highlight matching bracket */
GtkWidget *bracket_matching_checkbutton; GtkWidget *bracket_matching_checkbutton;
/* Right margin */ /* Right margin */
GtkWidget *right_margin_checkbutton; GtkWidget *right_margin_checkbutton;
GtkWidget *right_margin_position_spinbutton; GtkWidget *right_margin_position_spinbutton;
@ -136,7 +136,7 @@ struct _XedPreferencesDialogPrivate
G_DEFINE_TYPE(XedPreferencesDialog, xed_preferences_dialog, GTK_TYPE_DIALOG) G_DEFINE_TYPE(XedPreferencesDialog, xed_preferences_dialog, GTK_TYPE_DIALOG)
static void static void
xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass) xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
@ -145,7 +145,7 @@ xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass)
} }
static void static void
dialog_response_handler (GtkDialog *dlg, dialog_response_handler (GtkDialog *dlg,
gint res_id) gint res_id)
{ {
xed_debug (DEBUG_PREFS); xed_debug (DEBUG_PREFS);
@ -176,7 +176,7 @@ tabs_width_spinbutton_value_changed (GtkSpinButton *spin_button,
xed_prefs_manager_set_tabs_size (gtk_spin_button_get_value_as_int (spin_button)); xed_prefs_manager_set_tabs_size (gtk_spin_button_get_value_as_int (spin_button));
} }
static void static void
insert_spaces_checkbutton_toggled (GtkToggleButton *button, insert_spaces_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
@ -209,12 +209,12 @@ auto_save_checkbutton_toggled (GtkToggleButton *button,
if (gtk_toggle_button_get_active (button)) if (gtk_toggle_button_get_active (button))
{ {
gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton,
xed_prefs_manager_auto_save_interval_can_set()); xed_prefs_manager_auto_save_interval_can_set());
xed_prefs_manager_set_auto_save (TRUE); xed_prefs_manager_set_auto_save (TRUE);
} }
else else
{ {
gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, FALSE); gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, FALSE);
xed_prefs_manager_set_auto_save (FALSE); xed_prefs_manager_set_auto_save (FALSE);
@ -228,7 +228,7 @@ backup_copy_checkbutton_toggled (GtkToggleButton *button,
xed_debug (DEBUG_PREFS); xed_debug (DEBUG_PREFS);
g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton)); g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton));
xed_prefs_manager_set_create_backup_copy (gtk_toggle_button_get_active (button)); xed_prefs_manager_set_create_backup_copy (gtk_toggle_button_get_active (button));
} }
@ -253,9 +253,9 @@ setup_editor_page (XedPreferencesDialog *dlg)
/* Set initial state */ /* Set initial state */
gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton), gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->priv->tabs_width_spinbutton),
(guint) xed_prefs_manager_get_tabs_size ()); (guint) xed_prefs_manager_get_tabs_size ());
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->insert_spaces_checkbutton),
xed_prefs_manager_get_insert_spaces ()); xed_prefs_manager_get_insert_spaces ());
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->auto_indent_checkbutton),
xed_prefs_manager_get_auto_indent ()); xed_prefs_manager_get_auto_indent ());
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->backup_copy_checkbutton),
xed_prefs_manager_get_create_backup_copy ()); xed_prefs_manager_get_create_backup_copy ());
@ -272,7 +272,7 @@ setup_editor_page (XedPreferencesDialog *dlg)
auto_save_interval); auto_save_interval);
/* Set widget sensitivity */ /* Set widget sensitivity */
gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox, gtk_widget_set_sensitive (dlg->priv->tabs_width_hbox,
xed_prefs_manager_tabs_size_can_set ()); xed_prefs_manager_tabs_size_can_set ());
gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton, gtk_widget_set_sensitive (dlg->priv->insert_spaces_checkbutton,
xed_prefs_manager_insert_spaces_can_set ()); xed_prefs_manager_insert_spaces_can_set ());
@ -280,9 +280,9 @@ setup_editor_page (XedPreferencesDialog *dlg)
xed_prefs_manager_auto_indent_can_set ()); xed_prefs_manager_auto_indent_can_set ());
gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton, gtk_widget_set_sensitive (dlg->priv->backup_copy_checkbutton,
xed_prefs_manager_create_backup_copy_can_set ()); xed_prefs_manager_create_backup_copy_can_set ());
gtk_widget_set_sensitive (dlg->priv->autosave_hbox, gtk_widget_set_sensitive (dlg->priv->autosave_hbox,
xed_prefs_manager_auto_save_can_set ()); xed_prefs_manager_auto_save_can_set ());
gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton, gtk_widget_set_sensitive (dlg->priv->auto_save_spinbutton,
auto_save && auto_save &&
xed_prefs_manager_auto_save_interval_can_set ()); xed_prefs_manager_auto_save_interval_can_set ());
@ -317,7 +317,7 @@ static void
display_line_numbers_checkbutton_toggled (GtkToggleButton *button, display_line_numbers_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
g_return_if_fail (button == g_return_if_fail (button ==
GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton)); GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton));
xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button)); xed_prefs_manager_set_display_line_numbers (gtk_toggle_button_get_active (button));
@ -327,7 +327,7 @@ static void
highlight_current_line_checkbutton_toggled (GtkToggleButton *button, highlight_current_line_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
g_return_if_fail (button == g_return_if_fail (button ==
GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton)); GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton));
xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button)); xed_prefs_manager_set_highlight_current_line (gtk_toggle_button_get_active (button));
@ -337,7 +337,7 @@ static void
bracket_matching_checkbutton_toggled (GtkToggleButton *button, bracket_matching_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
g_return_if_fail (button == g_return_if_fail (button ==
GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton)); GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton));
xed_prefs_manager_set_bracket_matching ( xed_prefs_manager_set_bracket_matching (
@ -347,21 +347,21 @@ bracket_matching_checkbutton_toggled (GtkToggleButton *button,
static gboolean split_button_state = TRUE; static gboolean split_button_state = TRUE;
static void static void
wrap_mode_checkbutton_toggled (GtkToggleButton *button, wrap_mode_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton))) if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->wrap_text_checkbutton)))
{ {
xed_prefs_manager_set_wrap_mode (GTK_WRAP_NONE); xed_prefs_manager_set_wrap_mode (GTK_WRAP_NONE);
gtk_widget_set_sensitive (dlg->priv->split_checkbutton, gtk_widget_set_sensitive (dlg->priv->split_checkbutton,
FALSE); FALSE);
gtk_toggle_button_set_inconsistent ( gtk_toggle_button_set_inconsistent (
GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE); GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton), TRUE);
} }
else else
{ {
gtk_widget_set_sensitive (dlg->priv->split_checkbutton, gtk_widget_set_sensitive (dlg->priv->split_checkbutton,
TRUE); TRUE);
gtk_toggle_button_set_inconsistent ( gtk_toggle_button_set_inconsistent (
@ -371,13 +371,13 @@ wrap_mode_checkbutton_toggled (GtkToggleButton *button,
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton))) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->priv->split_checkbutton)))
{ {
split_button_state = TRUE; split_button_state = TRUE;
xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD); xed_prefs_manager_set_wrap_mode (GTK_WRAP_WORD);
} }
else else
{ {
split_button_state = FALSE; split_button_state = FALSE;
xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR); xed_prefs_manager_set_wrap_mode (GTK_WRAP_CHAR);
} }
} }
@ -388,24 +388,24 @@ right_margin_checkbutton_toggled (GtkToggleButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
gboolean active; gboolean active;
g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton)); g_return_if_fail (button == GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton));
active = gtk_toggle_button_get_active (button); active = gtk_toggle_button_get_active (button);
xed_prefs_manager_set_display_right_margin (active); xed_prefs_manager_set_display_right_margin (active);
gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox,
active && active &&
xed_prefs_manager_right_margin_position_can_set ()); xed_prefs_manager_right_margin_position_can_set ());
} }
static void static void
right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button, right_margin_position_spinbutton_value_changed (GtkSpinButton *spin_button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
gint value; gint value;
g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton)); g_return_if_fail (spin_button == GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton));
value = CLAMP (gtk_spin_button_get_value_as_int (spin_button), 1, 160); value = CLAMP (gtk_spin_button_get_value_as_int (spin_button), 1, 160);
@ -421,14 +421,14 @@ setup_view_page (XedPreferencesDialog *dlg)
gboolean wrap_mode_can_set; gboolean wrap_mode_can_set;
xed_debug (DEBUG_PREFS); xed_debug (DEBUG_PREFS);
/* Set initial state */ /* Set initial state */
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->display_line_numbers_checkbutton),
xed_prefs_manager_get_display_line_numbers ()); xed_prefs_manager_get_display_line_numbers ());
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->highlight_current_line_checkbutton),
xed_prefs_manager_get_highlight_current_line ()); xed_prefs_manager_get_highlight_current_line ());
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton), gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->priv->bracket_matching_checkbutton),
xed_prefs_manager_get_bracket_matching ()); xed_prefs_manager_get_bracket_matching ());
@ -458,15 +458,15 @@ setup_view_page (XedPreferencesDialog *dlg)
} }
display_right_margin = xed_prefs_manager_get_display_right_margin (); display_right_margin = xed_prefs_manager_get_display_right_margin ();
gtk_toggle_button_set_active ( gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton), GTK_TOGGLE_BUTTON (dlg->priv->right_margin_checkbutton),
display_right_margin); display_right_margin);
gtk_spin_button_set_value ( gtk_spin_button_set_value (
GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton), GTK_SPIN_BUTTON (dlg->priv->right_margin_position_spinbutton),
(guint)CLAMP (xed_prefs_manager_get_right_margin_position (), 1, 160)); (guint)CLAMP (xed_prefs_manager_get_right_margin_position (), 1, 160));
/* Set widgets sensitivity */ /* Set widgets sensitivity */
gtk_widget_set_sensitive (dlg->priv->display_line_numbers_checkbutton, gtk_widget_set_sensitive (dlg->priv->display_line_numbers_checkbutton,
xed_prefs_manager_display_line_numbers_can_set ()); xed_prefs_manager_display_line_numbers_can_set ());
@ -475,45 +475,45 @@ setup_view_page (XedPreferencesDialog *dlg)
gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton, gtk_widget_set_sensitive (dlg->priv->bracket_matching_checkbutton,
xed_prefs_manager_bracket_matching_can_set ()); xed_prefs_manager_bracket_matching_can_set ());
wrap_mode_can_set = xed_prefs_manager_wrap_mode_can_set (); wrap_mode_can_set = xed_prefs_manager_wrap_mode_can_set ();
gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton, gtk_widget_set_sensitive (dlg->priv->wrap_text_checkbutton,
wrap_mode_can_set); wrap_mode_can_set);
gtk_widget_set_sensitive (dlg->priv->split_checkbutton, gtk_widget_set_sensitive (dlg->priv->split_checkbutton,
wrap_mode_can_set && wrap_mode_can_set &&
(wrap_mode != GTK_WRAP_NONE)); (wrap_mode != GTK_WRAP_NONE));
gtk_widget_set_sensitive (dlg->priv->right_margin_checkbutton, gtk_widget_set_sensitive (dlg->priv->right_margin_checkbutton,
xed_prefs_manager_display_right_margin_can_set ()); xed_prefs_manager_display_right_margin_can_set ());
gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox, gtk_widget_set_sensitive (dlg->priv->right_margin_position_hbox,
display_right_margin && display_right_margin &&
xed_prefs_manager_right_margin_position_can_set ()); xed_prefs_manager_right_margin_position_can_set ());
/* Connect signals */ /* Connect signals */
g_signal_connect (dlg->priv->display_line_numbers_checkbutton, g_signal_connect (dlg->priv->display_line_numbers_checkbutton,
"toggled", "toggled",
G_CALLBACK (display_line_numbers_checkbutton_toggled), G_CALLBACK (display_line_numbers_checkbutton_toggled),
dlg); dlg);
g_signal_connect (dlg->priv->highlight_current_line_checkbutton, g_signal_connect (dlg->priv->highlight_current_line_checkbutton,
"toggled", "toggled",
G_CALLBACK (highlight_current_line_checkbutton_toggled), G_CALLBACK (highlight_current_line_checkbutton_toggled),
dlg); dlg);
g_signal_connect (dlg->priv->bracket_matching_checkbutton, g_signal_connect (dlg->priv->bracket_matching_checkbutton,
"toggled", "toggled",
G_CALLBACK (bracket_matching_checkbutton_toggled), G_CALLBACK (bracket_matching_checkbutton_toggled),
dlg); dlg);
g_signal_connect (dlg->priv->wrap_text_checkbutton, g_signal_connect (dlg->priv->wrap_text_checkbutton,
"toggled", "toggled",
G_CALLBACK (wrap_mode_checkbutton_toggled), G_CALLBACK (wrap_mode_checkbutton_toggled),
dlg); dlg);
g_signal_connect (dlg->priv->split_checkbutton, g_signal_connect (dlg->priv->split_checkbutton,
"toggled", "toggled",
G_CALLBACK (wrap_mode_checkbutton_toggled), G_CALLBACK (wrap_mode_checkbutton_toggled),
dlg); dlg);
g_signal_connect (dlg->priv->right_margin_checkbutton, g_signal_connect (dlg->priv->right_margin_checkbutton,
"toggled", "toggled",
G_CALLBACK (right_margin_checkbutton_toggled), G_CALLBACK (right_margin_checkbutton_toggled),
dlg); dlg);
g_signal_connect (dlg->priv->right_margin_position_spinbutton, g_signal_connect (dlg->priv->right_margin_position_spinbutton,
"value_changed", "value_changed",
G_CALLBACK (right_margin_position_spinbutton_value_changed), G_CALLBACK (right_margin_position_spinbutton_value_changed),
dlg); dlg);
} }
@ -532,7 +532,7 @@ default_font_font_checkbutton_toggled (GtkToggleButton *button,
} }
else else
{ {
gtk_widget_set_sensitive (dlg->priv->font_hbox, gtk_widget_set_sensitive (dlg->priv->font_hbox,
xed_prefs_manager_editor_font_can_set ()); xed_prefs_manager_editor_font_can_set ());
xed_prefs_manager_set_use_default_font (FALSE); xed_prefs_manager_set_use_default_font (FALSE);
} }
@ -575,8 +575,8 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg)
dlg->priv->default_font_checkbutton, dlg->priv->default_font_checkbutton,
ATK_RELATION_CONTROLLED_BY); ATK_RELATION_CONTROLLED_BY);
xed_utils_set_atk_relation (dlg->priv->default_font_checkbutton, xed_utils_set_atk_relation (dlg->priv->default_font_checkbutton,
dlg->priv->font_button, dlg->priv->font_button,
ATK_RELATION_CONTROLLER_FOR); ATK_RELATION_CONTROLLER_FOR);
editor_font = xed_prefs_manager_get_system_font (); editor_font = xed_prefs_manager_get_system_font ();
label = g_strdup_printf(_("_Use the system fixed width font (%s)"), label = g_strdup_printf(_("_Use the system fixed width font (%s)"),
@ -610,13 +610,13 @@ setup_font_colors_page_font_section (XedPreferencesDialog *dlg)
dlg); dlg);
/* Set initial widget sensitivity */ /* Set initial widget sensitivity */
gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton, gtk_widget_set_sensitive (dlg->priv->default_font_checkbutton,
xed_prefs_manager_use_default_font_can_set ()); xed_prefs_manager_use_default_font_can_set ());
if (use_default_font) if (use_default_font)
gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE); gtk_widget_set_sensitive (dlg->priv->font_hbox, FALSE);
else else
gtk_widget_set_sensitive (dlg->priv->font_hbox, gtk_widget_set_sensitive (dlg->priv->font_hbox,
xed_prefs_manager_editor_font_can_set ()); xed_prefs_manager_editor_font_can_set ());
} }
@ -625,8 +625,8 @@ set_buttons_sensisitivity_according_to_scheme (XedPreferencesDialog *dlg,
const gchar *scheme_id) const gchar *scheme_id)
{ {
gboolean editable; gboolean editable;
editable = (scheme_id != NULL) && editable = (scheme_id != NULL) &&
_xed_style_scheme_manager_scheme_is_xed_user_scheme ( _xed_style_scheme_manager_scheme_is_xed_user_scheme (
xed_get_style_scheme_manager (), xed_get_style_scheme_manager (),
scheme_id); scheme_id);
@ -694,7 +694,7 @@ ensure_color_scheme_id (const gchar *id)
return gtk_source_style_scheme_get_id (scheme); return gtk_source_style_scheme_get_id (scheme);
} }
/* If def_id is NULL, use the default scheme as returned by /* If def_id is NULL, use the default scheme as returned by
* xed_style_scheme_manager_get_default_scheme. If this one returns NULL * xed_style_scheme_manager_get_default_scheme. If this one returns NULL
* use the first available scheme as default */ * use the first available scheme as default */
static const gchar * static const gchar *
@ -702,17 +702,17 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id)
{ {
GSList *schemes; GSList *schemes;
GSList *l; GSList *l;
gtk_list_store_clear (dlg->priv->schemes_treeview_model); gtk_list_store_clear (dlg->priv->schemes_treeview_model);
def_id = ensure_color_scheme_id (def_id); def_id = ensure_color_scheme_id (def_id);
if (def_id == NULL) if (def_id == NULL)
{ {
g_warning ("Cannot build the list of available color schemes.\n" g_warning ("Cannot build the list of available color schemes.\n"
"Please check your GtkSourceView installation."); "Please check your GtkSourceView installation.");
return NULL; return NULL;
} }
schemes = xed_style_scheme_manager_list_schemes_sorted (xed_get_style_scheme_manager ()); schemes = xed_style_scheme_manager_list_schemes_sorted (xed_get_style_scheme_manager ());
l = schemes; l = schemes;
while (l != NULL) while (l != NULL)
@ -724,7 +724,7 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id)
GtkTreeIter iter; GtkTreeIter iter;
scheme = GTK_SOURCE_STYLE_SCHEME (l->data); scheme = GTK_SOURCE_STYLE_SCHEME (l->data);
id = gtk_source_style_scheme_get_id (scheme); id = gtk_source_style_scheme_get_id (scheme);
name = gtk_source_style_scheme_get_name (scheme); name = gtk_source_style_scheme_get_name (scheme);
description = gtk_source_style_scheme_get_description (scheme); description = gtk_source_style_scheme_get_description (scheme);
@ -741,39 +741,39 @@ populate_color_scheme_list (XedPreferencesDialog *dlg, const gchar *def_id)
if (strcmp (id, def_id) == 0) if (strcmp (id, def_id) == 0)
{ {
GtkTreeSelection *selection; GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->schemes_treeview));
gtk_tree_selection_select_iter (selection, &iter); gtk_tree_selection_select_iter (selection, &iter);
} }
l = g_slist_next (l); l = g_slist_next (l);
} }
g_slist_free (schemes); g_slist_free (schemes);
return def_id; return def_id;
} }
static void static void
add_scheme_chooser_response_cb (GtkDialog *chooser, add_scheme_chooser_response_cb (GtkDialog *chooser,
gint res_id, gint res_id,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
gchar* filename; gchar* filename;
const gchar *scheme_id; const gchar *scheme_id;
if (res_id != GTK_RESPONSE_ACCEPT) if (res_id != GTK_RESPONSE_ACCEPT)
{ {
gtk_widget_hide (GTK_WIDGET (chooser)); gtk_widget_hide (GTK_WIDGET (chooser));
return; return;
} }
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
if (filename == NULL) if (filename == NULL)
return; return;
gtk_widget_hide (GTK_WIDGET (chooser)); gtk_widget_hide (GTK_WIDGET (chooser));
scheme_id = _xed_style_scheme_manager_install_scheme ( scheme_id = _xed_style_scheme_manager_install_scheme (
xed_get_style_scheme_manager (), xed_get_style_scheme_manager (),
filename); filename);
@ -793,14 +793,14 @@ add_scheme_chooser_response_cb (GtkDialog *chooser,
set_buttons_sensisitivity_according_to_scheme (dlg, scheme_id); set_buttons_sensisitivity_according_to_scheme (dlg, scheme_id);
} }
static void static void
install_scheme_clicked (GtkButton *button, install_scheme_clicked (GtkButton *button,
XedPreferencesDialog *dlg) XedPreferencesDialog *dlg)
{ {
GtkWidget *chooser; GtkWidget *chooser;
GtkFileFilter *filter; GtkFileFilter *filter;
if (dlg->priv->install_scheme_file_schooser != NULL) { if (dlg->priv->install_scheme_file_schooser != NULL) {
gtk_window_present (GTK_WINDOW (dlg->priv->install_scheme_file_schooser)); gtk_window_present (GTK_WINDOW (dlg->priv->install_scheme_file_schooser));
gtk_widget_grab_focus (dlg->priv->install_scheme_file_schooser); gtk_widget_grab_focus (dlg->priv->install_scheme_file_schooser);
@ -813,13 +813,13 @@ install_scheme_clicked (GtkButton *button,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL); NULL);
xed_dialog_add_button (GTK_DIALOG (chooser), xed_dialog_add_button (GTK_DIALOG (chooser),
_("A_dd Scheme"), _("A_dd Scheme"),
GTK_STOCK_ADD, GTK_STOCK_ADD,
GTK_RESPONSE_ACCEPT); GTK_RESPONSE_ACCEPT);
gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE); gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE);
/* Filters */ /* Filters */
filter = gtk_file_filter_new (); filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("Color Scheme Files")); gtk_file_filter_set_name (filter, _("Color Scheme Files"));
@ -827,25 +827,25 @@ install_scheme_clicked (GtkButton *button,
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter);
filter = gtk_file_filter_new (); filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("All Files")); gtk_file_filter_set_name (filter, _("All Files"));
gtk_file_filter_add_pattern (filter, "*"); gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT); gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT);
g_signal_connect (chooser, g_signal_connect (chooser,
"response", "response",
G_CALLBACK (add_scheme_chooser_response_cb), G_CALLBACK (add_scheme_chooser_response_cb),
dlg); dlg);
dlg->priv->install_scheme_file_schooser = chooser; dlg->priv->install_scheme_file_schooser = chooser;
g_object_add_weak_pointer (G_OBJECT (chooser), g_object_add_weak_pointer (G_OBJECT (chooser),
(gpointer) &dlg->priv->install_scheme_file_schooser); (gpointer) &dlg->priv->install_scheme_file_schooser);
gtk_widget_show (chooser); gtk_widget_show (chooser);
} }
static void static void
@ -870,7 +870,7 @@ uninstall_scheme_clicked (GtkButton *button,
ID_COLUMN, &id, ID_COLUMN, &id,
NAME_COLUMN, &name, NAME_COLUMN, &name,
-1); -1);
if (!_xed_style_scheme_manager_uninstall_scheme (xed_get_style_scheme_manager (), id)) if (!_xed_style_scheme_manager_uninstall_scheme (xed_get_style_scheme_manager (), id))
{ {
xed_warning (GTK_WINDOW (dlg), xed_warning (GTK_WINDOW (dlg),
@ -878,7 +878,7 @@ uninstall_scheme_clicked (GtkButton *button,
name); name);
} }
else else
{ {
const gchar *real_new_id; const gchar *real_new_id;
gchar *new_id = NULL; gchar *new_id = NULL;
GtkTreePath *path; GtkTreePath *path;
@ -899,13 +899,13 @@ uninstall_scheme_clicked (GtkButton *button,
gtk_tree_path_next (path); gtk_tree_path_next (path);
if (!gtk_tree_model_get_iter (model, &new_iter, path)) if (!gtk_tree_model_get_iter (model, &new_iter, path))
{ {
/* It seems the removed style scheme was the /* It seems the removed style scheme was the
* last of the list. Try to move to the * last of the list. Try to move to the
* previous one */ * previous one */
gtk_tree_path_free (path); gtk_tree_path_free (path);
path = gtk_tree_model_get_path (model, &iter); path = gtk_tree_model_get_path (model, &iter);
gtk_tree_path_prev (path); gtk_tree_path_prev (path);
if (gtk_tree_model_get_iter (model, &new_iter, path)) if (gtk_tree_model_get_iter (model, &new_iter, path))
new_iter_set = TRUE; new_iter_set = TRUE;
@ -914,17 +914,17 @@ uninstall_scheme_clicked (GtkButton *button,
new_iter_set = TRUE; new_iter_set = TRUE;
gtk_tree_path_free (path); gtk_tree_path_free (path);
if (new_iter_set) if (new_iter_set)
gtk_tree_model_get (model, &new_iter, gtk_tree_model_get (model, &new_iter,
ID_COLUMN, &new_id, ID_COLUMN, &new_id,
-1); -1);
real_new_id = populate_color_scheme_list (dlg, new_id); real_new_id = populate_color_scheme_list (dlg, new_id);
g_free (new_id); g_free (new_id);
set_buttons_sensisitivity_according_to_scheme (dlg, real_new_id); set_buttons_sensisitivity_according_to_scheme (dlg, real_new_id);
if (real_new_id != NULL) if (real_new_id != NULL)
xed_prefs_manager_set_source_style_scheme (real_new_id); xed_prefs_manager_set_source_style_scheme (real_new_id);
} }
@ -980,9 +980,9 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg)
GtkTreeViewColumn *column; GtkTreeViewColumn *column;
GtkTreeSelection *selection; GtkTreeSelection *selection;
const gchar *def_id; const gchar *def_id;
xed_debug (DEBUG_PREFS); xed_debug (DEBUG_PREFS);
/* Create GtkListStore for styles & setup treeview. */ /* Create GtkListStore for styles & setup treeview. */
dlg->priv->schemes_treeview_model = gtk_list_store_new (NUM_COLUMNS, dlg->priv->schemes_treeview_model = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_STRING, G_TYPE_STRING,
@ -1014,7 +1014,7 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg)
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
def_id = populate_color_scheme_list (dlg, NULL); def_id = populate_color_scheme_list (dlg, NULL);
/* Connect signals */ /* Connect signals */
g_signal_connect (dlg->priv->schemes_treeview, g_signal_connect (dlg->priv->schemes_treeview,
"cursor-changed", "cursor-changed",
@ -1028,7 +1028,7 @@ setup_font_colors_page_style_scheme_section (XedPreferencesDialog *dlg)
"clicked", "clicked",
G_CALLBACK (uninstall_scheme_clicked), G_CALLBACK (uninstall_scheme_clicked),
dlg); dlg);
/* Set initial widget sensitivity */ /* Set initial widget sensitivity */
set_buttons_sensisitivity_according_to_scheme (dlg, def_id); set_buttons_sensisitivity_according_to_scheme (dlg, def_id);
} }
@ -1047,7 +1047,7 @@ setup_plugins_page (XedPreferencesDialog *dlg)
xed_debug (DEBUG_PREFS); xed_debug (DEBUG_PREFS);
page_content = xed_plugin_manager_new (); page_content = peas_gtk_plugin_manager_new (NULL);
g_return_if_fail (page_content != NULL); g_return_if_fail (page_content != NULL);
gtk_box_pack_start (GTK_BOX (dlg->priv->plugin_manager_place_holder), gtk_box_pack_start (GTK_BOX (dlg->priv->plugin_manager_place_holder),
@ -1094,12 +1094,12 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg)
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); /* 2 * 5 + 2 = 12 */ gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); /* 2 * 5 + 2 = 12 */
gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5); gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5);
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6); gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6);
g_signal_connect (dlg, g_signal_connect (dlg,
"response", "response",
G_CALLBACK (dialog_response_handler), G_CALLBACK (dialog_response_handler),
NULL); NULL);
file = xed_dirs_get_ui_file ("xed-preferences-dialog.ui"); file = xed_dirs_get_ui_file ("xed-preferences-dialog.ui");
ret = xed_utils_get_ui_objects (file, ret = xed_utils_get_ui_objects (file,
root_objects, root_objects,
@ -1144,11 +1144,11 @@ xed_preferences_dialog_init (XedPreferencesDialog *dlg)
if (!ret) if (!ret)
{ {
gtk_widget_show (error_widget); gtk_widget_show (error_widget);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
error_widget, error_widget,
TRUE, TRUE, 0); TRUE, TRUE, 0);
return; return;
} }

View File

@ -95,17 +95,17 @@ gchar* xed_dirs_get_xed_plugins_dir(void)
return plugin_dir; return plugin_dir;
} }
gchar* xed_dirs_get_xed_plugin_loaders_dir(void) gchar* xed_dirs_get_xed_plugins_data_dir (void)
{ {
gchar* lib_dir; gchar* data_dir;
gchar* loader_dir; gchar* plugin_data_dir;
lib_dir = xed_dirs_get_xed_lib_dir(); data_dir = xed_dirs_get_xed_data_dir ();
loader_dir = g_build_filename(lib_dir, "plugin-loaders", NULL); plugin_data_dir = g_build_filename (data_dir, "plugins", NULL);
g_free(lib_dir); g_free (data_dir);
return loader_dir; return plugin_data_dir;
} }
gchar* xed_dirs_get_ui_file(const gchar* file) gchar* xed_dirs_get_ui_file(const gchar* file)

View File

@ -16,8 +16,8 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, * Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
@ -44,8 +44,7 @@ gchar *xed_dirs_get_xed_lib_dir (void);
gchar *xed_dirs_get_xed_plugins_dir (void); gchar *xed_dirs_get_xed_plugins_dir (void);
gchar *xed_dirs_get_xed_plugin_loaders_dir gchar *xed_dirs_get_xed_plugins_data_dir (void);
(void);
gchar *xed_dirs_get_ui_file (const gchar *file); gchar *xed_dirs_get_ui_file (const gchar *file);

View File

@ -35,827 +35,109 @@
#include <string.h> #include <string.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <girepository.h>
#include "xed-plugins-engine.h" #include "xed-plugins-engine.h"
#include "xed-plugin-info-priv.h"
#include "xed-plugin.h"
#include "xed-debug.h" #include "xed-debug.h"
#include "xed-app.h" #include "xed-app.h"
#include "xed-prefs-manager.h" #include "xed-prefs-manager.h"
#include "xed-plugin-loader.h"
#include "xed-object-module.h"
#include "xed-dirs.h" #include "xed-dirs.h"
#define XED_PLUGINS_ENGINE_BASE_KEY "/apps/xed/plugins" G_DEFINE_TYPE (XedPluginsEngine, xed_plugins_engine, PEAS_TYPE_ENGINE)
#define XED_PLUGINS_ENGINE_KEY XED_PLUGINS_ENGINE_BASE_KEY "/active-plugins"
#define PLUGIN_EXT ".xed-plugin"
#define LOADER_EXT G_MODULE_SUFFIX
typedef struct
{
XedPluginLoader *loader;
XedObjectModule *module;
} LoaderInfo;
/* Signals */
enum
{
ACTIVATE_PLUGIN,
DEACTIVATE_PLUGIN,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(XedPluginsEngine, xed_plugins_engine, G_TYPE_OBJECT)
struct _XedPluginsEnginePrivate struct _XedPluginsEnginePrivate
{ {
GList *plugin_list; GSettings *plugin_settings;
GHashTable *loaders;
gboolean activate_from_prefs;
}; };
XedPluginsEngine *default_engine = NULL; XedPluginsEngine *default_engine = NULL;
static void xed_plugins_engine_activate_plugin_real (XedPluginsEngine *engine,
XedPluginInfo *info);
static void xed_plugins_engine_deactivate_plugin_real (XedPluginsEngine *engine,
XedPluginInfo *info);
typedef gboolean (*LoadDirCallback)(XedPluginsEngine *engine, const gchar *filename, gpointer userdata);
static gboolean
load_dir_real (XedPluginsEngine *engine,
const gchar *dir,
const gchar *suffix,
LoadDirCallback callback,
gpointer userdata)
{
GError *error = NULL;
GDir *d;
const gchar *dirent;
gboolean ret = TRUE;
g_return_val_if_fail (dir != NULL, TRUE);
xed_debug_message (DEBUG_PLUGINS, "DIR: %s", dir);
d = g_dir_open (dir, 0, &error);
if (!d)
{
g_warning ("%s", error->message);
g_error_free (error);
return TRUE;
}
while ((dirent = g_dir_read_name (d)))
{
gchar *filename;
if (!g_str_has_suffix (dirent, suffix))
continue;
filename = g_build_filename (dir, dirent, NULL);
ret = callback (engine, filename, userdata);
g_free (filename);
if (!ret)
break;
}
g_dir_close (d);
return ret;
}
static gboolean
load_plugin_info (XedPluginsEngine *engine,
const gchar *filename,
gpointer userdata)
{
XedPluginInfo *info;
info = _xed_plugin_info_new (filename);
if (info == NULL)
return TRUE;
/* If a plugin with this name has already been loaded
* drop this one (user plugins override system plugins) */
if (xed_plugins_engine_get_plugin_info (engine, xed_plugin_info_get_module_name (info)) != NULL)
{
xed_debug_message (DEBUG_PLUGINS, "Two or more plugins named '%s'. "
"Only the first will be considered.\n",
xed_plugin_info_get_module_name (info));
_xed_plugin_info_unref (info);
return TRUE;
}
engine->priv->plugin_list = g_list_prepend (engine->priv->plugin_list, info);
xed_debug_message (DEBUG_PLUGINS, "Plugin %s loaded", info->name);
return TRUE;
}
static void
load_all_plugins (XedPluginsEngine *engine)
{
gchar *plugin_dir;
const gchar *pdirs_env = NULL;
/* load user plugins */
plugin_dir = xed_dirs_get_user_plugins_dir ();
if (g_file_test (plugin_dir, G_FILE_TEST_IS_DIR))
{
load_dir_real (engine,
plugin_dir,
PLUGIN_EXT,
load_plugin_info,
NULL);
}
g_free (plugin_dir);
/* load system plugins */
pdirs_env = g_getenv ("XED_PLUGINS_PATH");
xed_debug_message (DEBUG_PLUGINS, "XED_PLUGINS_PATH=%s", pdirs_env);
if (pdirs_env != NULL)
{
gchar **pdirs;
gint i;
pdirs = g_strsplit (pdirs_env, G_SEARCHPATH_SEPARATOR_S, 0);
for (i = 0; pdirs[i] != NULL; i++)
{
if (!load_dir_real (engine,
pdirs[i],
PLUGIN_EXT,
load_plugin_info,
NULL))
{
break;
}
}
g_strfreev (pdirs);
}
else
{
plugin_dir = xed_dirs_get_xed_plugins_dir ();
load_dir_real (engine,
plugin_dir,
PLUGIN_EXT,
load_plugin_info,
NULL);
g_free (plugin_dir);
}
}
static guint
hash_lowercase (gconstpointer data)
{
gchar *lowercase;
guint ret;
lowercase = g_ascii_strdown ((const gchar *)data, -1);
ret = g_str_hash (lowercase);
g_free (lowercase);
return ret;
}
static gboolean
equal_lowercase (gconstpointer a, gconstpointer b)
{
return g_ascii_strcasecmp ((const gchar *)a, (const gchar *)b) == 0;
}
static void
loader_destroy (LoaderInfo *info)
{
if (!info)
return;
if (info->loader)
g_object_unref (info->loader);
g_free (info);
}
static void
add_loader (XedPluginsEngine *engine,
const gchar *loader_id,
XedObjectModule *module)
{
LoaderInfo *info;
info = g_new (LoaderInfo, 1);
info->loader = NULL;
info->module = module;
g_hash_table_insert (engine->priv->loaders, g_strdup (loader_id), info);
}
static void static void
xed_plugins_engine_init (XedPluginsEngine *engine) xed_plugins_engine_init (XedPluginsEngine *engine)
{ {
xed_debug (DEBUG_PLUGINS); gchar *private_path;
GError *error = NULL;
if (!g_module_supported ()) xed_debug (DEBUG_PLUGINS);
{
g_warning ("xed is not able to initialize the plugins engine.");
return;
}
engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine, engine->priv = G_TYPE_INSTANCE_GET_PRIVATE (engine, XED_TYPE_PLUGINS_ENGINE, XedPluginsEnginePrivate);
XED_TYPE_PLUGINS_ENGINE,
XedPluginsEnginePrivate);
load_all_plugins (engine); engine->priv->plugin_settings = g_settings_new (XED_SCHEMA);
/* make sure that the first reactivation will read active plugins peas_engine_enable_loader (PEAS_ENGINE (engine), "python3");
from the prefs */
engine->priv->activate_from_prefs = TRUE;
/* mapping from loadername -> loader object */ /* This should be moved to libpeas */
engine->priv->loaders = g_hash_table_new_full (hash_lowercase, if (!g_irepository_require (g_irepository_get_default (), "Peas", "1.0", 0, &error))
equal_lowercase, {
(GDestroyNotify)g_free, g_warning ("Could not load Peas repository: %s", error->message);
(GDestroyNotify)loader_destroy); g_error_free (error);
error = NULL;
}
if (!g_irepository_require (g_irepository_get_default (), "PeasGtk", "1.0", 0, &error))
{
g_warning ("Could not load PeasGtk repository: %s", error->message);
g_error_free (error);
error = NULL;
}
private_path = g_build_filename (LIBDIR, "girepository-1.0", NULL);
if (!g_irepository_require_private (g_irepository_get_default (), private_path, "Xed", "1.0", 0, &error))
{
g_warning ("Could not load Xed repository: %s", error->message);
g_error_free (error);
error = NULL;
}
g_free (private_path);
peas_engine_add_search_path (PEAS_ENGINE (engine),
xed_dirs_get_user_plugins_dir (),
xed_dirs_get_user_plugins_dir ());
peas_engine_add_search_path (PEAS_ENGINE (engine),
xed_dirs_get_xed_plugins_dir(),
xed_dirs_get_xed_plugins_data_dir());
g_settings_bind (engine->priv->plugin_settings, GPM_ACTIVE_PLUGINS,
engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT);
} }
static void static void
loader_garbage_collect (const char *id, LoaderInfo *info) xed_plugins_engine_dispose (GObject *object)
{ {
if (info->loader) XedPluginsEngine *engine = XED_PLUGINS_ENGINE (object);
xed_plugin_loader_garbage_collect (info->loader);
}
void if (engine->priv->plugin_settings != NULL)
xed_plugins_engine_garbage_collect (XedPluginsEngine *engine) {
{ g_object_unref (engine->priv->plugin_settings);
g_hash_table_foreach (engine->priv->loaders, engine->priv->plugin_settings = NULL;
(GHFunc) loader_garbage_collect, }
NULL);
}
static void G_OBJECT_CLASS (xed_plugins_engine_parent_class)->dispose (object);
xed_plugins_engine_finalize (GObject *object)
{
XedPluginsEngine *engine = XED_PLUGINS_ENGINE (object);
GList *item;
xed_debug (DEBUG_PLUGINS);
/* Firs deactivate all plugins */
for (item = engine->priv->plugin_list; item; item = item->next)
{
XedPluginInfo *info = XED_PLUGIN_INFO (item->data);
if (xed_plugin_info_is_active (info))
xed_plugins_engine_deactivate_plugin_real (engine, info);
}
/* unref the loaders */
g_hash_table_destroy (engine->priv->loaders);
/* and finally free the infos */
for (item = engine->priv->plugin_list; item; item = item->next)
{
XedPluginInfo *info = XED_PLUGIN_INFO (item->data);
_xed_plugin_info_unref (info);
}
g_list_free (engine->priv->plugin_list);
G_OBJECT_CLASS (xed_plugins_engine_parent_class)->finalize (object);
} }
static void static void
xed_plugins_engine_class_init (XedPluginsEngineClass *klass) xed_plugins_engine_class_init (XedPluginsEngineClass *klass)
{ {
GType the_type = G_TYPE_FROM_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = xed_plugins_engine_finalize; object_class->dispose = xed_plugins_engine_dispose;
klass->activate_plugin = xed_plugins_engine_activate_plugin_real;
klass->deactivate_plugin = xed_plugins_engine_deactivate_plugin_real;
signals[ACTIVATE_PLUGIN] = g_type_class_add_private (klass, sizeof (XedPluginsEnginePrivate));
g_signal_new ("activate-plugin",
the_type,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XedPluginsEngineClass, activate_plugin),
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
XED_TYPE_PLUGIN_INFO | G_SIGNAL_TYPE_STATIC_SCOPE);
signals[DEACTIVATE_PLUGIN] =
g_signal_new ("deactivate-plugin",
the_type,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (XedPluginsEngineClass, deactivate_plugin),
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
XED_TYPE_PLUGIN_INFO | G_SIGNAL_TYPE_STATIC_SCOPE);
g_type_class_add_private (klass, sizeof (XedPluginsEnginePrivate));
}
static gboolean
load_loader (XedPluginsEngine *engine,
const gchar *filename,
gpointer data)
{
XedObjectModule *module;
gchar *base;
gchar *path;
const gchar *id;
GType type;
/* try to load in the module */
path = g_path_get_dirname (filename);
base = g_path_get_basename (filename);
/* for now they are all resident */
module = xed_object_module_new (base,
path,
"register_xed_plugin_loader",
TRUE);
g_free (base);
g_free (path);
/* make sure to load the type definition */
if (!g_type_module_use (G_TYPE_MODULE (module)))
{
g_object_unref (module);
g_warning ("Plugin loader module `%s' could not be loaded", filename);
return TRUE;
}
/* get the exported type and check the name as exported by the
* loader interface */
type = xed_object_module_get_object_type (module);
id = xed_plugin_loader_type_get_id (type);
add_loader (engine, id, module);
g_type_module_unuse (G_TYPE_MODULE (module));
return TRUE;
}
static void
ensure_loader (LoaderInfo *info)
{
if (info->loader == NULL && info->module != NULL)
{
/* create a new loader object */
XedPluginLoader *loader;
loader = (XedPluginLoader *)xed_object_module_new_object (info->module, NULL);
if (loader == NULL || !XED_IS_PLUGIN_LOADER (loader))
{
g_warning ("Loader object is not a valid XedPluginLoader instance");
if (loader != NULL && G_IS_OBJECT (loader))
g_object_unref (loader);
}
else
{
info->loader = loader;
}
}
}
static XedPluginLoader *
get_plugin_loader (XedPluginsEngine *engine, XedPluginInfo *info)
{
const gchar *loader_id;
LoaderInfo *loader_info;
loader_id = info->loader;
loader_info = (LoaderInfo *)g_hash_table_lookup (
engine->priv->loaders,
loader_id);
if (loader_info == NULL)
{
gchar *loader_dir;
loader_dir = xed_dirs_get_xed_plugin_loaders_dir ();
/* loader could not be found in the hash, try to find it by
scanning */
load_dir_real (engine,
loader_dir,
LOADER_EXT,
(LoadDirCallback)load_loader,
NULL);
g_free (loader_dir);
loader_info = (LoaderInfo *)g_hash_table_lookup (
engine->priv->loaders,
loader_id);
}
if (loader_info == NULL)
{
/* cache non-existent so we don't scan again */
add_loader (engine, loader_id, NULL);
return NULL;
}
ensure_loader (loader_info);
return loader_info->loader;
} }
XedPluginsEngine * XedPluginsEngine *
xed_plugins_engine_get_default (void) xed_plugins_engine_get_default (void)
{ {
if (default_engine != NULL) if (default_engine != NULL)
return default_engine; {
return default_engine;
}
default_engine = XED_PLUGINS_ENGINE (g_object_new (XED_TYPE_PLUGINS_ENGINE, NULL)); default_engine = XED_PLUGINS_ENGINE (g_object_new (XED_TYPE_PLUGINS_ENGINE, NULL));
g_object_add_weak_pointer (G_OBJECT (default_engine), g_object_add_weak_pointer (G_OBJECT (default_engine), (gpointer) &default_engine);
(gpointer) &default_engine);
return default_engine; return default_engine;
}
const GList *
xed_plugins_engine_get_plugin_list (XedPluginsEngine *engine)
{
xed_debug (DEBUG_PLUGINS);
return engine->priv->plugin_list;
}
static gint
compare_plugin_info_and_name (XedPluginInfo *info,
const gchar *module_name)
{
return strcmp (xed_plugin_info_get_module_name (info), module_name);
}
XedPluginInfo *
xed_plugins_engine_get_plugin_info (XedPluginsEngine *engine,
const gchar *name)
{
GList *l = g_list_find_custom (engine->priv->plugin_list,
name,
(GCompareFunc) compare_plugin_info_and_name);
return l == NULL ? NULL : (XedPluginInfo *) l->data;
}
static void
save_active_plugin_list (XedPluginsEngine *engine)
{
GSList *active_plugins = NULL;
GList *l;
for (l = engine->priv->plugin_list; l != NULL; l = l->next)
{
XedPluginInfo *info = (XedPluginInfo *) l->data;
if (xed_plugin_info_is_active (info))
{
active_plugins = g_slist_prepend (active_plugins,
(gpointer)xed_plugin_info_get_module_name (info));
}
}
xed_prefs_manager_set_active_plugins (active_plugins);
g_slist_free (active_plugins);
}
static gboolean
load_plugin (XedPluginsEngine *engine,
XedPluginInfo *info)
{
XedPluginLoader *loader;
gchar *path;
if (xed_plugin_info_is_active (info))
return TRUE;
if (!xed_plugin_info_is_available (info))
return FALSE;
loader = get_plugin_loader (engine, info);
if (loader == NULL)
{
g_warning ("Could not find loader `%s' for plugin `%s'", info->loader, info->name);
info->available = FALSE;
return FALSE;
}
path = g_path_get_dirname (info->file);
g_return_val_if_fail (path != NULL, FALSE);
info->plugin = xed_plugin_loader_load (loader, info, path);
g_free (path);
if (info->plugin == NULL)
{
g_warning ("Error loading plugin '%s'", info->name);
info->available = FALSE;
return FALSE;
}
return TRUE;
}
static void
xed_plugins_engine_activate_plugin_real (XedPluginsEngine *engine,
XedPluginInfo *info)
{
const GList *wins;
if (!load_plugin (engine, info))
return;
for (wins = xed_app_get_windows (xed_app_get_default ());
wins != NULL;
wins = wins->next)
{
xed_plugin_activate (info->plugin, XED_WINDOW (wins->data));
}
}
gboolean
xed_plugins_engine_activate_plugin (XedPluginsEngine *engine,
XedPluginInfo *info)
{
xed_debug (DEBUG_PLUGINS);
g_return_val_if_fail (info != NULL, FALSE);
if (!xed_plugin_info_is_available (info))
return FALSE;
if (xed_plugin_info_is_active (info))
return TRUE;
g_signal_emit (engine, signals[ACTIVATE_PLUGIN], 0, info);
if (xed_plugin_info_is_active (info))
save_active_plugin_list (engine);
return xed_plugin_info_is_active (info);
}
static void
call_plugin_deactivate (XedPlugin *plugin,
XedWindow *window)
{
xed_plugin_deactivate (plugin, window);
/* ensure update of ui manager, because we suspect it does something
with expected static strings in the type module (when unloaded the
strings don't exist anymore, and ui manager updates in an idle
func) */
gtk_ui_manager_ensure_update (xed_window_get_ui_manager (window));
}
static void
xed_plugins_engine_deactivate_plugin_real (XedPluginsEngine *engine,
XedPluginInfo *info)
{
const GList *wins;
XedPluginLoader *loader;
if (!xed_plugin_info_is_active (info) ||
!xed_plugin_info_is_available (info))
return;
for (wins = xed_app_get_windows (xed_app_get_default ());
wins != NULL;
wins = wins->next)
{
call_plugin_deactivate (info->plugin, XED_WINDOW (wins->data));
}
/* first unref the plugin (the loader still has one) */
g_object_unref (info->plugin);
/* find the loader and tell it to gc and unload the plugin */
loader = get_plugin_loader (engine, info);
xed_plugin_loader_garbage_collect (loader);
xed_plugin_loader_unload (loader, info);
info->plugin = NULL;
}
gboolean
xed_plugins_engine_deactivate_plugin (XedPluginsEngine *engine,
XedPluginInfo *info)
{
xed_debug (DEBUG_PLUGINS);
g_return_val_if_fail (info != NULL, FALSE);
if (!xed_plugin_info_is_active (info))
return TRUE;
g_signal_emit (engine, signals[DEACTIVATE_PLUGIN], 0, info);
if (!xed_plugin_info_is_active (info))
save_active_plugin_list (engine);
return !xed_plugin_info_is_active (info);
}
void
xed_plugins_engine_activate_plugins (XedPluginsEngine *engine,
XedWindow *window)
{
GSList *active_plugins = NULL;
GList *pl;
xed_debug (DEBUG_PLUGINS);
g_return_if_fail (XED_IS_PLUGINS_ENGINE (engine));
g_return_if_fail (XED_IS_WINDOW (window));
/* the first time, we get the 'active' plugins from GSettings */
if (engine->priv->activate_from_prefs)
{
active_plugins = xed_prefs_manager_get_active_plugins ();
}
for (pl = engine->priv->plugin_list; pl; pl = pl->next)
{
XedPluginInfo *info = (XedPluginInfo*)pl->data;
if (engine->priv->activate_from_prefs &&
g_slist_find_custom (active_plugins,
xed_plugin_info_get_module_name (info),
(GCompareFunc)strcmp) == NULL)
continue;
/* If plugin is not active, don't try to activate/load it */
if (!engine->priv->activate_from_prefs &&
!xed_plugin_info_is_active (info))
continue;
if (load_plugin (engine, info))
xed_plugin_activate (info->plugin,
window);
}
if (engine->priv->activate_from_prefs)
{
g_slist_foreach (active_plugins, (GFunc) g_free, NULL);
g_slist_free (active_plugins);
engine->priv->activate_from_prefs = FALSE;
}
xed_debug_message (DEBUG_PLUGINS, "End");
/* also call update_ui after activation */
xed_plugins_engine_update_plugins_ui (engine, window);
}
void
xed_plugins_engine_deactivate_plugins (XedPluginsEngine *engine,
XedWindow *window)
{
GList *pl;
xed_debug (DEBUG_PLUGINS);
g_return_if_fail (XED_IS_PLUGINS_ENGINE (engine));
g_return_if_fail (XED_IS_WINDOW (window));
for (pl = engine->priv->plugin_list; pl; pl = pl->next)
{
XedPluginInfo *info = (XedPluginInfo*)pl->data;
/* check if the plugin is actually active */
if (!xed_plugin_info_is_active (info))
continue;
/* call deactivate for the plugin for this window */
xed_plugin_deactivate (info->plugin, window);
}
xed_debug_message (DEBUG_PLUGINS, "End");
}
void
xed_plugins_engine_update_plugins_ui (XedPluginsEngine *engine,
XedWindow *window)
{
GList *pl;
xed_debug (DEBUG_PLUGINS);
g_return_if_fail (XED_IS_PLUGINS_ENGINE (engine));
g_return_if_fail (XED_IS_WINDOW (window));
/* call update_ui for all active plugins */
for (pl = engine->priv->plugin_list; pl; pl = pl->next)
{
XedPluginInfo *info = (XedPluginInfo*)pl->data;
if (!xed_plugin_info_is_active (info))
continue;
xed_debug_message (DEBUG_PLUGINS, "Updating UI of %s", info->name);
xed_plugin_update_ui (info->plugin, window);
}
}
void
xed_plugins_engine_configure_plugin (XedPluginsEngine *engine,
XedPluginInfo *info,
GtkWindow *parent)
{
GtkWidget *conf_dlg;
GtkWindowGroup *wg;
xed_debug (DEBUG_PLUGINS);
g_return_if_fail (info != NULL);
conf_dlg = xed_plugin_create_configure_dialog (info->plugin);
g_return_if_fail (conf_dlg != NULL);
gtk_window_set_transient_for (GTK_WINDOW (conf_dlg),
parent);
wg = gtk_window_get_group (parent);
if (wg == NULL)
{
wg = gtk_window_group_new ();
gtk_window_group_add_window (wg, parent);
}
gtk_window_group_add_window (wg,
GTK_WINDOW (conf_dlg));
gtk_window_set_modal (GTK_WINDOW (conf_dlg), TRUE);
gtk_widget_show (conf_dlg);
}
void
xed_plugins_engine_active_plugins_changed (XedPluginsEngine *engine)
{
gboolean to_activate;
GSList *active_plugins;
GList *pl;
xed_debug (DEBUG_PLUGINS);
active_plugins = xed_prefs_manager_get_active_plugins ();
for (pl = engine->priv->plugin_list; pl; pl = pl->next)
{
XedPluginInfo *info = (XedPluginInfo*)pl->data;
if (!xed_plugin_info_is_available (info))
continue;
to_activate = (g_slist_find_custom (active_plugins,
xed_plugin_info_get_module_name (info),
(GCompareFunc)strcmp) != NULL);
if (!xed_plugin_info_is_active (info) && to_activate)
g_signal_emit (engine, signals[ACTIVATE_PLUGIN], 0, info);
else if (xed_plugin_info_is_active (info) && !to_activate)
g_signal_emit (engine, signals[DEACTIVATE_PLUGIN], 0, info);
}
g_slist_foreach (active_plugins, (GFunc) g_free, NULL);
g_slist_free (active_plugins);
}
void
xed_plugins_engine_rescan_plugins (XedPluginsEngine *engine)
{
xed_debug (DEBUG_PLUGINS);
load_all_plugins (engine);
} }

View File

@ -2,7 +2,7 @@
* xed-plugins-engine.h * xed-plugins-engine.h
* This file is part of xed * This file is part of xed
* *
* Copyright (C) 2002-2005 - Paolo Maggi * Copyright (C) 2002-2005 - Paolo Maggi
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -16,14 +16,14 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, * Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
/* /*
* Modified by the xed Team, 2002-2005. See the AUTHORS file for a * Modified by the xed Team, 2002-2005. See the AUTHORS file for a
* list of people on the xed Team. * list of people on the xed Team.
* See the ChangeLog files for a list of changes. * See the ChangeLog files for a list of changes.
* *
* $Id$ * $Id$
*/ */
@ -32,9 +32,7 @@
#define __XED_PLUGINS_ENGINE_H__ #define __XED_PLUGINS_ENGINE_H__
#include <glib.h> #include <glib.h>
#include "xed-window.h" #include <libpeas/peas-engine.h>
#include "xed-plugin-info.h"
#include "xed-plugin.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -45,62 +43,25 @@ G_BEGIN_DECLS
#define XED_IS_PLUGINS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PLUGINS_ENGINE)) #define XED_IS_PLUGINS_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_PLUGINS_ENGINE))
#define XED_PLUGINS_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_PLUGINS_ENGINE, XedPluginsEngineClass)) #define XED_PLUGINS_ENGINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_PLUGINS_ENGINE, XedPluginsEngineClass))
typedef struct _XedPluginsEngine XedPluginsEngine; typedef struct _XedPluginsEngine XedPluginsEngine;
typedef struct _XedPluginsEnginePrivate XedPluginsEnginePrivate; typedef struct _XedPluginsEnginePrivate XedPluginsEnginePrivate;
struct _XedPluginsEngine struct _XedPluginsEngine
{ {
GObject parent; PeasEngine parent;
XedPluginsEnginePrivate *priv; XedPluginsEnginePrivate *priv;
}; };
typedef struct _XedPluginsEngineClass XedPluginsEngineClass; typedef struct _XedPluginsEngineClass XedPluginsEngineClass;
struct _XedPluginsEngineClass struct _XedPluginsEngineClass
{ {
GObjectClass parent_class; PeasEngineClass parent_class;
void (* activate_plugin) (XedPluginsEngine *engine,
XedPluginInfo *info);
void (* deactivate_plugin) (XedPluginsEngine *engine,
XedPluginInfo *info);
}; };
GType xed_plugins_engine_get_type (void) G_GNUC_CONST; GType xed_plugins_engine_get_type (void) G_GNUC_CONST;
XedPluginsEngine *xed_plugins_engine_get_default (void); XedPluginsEngine *xed_plugins_engine_get_default (void);
void xed_plugins_engine_garbage_collect (XedPluginsEngine *engine);
const GList *xed_plugins_engine_get_plugin_list (XedPluginsEngine *engine);
XedPluginInfo *xed_plugins_engine_get_plugin_info (XedPluginsEngine *engine,
const gchar *name);
/* plugin load and unloading (overall, for all windows) */
gboolean xed_plugins_engine_activate_plugin (XedPluginsEngine *engine,
XedPluginInfo *info);
gboolean xed_plugins_engine_deactivate_plugin (XedPluginsEngine *engine,
XedPluginInfo *info);
void xed_plugins_engine_configure_plugin (XedPluginsEngine *engine,
XedPluginInfo *info,
GtkWindow *parent);
/* plugin activation/deactivation per window, private to XedWindow */
void xed_plugins_engine_activate_plugins (XedPluginsEngine *engine,
XedWindow *window);
void xed_plugins_engine_deactivate_plugins (XedPluginsEngine *engine,
XedWindow *window);
void xed_plugins_engine_update_plugins_ui (XedPluginsEngine *engine,
XedWindow *window);
/* private for GSettings notification */
void xed_plugins_engine_active_plugins_changed
(XedPluginsEngine *engine);
void xed_plugins_engine_rescan_plugins (XedPluginsEngine *engine);
G_END_DECLS G_END_DECLS

View File

@ -112,10 +112,6 @@ static void xed_prefs_manager_auto_save_changed (GSettings *settings,
gchar *key, gchar *key,
gpointer user_data); gpointer user_data);
static void xed_prefs_manager_active_plugins_changed (GSettings *settings,
gchar *key,
gpointer user_data);
/* GUI state is serialized to a .desktop file, not in GSettings */ /* GUI state is serialized to a .desktop file, not in GSettings */
#define XED_STATE_DEFAULT_WINDOW_STATE 0 #define XED_STATE_DEFAULT_WINDOW_STATE 0
@ -708,11 +704,6 @@ xed_prefs_manager_app_init (void)
"changed::" GPM_WRITABLE_VFS_SCHEMES, "changed::" GPM_WRITABLE_VFS_SCHEMES,
G_CALLBACK (xed_prefs_manager_auto_save_changed), G_CALLBACK (xed_prefs_manager_auto_save_changed),
NULL); NULL);
g_signal_connect (xed_prefs_manager->settings,
"changed::" GPM_ACTIVE_PLUGINS,
G_CALLBACK (xed_prefs_manager_active_plugins_changed),
NULL);
} }
return xed_prefs_manager != NULL; return xed_prefs_manager != NULL;
@ -1305,7 +1296,7 @@ xed_prefs_manager_source_style_scheme_changed (GSettings *settings,
for (l = docs; l != NULL; l = l->next) for (l = docs; l != NULL; l = l->next)
{ {
g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data));
gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data),
style); style);
} }
@ -1394,21 +1385,3 @@ xed_prefs_manager_auto_save_changed (GSettings *settings,
g_list_free (docs); g_list_free (docs);
} }
} }
static void
xed_prefs_manager_active_plugins_changed (GSettings *settings,
gchar *key,
gpointer user_data)
{
xed_debug (DEBUG_PREFS);
if (strcmp (key, GPM_ACTIVE_PLUGINS) == 0)
{
XedPluginsEngine *engine;
engine = xed_plugins_engine_get_default ();
xed_plugins_engine_active_plugins_changed (engine);
}
}

View File

@ -2,7 +2,7 @@
* xed-window-private.h * xed-window-private.h
* This file is part of xed * This file is part of xed
* *
* Copyright (C) 2005 - Paolo Maggi * Copyright (C) 2005 - Paolo Maggi
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -16,14 +16,14 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, * Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
/* /*
* Modified by the xed Team, 2005. See the AUTHORS file for a * Modified by the xed Team, 2005. See the AUTHORS file for a
* list of people on the xed Team. * list of people on the xed Team.
* See the ChangeLog files for a list of changes. * See the ChangeLog files for a list of changes.
* *
* $Id$ * $Id$
*/ */
@ -31,6 +31,8 @@
#ifndef __XED_WINDOW_PRIVATE_H__ #ifndef __XED_WINDOW_PRIVATE_H__
#define __XED_WINDOW_PRIVATE_H__ #define __XED_WINDOW_PRIVATE_H__
#include <libpeas/peas-extension-set.h>
#include "xed/xed-window.h" #include "xed/xed-window.h"
#include "xed-prefs-manager.h" #include "xed-prefs-manager.h"
#include "xed-message-bus.h" #include "xed-message-bus.h"
@ -48,11 +50,12 @@ struct _XedWindowPrivate
GtkWidget *hpaned; GtkWidget *hpaned;
GtkWidget *vpaned; GtkWidget *vpaned;
GtkWidget *tab_width_combo; GtkWidget *tab_width_combo;
GtkWidget *language_combo; GtkWidget *language_combo;
XedMessageBus *message_bus; XedMessageBus *message_bus;
PeasExtensionSet *extensions;
/* Widgets for fullscreen mode */ /* Widgets for fullscreen mode */
GtkWidget *fullscreen_controls; GtkWidget *fullscreen_controls;
@ -61,8 +64,8 @@ struct _XedWindowPrivate
gboolean fullscreen_animation_enter; gboolean fullscreen_animation_enter;
/* statusbar and context ids for statusbar messages */ /* statusbar and context ids for statusbar messages */
GtkWidget *statusbar; GtkWidget *statusbar;
GtkWidget *searchbar; GtkWidget *searchbar;
guint generic_message_cid; guint generic_message_cid;
guint tip_message_cid; guint tip_message_cid;
guint tab_width_id; guint tab_width_id;
@ -93,7 +96,7 @@ struct _XedWindowPrivate
gint num_tabs_with_error; gint num_tabs_with_error;
gint width; gint width;
gint height; gint height;
GdkWindowState window_state; GdkWindowState window_state;
gint side_panel_size; gint side_panel_size;

View File

@ -9,6 +9,8 @@
#include <gio/gio.h> #include <gio/gio.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gtksourceview/gtksource.h> #include <gtksourceview/gtksource.h>
#include <libpeas/peas-activatable.h>
#include <libpeas/peas-extension-set.h>
#include "xed-ui.h" #include "xed-ui.h"
#include "xed-window.h" #include "xed-window.h"
@ -154,14 +156,18 @@ xed_window_dispose (GObject *object)
/* First of all, force collection so that plugins /* First of all, force collection so that plugins
* really drop some of the references. * really drop some of the references.
*/ */
xed_plugins_engine_garbage_collect (xed_plugins_engine_get_default ()); peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default()));
/* save the panes position and make sure to deactivate plugins /* save the panes position and make sure to deactivate plugins
* for this window, but only once */ * for this window, but only once */
if (!window->priv->dispose_has_run) if (!window->priv->dispose_has_run)
{ {
save_panes_state (window); save_panes_state (window);
xed_plugins_engine_deactivate_plugins (xed_plugins_engine_get_default (), window); /* Note that unreffing the extension will automatically remove
all extensions which in turn will deactivate the extension */
g_object_unref (window->priv->extensions);
peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ()));
window->priv->dispose_has_run = TRUE; window->priv->dispose_has_run = TRUE;
} }
@ -203,9 +209,8 @@ xed_window_dispose (GObject *object)
window->priv->window_group = NULL; window->priv->window_group = NULL;
} }
/* Now that there have broken some reference loops, force collection again. /* Now that there have broken some reference loops, force collection again. */
*/ peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ()));
xed_plugins_engine_garbage_collect (xed_plugins_engine_get_default ());
G_OBJECT_CLASS (xed_window_parent_class)->dispose (object); G_OBJECT_CLASS (xed_window_parent_class)->dispose (object);
} }
@ -293,7 +298,7 @@ static void
xed_window_tab_removed (XedWindow *window, xed_window_tab_removed (XedWindow *window,
XedTab *tab) XedTab *tab)
{ {
xed_plugins_engine_garbage_collect (xed_plugins_engine_get_default ()); peas_engine_garbage_collect (PEAS_ENGINE (xed_plugins_engine_get_default ()));
} }
static void static void
@ -641,7 +646,7 @@ set_sensitivity_according_to_tab (XedWindow *window,
update_next_prev_doc_sensitivity (window, tab); update_next_prev_doc_sensitivity (window, tab);
xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); peas_extension_set_call (window->priv->extensions, "update_state", window);
} }
static void static void
@ -2289,7 +2294,7 @@ sync_name (XedTab *tab,
g_free (escaped_name); g_free (escaped_name);
g_free (tip); g_free (tip);
xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); peas_extension_set_call (window->priv->extensions, "update_state", window);
} }
static XedWindow * static XedWindow *
@ -2702,7 +2707,7 @@ selection_changed (XedDocument *doc,
gtk_action_set_sensitive (action, gtk_action_set_sensitive (action,
state_normal && editable && gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER(doc))); state_normal && editable && gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER(doc)));
xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); peas_extension_set_call (window->priv->extensions, "update_state", window);
} }
static void static void
@ -2711,7 +2716,7 @@ sync_languages_menu (XedDocument *doc,
XedWindow *window) XedWindow *window)
{ {
update_languages_menu (window); update_languages_menu (window);
xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); peas_extension_set_call (window->priv->extensions, "update_state", window);
} }
static void static void
@ -2721,7 +2726,7 @@ readonly_changed (XedDocument *doc,
{ {
set_sensitivity_according_to_tab (window, window->priv->active_tab); set_sensitivity_according_to_tab (window, window->priv->active_tab);
sync_name (window->priv->active_tab, NULL, window); sync_name (window->priv->active_tab, NULL, window);
xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); peas_extension_set_call (window->priv->extensions, "update_state", window);
} }
static void static void
@ -2729,7 +2734,7 @@ editable_changed (XedView *view,
GParamSpec *arg1, GParamSpec *arg1,
XedWindow *window) XedWindow *window)
{ {
xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); peas_extension_set_call (window->priv->extensions, "update_state", window);
} }
static void static void
@ -2871,7 +2876,7 @@ notebook_tab_removed (XedNotebook *notebook,
if (window->priv->num_tabs == 0) if (window->priv->num_tabs == 0)
{ {
xed_plugins_engine_update_plugins_ui (xed_plugins_engine_get_default (), window); peas_extension_set_call (window->priv->extensions, "update_state", window);
} }
update_window_state (window); update_window_state (window);
@ -3272,6 +3277,28 @@ add_notebook (XedWindow *window,
connect_notebook_signals (window, notebook); connect_notebook_signals (window, notebook);
} }
static void
on_extension_added (PeasExtensionSet *extensions,
PeasPluginInfo *info,
PeasExtension *exten,
XedWindow *window)
{
peas_extension_call (exten, "activate", window);
}
static void
on_extension_removed (PeasExtensionSet *extensions,
PeasPluginInfo *info,
PeasExtension *exten,
XedWindow *window)
{
peas_extension_call (exten, "deactivate", window);
/* Ensure update of the ui manager, because we suspect it does something with expected static strings in the
* type module (when unloaded the strings don't exist anymore, and the ui manager update in a idle func) */
gtk_ui_manager_ensure_update (window->priv->manager);
}
static void static void
xed_window_init (XedWindow *window) xed_window_init (XedWindow *window)
{ {
@ -3378,7 +3405,13 @@ xed_window_init (XedWindow *window)
xed_debug_message (DEBUG_WINDOW, "Update plugins ui"); xed_debug_message (DEBUG_WINDOW, "Update plugins ui");
xed_plugins_engine_activate_plugins (xed_plugins_engine_get_default (), window); window->priv->extensions = peas_extension_set_new (PEAS_ENGINE (xed_plugins_engine_get_default ()),
PEAS_TYPE_ACTIVATABLE, "object", window, NULL);
peas_extension_set_call (window->priv->extensions, "activate");
g_signal_connect (window->priv->extensions, "extension-added", G_CALLBACK (on_extension_added), window);
g_signal_connect (window->priv->extensions, "extension-removed", G_CALLBACK (on_extension_removed), window);
/* set visibility of panes. /* set visibility of panes.
* This needs to be done after plugins activatation */ * This needs to be done after plugins activatation */