[evolution/wip/webkit2] Pack EAttachmentBar properly under the preview



commit b6b6923daf12b632edf6c8e89de6e13a3db84882
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jul 8 09:29:24 2016 +0200

    Pack EAttachmentBar properly under the preview
    
    ...thus it stays there in both the Vertical and the Classic views.
    Also pack respective views in the EAttachmentBar in a scrollable
    window, thus the bar doesn't use too much space.

 e-util/e-attachment-bar.c                |   16 ++++-
 mail/e-mail-browser.c                    |    3 +-
 mail/e-mail-display.c                    |  105 +++++++++---------------------
 mail/e-mail-display.h                    |    5 +-
 mail/e-mail-paned-view.c                 |   14 ++++-
 modules/mail/e-mail-shell-content.c      |   15 +----
 modules/mail/e-mail-shell-content.h      |    2 -
 modules/mail/e-mail-shell-view-actions.c |   14 +++--
 8 files changed, 68 insertions(+), 106 deletions(-)
---
diff --git a/e-util/e-attachment-bar.c b/e-util/e-attachment-bar.c
index 3916d00..b34b469 100644
--- a/e-util/e-attachment-bar.c
+++ b/e-util/e-attachment-bar.c
@@ -597,7 +597,7 @@ e_attachment_bar_init (EAttachmentBar *bar)
        EAttachmentView *view;
        GtkSizeGroup *size_group;
        GtkWidget *container;
-       GtkWidget *widget;
+       GtkWidget *widget, *scrolled_window;
        GtkAction *action;
 
        bar->priv = E_ATTACHMENT_BAR_GET_PRIVATE (bar);
@@ -627,10 +627,15 @@ e_attachment_bar_init (EAttachmentBar *bar)
 
        container = widget;
 
+       scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, 
GTK_POLICY_AUTOMATIC);
+       gtk_container_add (GTK_CONTAINER (container), scrolled_window);
+       gtk_widget_show (scrolled_window);
+
        widget = e_attachment_icon_view_new ();
        gtk_widget_set_can_focus (widget, TRUE);
        gtk_icon_view_set_model (GTK_ICON_VIEW (widget), bar->priv->model);
-       gtk_container_add (GTK_CONTAINER (container), widget);
+       gtk_container_add (GTK_CONTAINER (scrolled_window), widget);
        bar->priv->icon_view = g_object_ref (widget);
        gtk_widget_show (widget);
 
@@ -644,10 +649,15 @@ e_attachment_bar_init (EAttachmentBar *bar)
 
        container = widget;
 
+       scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, 
GTK_POLICY_AUTOMATIC);
+       gtk_container_add (GTK_CONTAINER (container), scrolled_window);
+       gtk_widget_show (scrolled_window);
+
        widget = e_attachment_tree_view_new ();
        gtk_widget_set_can_focus (widget, TRUE);
        gtk_tree_view_set_model (GTK_TREE_VIEW (widget), bar->priv->model);
-       gtk_container_add (GTK_CONTAINER (container), widget);
+       gtk_container_add (GTK_CONTAINER (scrolled_window), widget);
        bar->priv->tree_view = g_object_ref (widget);
        gtk_widget_show (widget);
 
diff --git a/mail/e-mail-browser.c b/mail/e-mail-browser.c
index 3e61004..dcaff2f 100644
--- a/mail/e-mail-browser.c
+++ b/mail/e-mail-browser.c
@@ -754,8 +754,7 @@ mail_browser_constructed (GObject *object)
                TRUE, TRUE, 0);
 
        attachment_store = e_mail_display_get_attachment_store (E_MAIL_DISPLAY (display));
-       widget = e_attachment_bar_new (attachment_store);
-       e_mail_display_set_attachment_view (E_MAIL_DISPLAY (display), E_ATTACHMENT_VIEW (widget));
+       widget = GTK_WIDGET (e_mail_display_get_attachment_view (E_MAIL_DISPLAY (display)));
        gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
        gtk_widget_show (widget);
 
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 6afd315..2d0b76b 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -58,7 +58,7 @@ typedef enum {
 
 struct _EMailDisplayPrivate {
        EAttachmentStore *attachment_store;
-       GWeakRef *attachment_view; /* EAttachmentView * */
+       EAttachmentView *attachment_view;
        GHashTable *attachment_flags; /* EAttachment * ~> guint bit-or of EAttachmentFlags */
        guint attachment_inline_ui_id;
 
@@ -618,7 +618,7 @@ mail_display_change_attachment_visibility (EMailDisplay *display,
 
        g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
-       view = e_mail_display_ref_attachment_view (display);
+       view = e_mail_display_get_attachment_view (display);
        g_return_if_fail (view != NULL);
 
        if (all)
@@ -634,7 +634,6 @@ mail_display_change_attachment_visibility (EMailDisplay *display,
        }
 
        g_list_free_full (attachments, g_object_unref);
-       g_clear_object (&view);
 }
 
 static void
@@ -646,7 +645,7 @@ mail_attachment_change_zoom (EMailDisplay *display,
 
        g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
-       view = e_mail_display_ref_attachment_view (display);
+       view = e_mail_display_get_attachment_view (display);
        g_return_if_fail (view != NULL);
 
        attachments = view ? e_attachment_view_get_selected_attachments (view) : NULL;
@@ -684,7 +683,6 @@ mail_attachment_change_zoom (EMailDisplay *display,
        }
 
        g_list_free_full (attachments, g_object_unref);
-       g_clear_object (&view);
 }
 
 static void
@@ -894,7 +892,7 @@ mail_display_attachment_inline_update_actions (EMailDisplay *display)
 
        g_list_free_full (attachments, g_object_unref);
 
-       view = e_mail_display_ref_attachment_view (display);
+       view = e_mail_display_get_attachment_view (display);
        attachments = view ? e_attachment_view_get_selected_attachments (view) : NULL;
        n_selected = g_list_length (attachments);
 
@@ -916,8 +914,6 @@ mail_display_attachment_inline_update_actions (EMailDisplay *display)
        }
        g_list_free_full (attachments, g_object_unref);
 
-       g_clear_object (&view);
-
        action = gtk_action_group_get_action (action_group, "show");
        gtk_action_set_visible (action, can_show && !shown);
 
@@ -1040,7 +1036,7 @@ mail_display_attachment_menu_clicked_cb (EWebView *web_view,
        g_return_if_fail (element_position != NULL);
 
        display = E_MAIL_DISPLAY (web_view);
-       view = e_mail_display_ref_attachment_view (display);
+       view = e_mail_display_get_attachment_view (display);
        attachment = mail_display_ref_attachment_from_element (display, element_value);
 
        if (view && attachment) {
@@ -1063,7 +1059,6 @@ mail_display_attachment_menu_clicked_cb (EWebView *web_view,
        }
 
        g_clear_object (&attachment);
-       g_clear_object (&view);
 }
 
 static void
@@ -1213,12 +1208,6 @@ mail_display_set_property (GObject *object,
                            GParamSpec *pspec)
 {
        switch (property_id) {
-               case PROP_ATTACHMENT_VIEW:
-                       e_mail_display_set_attachment_view (
-                               E_MAIL_DISPLAY (object),
-                               g_value_get_object (value));
-                       return;
-
                case PROP_HEADERS_COLLAPSABLE:
                        e_mail_display_set_headers_collapsable (
                                E_MAIL_DISPLAY (object),
@@ -1268,9 +1257,9 @@ mail_display_get_property (GObject *object,
                        return;
 
                case PROP_ATTACHMENT_VIEW:
-                       g_value_take_object (
+                       g_value_set_object (
                                value,
-                               e_mail_display_ref_attachment_view (
+                               e_mail_display_get_attachment_view (
                                E_MAIL_DISPLAY (object)));
                        return;
 
@@ -1356,12 +1345,11 @@ mail_display_dispose (GObject *object)
                        G_CALLBACK (mail_display_attachment_removed_cb), object);
        }
 
-       e_mail_display_set_attachment_view (E_MAIL_DISPLAY (object), NULL);
-
        g_clear_object (&priv->part_list);
        g_clear_object (&priv->formatter);
        g_clear_object (&priv->settings);
        g_clear_object (&priv->attachment_store);
+       g_clear_object (&priv->attachment_view);
        g_clear_object (&priv->attachment_inline_group);
 
        /* Chain up to parent's dispose() method. */
@@ -1390,7 +1378,6 @@ mail_display_finalize (GObject *object)
        g_clear_object (&priv->remote_content);
        g_mutex_unlock (&priv->remote_content_lock);
        g_mutex_clear (&priv->remote_content_lock);
-       e_weak_ref_free (priv->attachment_view);
 
        /* Chain up to parent's finalize() method. */
        G_OBJECT_CLASS (e_mail_display_parent_class)->finalize (object);
@@ -1454,6 +1441,8 @@ mail_display_constructed (GObject *object)
 {
        EContentRequest *content_request;
        EWebView *web_view;
+       EMailDisplay *display;
+       GtkUIManager *ui_manager;
 
        e_extensible_load_extensions (E_EXTENSIBLE (object));
 
@@ -1462,6 +1451,7 @@ mail_display_constructed (GObject *object)
 
        mail_display_web_view_initialize (WEBKIT_WEB_VIEW (object));
 
+       display = E_MAIL_DISPLAY (object);
        web_view = E_WEB_VIEW (object);
 
        e_web_view_update_fonts (web_view);
@@ -1478,6 +1468,23 @@ mail_display_constructed (GObject *object)
        content_request = e_cid_request_new ();
        e_web_view_register_content_request_for_scheme (web_view, "cid", content_request);
        g_object_unref (content_request);
+
+       display->priv->attachment_view = g_object_ref_sink (e_attachment_bar_new 
(display->priv->attachment_store));
+
+       ui_manager = e_attachment_view_get_ui_manager (display->priv->attachment_view);
+       if (ui_manager) {
+               GError *error = NULL;
+
+               gtk_ui_manager_insert_action_group (ui_manager, display->priv->attachment_inline_group, -1);
+
+               display->priv->attachment_inline_ui_id = gtk_ui_manager_add_ui_from_string (ui_manager,
+                       attachment_popup_ui, -1, &error);
+
+               if (error) {
+                       g_warning ("%s: Failed to read attachment_popup_ui: %s", G_STRFUNC, error->message);
+                       g_clear_error (&error);
+               }
+       }
 }
 
 static void
@@ -1842,7 +1849,7 @@ e_mail_display_class_init (EMailDisplayClass *class)
                        "Attachment View",
                        NULL,
                        E_TYPE_ATTACHMENT_VIEW,
-                       G_PARAM_READWRITE |
+                       G_PARAM_READABLE |
                        G_PARAM_STATIC_STRINGS));
 
        g_object_class_install_property (
@@ -1920,7 +1927,6 @@ e_mail_display_init (EMailDisplay *display)
        display->priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
 
        display->priv->attachment_store = E_ATTACHMENT_STORE (e_attachment_store_new ());
-       display->priv->attachment_view = e_weak_ref_new (NULL);
        display->priv->attachment_flags = g_hash_table_new (g_direct_hash, g_direct_equal);
        display->priv->attachment_inline_group = gtk_action_group_new ("e-mail-display-attachment-inline");
 
@@ -2085,61 +2091,12 @@ e_mail_display_get_attachment_store (EMailDisplay *display)
        return display->priv->attachment_store;
 }
 
-void
-e_mail_display_set_attachment_view (EMailDisplay *display,
-                                   EAttachmentView *view)
-{
-       EAttachmentView *previous_view;
-
-       g_return_if_fail (E_IS_MAIL_DISPLAY (display));
-       if (view)
-               g_return_if_fail (E_IS_ATTACHMENT_VIEW (view));
-
-       previous_view = g_weak_ref_get (display->priv->attachment_view);
-       if (previous_view) {
-               GtkUIManager *ui_manager;
-
-               ui_manager = e_attachment_view_get_ui_manager (previous_view);
-               if (ui_manager) {
-                       gtk_ui_manager_remove_ui (ui_manager, display->priv->attachment_inline_ui_id);
-                       display->priv->attachment_inline_ui_id = 0;
-
-                       gtk_ui_manager_remove_action_group (ui_manager, 
display->priv->attachment_inline_group);
-               }
-
-               g_clear_object (&previous_view);
-       }
-
-       g_weak_ref_set (display->priv->attachment_view, view);
-
-       if (view) {
-               GtkUIManager *ui_manager;
-
-               ui_manager = e_attachment_view_get_ui_manager (view);
-               if (ui_manager) {
-                       GError *error = NULL;
-
-                       gtk_ui_manager_insert_action_group (ui_manager, 
display->priv->attachment_inline_group, -1);
-
-                       display->priv->attachment_inline_ui_id = gtk_ui_manager_add_ui_from_string 
(ui_manager,
-                               attachment_popup_ui, -1, &error);
-
-                       if (error) {
-                               g_warning ("%s: Failed to read attachment_popup_ui: %s", G_STRFUNC, 
error->message);
-                               g_clear_error (&error);
-                       }
-               }
-       }
-
-       g_object_notify (G_OBJECT (display), "attachment-view");
-}
-
 EAttachmentView *
-e_mail_display_ref_attachment_view (EMailDisplay *display)
+e_mail_display_get_attachment_view (EMailDisplay *display)
 {
        g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), NULL);
 
-       return g_weak_ref_get (display->priv->attachment_view);
+       return display->priv->attachment_view;
 }
 
 EMailFormatterMode
diff --git a/mail/e-mail-display.h b/mail/e-mail-display.h
index a850eab..3670f91 100644
--- a/mail/e-mail-display.h
+++ b/mail/e-mail-display.h
@@ -65,11 +65,8 @@ GtkWidget *  e_mail_display_new              (EMailRemoteContent *remote_content);
 EAttachmentStore *
                e_mail_display_get_attachment_store
                                                (EMailDisplay *display);
-void           e_mail_display_set_attachment_view
-                                               (EMailDisplay *display,
-                                                EAttachmentView *view);
 EAttachmentView *
-               e_mail_display_ref_attachment_view
+               e_mail_display_get_attachment_view
                                                (EMailDisplay *display);
 EMailFormatterMode
                e_mail_display_get_mode         (EMailDisplay *display);
diff --git a/mail/e-mail-paned-view.c b/mail/e-mail-paned-view.c
index 47bc059..cf5635e 100644
--- a/mail/e-mail-paned-view.c
+++ b/mail/e-mail-paned-view.c
@@ -675,7 +675,7 @@ mail_paned_view_constructed (GObject *object)
        EMailView *view;
        GtkWidget *message_list;
        GtkWidget *container;
-       GtkWidget *widget;
+       GtkWidget *widget, *vbox;
 
        priv = E_MAIL_PANED_VIEW_GET_PRIVATE (object);
 
@@ -737,8 +737,13 @@ mail_paned_view_constructed (GObject *object)
 
        container = priv->paned;
 
+       vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
        widget = e_preview_pane_new (E_WEB_VIEW (priv->display));
-       gtk_paned_pack2 (GTK_PANED (container), widget, FALSE, FALSE);
+
+       gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (e_mail_display_get_attachment_view (priv->display)), 
FALSE, FALSE, 0);
+
+       gtk_paned_pack2 (GTK_PANED (container), vbox, FALSE, FALSE);
        priv->preview_pane = g_object_ref (widget);
        gtk_widget_show (GTK_WIDGET (priv->display));
        gtk_widget_show (widget);
@@ -748,6 +753,11 @@ mail_paned_view_constructed (GObject *object)
                widget, "visible",
                G_BINDING_SYNC_CREATE);
 
+       e_binding_bind_property (
+               object, "preview-visible",
+               vbox, "visible",
+               G_BINDING_SYNC_CREATE);
+
        /* Load the view instance. */
 
        e_mail_view_update_view_instance (E_MAIL_VIEW (object));
diff --git a/modules/mail/e-mail-shell-content.c b/modules/mail/e-mail-shell-content.c
index 55a2891..917c6cf 100644
--- a/modules/mail/e-mail-shell-content.c
+++ b/modules/mail/e-mail-shell-content.c
@@ -43,7 +43,6 @@
 
 struct _EMailShellContentPrivate {
        EMailView *mail_view;
-       GtkWidget *attachment_bar; /* not referenced */
 };
 
 enum {
@@ -238,11 +237,7 @@ mail_shell_content_constructed (GObject *object)
 
        display = e_mail_reader_get_mail_display (E_MAIL_READER (object));
        attachment_store = e_mail_display_get_attachment_store (display);
-       widget = e_attachment_bar_new (attachment_store);
-       e_mail_display_set_attachment_view (display, E_ATTACHMENT_VIEW (widget));
-       gtk_box_pack_start (vbox, widget, FALSE, FALSE, 0);
-
-       priv->attachment_bar = widget;
+       widget = GTK_WIDGET (e_mail_display_get_attachment_view (display));
 
        e_binding_bind_property_full (
                attachment_store, "num-attachments",
@@ -555,14 +550,6 @@ e_mail_shell_content_get_mail_view (EMailShellContent *mail_shell_content)
        return mail_shell_content->priv->mail_view;
 }
 
-GtkWidget *
-e_mail_shell_content_get_attachment_bar (EMailShellContent *mail_shell_content)
-{
-       g_return_val_if_fail (E_IS_MAIL_SHELL_CONTENT (mail_shell_content), NULL);
-
-       return mail_shell_content->priv->attachment_bar;
-}
-
 EShellSearchbar *
 e_mail_shell_content_get_searchbar (EMailShellContent *mail_shell_content)
 {
diff --git a/modules/mail/e-mail-shell-content.h b/modules/mail/e-mail-shell-content.h
index f9dce15..db9ef85 100644
--- a/modules/mail/e-mail-shell-content.h
+++ b/modules/mail/e-mail-shell-content.h
@@ -67,8 +67,6 @@ GtkWidget *   e_mail_shell_content_new
                                        (EShellView *shell_view);
 EMailView *    e_mail_shell_content_get_mail_view
                                        (EMailShellContent *mail_shell_content);
-GtkWidget *    e_mail_shell_content_get_attachment_bar
-                                       (EMailShellContent *mail_shell_content);
 EShellSearchbar *
                e_mail_shell_content_get_searchbar
                                        (EMailShellContent *mail_shell_content);
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index 48cefd4..a38686f 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -259,18 +259,22 @@ static void
 action_mail_attachment_bar_cb (GtkAction *action,
                               EMailShellView *mail_shell_view)
 {
-       GtkWidget *attachment_bar;
+       EMailDisplay *mail_display;
+       EAttachmentView *attachment_view;
 
-       attachment_bar = e_mail_shell_content_get_attachment_bar (mail_shell_view->priv->mail_shell_content);
+       g_return_if_fail (E_IS_MAIL_SHELL_VIEW (mail_shell_view));
+
+       mail_display = e_mail_reader_get_mail_display (E_MAIL_READER 
(mail_shell_view->priv->mail_shell_content));
+       attachment_view = e_mail_display_get_attachment_view (mail_display);
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
                EAttachmentStore *store;
                guint num_attachments;
 
-               store = e_attachment_bar_get_store (E_ATTACHMENT_BAR (attachment_bar));
+               store = e_attachment_bar_get_store (E_ATTACHMENT_BAR (attachment_view));
                num_attachments = e_attachment_store_get_num_attachments (store);
-               gtk_widget_set_visible (attachment_bar, num_attachments > 0);
+               gtk_widget_set_visible (GTK_WIDGET (attachment_view), num_attachments > 0);
        } else {
-               gtk_widget_hide (attachment_bar);
+               gtk_widget_hide (GTK_WIDGET (attachment_view));
        }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]