Fix for bug NB#81584.
[modest] / src / widgets / modest-recpt-view.c
index 93edff3..cb8511c 100644 (file)
@@ -85,11 +85,19 @@ modest_recpt_view_set_recipients (ModestRecptView *recpt_view, const gchar *reci
 {
        const GtkWidget *text_view = NULL;
        GtkTextBuffer *buffer = NULL;
+       gchar *std_recipients;
 
        text_view = modest_scroll_text_get_text_view (MODEST_SCROLL_TEXT (recpt_view));
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
 
-       gtk_text_buffer_set_text (buffer, recipients, -1);
+       if (recipients == NULL) {
+               std_recipients = NULL;
+       } else {
+               std_recipients = modest_text_utils_address_with_standard_length (recipients);
+       }
+
+       gtk_text_buffer_set_text (buffer, std_recipients, -1);
+       g_free (std_recipients);
        if (GTK_WIDGET_REALIZED (recpt_view))
                gtk_widget_queue_resize (GTK_WIDGET (recpt_view));
 
@@ -134,13 +142,14 @@ button_release_event (GtkWidget *widget,
                        gint buffer_x, buffer_y;
                        int index;
                        GtkTextIter iter;
+                       gtk_widget_grab_focus (GTK_WIDGET (text_view));
                        gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view), GTK_TEXT_WINDOW_WIDGET,
                                                               event->x, event->y, &buffer_x, &buffer_y);
                        gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, buffer_x, buffer_y);
                        index = gtk_text_iter_get_offset (&iter);
                        
                        if (!gtk_text_iter_is_end (&iter)) {
-                               int selection_start, selection_end;
+                               guint selection_start, selection_end;
                                gboolean selected = FALSE;
                                GtkTextIter start_iter, end_iter;
                                GtkTextBuffer *buffer;
@@ -157,23 +166,24 @@ button_release_event (GtkWidget *widget,
                                        gtk_text_buffer_get_end_iter (buffer, &end_iter);
                                        text = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE);
 
-                                       modest_text_utils_address_range_at_position (text,
-                                                                                    index,
-                                                                                    &selection_start, &selection_end);
-                                       /* TODO: now gtk label tries to select more than the label as usual,
-                                        *  and we force it to recover the selected region for the defined area.
-                                        *  It should be fixed (maybe preventing gtklabel to manage selections
-                                        *  in parallel with us
-                                        */
-                                       gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, selection_start);
-                                       gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, selection_end);
-                                       gtk_text_buffer_select_range (buffer, &start_iter, &end_iter);
-                                       
-                                       if (text)
+                                       /* text will not be NULL, but source code checkers should be satisfied */
+                                       if (text) {
+                                               modest_text_utils_address_range_at_position (text,
+                                                                                            index,
+                                                                                            &selection_start, &selection_end);
+                                               /* TODO: now gtk label tries to select more than the label as usual,
+                                                *  and we force it to recover the selected region for the defined area.
+                                                *  It should be fixed (maybe preventing gtklabel to manage selections
+                                                *  in parallel with us
+                                                */
+                                               gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, selection_start);
+                                               gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, selection_end);
+                                               gtk_text_buffer_select_range (buffer, &start_iter, &end_iter);
+                                               
                                                g_free (text);
-                                                                     
+                                       }                     
                                }
-
+                               
                                if (selected) {
                                        gchar *selection;