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 GeditSpellChecker * get_spell_checker_from_document (GeditDocument *doc) { GeditSpellChecker *spell; gpointer data; gedit_debug (DEBUG_PLUGINS); g_return_val_if_fail (doc != NULL, NULL); data = g_object_get_qdata (G_OBJECT (doc), spell_checker_id); if (data == NULL) { const GeditSpellCheckerLanguage *lang = NULL; gchar *value = NULL; spell = gedit_spell_checker_new (); value = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_LANGUAGE); if (value != NULL) { lang = gedit_spell_checker_language_from_key (value); g_free (value); } if (lang != NULL) { gedit_spell_checker_set_language (spell, lang); } g_object_set_qdata_full (G_OBJECT (doc), spell_checker_id, spell, (GDestroyNotify) g_object_unref); g_signal_connect (spell, "set_language", G_CALLBACK (set_spell_language_cb), doc); } else { g_return_val_if_fail (GEDIT_IS_SPELL_CHECKER (data), NULL); spell = GEDIT_SPELL_CHECKER (data); } return spell; }
static GtkSourceLanguage * guess_language (GeditDocument *doc) { GeditDocumentPrivate *priv; gchar *data; GtkSourceLanguageManager *manager = gtk_source_language_manager_get_default (); GtkSourceLanguage *language = NULL; priv = gedit_document_get_instance_private (doc); data = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_LANGUAGE); if (data != NULL) { gedit_debug_message (DEBUG_DOCUMENT, "Language from metadata: %s", data); if (!g_str_equal (data, NO_LANGUAGE_NAME)) { language = gtk_source_language_manager_get_language (manager, data); } g_free (data); } else { GFile *location; gchar *basename = NULL; location = gtk_source_file_get_location (priv->file); gedit_debug_message (DEBUG_DOCUMENT, "Sniffing Language"); if (location != NULL) { basename = g_file_get_basename (location); } else if (priv->short_name != NULL) { basename = g_strdup (priv->short_name); } language = gtk_source_language_manager_guess_language (manager, basename, priv->content_type); g_free (basename); } return language; }
static void load_bookmark_metadata (GeditView *view) { GeditDocument *doc; gchar *bookmarks_attr; doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); bookmarks_attr = gedit_document_get_metadata (doc, METADATA_ATTR); if (bookmarks_attr != NULL) { gchar **bookmarks; bookmarks = g_strsplit (bookmarks_attr, ",", -1); g_free (bookmarks_attr); load_bookmarks (view, bookmarks); g_strfreev (bookmarks); } }
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 set_language_from_metadata (GeditSpellChecker *spell, GeditDocument *doc) { const GeditSpellCheckerLanguage *lang = NULL; gchar *value = NULL; value = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_LANGUAGE); if (value != NULL) { lang = gedit_spell_checker_language_from_key (value); g_free (value); } if (lang != NULL) { g_signal_handlers_block_by_func (spell, set_spell_language_cb, doc); gedit_spell_checker_set_language (spell, lang); g_signal_handlers_unblock_by_func (spell, set_spell_language_cb, doc); } }