[gedit/gnome-3-16] spell: fix bug with document metadata
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/gnome-3-16] spell: fix bug with document metadata
- Date: Sun, 7 Jun 2015 14:55:12 +0000 (UTC)
commit f2beb86ace88f9e4009feacf9c96629590073ced
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Jun 7 14:51:43 2015 +0200
spell: fix bug with document metadata
See the comment in the code.
With one document, the bug was easy to reproduce:
1. open document <file> in gedit
2. activate the auto spell -> metadata set to 1
3. close gedit
4. $ gedit <file> -> spell checking disabled, but should be enabled
https://bugzilla.gnome.org/show_bug.cgi?id=741853
plugins/spell/gedit-spell-plugin.c | 56 +++++++++++++++++++++++++++++------
1 files changed, 46 insertions(+), 10 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index 66ea961..9e507da 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -89,15 +89,16 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditSpellPlugin,
gedit_window_activatable_iface_init)
G_ADD_PRIVATE_DYNAMIC (GeditSpellPlugin))
-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 spell_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
+static void set_language_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
+static void auto_spell_activate_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
+static void auto_spell_change_state_cb (GSimpleAction *action, GVariant *state, gpointer data);
static GActionEntry action_entries[] =
{
{ "check-spell", spell_cb },
{ "config-spell", set_language_cb },
- { "auto-spell", NULL, NULL, "false", auto_spell_cb }
+ { "auto-spell", auto_spell_activate_cb, NULL, "false", auto_spell_change_state_cb }
};
static GQuark spell_checker_id = 0;
@@ -895,20 +896,27 @@ set_auto_spell (GeditWindow *window,
}
static void
-auto_spell_cb (GSimpleAction *action,
- GVariant *state,
- gpointer data)
+auto_spell_activate_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer data)
{
GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data);
GeditSpellPluginPrivate *priv = plugin->priv;
- GeditView *view;
+ GVariant *state;
gboolean active;
+ GeditView *view;
gedit_debug (DEBUG_PLUGINS);
+ state = g_action_get_state (G_ACTION (action));
+ g_return_if_fail (state != NULL);
+
active = g_variant_get_boolean (state);
+ g_variant_unref (state);
- gedit_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");
+ /* We must toggle ourself the value. */
+ active = !active;
+ g_action_change_state (G_ACTION (action), g_variant_new_boolean (active));
view = gedit_window_get_active_view (priv->window);
if (view != NULL)
@@ -917,10 +925,38 @@ auto_spell_cb (GSimpleAction *action,
doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ /* Set metadata in the "activate" handler, not in "change-state"
+ * because "change-state" is called every time the state
+ * changes, not specifically when the user has changed the state
+ * herself. For example "change-state" is called to initialize
+ * the sate to the default value specified in the GActionEntry.
+ */
gedit_document_set_metadata (doc,
GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED,
- active ? "1" : NULL, NULL);
+ active ? "1" : NULL,
+ NULL);
+ }
+}
+
+static void
+auto_spell_change_state_cb (GSimpleAction *action,
+ GVariant *state,
+ gpointer data)
+{
+ GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data);
+ GeditSpellPluginPrivate *priv = plugin->priv;
+ GeditView *view;
+ gboolean active;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ active = g_variant_get_boolean (state);
+ gedit_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");
+
+ view = gedit_window_get_active_view (priv->window);
+ if (view != NULL)
+ {
set_auto_spell (priv->window, view, active);
g_simple_action_set_state (action, g_variant_new_boolean (active));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]