From e389368a910e4663c5c0247cf3be15068d508310 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 26 Dec 2016 13:44:07 -0800 Subject: [PATCH] spell-plugin: Port to libpeas Adapted from: https://github.com/mate-desktop/pluma/commit/67a0f36183ed2fe4dd66a044566e523b4b256fe4 --- plugins/spell/xed-spell-plugin.c | 520 +++++++++++++++---------------- plugins/spell/xed-spell-plugin.h | 35 ++- 2 files changed, 268 insertions(+), 287 deletions(-) diff --git a/plugins/spell/xed-spell-plugin.c b/plugins/spell/xed-spell-plugin.c index 32ac6eb..88e2114 100644 --- a/plugins/spell/xed-spell-plugin.c +++ b/plugins/spell/xed-spell-plugin.c @@ -1,13 +1,13 @@ /* * xed-spell-plugin.c - * - * Copyright (C) 2002-2005 Paolo Maggi + * + * Copyright (C) 2002-2005 Paolo Maggi * * 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, 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 @@ -31,9 +31,11 @@ #include #include +#include +#include +#include #include -#include #include #include #include @@ -46,7 +48,6 @@ #define XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE "metadata::xed-spell-language" #define XED_METADATA_ATTRIBUTE_SPELL_ENABLED "metadata::xed-spell-enabled" -#define WINDOW_DATA_KEY "XedSpellPluginWindowData" #define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_1" #define XED_SPELL_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ @@ -57,32 +58,40 @@ #define SPELL_SCHEMA "org.x.editor.plugins.spell" #define AUTOCHECK_TYPE_KEY "autocheck-type" -XED_PLUGIN_REGISTER_TYPE(XedSpellPlugin, xed_spell_plugin) +static void peas_activatable_iface_init (PeasActivatableInterface *iface); +static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); -typedef struct +G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedSpellPlugin, + xed_spell_plugin, + PEAS_TYPE_EXTENSION_BASE, + 0, + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, + peas_activatable_iface_init) + G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, + peas_gtk_configurable_iface_init)) + +enum { + PROP_0, + PROP_OBJECT +}; + +struct _XedSpellPluginPrivate +{ + GtkWidget *window; + GtkActionGroup *action_group; guint ui_id; guint message_cid; gulong tab_added_id; gulong tab_removed_id; - XedSpellPlugin *plugin; -} WindowData; -typedef struct -{ - XedPlugin *plugin; - XedWindow *window; -} ActionData; - -struct _XedSpellPluginPrivate -{ GSettings *settings; }; -static void spell_cb (GtkAction *action, ActionData *action_data); -static void set_language_cb (GtkAction *action, ActionData *action_data); -static void auto_spell_cb (GtkAction *action, XedWindow *window); +static void spell_cb (GtkAction *action, XedSpellPlugin *plugin); +static void set_language_cb (GtkAction *action, XedSpellPlugin *plugin); +static void auto_spell_cb (GtkAction *action, XedSpellPlugin *plugin); /* UI actions. */ static const GtkActionEntry action_entries[] = @@ -120,13 +129,13 @@ typedef struct _SpellConfigureDialog SpellConfigureDialog; struct _SpellConfigureDialog { - GtkWidget *dialog; + GtkWidget *content; GtkWidget *never; GtkWidget *always; GtkWidget *document; - XedSpellPlugin *plugin; + GSettings *settings; }; typedef enum @@ -163,18 +172,30 @@ xed_spell_plugin_init (XedSpellPlugin *plugin) } static void -xed_spell_plugin_finalize (GObject *object) +xed_spell_plugin_dispose (GObject *object) { XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); - xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin finalizing"); + xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin disposing"); + + if (plugin->priv->window != NULL) + { + g_object_unref (plugin->priv->window); + plugin->priv->window = NULL; + } + + if (plugin->priv->action_group) + { + g_object_unref (plugin->priv->action_group); + plugin->priv->action_group = NULL; + } g_object_unref (G_OBJECT (plugin->priv->settings)); - G_OBJECT_CLASS (xed_spell_plugin_parent_class)->finalize (object); + G_OBJECT_CLASS (xed_spell_plugin_parent_class)->dispose (object); } -static void +static void set_spell_language_cb (XedSpellChecker *spell, const XedSpellCheckerLanguage *lang, XedDocument *doc) @@ -226,16 +247,16 @@ get_autocheck_type (XedSpellPlugin *plugin) } static void -set_autocheck_type (XedSpellPlugin *plugin, +set_autocheck_type (GSettings *settings, XedSpellPluginAutocheckType autocheck_type) { - if (!g_settings_is_writable (plugin->priv->settings, + if (!g_settings_is_writable (settings, AUTOCHECK_TYPE_KEY)) { return; } - g_settings_set_enum (plugin->priv->settings, + g_settings_set_enum (settings, AUTOCHECK_TYPE_KEY, autocheck_type); } @@ -258,9 +279,9 @@ get_spell_checker_from_document (XedDocument *doc) set_language_from_metadata (spell, doc); - g_object_set_qdata_full (G_OBJECT (doc), - spell_checker_id, - spell, + g_object_set_qdata_full (G_OBJECT (doc), + spell_checker_id, + spell, (GDestroyNotify) g_object_unref); g_signal_connect (spell, @@ -307,24 +328,24 @@ update_current (XedDocument *doc, range = get_check_range (doc); g_return_if_fail (range != NULL); - gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), + gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (doc), &iter, current); if (!gtk_text_iter_inside_word (&iter)) - { + { /* if we're not inside a word, * we must be in some spaces. * skip forward to the beginning of the next word. */ if (!gtk_text_iter_is_end (&iter)) { gtk_text_iter_forward_word_end (&iter); - gtk_text_iter_backward_word_start (&iter); + gtk_text_iter_backward_word_start (&iter); } } else { if (!gtk_text_iter_starts_word (&iter)) - gtk_text_iter_backward_word_start (&iter); + gtk_text_iter_backward_word_start (&iter); } gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), @@ -332,7 +353,7 @@ update_current (XedDocument *doc, range->end_mark); if (gtk_text_iter_compare (&end_iter, &iter) < 0) - { + { gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (doc), range->current_mark, &end_iter); @@ -374,9 +395,9 @@ set_check_range (XedDocument *doc, range->current_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (doc), "check_range_current_mark", &iter, TRUE); - g_object_set_qdata_full (G_OBJECT (doc), - check_range_id, - range, + g_object_set_qdata_full (G_OBJECT (doc), + check_range_id, + range, (GDestroyNotify)g_free); } @@ -435,12 +456,12 @@ get_current_word (XedDocument *doc, gint *start, gint *end) range = get_check_range (doc); g_return_val_if_fail (range != NULL, NULL); - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), &end_iter, range->end_mark); range_end = gtk_text_iter_get_offset (&end_iter); - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), ¤t_iter, range->current_mark); end_iter = current_iter; @@ -481,7 +502,7 @@ goto_next_word (XedDocument *doc) range = get_check_range (doc); g_return_val_if_fail (range != NULL, FALSE); - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), ¤t_iter, range->current_mark); gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &end_iter); @@ -587,7 +608,7 @@ ignore_cb (XedSpellCheckerDialog *dlg, if (word == NULL) { xed_spell_checker_dialog_set_completed (dlg); - + return; } @@ -739,7 +760,6 @@ get_configure_dialog (XedSpellPlugin *plugin) SpellConfigureDialog *dialog = NULL; gchar *data_dir; gchar *ui_file; - GtkWidget *content; XedSpellPluginAutocheckType autocheck_type; GtkWidget *error_widget; gboolean ret; @@ -750,37 +770,15 @@ get_configure_dialog (XedSpellPlugin *plugin) xed_debug (DEBUG_PLUGINS); - GtkWidget *dlg = gtk_dialog_new_with_buttons (_("Configure Spell Checker plugin..."), - NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - GTK_STOCK_HELP, - GTK_RESPONSE_HELP, - NULL); + dialog = g_slice_new (SpellConfigureDialog); + dialog->settings = g_object_ref (plugin->priv->settings); - g_return_val_if_fail (dlg != NULL, NULL); - - dialog = g_new0 (SpellConfigureDialog, 1); - dialog->dialog = dlg; - - - /* HIG defaults */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)), 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), - 5); - gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), 6); - - data_dir = xed_plugin_get_data_dir (XED_PLUGIN (plugin)); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); ui_file = g_build_filename (data_dir, "xed-spell-setup-dialog.ui", NULL); ret = xed_utils_get_ui_objects (ui_file, root_objects, &error_widget, - "spell_dialog_content", &content, + "spell_dialog_content", &dialog->content, "autocheck_never", &dialog->never, "autocheck_document", &dialog->document, "autocheck_always", &dialog->always, @@ -791,18 +789,9 @@ get_configure_dialog (XedSpellPlugin *plugin) if (!ret) { - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - error_widget, TRUE, TRUE, 0); - - gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5); - - gtk_widget_show (error_widget); - - return dialog; + return NULL; } - gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE); - autocheck_type = get_autocheck_type (plugin); if (autocheck_type == AUTOCHECK_ALWAYS) @@ -818,75 +807,46 @@ get_configure_dialog (XedSpellPlugin *plugin) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->never), TRUE); } - gtk_window_set_default_size (GTK_WIDGET (content), 15, 120); - - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))), - content, FALSE, FALSE, 0); - g_object_unref (content); - gtk_container_set_border_width (GTK_CONTAINER (content), 5); - - gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog), - GTK_RESPONSE_OK); - return dialog; } static void -ok_button_pressed (SpellConfigureDialog *dialog) +configure_dialog_button_toggled (GtkToggleButton *button, + SpellConfigureDialog *dialog) { xed_debug (DEBUG_PLUGINS); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->always))) { - set_autocheck_type (dialog->plugin, AUTOCHECK_ALWAYS); + set_autocheck_type (dialog->settings, AUTOCHECK_ALWAYS); } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->document))) { - set_autocheck_type (dialog->plugin, AUTOCHECK_DOCUMENT); + set_autocheck_type (dialog->settings, AUTOCHECK_DOCUMENT); } else { - set_autocheck_type (dialog->plugin, AUTOCHECK_NEVER); + set_autocheck_type (dialog->settings, AUTOCHECK_NEVER); } } static void -configure_dialog_response_cb (GtkWidget *widget, - gint response, - SpellConfigureDialog *dialog) +configure_dialog_destroyed (GtkWidget *widget, + gpointer data) { - switch (response) - { - case GTK_RESPONSE_HELP: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP"); + SpellConfigureDialog *dialog = (SpellConfigureDialog *) data; - xed_help_display (GTK_WINDOW (widget), - NULL, - "xed-spell-checker-plugin"); - break; - } - case GTK_RESPONSE_OK: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK"); + xed_debug (DEBUG_PLUGINS); - ok_button_pressed (dialog); - - gtk_widget_destroy (dialog->dialog); - break; - } - case GTK_RESPONSE_CANCEL: - { - xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL"); - gtk_widget_destroy (dialog->dialog); - } - } + g_object_unref (dialog->settings); + g_slice_free (SpellConfigureDialog, data); } static void set_language_cb (GtkAction *action, - ActionData *action_data) + XedSpellPlugin *plugin) { + XedWindow *window; XedDocument *doc; XedSpellChecker *spell; const XedSpellCheckerLanguage *lang; @@ -896,7 +856,8 @@ set_language_cb (GtkAction *action, xed_debug (DEBUG_PLUGINS); - doc = xed_window_get_active_document (action_data->window); + window = XED_WINDOW (plugin->priv->window); + doc = xed_window_get_active_document (window); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); @@ -904,13 +865,13 @@ set_language_cb (GtkAction *action, lang = xed_spell_checker_get_language (spell); - data_dir = xed_plugin_get_data_dir (action_data->plugin); - dlg = xed_spell_language_dialog_new (GTK_WINDOW (action_data->window), + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); + dlg = xed_spell_language_dialog_new (GTK_WINDOW (window), lang, data_dir); g_free (data_dir); - wg = xed_window_get_group (action_data->window); + wg = xed_window_get_group (window); gtk_window_group_add_window (wg, GTK_WINDOW (dlg)); @@ -926,8 +887,10 @@ set_language_cb (GtkAction *action, static void spell_cb (GtkAction *action, - ActionData *action_data) + XedSpellPlugin *plugin) { + XedSpellPluginPrivate *data; + XedWindow *window; XedView *view; XedDocument *doc; XedSpellChecker *spell; @@ -938,7 +901,9 @@ spell_cb (GtkAction *action, xed_debug (DEBUG_PLUGINS); - view = xed_window_get_active_view (action_data->window); + data = plugin->priv; + window = XED_WINDOW (data->window); + view = xed_window_get_active_view (window); g_return_if_fail (view != NULL); doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); @@ -949,14 +914,9 @@ spell_cb (GtkAction *action, if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0) { - WindowData *data; GtkWidget *statusbar; - data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - statusbar = xed_window_get_statusbar (action_data->window); + statusbar = xed_window_get_statusbar (window); xed_statusbar_flash_message (XED_STATUSBAR (statusbar), data->message_cid, _("The document is empty.")); @@ -979,14 +939,9 @@ spell_cb (GtkAction *action, word = get_next_misspelled_word (view); if (word == NULL) { - WindowData *data; GtkWidget *statusbar; - data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window), - WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); - - statusbar = xed_window_get_statusbar (action_data->window); + statusbar = xed_window_get_statusbar (window); xed_statusbar_flash_message (XED_STATUSBAR (statusbar), data->message_cid, _("No misspelled words")); @@ -994,12 +949,13 @@ spell_cb (GtkAction *action, return; } - data_dir = xed_plugin_get_data_dir (action_data->plugin); + data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); dlg = xed_spell_checker_dialog_new_from_spell_checker (spell, data_dir); g_free (data_dir); + gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); gtk_window_set_transient_for (GTK_WINDOW (dlg), - GTK_WINDOW (action_data->window)); + GTK_WINDOW (window)); g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view); g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view); @@ -1054,15 +1010,16 @@ set_auto_spell (XedWindow *window, static void auto_spell_cb (GtkAction *action, - XedWindow *window) + XedSpellPlugin *plugin) { - + XedWindow *window; XedDocument *doc; gboolean active; - WindowData *data; xed_debug (DEBUG_PLUGINS); + window = XED_WINDOW (plugin->priv->window); + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); xed_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated"); @@ -1071,12 +1028,8 @@ auto_spell_cb (GtkAction *action, if (doc == NULL) return; - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - if (get_autocheck_type(data->plugin) == AUTOCHECK_DOCUMENT) + if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) { - xed_document_set_metadata (doc, XED_METADATA_ATTRIBUTE_SPELL_ENABLED, active ? "1" : NULL, NULL); @@ -1086,26 +1039,10 @@ auto_spell_cb (GtkAction *action, } static void -free_window_data (WindowData *data) -{ - g_return_if_fail (data != NULL); - - g_object_unref (data->action_group); - g_slice_free (WindowData, data); -} - -static void -free_action_data (gpointer data) -{ - g_return_if_fail (data != NULL); - - g_slice_free (ActionData, data); -} - -static void -update_ui_real (XedWindow *window, - WindowData *data) +update_ui (XedSpellPlugin *plugin) { + XedSpellPluginPrivate *data; + XedWindow *window; XedDocument *doc; XedView *view; gboolean autospell; @@ -1113,6 +1050,8 @@ update_ui_real (XedWindow *window, xed_debug (DEBUG_PLUGINS); + data = plugin->priv; + window = XED_WINDOW (data->window); doc = xed_window_get_active_document (window); view = xed_window_get_active_view (window); @@ -1133,14 +1072,14 @@ update_ui_real (XedWindow *window, { action = gtk_action_group_get_action (data->action_group, "AutoSpell"); - + g_signal_handlers_block_by_func (action, auto_spell_cb, - window); + plugin); set_auto_spell (window, doc, autospell); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), autospell); g_signal_handlers_unblock_by_func (action, auto_spell_cb, - window); + plugin); } } @@ -1150,20 +1089,16 @@ update_ui_real (XedWindow *window, } static void -set_auto_spell_from_metadata (XedWindow *window, +set_auto_spell_from_metadata (XedSpellPlugin *plugin, XedDocument *doc, GtkActionGroup *action_group) { gboolean active = FALSE; gchar *active_str = NULL; + XedWindow *window; XedDocument *active_doc; XedSpellPluginAutocheckType autocheck_type; - WindowData *data; - - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - autocheck_type = get_autocheck_type(data->plugin); + autocheck_type = get_autocheck_type (plugin); switch (autocheck_type) { @@ -1187,10 +1122,12 @@ set_auto_spell_from_metadata (XedWindow *window, if (active_str) { active = *active_str == '1'; - + g_free (active_str); } + window = XED_WINDOW (plugin->priv->window); + set_auto_spell (window, doc, active); /* In case that the doc is the active one we mark the spell action */ @@ -1199,27 +1136,26 @@ set_auto_spell_from_metadata (XedWindow *window, if (active_doc == doc && action_group != NULL) { GtkAction *action; - + action = gtk_action_group_get_action (action_group, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, - window); + plugin); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active); g_signal_handlers_unblock_by_func (action, auto_spell_cb, - window); + plugin); } } static void on_document_loaded (XedDocument *doc, const GError *error, - XedWindow *window) + XedSpellPlugin *plugin) { if (error == NULL) { - WindowData *data; XedSpellChecker *spell; spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), @@ -1229,22 +1165,18 @@ on_document_loaded (XedDocument *doc, set_language_from_metadata (spell, doc); } - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - set_auto_spell_from_metadata (window, doc, data->action_group); + set_auto_spell_from_metadata (plugin, doc, plugin->priv->action_group); } } static void on_document_saved (XedDocument *doc, const GError *error, - XedWindow *window) + XedSpellPlugin *plugin) { XedAutomaticSpellChecker *autospell; XedSpellChecker *spell; const gchar *key; - WindowData *data; if (error != NULL) { @@ -1264,10 +1196,7 @@ on_document_saved (XedDocument *doc, key = NULL; } - data = g_object_get_data (G_OBJECT (window), - WINDOW_DATA_KEY); - - if (get_autocheck_type(data->plugin) == AUTOCHECK_DOCUMENT) + if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) { xed_document_set_metadata (doc, @@ -1289,7 +1218,7 @@ on_document_saved (XedDocument *doc, static void tab_added_cb (XedWindow *window, XedTab *tab, - gpointer useless) + XedSpellPlugin *plugin) { XedDocument *doc; @@ -1297,189 +1226,206 @@ tab_added_cb (XedWindow *window, g_signal_connect (doc, "loaded", G_CALLBACK (on_document_loaded), - window); + plugin); g_signal_connect (doc, "saved", G_CALLBACK (on_document_saved), - window); + plugin); } static void tab_removed_cb (XedWindow *window, XedTab *tab, - gpointer useless) + XedSpellPlugin *plugin) { XedDocument *doc; doc = xed_tab_get_document (tab); - - g_signal_handlers_disconnect_by_func (doc, on_document_loaded, window); - g_signal_handlers_disconnect_by_func (doc, on_document_saved, window); + + g_signal_handlers_disconnect_by_func (doc, on_document_loaded, plugin); + g_signal_handlers_disconnect_by_func (doc, on_document_saved, plugin); } static void -impl_activate (XedPlugin *plugin, - XedWindow *window) +xed_spell_plugin_activate (PeasActivatable *activatable) { + XedSpellPlugin *plugin; + XedSpellPluginPrivate *data; + XedWindow *window; GtkUIManager *manager; - WindowData *data; - ActionData *action_data; GList *docs, *l; xed_debug (DEBUG_PLUGINS); - data = g_slice_new (WindowData); - data->plugin = XED_SPELL_PLUGIN (plugin); - action_data = g_slice_new (ActionData); - action_data->plugin = plugin; - action_data->window = window; + plugin = XED_SPELL_PLUGIN (activatable); + data = plugin->priv; + window = XED_WINDOW (data->window); manager = xed_window_get_ui_manager (window); data->action_group = gtk_action_group_new ("XedSpellPluginActions"); - gtk_action_group_set_translation_domain (data->action_group, + gtk_action_group_set_translation_domain (data->action_group, GETTEXT_PACKAGE); - gtk_action_group_add_actions_full (data->action_group, + gtk_action_group_add_actions (data->action_group, action_entries, G_N_ELEMENTS (action_entries), - action_data, - (GDestroyNotify) free_action_data); - gtk_action_group_add_toggle_actions (data->action_group, + plugin); + gtk_action_group_add_toggle_actions (data->action_group, toggle_action_entries, G_N_ELEMENTS (toggle_action_entries), - window); + plugin); gtk_ui_manager_insert_action_group (manager, data->action_group, -1); data->ui_id = gtk_ui_manager_new_merge_id (manager); data->message_cid = gtk_statusbar_get_context_id - (GTK_STATUSBAR (xed_window_get_statusbar (window)), + (GTK_STATUSBAR (xed_window_get_statusbar (window)), "spell_plugin_message"); - g_object_set_data_full (G_OBJECT (window), - WINDOW_DATA_KEY, - data, - (GDestroyNotify) free_window_data); - gtk_ui_manager_add_ui (manager, data->ui_id, MENU_PATH, "CheckSpell", "CheckSpell", - GTK_UI_MANAGER_MENUITEM, + GTK_UI_MANAGER_MENUITEM, FALSE); - gtk_ui_manager_add_ui (manager, - data->ui_id, + gtk_ui_manager_add_ui (manager, + data->ui_id, MENU_PATH, - "AutoSpell", "AutoSpell", - GTK_UI_MANAGER_MENUITEM, + "AutoSpell", + GTK_UI_MANAGER_MENUITEM, FALSE); - gtk_ui_manager_add_ui (manager, - data->ui_id, + gtk_ui_manager_add_ui (manager, + data->ui_id, MENU_PATH, - "ConfigSpell", "ConfigSpell", - GTK_UI_MANAGER_MENUITEM, + "ConfigSpell", + GTK_UI_MANAGER_MENUITEM, FALSE); - update_ui_real (window, data); + update_ui (plugin); docs = xed_window_get_documents (window); for (l = docs; l != NULL; l = g_list_next (l)) { XedDocument *doc = XED_DOCUMENT (l->data); - set_auto_spell_from_metadata (window, doc, + set_auto_spell_from_metadata (plugin, doc, data->action_group); g_signal_handlers_disconnect_by_func (doc, on_document_loaded, - window); + plugin); g_signal_handlers_disconnect_by_func (doc, on_document_saved, - window); + plugin); } data->tab_added_id = g_signal_connect (window, "tab-added", - G_CALLBACK (tab_added_cb), NULL); + G_CALLBACK (tab_added_cb), plugin); data->tab_removed_id = g_signal_connect (window, "tab-removed", - G_CALLBACK (tab_removed_cb), NULL); + G_CALLBACK (tab_removed_cb), plugin); } static void -impl_deactivate (XedPlugin *plugin, - XedWindow *window) +xed_spell_plugin_deactivate (PeasActivatable *activatable) { + XedSpellPluginPrivate *data; + XedWindow *window; GtkUIManager *manager; - WindowData *data; xed_debug (DEBUG_PLUGINS); - manager = xed_window_get_ui_manager (window); + data = XED_SPELL_PLUGIN (activatable)->priv; + window = XED_WINDOW (data->window); - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); + manager = xed_window_get_ui_manager (window); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->action_group); g_signal_handler_disconnect (window, data->tab_added_id); g_signal_handler_disconnect (window, data->tab_removed_id); - - g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); } static void -impl_update_ui (XedPlugin *plugin, - XedWindow *window) +xed_spell_plugin_update_state (PeasActivatable *activatable) { - WindowData *data; + xed_debug (DEBUG_PLUGINS); - xed_debug (DEBUG_PLUGINS); + update_ui (XED_SPELL_PLUGIN (activatable)); +} - data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); - g_return_if_fail (data != NULL); +static void +xed_spell_plugin_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); - update_ui_real (window, data); + switch (prop_id) + { + case PROP_OBJECT: + plugin->priv->window = GTK_WIDGET (g_value_dup_object (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +xed_spell_plugin_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object); + + switch (prop_id) + { + case PROP_OBJECT: + g_value_set_object (value, plugin->priv->window); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static GtkWidget * -impl_create_configure_dialog (XedPlugin *plugin) +xed_spell_plugin_create_configure_widget (PeasGtkConfigurable *configurable) { SpellConfigureDialog *dialog; - dialog = get_configure_dialog(XED_SPELL_PLUGIN (plugin)); + dialog = get_configure_dialog (XED_SPELL_PLUGIN (configurable)); - dialog->plugin = XED_SPELL_PLUGIN (plugin); + g_signal_connect (dialog->always, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->document, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->never, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog); + g_signal_connect (dialog->content, "destroy", G_CALLBACK (configure_dialog_destroyed), dialog); - g_signal_connect (dialog->dialog, - "response", - G_CALLBACK (configure_dialog_response_cb), - dialog); - - return GTK_WIDGET (dialog->dialog); + return dialog->content; } static void xed_spell_plugin_class_init (XedSpellPluginClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass); - object_class->finalize = xed_spell_plugin_finalize; + object_class->dispose = xed_spell_plugin_dispose; + object_class->set_property = xed_spell_plugin_set_property; + object_class->get_property = xed_spell_plugin_get_property; - plugin_class->activate = impl_activate; - plugin_class->deactivate = impl_deactivate; - plugin_class->update_ui = impl_update_ui; - - plugin_class->create_configure_dialog = impl_create_configure_dialog; + g_object_class_override_property (object_class, PROP_OBJECT, "object"); if (spell_checker_id == 0) spell_checker_id = g_quark_from_string ("XedSpellCheckerID"); @@ -1489,3 +1435,37 @@ xed_spell_plugin_class_init (XedSpellPluginClass *klass) g_type_class_add_private (object_class, sizeof (XedSpellPluginPrivate)); } + +static void +xed_spell_plugin_class_finalize (XedSpellPluginClass *klass) +{ + /* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */ +} + +static void +peas_activatable_iface_init (PeasActivatableInterface *iface) +{ + iface->activate = xed_spell_plugin_activate; + iface->deactivate = xed_spell_plugin_deactivate; + iface->update_state = xed_spell_plugin_update_state; +} + +static void +peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface) +{ + iface->create_configure_widget = xed_spell_plugin_create_configure_widget; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + xed_spell_plugin_register_type (G_TYPE_MODULE (module)); + + peas_object_module_register_extension_type (module, + PEAS_TYPE_ACTIVATABLE, + XED_TYPE_SPELL_PLUGIN); + + peas_object_module_register_extension_type (module, + PEAS_GTK_TYPE_CONFIGURABLE, + XED_TYPE_SPELL_PLUGIN); +} diff --git a/plugins/spell/xed-spell-plugin.h b/plugins/spell/xed-spell-plugin.h index 998ef40..be2982c 100644 --- a/plugins/spell/xed-spell-plugin.h +++ b/plugins/spell/xed-spell-plugin.h @@ -1,7 +1,7 @@ /* * xed-spell-plugin.h - * - * Copyright (C) 2002-2005 Paolo Maggi + * + * Copyright (C) 2002-2005 Paolo Maggi * * 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 @@ -25,52 +25,53 @@ #include #include -#include +#include +#include G_BEGIN_DECLS /* * Type checking and casting macros */ -#define XED_TYPE_SPELL_PLUGIN (xed_spell_plugin_get_type ()) -#define XED_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPlugin)) -#define XED_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) -#define XED_IS_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SPELL_PLUGIN)) -#define XED_IS_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SPELL_PLUGIN)) -#define XED_SPELL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) +#define XED_TYPE_SPELL_PLUGIN (xed_spell_plugin_get_type ()) +#define XED_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPlugin)) +#define XED_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) +#define XED_IS_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SPELL_PLUGIN)) +#define XED_IS_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SPELL_PLUGIN)) +#define XED_SPELL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass)) /* Private structure type */ -typedef struct _XedSpellPluginPrivate XedSpellPluginPrivate; +typedef struct _XedSpellPluginPrivate XedSpellPluginPrivate; /* * Main object structure */ -typedef struct _XedSpellPlugin XedSpellPlugin; +typedef struct _XedSpellPlugin XedSpellPlugin; struct _XedSpellPlugin { - XedPlugin parent_instance; + PeasExtensionBase parent_instance; - XedSpellPluginPrivate *priv; + XedSpellPluginPrivate *priv; }; /* * Class definition */ -typedef struct _XedSpellPluginClass XedSpellPluginClass; +typedef struct _XedSpellPluginClass XedSpellPluginClass; struct _XedSpellPluginClass { - XedPluginClass parent_class; + PeasExtensionBaseClass parent_class; }; /* * Public methods */ -GType xed_spell_plugin_get_type (void) G_GNUC_CONST; +GType xed_spell_plugin_get_type (void) G_GNUC_CONST; /* All the plugins must implement this function */ -G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_END_DECLS