~ubuntu-branches/ubuntu/natty/bluefish/natty-proposed

« back to all changes in this revision

Viewing changes to src/bfspell.c

  • Committer: Bazaar Package Importer
  • Author(s): Davide Puricelli (evo)
  • Date: 2005-04-23 17:05:18 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050423170518-pb8zi3vg32cm6g04
Tags: 1.0-1
* Acknowledge NMU, thanks Leo; closes: #291222.
* Updated debian/ files, thanks Daniel Leidert. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Bluefish HTML Editor
 
2
 * bfspell.c - aspell spell checker
 
3
 *
 
4
 * Copyright (C) 2002-2004 Olivier Sessink
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
/* #define DEBUG */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#ifdef HAVE_LIBASPELL
 
25
#include <aspell.h>
 
26
#include <gtk/gtk.h>
 
27
#include <string.h>
 
28
 
 
29
#include "bluefish.h"
 
30
#include "gtk_easy.h"
 
31
#include "document.h"
 
32
#include "stringlist.h"
 
33
#include "bfspell.h"
 
34
/*
 
35
 * indent -ts4 -kr
 
36
 */
 
37
typedef enum {filtnone,filthtml} Tspellfilter;
 
38
 
 
39
typedef struct {
 
40
        AspellConfig *spell_config;
 
41
        AspellSpeller *spell_checker;
 
42
        Tspellfilter filtert;
 
43
        GtkWidget *win;
 
44
        GtkWidget *lang;
 
45
        GtkWidget *filter;
 
46
        GList *langs;
 
47
        GtkWidget *dict;
 
48
        GtkWidget *runbut;
 
49
        GtkWidget *repbut;
 
50
        GtkWidget *ignbut;
 
51
        GtkWidget *in_doc;
 
52
        GtkWidget *in_sel;
 
53
        /* during the checking */
 
54
        GtkWidget *incorrectword;
 
55
        GtkWidget *suggestions;
 
56
        Tdocument *doc;
 
57
        gint offset;
 
58
        gint stop_position;
 
59
        GtkTextMark* so;
 
60
        GtkTextMark* eo;
 
61
        Tbfwin *bfwin;
 
62
} Tbfspell;
 
63
 
 
64
static void spell_gui_set_button_status(Tbfspell *bfspell, gboolean is_running) {
 
65
        gtk_widget_set_sensitive(bfspell->runbut,!is_running);
 
66
        gtk_widget_set_sensitive(bfspell->lang,!is_running);
 
67
        gtk_widget_set_sensitive(bfspell->repbut,is_running);
 
68
        gtk_widget_set_sensitive(bfspell->ignbut,is_running);
 
69
}
 
70
 
 
71
static gboolean test_unichar(gunichar ch,gpointer data) {
 
72
        if (ch == GPOINTER_TO_INT(data)) {
 
73
                return TRUE;
 
74
        } else {
 
75
                return FALSE;
 
76
        }
 
77
}
 
78
 
 
79
/* return value should be freed by the calling function */
 
80
gchar *doc_get_next_word(Tbfspell *bfspell, GtkTextIter *itstart, GtkTextIter *itend) {
 
81
        gboolean havestart=FALSE;
 
82
        gchar *retval;
 
83
        
 
84
        if (bfspell->eo && bfspell->offset ==-1) {
 
85
                gtk_text_buffer_get_iter_at_mark(bfspell->doc->buffer,itstart,bfspell->eo);
 
86
        } else {
 
87
                gtk_text_buffer_get_iter_at_offset(bfspell->doc->buffer,itstart,bfspell->offset);
 
88
        }
 
89
        havestart = gtk_text_iter_starts_word(itstart);
 
90
        while (!havestart) {
 
91
                if (bfspell->filtert == filthtml)  {
 
92
                        /* 60 is the ascii code for <, 62 for > */
 
93
                        if (gtk_text_iter_get_char(itstart) == 60) {
 
94
                                gtk_text_iter_forward_find_char(itstart, test_unichar,GINT_TO_POINTER(62), NULL);
 
95
                        }
 
96
                }
 
97
                if (!gtk_text_iter_forward_char(itstart)) {
 
98
                        return NULL;
 
99
                }
 
100
                havestart = gtk_text_iter_starts_word(itstart);
 
101
        }
 
102
        *itend = *itstart;
 
103
        gtk_text_iter_forward_word_end(itend);
 
104
 
 
105
        bfspell->offset = gtk_text_iter_get_offset(itend);
 
106
        if (bfspell->offset > bfspell->stop_position) {
 
107
                return NULL;
 
108
        }
 
109
        retval = gtk_text_buffer_get_text(bfspell->doc->buffer,itstart,itend,FALSE);
 
110
        if (strlen(retval)<1) {
 
111
                g_free(retval);
 
112
                return NULL;
 
113
        }
 
114
        return retval;
 
115
}
 
116
 
 
117
void spell_add_to_session(Tbfspell *bfspell, gboolean to_session, const gchar * word) {
 
118
        DEBUG_MSG("spell_add_to_session, to_session=%d, word=%s\n",to_session,word);
 
119
        if (to_session) {
 
120
                aspell_speller_add_to_session(bfspell->spell_checker, word, -1);
 
121
        } else {
 
122
                aspell_speller_add_to_personal(bfspell->spell_checker, word, -1);
 
123
        }
 
124
 
 
125
}
 
126
 
 
127
gboolean spell_check_word(Tbfspell *bfspell, gchar * tocheck, GtkTextIter *itstart, GtkTextIter *itend) {
 
128
        int correct = aspell_speller_check(bfspell->spell_checker, tocheck, -1);
 
129
        DEBUG_MSG("word '%s' has correct=%d\n",tocheck,correct);
 
130
        if (!correct) {
 
131
                AspellWordList *awl = (AspellWordList *)aspell_speller_suggest(bfspell->spell_checker, tocheck,-1);
 
132
                if (!bfspell->so || !bfspell->eo) {
 
133
                        bfspell->so = gtk_text_buffer_create_mark(bfspell->doc->buffer,NULL,itstart,FALSE);
 
134
                        bfspell->eo = gtk_text_buffer_create_mark(bfspell->doc->buffer,NULL,itend,TRUE);
 
135
                } else {
 
136
                        gtk_text_buffer_move_mark(bfspell->doc->buffer,bfspell->so,itstart);
 
137
                        gtk_text_buffer_move_mark(bfspell->doc->buffer,bfspell->eo,itend);
 
138
                }
 
139
                doc_select_region(bfspell->doc, gtk_text_iter_get_offset(itstart),gtk_text_iter_get_offset(itend) , TRUE);
 
140
                bfspell->offset = -1;
 
141
                gtk_entry_set_text(GTK_ENTRY(bfspell->incorrectword), tocheck);
 
142
                gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(bfspell->suggestions)->entry), "");
 
143
                if (awl == 0) {
 
144
                        DEBUG_MSG("spell_check_word error: %s\n", aspell_speller_error_message(bfspell->spell_checker));
 
145
                } else {
 
146
                        GList *poplist=NULL;
 
147
                        AspellStringEnumeration *els = aspell_word_list_elements(awl);
 
148
                        const char *word;
 
149
                        while ((word = aspell_string_enumeration_next(els)) != 0) {
 
150
                                poplist = g_list_append(poplist,g_strdup(word));
 
151
                        }
 
152
                        if (!poplist) {
 
153
                                poplist = g_list_append(poplist, g_strdup("(no suggested words)"));
 
154
                        }
 
155
                        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(bfspell->suggestions)->entry), "");
 
156
                        gtk_combo_set_popdown_strings(GTK_COMBO(bfspell->suggestions), poplist);
 
157
                        free_stringlist(poplist);
 
158
                        delete_aspell_string_enumeration(els);
 
159
                }
 
160
                return FALSE;
 
161
        } else {
 
162
                return TRUE;
 
163
        }
 
164
}
 
165
 
 
166
static void spell_run_finished(Tbfspell *bfspell) {
 
167
        GList *poplist = NULL;
 
168
        DEBUG_MSG("spell_run_finished\n");
 
169
        gtk_entry_set_text(GTK_ENTRY(bfspell->incorrectword), "");
 
170
        gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(bfspell->suggestions)->entry), "");
 
171
        poplist = g_list_append(poplist,"");
 
172
        gtk_combo_set_popdown_strings(GTK_COMBO(bfspell->suggestions), poplist);
 
173
        g_list_free(poplist);
 
174
        bfspell->offset = 0;
 
175
        aspell_speller_save_all_word_lists(bfspell->spell_checker);
 
176
        delete_aspell_speller(bfspell->spell_checker);
 
177
        bfspell->spell_checker = NULL;
 
178
        spell_gui_set_button_status(bfspell, FALSE);
 
179
}
 
180
 
 
181
gboolean spell_run(Tbfspell *bfspell) {
 
182
        GtkTextIter itstart,itend;
 
183
        gchar *word = doc_get_next_word(bfspell, &itstart,&itend);
 
184
        DEBUG_MSG("spell_run, started, bfspell=%p, word=%s\n",bfspell,word);
 
185
        if (!word) {
 
186
                spell_run_finished(bfspell);
 
187
                return FALSE; /* finished */
 
188
        }
 
189
        while (word) {
 
190
                DEBUG_MSG("spell_run: word '%s'\n", word);
 
191
                if (spell_check_word(bfspell,word,&itstart,&itend)) {
 
192
                        g_free(word);
 
193
                        word = doc_get_next_word(bfspell,&itstart,&itend);
 
194
                        if (!word) {
 
195
                                spell_run_finished(bfspell);
 
196
                                return FALSE; /* finished */
 
197
                        }
 
198
                } else { /* not correct ! */
 
199
                        g_free(word);
 
200
                        word = NULL;
 
201
                }
 
202
        }
 
203
        return TRUE; /* not yet finished */
 
204
}
 
205
 
 
206
void spell_start(Tbfspell *bfspell) {
 
207
        DEBUG_MSG("spell_start, started for bfspell=%p\n",bfspell);
 
208
        bfspell->spell_config = new_aspell_config();
 
209
        DEBUG_MSG("spell_start, created spell_config at %p\n",bfspell->spell_config);
 
210
        /*
 
211
         * default language should come from config file, runtime from GUI,
 
212
         * should first set the default one 
 
213
         */
 
214
        aspell_config_replace(bfspell->spell_config, "lang", main_v->props.spell_default_lang);
 
215
        DEBUG_MSG("spell_start, default lang=%s\n",main_v->props.spell_default_lang);
 
216
        /*
 
217
         * it is unclear from the manual if aspell supports utf-8 in the
 
218
         * library, the utility does not support it.. 
 
219
         */
 
220
        aspell_config_replace(bfspell->spell_config, "encoding", "utf-8");
 
221
        /*
 
222
         * from the aspell manual 
 
223
         */
 
224
}
 
225
 
 
226
static void spell_gui_destroy(GtkWidget * widget, Tbfspell *bfspell) {
 
227
        DEBUG_MSG("spell_gui_destroy started\n");
 
228
        window_destroy(bfspell->win);
 
229
        if (bfspell->spell_checker) {
 
230
                aspell_speller_save_all_word_lists(bfspell->spell_checker);
 
231
                delete_aspell_speller(bfspell->spell_checker);
 
232
        }
 
233
        delete_aspell_config(bfspell->spell_config);
 
234
        if (bfspell->so) {
 
235
                gtk_text_buffer_delete_mark(bfspell->doc->buffer, bfspell->so);
 
236
        }
 
237
        if (bfspell->eo) {
 
238
                gtk_text_buffer_delete_mark(bfspell->doc->buffer, bfspell->eo);
 
239
        }
 
240
        g_free(bfspell);
 
241
}
 
242
 
 
243
void spell_gui_cancel_clicked_cb(GtkWidget *widget, Tbfspell *bfspell) {
 
244
        spell_gui_destroy(NULL, bfspell);
 
245
}
 
246
 
 
247
void spell_gui_ok_clicked_cb(GtkWidget *widget, Tbfspell *bfspell) {
 
248
        AspellCanHaveError *possible_err;
 
249
        const gchar *lang;
 
250
        DEBUG_MSG("spell_gui_ok_clicked_cb, bfspell=%p, bfwin=%p\n",bfspell, bfspell->bfwin);
 
251
        bfspell->doc = bfspell->bfwin->current_document;
 
252
        {
 
253
                gint indx;
 
254
                indx = gtk_option_menu_get_history(GTK_OPTION_MENU(bfspell->lang));
 
255
                lang = g_list_nth_data(bfspell->langs, indx);
 
256
                DEBUG_MSG("spell_gui_ok_clicked_cb, indx=%d has language %s\n",indx,lang);
 
257
        }
 
258
        aspell_config_replace(bfspell->spell_config, "lang", lang);
 
259
 
 
260
        DEBUG_MSG("spell_gui_ok_clicked_cb, about to create speller for spell_config=%p\n",bfspell->spell_config);
 
261
        possible_err = new_aspell_speller(bfspell->spell_config);
 
262
        bfspell->spell_checker = 0;
 
263
        if (aspell_error_number(possible_err) != 0) {
 
264
                DEBUG_MSG(aspell_error_message(possible_err));
 
265
                /* now send an error, and stop */
 
266
                return;
 
267
        } else {
 
268
                bfspell->spell_checker = to_aspell_speller(possible_err);
 
269
        }
 
270
 
 
271
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(bfspell->in_doc))) {
 
272
                bfspell->stop_position = gtk_text_buffer_get_char_count(bfspell->doc->buffer);
 
273
        } else {
 
274
                GtkTextIter start, end;
 
275
                gtk_text_buffer_get_selection_bounds(bfspell->doc->buffer,&start,&end);
 
276
                bfspell->offset = gtk_text_iter_get_offset(&start);
 
277
                bfspell->stop_position = gtk_text_iter_get_offset(&end);
 
278
        }
 
279
        DEBUG_MSG("about to start spell_run()\n");
 
280
        if (spell_run(bfspell)) {
 
281
                spell_gui_set_button_status(bfspell,TRUE);
 
282
        } else {
 
283
                spell_gui_set_button_status(bfspell,FALSE);
 
284
        }
 
285
}
 
286
 
 
287
void spell_gui_fill_dicts(Tbfspell *bfspell) {
 
288
        GtkWidget *menu, *menuitem;
 
289
        AspellDictInfoEnumeration * dels;
 
290
        AspellDictInfoList * dlist;
 
291
        const AspellDictInfo * entry;
 
292
 
 
293
        dlist = get_aspell_dict_info_list(bfspell->spell_config);
 
294
        dels = aspell_dict_info_list_elements(dlist);
 
295
        free_stringlist(bfspell->langs);
 
296
        bfspell->langs = NULL;
 
297
        menu = gtk_menu_new();  
 
298
        gtk_option_menu_set_menu(GTK_OPTION_MENU(bfspell->lang), menu);
 
299
        while ( (entry = aspell_dict_info_enumeration_next(dels)) != 0) {
 
300
                GtkWidget *label;
 
301
                menuitem = gtk_menu_item_new();
 
302
                label = gtk_label_new(entry->name);
 
303
                gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
 
304
                gtk_container_add(GTK_CONTAINER(menuitem), label);
 
305
/*              g_signal_connect(G_OBJECT (menuitem), "activate",G_CALLBACK(),GINT_TO_POINTER(0));*/
 
306
                if (strcmp(entry->name, main_v->props.spell_default_lang) == 0) {
 
307
                        DEBUG_MSG("spell_gui_fill_dicts, lang %s is the default language, inserting menuitem %p at position 0\n",entry->name,menuitem);
 
308
                        gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 0);
 
309
                        bfspell->langs = g_list_prepend(bfspell->langs,g_strdup(entry->name));
 
310
                } else {
 
311
                        DEBUG_MSG("spell_gui_fill_dicts, lang %s is not the default language, appending menuitem %p\n",entry->name,menuitem);
 
312
                        gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
313
                        bfspell->langs = g_list_append(bfspell->langs,g_strdup(entry->name));
 
314
                }
 
315
        }
 
316
        delete_aspell_dict_info_enumeration(dels);
 
317
        gtk_widget_show_all(menu);
 
318
        gtk_option_menu_set_menu(GTK_OPTION_MENU(bfspell->lang), menu);
 
319
        DEBUG_MSG("spell_gui_fill_dicts, set item 0 as selected item\n");
 
320
        gtk_option_menu_set_history(GTK_OPTION_MENU(bfspell->lang),0);
 
321
}
 
322
 
 
323
void spell_gui_add_clicked(GtkWidget *widget, Tbfspell *bfspell) {
 
324
        const gchar *original = gtk_entry_get_text(GTK_ENTRY(bfspell->incorrectword));
 
325
        if (strlen(original)) {
 
326
                if (gtk_option_menu_get_history(GTK_OPTION_MENU(bfspell->dict))) {
 
327
                        spell_add_to_session(bfspell, FALSE,original);
 
328
                } else {
 
329
                        spell_add_to_session(bfspell, TRUE,original);
 
330
                }
 
331
        }
 
332
}
 
333
void spell_gui_ignore_clicked(GtkWidget *widget, Tbfspell *bfspell) {
 
334
        DEBUG_MSG("ignore\n");
 
335
        if (spell_run(bfspell)) {
 
336
                spell_gui_set_button_status(bfspell,TRUE);
 
337
        } else {
 
338
                spell_gui_set_button_status(bfspell,FALSE);
 
339
        }
 
340
}
 
341
void spell_gui_replace_clicked(GtkWidget *widget, Tbfspell *bfspell) {
 
342
        gint start, end;
 
343
        GtkTextIter iter;
 
344
        const gchar *original = gtk_entry_get_text(GTK_ENTRY(bfspell->incorrectword));
 
345
        const gchar *newstring = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(bfspell->suggestions)->entry));
 
346
 
 
347
        aspell_speller_store_replacement(bfspell->spell_checker,original,-1,newstring,-1);
 
348
 
 
349
        gtk_text_buffer_get_iter_at_mark(bfspell->doc->buffer,&iter,bfspell->so);
 
350
        start = gtk_text_iter_get_offset(&iter);
 
351
        gtk_text_buffer_get_iter_at_mark(bfspell->doc->buffer,&iter,bfspell->eo);
 
352
        end = gtk_text_iter_get_offset(&iter);
 
353
        DEBUG_MSG("set %s from %d to %d\n",newstring,start,end);
 
354
        doc_replace_text(bfspell->doc, newstring, start, end);
 
355
        if (spell_run(bfspell)) {
 
356
                spell_gui_set_button_status(bfspell, TRUE);
 
357
        } else {
 
358
                spell_gui_set_button_status(bfspell, FALSE);
 
359
        }
 
360
}
 
361
 
 
362
static void defaultlang_clicked_lcb(GtkWidget *widget,Tbfspell *bfspell) {
 
363
        const gchar *lang;
 
364
        gint indx;
 
365
        indx = gtk_option_menu_get_history(GTK_OPTION_MENU(bfspell->lang));
 
366
        lang = g_list_nth_data(bfspell->langs, indx);
 
367
        g_free(main_v->props.spell_default_lang);
 
368
        DEBUG_MSG("defaultlang_clicked_lcb, index=%d, default lang is now %s\n",indx, lang);
 
369
        main_v->props.spell_default_lang = g_strdup(lang);
 
370
}
 
371
void filter_changed_lcb(GtkOptionMenu *optionmenu,Tbfspell *bfspell) {
 
372
        bfspell->filtert = gtk_option_menu_get_history(GTK_OPTION_MENU(bfspell->filter));
 
373
}
 
374
 
 
375
void spell_gui(Tbfspell *bfspell) {
 
376
        GtkWidget *vbox, *hbox, *but, *frame, *table, *label;
 
377
        bfspell->win = window_full(_("Check Spelling"), GTK_WIN_POS_NONE, 3, G_CALLBACK(spell_gui_destroy),bfspell, TRUE);
 
378
        vbox = gtk_vbox_new(FALSE, 2);
 
379
        gtk_container_add(GTK_CONTAINER(bfspell->win), vbox);
 
380
        
 
381
        frame = gtk_frame_new(_("Checking"));
 
382
        gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
 
383
        table = gtk_table_new(3,5,FALSE);
 
384
        gtk_table_set_col_spacings(GTK_TABLE(table), 6);
 
385
        gtk_table_set_row_spacings(GTK_TABLE(table), 6);
 
386
        gtk_container_add(GTK_CONTAINER(frame), table);
 
387
        
 
388
        bfspell->incorrectword = gtk_entry_new();
 
389
        gtk_entry_set_editable(GTK_ENTRY(bfspell->incorrectword),FALSE);
 
390
        bf_mnemonic_label_tad_with_alignment(_("_Misspelled word:"), bfspell->incorrectword, 1, 0.5, table, 1, 2, 0, 1);
 
391
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->incorrectword,2,3,0,1);
 
392
        
 
393
        bfspell->suggestions = gtk_combo_new();
 
394
        bf_mnemonic_label_tad_with_alignment(_("Change _to:"), bfspell->suggestions, 1, 0.5, table, 1, 2, 1, 2);
 
395
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->suggestions,2,3,1,2);
 
396
 
 
397
        bfspell->ignbut = bf_generic_mnemonic_button(_("I_gnore"), G_CALLBACK(spell_gui_ignore_clicked), bfspell);
 
398
        bfspell->repbut = bf_generic_mnemonic_button(_("_Replace"), G_CALLBACK(spell_gui_replace_clicked), bfspell);
 
399
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->ignbut,3,4,0,1);
 
400
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->repbut,3,4,1,2);
 
401
        
 
402
        gtk_widget_set_sensitive(bfspell->repbut,FALSE);
 
403
        gtk_widget_set_sensitive(bfspell->ignbut,FALSE);
 
404
        
 
405
        /* lower GUI part */
 
406
        table = gtk_table_new(5,3,FALSE);
 
407
        gtk_table_set_col_spacings(GTK_TABLE(table), 6);
 
408
        gtk_table_set_row_spacings(GTK_TABLE(table), 6);        
 
409
        gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
 
410
 
 
411
        bfspell->in_doc = gtk_radio_button_new_with_mnemonic(NULL, _("In _document"));
 
412
        bfspell->in_sel = gtk_radio_button_new_with_mnemonic(gtk_radio_button_get_group(GTK_RADIO_BUTTON(bfspell->in_doc)), _("I_n selection"));
 
413
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->in_doc,0,1,0,1);
 
414
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->in_sel,1,2,0,1);
 
415
 
 
416
        {
 
417
                GtkWidget *menu, *menuitem;
 
418
                bfspell->dict = gtk_option_menu_new();
 
419
                menu = gtk_menu_new();
 
420
                gtk_option_menu_set_menu(GTK_OPTION_MENU(bfspell->dict), menu);
 
421
                menuitem = gtk_menu_item_new_with_label(_("personal dictionary"));
 
422
/*              g_signal_connect(G_OBJECT (menuitem), "activate",G_CALLBACK(),GINT_TO_POINTER(0));*/
 
423
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
424
                menuitem = gtk_menu_item_new_with_label(_("session dictionary"));
 
425
/*              g_signal_connect(G_OBJECT (menuitem), "activate",G_CALLBACK(),GINT_TO_POINTER(1));*/
 
426
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
427
                gtk_option_menu_set_history(GTK_OPTION_MENU(bfspell->dict),0);
 
428
        }
 
429
 
 
430
        label = gtk_label_new(_("Dictionary:"));
 
431
        gtk_table_attach_defaults(GTK_TABLE(table), label,0,1,2,3);
 
432
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
 
433
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->dict,1,2,2,3);
 
434
        but = bf_generic_mnemonic_button(_("_Add"), G_CALLBACK(spell_gui_add_clicked), bfspell);
 
435
        gtk_table_attach_defaults(GTK_TABLE(table), but,2,3,2,3);
 
436
 
 
437
        bfspell->lang = gtk_option_menu_new();
 
438
        label = gtk_label_new(_("Language:"));
 
439
        gtk_table_attach_defaults(GTK_TABLE(table), label,0,1,3,4);
 
440
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
 
441
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->lang,1,2,3,4);
 
442
        but = bf_generic_mnemonic_button(_("Set defa_ult"), G_CALLBACK(defaultlang_clicked_lcb), bfspell);
 
443
        gtk_table_attach_defaults(GTK_TABLE(table), but,2,3,3,4);
 
444
 
 
445
        bfspell->filter = gtk_option_menu_new();
 
446
        label = gtk_label_new(_("Filter:"));
 
447
        gtk_table_attach_defaults(GTK_TABLE(table), label,0,1,4,5);
 
448
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
 
449
        gtk_table_attach_defaults(GTK_TABLE(table), bfspell->filter,1,2,4,5);
 
450
        {
 
451
                GtkWidget *menu, *menuitem;
 
452
                menu = gtk_menu_new();
 
453
                gtk_option_menu_set_menu(GTK_OPTION_MENU(bfspell->filter), menu);               
 
454
                menuitem = gtk_menu_item_new_with_label(_("no filter"));
 
455
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
456
                menuitem = gtk_menu_item_new_with_label(_("html filter"));
 
457
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
458
        }
 
459
        g_signal_connect(G_OBJECT(bfspell->filter),"changed",G_CALLBACK(filter_changed_lcb),bfspell);
 
460
        gtk_option_menu_set_history(GTK_OPTION_MENU(bfspell->filter),1);
 
461
 
 
462
        gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 12);
 
463
 
 
464
        hbox = gtk_hbutton_box_new();
 
465
        gtk_hbutton_box_set_layout_default(GTK_BUTTONBOX_END);
 
466
        gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 12);
 
467
        
 
468
        but = bf_gtkstock_button(GTK_STOCK_CLOSE, G_CALLBACK(spell_gui_cancel_clicked_cb), bfspell);
 
469
        gtk_box_pack_start(GTK_BOX(hbox),but,FALSE, FALSE, 0);
 
470
        bfspell->runbut = bf_gtkstock_button(GTK_STOCK_SPELL_CHECK,G_CALLBACK(spell_gui_ok_clicked_cb),bfspell);
 
471
        gtk_box_pack_start(GTK_BOX(hbox),bfspell->runbut,FALSE, FALSE, 0);
 
472
        
 
473
        gtk_window_set_default(GTK_WINDOW(bfspell->win), bfspell->runbut);
 
474
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 
475
 
 
476
        gtk_widget_show_all(bfspell->win);
 
477
}
 
478
 
 
479
void spell_check_cb(GtkWidget *widget, Tbfwin *bfwin) {
 
480
        Tbfspell *bfspell = NULL;
 
481
 
 
482
        bfspell = g_new0(Tbfspell,1);
 
483
        bfwin->bfspell = bfspell;
 
484
        bfspell->bfwin = bfwin;
 
485
 
 
486
        spell_gui(bfspell);
 
487
        flush_queue();
 
488
        spell_start(bfspell);
 
489
        spell_gui_fill_dicts(bfspell);
 
490
}
 
491
#endif /* HAVE_LIBASPELL */