static void set_auto_spell_from_metadata (GeditSpellPlugin *plugin, GeditView *view) { gboolean active = FALSE; gchar *active_str; GeditDocument *doc; GeditDocument *active_doc; doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); active_str = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED); if (active_str) { active = *active_str == '1'; g_free (active_str); } set_auto_spell (plugin->priv->window, view, active); /* In case that the doc is the active one we mark the spell action */ active_doc = gedit_window_get_active_document (plugin->priv->window); if (active_doc == doc) { GAction *action; action = g_action_map_lookup_action (G_ACTION_MAP (plugin->priv->window), "auto-spell"); g_action_change_state (action, g_variant_new_boolean (active)); } }
static void auto_spell_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) { GeditDocument *doc; 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); set_auto_spell (priv->window, view, active); g_simple_action_set_state (action, g_variant_new_boolean (active)); } }
static void auto_spell_cb (GtkAction *action, PlumaSpellPlugin *plugin) { PlumaWindow *window; PlumaDocument *doc; gboolean active; pluma_debug (DEBUG_PLUGINS); window = PLUMA_WINDOW (plugin->priv->window); active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); pluma_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated"); doc = pluma_window_get_active_document (window); if (doc == NULL) return; if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT) { pluma_document_set_metadata (doc, PLUMA_METADATA_ATTRIBUTE_SPELL_ENABLED, active ? "1" : NULL, NULL); } set_auto_spell (window, doc, active); }
static void update_ui (PlumaSpellPlugin *plugin) { PlumaSpellPluginPrivate *data; PlumaWindow *window; PlumaDocument *doc; PlumaView *view; gboolean autospell; GtkAction *action; pluma_debug (DEBUG_PLUGINS); data = plugin->priv; window = PLUMA_WINDOW (data->window); doc = pluma_window_get_active_document (window); view = pluma_window_get_active_view (window); autospell = (doc != NULL && pluma_automatic_spell_checker_get_from_document (doc) != NULL); if (doc != NULL) { PlumaTab *tab; PlumaTabState state; tab = pluma_window_get_active_tab (window); state = pluma_tab_get_state (tab); /* If the document is loading we can't get the metadata so we endup with an useless speller */ if (state == PLUMA_TAB_STATE_NORMAL) { action = gtk_action_group_get_action (data->action_group, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, 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, plugin); } } gtk_action_group_set_sensitive (data->action_group, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); }
static void update_ui_real (GeditWindow *window, WindowData *data) { GeditDocument *doc; GeditView *view; gboolean autospell; GtkAction *action; gedit_debug (DEBUG_PLUGINS); doc = gedit_window_get_active_document (window); view = gedit_window_get_active_view (window); autospell = (doc != NULL && gedit_automatic_spell_checker_get_from_document (doc) != NULL); if (doc != NULL) { GeditTab *tab; GeditTabState state; tab = gedit_window_get_active_tab (window); state = gedit_tab_get_state (tab); /* If the document is loading we can't get the metadata so we endup with an useless speller */ if (state == GEDIT_TAB_STATE_NORMAL) { action = gtk_action_group_get_action (data->action_group, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, window); 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); } } gtk_action_group_set_sensitive (data->action_group, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); }
static void set_auto_spell_from_metadata (GeditWindow *window, GeditDocument *doc, GtkActionGroup *action_group) { gboolean active = FALSE; gchar *active_str; GeditDocument *active_doc; active_str = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED); if (active_str) { active = *active_str == '1'; g_free (active_str); } set_auto_spell (window, doc, active); /* In case that the doc is the active one we mark the spell action */ active_doc = gedit_window_get_active_document (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); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active); g_signal_handlers_unblock_by_func (action, auto_spell_cb, window); } }
static void auto_spell_cb (GtkAction *action, GeditWindow *window) { GeditDocument *doc; gboolean active; gedit_debug (DEBUG_PLUGINS); active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); gedit_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated"); doc = gedit_window_get_active_document (window); if (doc == NULL) return; gedit_document_set_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED, active ? "1" : NULL, NULL); set_auto_spell (window, doc, active); }
static void set_auto_spell_from_metadata (PlumaSpellPlugin *plugin, PlumaDocument *doc, GtkActionGroup *action_group) { gboolean active = FALSE; gchar *active_str = NULL; PlumaWindow *window; PlumaDocument *active_doc; PlumaSpellPluginAutocheckType autocheck_type; autocheck_type = get_autocheck_type (plugin); switch (autocheck_type) { case AUTOCHECK_ALWAYS: { active = TRUE; break; } case AUTOCHECK_DOCUMENT: { active_str = pluma_document_get_metadata (doc, PLUMA_METADATA_ATTRIBUTE_SPELL_ENABLED); break; } case AUTOCHECK_NEVER: default: active = FALSE; break; } if (active_str) { active = *active_str == '1'; g_free (active_str); } window = PLUMA_WINDOW (plugin->priv->window); set_auto_spell (window, doc, active); /* In case that the doc is the active one we mark the spell action */ active_doc = pluma_window_get_active_document (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, plugin); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active); g_signal_handlers_unblock_by_func (action, auto_spell_cb, plugin); } }