* Removed a duplicated save_state call
[modest] / src / widgets / modest-attachments-view.c
index 09a7e77..c061ea6 100644 (file)
@@ -67,6 +67,7 @@ static gboolean button_press_event (GtkWidget *widget, GdkEventButton *event, Mo
 static gboolean motion_notify_event (GtkWidget *widget, GdkEventMotion *event, ModestAttachmentsView *atts_view);
 static gboolean button_release_event (GtkWidget *widget, GdkEventButton *event, ModestAttachmentsView *atts_view);
 static gboolean key_press_event (GtkWidget *widget, GdkEventKey *event, ModestAttachmentsView *atts_view);
+static gboolean focus_out_event (GtkWidget *widget, GdkEventFocus *event, ModestAttachmentsView *atts_view);
 static GtkWidget *get_att_view_at_coords (ModestAttachmentsView *atts_view,
                                          gdouble x, gdouble y);
 static void unselect_all (ModestAttachmentsView *atts_view);
@@ -132,10 +133,13 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
                TnyMimePart *part;
 
                part = TNY_MIME_PART (tny_iterator_get_current (iter));
-               if (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)) {
+               if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
                        modest_attachments_view_add_attachment (attachments_view, part);
                }
-               g_object_unref (part);
+
+               if (part)
+                       g_object_unref (part);
+
                tny_iterator_next (iter);
        }
 
@@ -240,6 +244,7 @@ modest_attachments_view_instance_init (GTypeInstance *instance, gpointer g_class
        g_signal_connect (G_OBJECT (instance), "button-release-event", G_CALLBACK (button_release_event), instance);
        g_signal_connect (G_OBJECT (instance), "motion-notify-event", G_CALLBACK (motion_notify_event), instance);
        g_signal_connect (G_OBJECT (instance), "key-press-event", G_CALLBACK (key_press_event), instance);
+       g_signal_connect (G_OBJECT (instance), "focus-out-event", G_CALLBACK (focus_out_event), instance);
 
        GTK_WIDGET_SET_FLAGS (instance, GTK_CAN_FOCUS);
 
@@ -750,3 +755,12 @@ own_clipboard (ModestAttachmentsView *atts_view)
                                      clipboard_get, clipboard_clear, G_OBJECT(atts_view));
                              
 }
+
+static gboolean 
+focus_out_event (GtkWidget *widget, GdkEventFocus *event, ModestAttachmentsView *atts_view)
+{
+       if (!gtk_widget_is_focus (widget))
+               unselect_all (atts_view);
+
+       return FALSE;
+}