|
|
8f91ed |
From 099aa09ff5eabf24005fcf94ca6a71a1a7138228 Mon Sep 17 00:00:00 2001
|
|
|
8f91ed |
From: =?UTF-8?q?S=C3=A9bastien=20Wilmet?= <swilmet@gnome.org>
|
|
|
8f91ed |
Date: Sun, 7 Jun 2015 14:51:43 +0200
|
|
|
8f91ed |
Subject: [PATCH 09/26] spell: fix bug with document metadata
|
|
|
8f91ed |
|
|
|
8f91ed |
See the comment in the code.
|
|
|
8f91ed |
|
|
|
8f91ed |
With one document, the bug was easy to reproduce:
|
|
|
8f91ed |
1. open document <file> in gedit
|
|
|
8f91ed |
2. activate the auto spell -> metadata set to 1
|
|
|
8f91ed |
3. close gedit
|
|
|
8f91ed |
4. $ gedit <file> -> spell checking disabled, but should be enabled
|
|
|
8f91ed |
|
|
|
8f91ed |
https://bugzilla.gnome.org/show_bug.cgi?id=741853
|
|
|
8f91ed |
---
|
|
|
8f91ed |
plugins/spell/gedit-spell-plugin.c | 56 +++++++++++++++++++++++++++++++-------
|
|
|
8f91ed |
1 file changed, 46 insertions(+), 10 deletions(-)
|
|
|
8f91ed |
|
|
|
8f91ed |
--- a/plugins/spell/gedit-spell-plugin.c
|
|
|
8f91ed |
+++ b/plugins/spell/gedit-spell-plugin.c
|
|
|
8f91ed |
@@ -89,15 +89,16 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditSpe
|
|
|
8f91ed |
gedit_window_activatable_iface_init)
|
|
|
8f91ed |
G_ADD_PRIVATE_DYNAMIC (GeditSpellPlugin))
|
|
|
8f91ed |
|
|
|
8f91ed |
-static void spell_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
|
|
|
8f91ed |
-static void set_language_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
|
|
|
8f91ed |
-static void auto_spell_cb (GSimpleAction *action, GVariant *state, gpointer data);
|
|
|
8f91ed |
+static void spell_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
|
|
|
8f91ed |
+static void set_language_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
|
|
|
8f91ed |
+static void auto_spell_activate_cb (GSimpleAction *action, GVariant *parameter, gpointer data);
|
|
|
8f91ed |
+static void auto_spell_change_state_cb (GSimpleAction *action, GVariant *state, gpointer data);
|
|
|
8f91ed |
|
|
|
8f91ed |
static GActionEntry action_entries[] =
|
|
|
8f91ed |
{
|
|
|
8f91ed |
{ "check-spell", spell_cb },
|
|
|
8f91ed |
{ "config-spell", set_language_cb },
|
|
|
8f91ed |
- { "auto-spell", NULL, NULL, "false", auto_spell_cb }
|
|
|
8f91ed |
+ { "auto-spell", auto_spell_activate_cb, NULL, "false", auto_spell_change_state_cb }
|
|
|
8f91ed |
};
|
|
|
8f91ed |
|
|
|
8f91ed |
static GQuark spell_checker_id = 0;
|
|
|
8f91ed |
@@ -874,20 +875,27 @@ set_auto_spell (GeditWindow *window,
|
|
|
8f91ed |
}
|
|
|
8f91ed |
|
|
|
8f91ed |
static void
|
|
|
8f91ed |
-auto_spell_cb (GSimpleAction *action,
|
|
|
8f91ed |
- GVariant *state,
|
|
|
8f91ed |
- gpointer data)
|
|
|
8f91ed |
+auto_spell_activate_cb (GSimpleAction *action,
|
|
|
8f91ed |
+ GVariant *parameter,
|
|
|
8f91ed |
+ gpointer data)
|
|
|
8f91ed |
{
|
|
|
8f91ed |
GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data);
|
|
|
8f91ed |
GeditSpellPluginPrivate *priv = plugin->priv;
|
|
|
8f91ed |
- GeditView *view;
|
|
|
8f91ed |
+ GVariant *state;
|
|
|
8f91ed |
gboolean active;
|
|
|
8f91ed |
+ GeditView *view;
|
|
|
8f91ed |
|
|
|
8f91ed |
gedit_debug (DEBUG_PLUGINS);
|
|
|
8f91ed |
|
|
|
8f91ed |
+ state = g_action_get_state (G_ACTION (action));
|
|
|
8f91ed |
+ g_return_if_fail (state != NULL);
|
|
|
8f91ed |
+
|
|
|
8f91ed |
active = g_variant_get_boolean (state);
|
|
|
8f91ed |
+ g_variant_unref (state);
|
|
|
8f91ed |
|
|
|
8f91ed |
- gedit_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");
|
|
|
8f91ed |
+ /* We must toggle ourself the value. */
|
|
|
8f91ed |
+ active = !active;
|
|
|
8f91ed |
+ g_action_change_state (G_ACTION (action), g_variant_new_boolean (active));
|
|
|
8f91ed |
|
|
|
8f91ed |
view = gedit_window_get_active_view (priv->window);
|
|
|
8f91ed |
if (view != NULL)
|
|
|
8f91ed |
@@ -896,10 +904,38 @@ auto_spell_cb (GSimpleAction *action,
|
|
|
8f91ed |
|
|
|
8f91ed |
doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
|
|
8f91ed |
|
|
|
8f91ed |
+ /* Set metadata in the "activate" handler, not in "change-state"
|
|
|
8f91ed |
+ * because "change-state" is called every time the state
|
|
|
8f91ed |
+ * changes, not specifically when the user has changed the state
|
|
|
8f91ed |
+ * herself. For example "change-state" is called to initialize
|
|
|
8f91ed |
+ * the sate to the default value specified in the GActionEntry.
|
|
|
8f91ed |
+ */
|
|
|
8f91ed |
gedit_document_set_metadata (doc,
|
|
|
8f91ed |
GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED,
|
|
|
8f91ed |
- active ? "1" : NULL, NULL);
|
|
|
8f91ed |
+ active ? "1" : NULL,
|
|
|
8f91ed |
+ NULL);
|
|
|
8f91ed |
+ }
|
|
|
8f91ed |
+}
|
|
|
8f91ed |
+
|
|
|
8f91ed |
+static void
|
|
|
8f91ed |
+auto_spell_change_state_cb (GSimpleAction *action,
|
|
|
8f91ed |
+ GVariant *state,
|
|
|
8f91ed |
+ gpointer data)
|
|
|
8f91ed |
+{
|
|
|
8f91ed |
+ GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data);
|
|
|
8f91ed |
+ GeditSpellPluginPrivate *priv = plugin->priv;
|
|
|
8f91ed |
+ GeditView *view;
|
|
|
8f91ed |
+ gboolean active;
|
|
|
8f91ed |
+
|
|
|
8f91ed |
+ gedit_debug (DEBUG_PLUGINS);
|
|
|
8f91ed |
+
|
|
|
8f91ed |
+ active = g_variant_get_boolean (state);
|
|
|
8f91ed |
|
|
|
8f91ed |
+ gedit_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");
|
|
|
8f91ed |
+
|
|
|
8f91ed |
+ view = gedit_window_get_active_view (priv->window);
|
|
|
8f91ed |
+ if (view != NULL)
|
|
|
8f91ed |
+ {
|
|
|
8f91ed |
set_auto_spell (priv->window, view, active);
|
|
|
8f91ed |
g_simple_action_set_state (action, g_variant_new_boolean (active));
|
|
|
8f91ed |
}
|