[gedit] Cleanup GAction code in the spell plugin



commit 430f350ade34ba57b99ce2c747eae06f9d2c00a5
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Feb 8 12:09:36 2014 +0100

    Cleanup GAction code in the spell plugin

 plugins/spell/gedit-spell-app-activatable.c |   10 ++--
 plugins/spell/gedit-spell-plugin.c          |   59 +++++++++++----------------
 2 files changed, 29 insertions(+), 40 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-app-activatable.c b/plugins/spell/gedit-spell-app-activatable.c
index 388b12b..6107f2d 100644
--- a/plugins/spell/gedit-spell-app-activatable.c
+++ b/plugins/spell/gedit-spell-app-activatable.c
@@ -129,18 +129,18 @@ gedit_spell_app_activatable_activate (GeditAppActivatable *activatable)
        GeditSpellAppActivatablePrivate *priv = gedit_spell_app_activatable_get_instance_private 
(app_activatable);
        GMenuItem *item;
 
-       gtk_application_add_accelerator (GTK_APPLICATION (priv->app), "<Shift>F7", "win.check_spell", NULL);
+       gtk_application_add_accelerator (GTK_APPLICATION (priv->app), "<Shift>F7", "win.check-spell", NULL);
        priv->menu_ext = gedit_app_activatable_extend_menu (activatable, "spell-section");
 
-       item = g_menu_item_new (_("_Check Spelling..."), "win.check_spell");
+       item = g_menu_item_new (_("_Check Spelling..."), "win.check-spell");
        gedit_menu_extension_append_menu_item (priv->menu_ext, item);
        g_object_unref (item);
 
-       item = g_menu_item_new (_("Set _Language..."), "win.config_spell");
+       item = g_menu_item_new (_("Set _Language..."), "win.config-spell");
        gedit_menu_extension_append_menu_item (priv->menu_ext, item);
        g_object_unref (item);
 
-       item = g_menu_item_new (_("_Highlight Misspelled Words"), "win.auto_spell");
+       item = g_menu_item_new (_("_Highlight Misspelled Words"), "win.auto-spell");
        gedit_menu_extension_append_menu_item (priv->menu_ext, item);
        g_object_unref (item);
 }
@@ -151,7 +151,7 @@ gedit_spell_app_activatable_deactivate (GeditAppActivatable *activatable)
        GeditSpellAppActivatable *app_activatable = GEDIT_SPELL_APP_ACTIVATABLE (activatable);
        GeditSpellAppActivatablePrivate *priv = gedit_spell_app_activatable_get_instance_private 
(app_activatable);
 
-       gtk_application_remove_accelerator (GTK_APPLICATION (priv->app), "win.check_spell", NULL);
+       gtk_application_remove_accelerator (GTK_APPLICATION (priv->app), "win.check-spell", NULL);
        g_clear_object (&priv->menu_ext);
 }
 
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index c89ab67..4070c2a 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -97,24 +97,11 @@ static void spell_cb        (GSimpleAction *action, GVariant *parameter, gpointer data)
 static void    set_language_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
 static void    auto_spell_cb   (GSimpleAction *action, GVariant *state, gpointer data);
 
-static void
-activate_toggle (GSimpleAction *action,
-                 GVariant      *parameter,
-                 gpointer       user_data)
-{
-       GVariant *state;
-
-       state = g_action_get_state (G_ACTION (action));
-       g_action_change_state (G_ACTION (action),
-                              g_variant_new_boolean (!g_variant_get_boolean (state)));
-       g_variant_unref (state);
-}
-
 static GActionEntry action_entries[] =
 {
-       { "check_spell", spell_cb },
-       { "config_spell", set_language_cb },
-       { "auto_spell", activate_toggle, NULL, "false", auto_spell_cb }
+       { "check-spell", spell_cb },
+       { "config-spell", set_language_cb },
+       { "auto-spell", NULL, NULL, "false", auto_spell_cb }
 };
 
 static GQuark spell_checker_id = 0;
@@ -899,7 +886,6 @@ auto_spell_cb (GSimpleAction  *action,
 {
        GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data);
        GeditSpellPluginPrivate *priv = plugin->priv;
-       GeditDocument *doc;
        GeditView *view;
        gboolean active;
 
@@ -910,17 +896,19 @@ auto_spell_cb (GSimpleAction  *action,
        gedit_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");
 
        view = gedit_window_get_active_view (priv->window);
-       if (view == NULL)
-               return;
+       if (view != NULL)
+       {
+               GeditDocument *doc;
 
-       doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+               doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
 
-       gedit_document_set_metadata (doc,
-                                    GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED,
-                                    active ? "1" : NULL, NULL);
+               gedit_document_set_metadata (doc,
+                                            GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED,
+                                            active ? "1" : NULL, NULL);
 
-       set_auto_spell (priv->window, view, active);
-       g_simple_action_set_state (action, g_variant_new_boolean (active));
+               set_auto_spell (priv->window, view, active);
+               g_simple_action_set_state (action, g_variant_new_boolean (active));
+       }
 }
 
 static void
@@ -939,19 +927,19 @@ update_ui (GeditSpellPlugin *plugin)
        view = gedit_window_get_active_view (priv->window);
 
        check_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window),
-                                                        "check_spell");
+                                                        "check-spell");
        g_simple_action_set_enabled (G_SIMPLE_ACTION (check_spell_action),
                                     (view != NULL) &&
                                     gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
 
        config_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window),
-                                                         "config_spell");
+                                                         "config-spell");
        g_simple_action_set_enabled (G_SIMPLE_ACTION (config_spell_action),
                                     (view != NULL) &&
                                     gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
 
        auto_spell_action = g_action_map_lookup_action (G_ACTION_MAP (priv->window),
-                                                       "auto_spell");
+                                                       "auto-spell");
        g_simple_action_set_enabled (G_SIMPLE_ACTION (auto_spell_action),
                                     (view != NULL) &&
                                     gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
@@ -1011,7 +999,7 @@ set_auto_spell_from_metadata (GeditSpellPlugin *plugin,
                GAction *action;
 
                action = g_action_map_lookup_action (G_ACTION_MAP (plugin->priv->window),
-                                                    "auto_spell");
+                                                    "auto-spell");
                g_action_change_state (action, g_variant_new_boolean (active));
        }
 }
@@ -1089,11 +1077,12 @@ tab_added_cb (GeditWindow      *window,
           attach the view to the automatic spell checker. */
        g_object_set_data (G_OBJECT (doc), GEDIT_AUTOMATIC_SPELL_VIEW, view);
 
-       g_signal_connect (doc, "loaded",
+       g_signal_connect (doc,
+                         "loaded",
                          G_CALLBACK (on_document_loaded),
                          plugin);
-
-       g_signal_connect (doc, "saved",
+       g_signal_connect (doc,
+                         "saved",
                          G_CALLBACK (on_document_saved),
                          plugin);
 }
@@ -1160,11 +1149,11 @@ gedit_spell_plugin_deactivate (GeditWindowActivatable *activatable)
        priv = GEDIT_SPELL_PLUGIN (activatable)->priv;
 
        g_action_map_remove_action (G_ACTION_MAP (priv->window),
-                                   "check_spell");
+                                   "check-spell");
        g_action_map_remove_action (G_ACTION_MAP (priv->window),
-                                   "config_spell");
+                                   "config-spell");
        g_action_map_remove_action (G_ACTION_MAP (priv->window),
-                                   "auto_spell");
+                                   "auto-spell");
 
        g_signal_handler_disconnect (priv->window, priv->tab_added_id);
        g_signal_handler_disconnect (priv->window, priv->tab_removed_id);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]