0.9.4claws47
[claws.git] / src / gtk / gtkaspell.c
index edfae15792f0dcef067eab4191e300020fa07a08..c9eaae836cfd124aecaf070821c5bd92142cb174 100644 (file)
@@ -44,6 +44,8 @@
 #include <time.h>
 #include <dirent.h>
 
+#include <glib.h>
+
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 #include <gtk/gtkoptionmenu.h>
@@ -1632,6 +1634,35 @@ gchar *gtkaspell_get_dictionary_menu_active_item(GtkWidget *menu)
   
 }
 
+gint gtkaspell_set_dictionary_menu_active_item(GtkWidget *menu, const gchar *dictionary)
+{
+       GList *cur;
+       gint n;
+
+       g_return_val_if_fail(menu != NULL, 0);
+       g_return_val_if_fail(dictionary != NULL, 0);
+       g_return_val_if_fail(GTK_IS_OPTION_MENU(menu), 0);
+
+       n = 0;
+       for (cur = GTK_MENU_SHELL(gtk_option_menu_get_menu(GTK_OPTION_MENU(menu)))->children;
+            cur != NULL; cur = cur->next) {
+               GtkWidget *menuitem;
+               gchar *dict_name;
+
+               menuitem = GTK_WIDGET(cur->data);
+               dict_name = gtk_object_get_data(GTK_OBJECT(menuitem), 
+                                               "dict_name");
+               if ((dict_name != NULL) && !strcmp2(dict_name, dictionary)) {
+                       gtk_option_menu_set_history(GTK_OPTION_MENU(menu), n);
+
+                       return 1;
+               }
+               n++;
+       }
+
+       return 0;
+}
+
 GtkWidget *gtkaspell_sugmode_option_menu_new(gint sugmode)
 {
        GtkWidget *menu;
@@ -2081,30 +2112,26 @@ static gboolean cancel_menu_cb(GtkMenuShell *w, gpointer data)
        
 }
 
-/* change_dict_cb() - Menu callback : change dict */
-static void change_dict_cb(GtkWidget *w, GtkAspell *gtkaspell)
+gboolean gtkaspell_change_dict(GtkAspell *gtkaspell, guchar *dictionary)
 {
        Dictionary      *dict;       
-       gchar           *fullname;
        GtkAspeller     *gtkaspeller;
        gint             sug_mode;
-  
-        fullname = (gchar *) gtk_object_get_data(GTK_OBJECT(w), "dict_name");
-       
-       if (!strcmp2(fullname, _("None")))
-               return;
 
+       g_return_val_if_fail(gtkaspell, FALSE);
+       g_return_val_if_fail(dictionary, FALSE);
+  
        sug_mode  = gtkaspell->default_sug_mode;
 
        dict = g_new0(Dictionary, 1);
-       dict->fullname = g_strdup(fullname);
+       dict->fullname = g_strdup(dictionary);
        dict->encoding = g_strdup(gtkaspell->gtkaspeller->dictionary->encoding);
 
        if (gtkaspell->use_alternate && gtkaspell->alternate_speller &&
            dict == gtkaspell->alternate_speller->dictionary) {
                use_alternate_dict(gtkaspell);
                dictionary_delete(dict);
-               return;
+               return TRUE;
        }
        
        gtkaspeller = gtkaspeller_new(dict);
@@ -2132,6 +2159,21 @@ static void change_dict_cb(GtkWidget *w, GtkAspell *gtkaspell)
 
        if (gtkaspell->config_menu)
                populate_submenu(gtkaspell, gtkaspell->config_menu);
+
+       return TRUE;    
+}
+
+/* change_dict_cb() - Menu callback : change dict */
+static void change_dict_cb(GtkWidget *w, GtkAspell *gtkaspell)
+{
+       gchar           *fullname;
+  
+        fullname = (gchar *) gtk_object_get_data(GTK_OBJECT(w), "dict_name");
+       
+       if (!strcmp2(fullname, _("None")))
+               return;
+
+       gtkaspell_change_dict(gtkaspell, fullname);
 }
 
 static void switch_to_alternate_cb(GtkWidget *w,