~ubuntu-branches/ubuntu/lucid/gedit/lucid-updates

« back to all changes in this revision

Viewing changes to plugins/spell/gedit-spell-plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-04-29 10:16:12 UTC
  • mfrom: (1.1.79 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429101612-cawm9u2kja132bpc
Tags: 2.30.2-0ubuntu1
* New upstream release:
  - Fix cut and paste typo that broke syntax detection

Show diffs side-by-side

added added

removed removed

Lines of Context:
157
157
                                     key, NULL);
158
158
}
159
159
 
 
160
static void
 
161
set_language_from_metadata (GeditSpellChecker *spell,
 
162
                            GeditDocument     *doc)
 
163
{
 
164
        const GeditSpellCheckerLanguage *lang = NULL;
 
165
        gchar *value = NULL;
 
166
 
 
167
        value = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_LANGUAGE);
 
168
 
 
169
        if (value != NULL)
 
170
        {
 
171
                lang = gedit_spell_checker_language_from_key (value);
 
172
                g_free (value);
 
173
        }
 
174
 
 
175
        if (lang != NULL)
 
176
        {
 
177
                g_signal_handlers_block_by_func (spell, set_spell_language_cb, doc);
 
178
                gedit_spell_checker_set_language (spell, lang);
 
179
                g_signal_handlers_unblock_by_func (spell, set_spell_language_cb, doc);
 
180
        }
 
181
}
 
182
 
160
183
static GeditSpellChecker *
161
184
get_spell_checker_from_document (GeditDocument *doc)
162
185
{
171
194
 
172
195
        if (data == NULL)
173
196
        {
174
 
                const GeditSpellCheckerLanguage *lang = NULL;
175
 
                gchar *value = NULL;
176
 
 
177
197
                spell = gedit_spell_checker_new ();
178
198
 
179
 
                value = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_LANGUAGE);
180
 
 
181
 
                if (value != NULL)
182
 
                {
183
 
                        lang = gedit_spell_checker_language_from_key (value);
184
 
                        g_free (value);
185
 
                }
186
 
 
187
 
                if (lang != NULL)
188
 
                {
189
 
                        gedit_spell_checker_set_language (spell, lang);
190
 
                }
 
199
                set_language_from_metadata (spell, doc);
191
200
 
192
201
                g_object_set_qdata_full (G_OBJECT (doc), 
193
202
                                         spell_checker_id, 
969
978
{
970
979
        if (error == NULL)
971
980
        {
972
 
                WindowData *data = g_object_get_data (G_OBJECT (window),
973
 
                                                      WINDOW_DATA_KEY);
974
 
        
 
981
                WindowData *data;
 
982
                GeditSpellChecker *spell;
 
983
 
 
984
                spell = GEDIT_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc),
 
985
                                                                 spell_checker_id));
 
986
                if (spell != NULL)
 
987
                {
 
988
                        set_language_from_metadata (spell, doc);
 
989
                }
 
990
 
 
991
                data = g_object_get_data (G_OBJECT (window),
 
992
                                          WINDOW_DATA_KEY);
 
993
 
975
994
                set_auto_spell_from_metadata (window, doc, data->action_group);
976
995
        }
977
996
}
978
997
 
979
998
static void
 
999
on_document_saved (GeditDocument *doc,
 
1000
                   const GError  *error,
 
1001
                   GeditWindow   *window)
 
1002
{
 
1003
        GeditAutomaticSpellChecker *autospell;
 
1004
        GeditSpellChecker *spell;
 
1005
        const gchar *key;
 
1006
 
 
1007
        if (error != NULL)
 
1008
        {
 
1009
                return;
 
1010
        }
 
1011
 
 
1012
        /* Make sure to save the metadata here too */
 
1013
        autospell = gedit_automatic_spell_checker_get_from_document (doc);
 
1014
        spell = GEDIT_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc), spell_checker_id));
 
1015
 
 
1016
        if (spell != NULL)
 
1017
        {
 
1018
                key = gedit_spell_checker_language_to_key (gedit_spell_checker_get_language (spell));
 
1019
        }
 
1020
        else
 
1021
        {
 
1022
                key = NULL;
 
1023
        }
 
1024
 
 
1025
        gedit_document_set_metadata (doc,
 
1026
                                     GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED,
 
1027
                                     autospell != NULL ? "1" : NULL,
 
1028
                                     GEDIT_METADATA_ATTRIBUTE_SPELL_LANGUAGE,
 
1029
                                     key,
 
1030
                                     NULL);
 
1031
}
 
1032
 
 
1033
static void
980
1034
tab_added_cb (GeditWindow *window,
981
1035
              GeditTab    *tab,
982
1036
              gpointer     useless)
990
1044
        g_signal_connect (doc, "loaded",
991
1045
                          G_CALLBACK (on_document_loaded),
992
1046
                          window);
 
1047
 
 
1048
        g_signal_connect (doc, "saved",
 
1049
                          G_CALLBACK (on_document_saved),
 
1050
                          window);
993
1051
}
994
1052
 
995
1053
static void
1004
1062
        view = gedit_tab_get_view (tab);
1005
1063
        
1006
1064
        g_signal_handlers_disconnect_by_func (doc, on_document_loaded, window);
 
1065
        g_signal_handlers_disconnect_by_func (doc, on_document_saved, window);
1007
1066
}
1008
1067
 
1009
1068
static void
1079
1138
        docs = gedit_window_get_documents (window);
1080
1139
        for (l = docs; l != NULL; l = g_list_next (l))
1081
1140
        {
1082
 
                set_auto_spell_from_metadata (window, GEDIT_DOCUMENT (l->data),
 
1141
                GeditDocument *doc = GEDIT_DOCUMENT (l->data);
 
1142
 
 
1143
                set_auto_spell_from_metadata (window, doc,
1083
1144
                                              data->action_group);
 
1145
 
 
1146
                g_signal_handlers_disconnect_by_func (doc,
 
1147
                                                      on_document_loaded,
 
1148
                                                      window);
 
1149
 
 
1150
                g_signal_handlers_disconnect_by_func (doc,
 
1151
                                                      on_document_saved,
 
1152
                                                      window);
1084
1153
        }
1085
1154
 
1086
1155
        data->tab_added_id =