[gthumb] sidebar: hide the sections that can't handle the current file



commit a2f8e5a9a5465873648a93cf94d29f9f3063a908
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jan 8 22:22:20 2019 +0100

    sidebar: hide the sections that can't handle the current file

 extensions/image_viewer/gth-image-histogram.c | 46 ++++++++-----
 extensions/map_view/gth-map-view.c            | 98 ++++++++++-----------------
 gthumb/gth-file-comment.c                     | 38 ++++++++---
 gthumb/gth-file-properties.c                  | 64 ++++++++++++++---
 gthumb/gth-sidebar-section.c                  | 59 ++++++++++------
 gthumb/gth-sidebar-section.h                  |  2 +-
 gthumb/gth-sidebar.c                          | 57 ++++++++++++++--
 gthumb/gth-sidebar.h                          |  8 ++-
 gthumb/resources/gthumb.css                   |  6 ++
 9 files changed, 250 insertions(+), 128 deletions(-)
---
diff --git a/extensions/image_viewer/gth-image-histogram.c b/extensions/image_viewer/gth-image-histogram.c
index 79930346..ffa99c7f 100644
--- a/extensions/image_viewer/gth-image-histogram.c
+++ b/extensions/image_viewer/gth-image-histogram.c
@@ -48,30 +48,43 @@ G_DEFINE_TYPE_WITH_CODE (GthImageHistogram,
                                                gth_image_histogram_gth_property_view_interface_init))
 
 
-static gboolean
-gth_image_histogram_real_set_file (GthPropertyView *base,
-                                  GthFileData     *file_data)
+static cairo_surface_t *
+gth_image_histogram_get_current_image (GthImageHistogram *self)
 {
-       GthImageHistogram *self = GTH_IMAGE_HISTOGRAM (base);
-       GthBrowser        *browser;
-       GthViewerPage     *viewer_page;
-
-       if (file_data == NULL) {
-               gth_histogram_calculate_for_image (self->priv->histogram, NULL);
-               return FALSE;
-       }
+       GthBrowser    *browser;
+       GthViewerPage *viewer_page;
 
-       browser = (GthBrowser *) gtk_widget_get_toplevel (GTK_WIDGET (base));
+       browser = (GthBrowser *) gtk_widget_get_toplevel (GTK_WIDGET (self));
        if (! gtk_widget_is_toplevel (GTK_WIDGET (browser)))
-               return FALSE;
+               return NULL;
 
        viewer_page = gth_browser_get_viewer_page (browser);
        if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
-               return FALSE;
+               return NULL;
 
-       gth_histogram_calculate_for_image (self->priv->histogram, gth_image_viewer_page_get_current_image 
(GTH_IMAGE_VIEWER_PAGE (viewer_page)));
+       return gth_image_viewer_page_get_current_image (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+}
+
+
+static gboolean
+gth_image_histogram_real_can_view (GthPropertyView *base,
+                                 GthFileData     *file_data)
+{
+       GthImageHistogram *self = GTH_IMAGE_HISTOGRAM (base);
+       return gth_image_histogram_get_current_image (self) != NULL;
+}
+
+
+static void
+gth_image_histogram_real_set_file (GthPropertyView *base,
+                                  GthFileData     *file_data)
+{
+       GthImageHistogram *self = GTH_IMAGE_HISTOGRAM (base);
+       cairo_surface_t   *image;
 
-       return TRUE;
+       image = gth_image_histogram_get_current_image (self);
+       if (image != NULL)
+               gth_histogram_calculate_for_image (self->priv->histogram, image);
 }
 
 
@@ -111,6 +124,7 @@ gth_image_histogram_gth_property_view_interface_init (GthPropertyViewInterface *
 {
        iface->get_name = gth_image_histogram_real_get_name;
        iface->get_icon = gth_image_histogram_real_get_icon;
+       iface->can_view = gth_image_histogram_real_can_view;
        iface->set_file = gth_image_histogram_real_set_file;
 }
 
diff --git a/extensions/map_view/gth-map-view.c b/extensions/map_view/gth-map-view.c
index a9b3f4c2..e37291c8 100644
--- a/extensions/map_view/gth-map-view.c
+++ b/extensions/map_view/gth-map-view.c
@@ -28,14 +28,14 @@
 #include <gthumb.h>
 #include "gth-map-view.h"
 
-#define LABEL_MAX_WIDTH 200
+
+#define MAP_HEIGHT 300
 
 
 static void gth_map_view_gth_property_view_interface_init (GthPropertyViewInterface *iface);
 
 
 struct _GthMapViewPrivate {
-       GtkWidget            *no_gps_label;
        GtkWidget            *embed;
        ChamplainView        *map_view;
        ChamplainMarkerLayer *marker_layer;
@@ -136,11 +136,12 @@ decimal_coordinates_to_string (double latitude,
 }
 
 
-static gboolean
-gth_map_view_real_set_file (GthPropertyView *base,
-                           GthFileData     *file_data)
+static int
+gth_map_view_get_coordinates (GthMapView  *self,
+                             GthFileData *file_data,
+                             double      *out_latitude,
+                             double      *out_longitude)
 {
-       GthMapView *self = GTH_MAP_VIEW (base);
        int         coordinates_available;
        double      latitude;
        double      longitude;
@@ -177,12 +178,37 @@ gth_map_view_real_set_file (GthPropertyView *base,
                }
        }
 
+       if (out_latitude != NULL)
+               *out_latitude = latitude;
+       if (out_longitude != NULL)
+               *out_longitude = longitude;
+
+       return coordinates_available;
+}
+
+
+static gboolean
+gth_map_view_real_can_view (GthPropertyView *base,
+                          GthFileData     *file_data)
+{
+       GthMapView *self = GTH_MAP_VIEW (base);
+       return gth_map_view_get_coordinates (self, file_data, NULL, NULL) == 2;
+}
+
+
+static void
+gth_map_view_real_set_file (GthPropertyView *base,
+                           GthFileData     *file_data)
+{
+       GthMapView *self = GTH_MAP_VIEW (base);
+       int         coordinates_available;
+       double      latitude;
+       double      longitude;
+
+       coordinates_available = gth_map_view_get_coordinates (self, file_data, &latitude, &longitude);
        if (coordinates_available == 2) {
                char *position;
 
-               gtk_widget_hide (self->priv->no_gps_label);
-               gtk_widget_show (self->priv->embed);
-
                position = decimal_coordinates_to_string (latitude, longitude);
                champlain_label_set_text (CHAMPLAIN_LABEL (self->priv->marker), position);
                g_free (position);
@@ -190,12 +216,6 @@ gth_map_view_real_set_file (GthPropertyView *base,
                champlain_location_set_location (CHAMPLAIN_LOCATION (self->priv->marker), latitude, 
longitude);
                champlain_view_center_on (CHAMPLAIN_VIEW (self->priv->map_view), latitude, longitude);
        }
-       else {
-               gtk_widget_hide (self->priv->embed);
-               gtk_widget_show (self->priv->no_gps_label);
-       }
-
-       return (coordinates_available == 2);
 }
 
 
@@ -220,41 +240,10 @@ gth_map_view_finalize (GObject *base)
 }
 
 
-static void
-gth_map_view_realize (GtkWidget *widget)
-{
-       GthMapView *self;
-
-       self = GTH_MAP_VIEW (widget);
-
-       GTK_WIDGET_CLASS (gth_map_view_parent_class)->realize (widget);
-       if (! gtk_widget_get_visible (self->priv->no_gps_label))
-               gtk_widget_show (self->priv->embed);
-}
-
-
-static void
-gth_map_view_unrealize (GtkWidget *widget)
-{
-       GthMapView *self;
-
-       self = GTH_MAP_VIEW (widget);
-
-       GTK_WIDGET_CLASS (gth_map_view_parent_class)->unrealize (widget);
-       gtk_widget_hide (self->priv->embed);
-}
-
-
 static void
 gth_map_view_class_init (GthMapViewClass *klass)
 {
-       GtkWidgetClass *widget_class;
-
        G_OBJECT_CLASS (klass)->finalize = gth_map_view_finalize;
-
-       widget_class = GTK_WIDGET_CLASS (klass);
-       widget_class->realize = gth_map_view_realize;
-       widget_class->unrealize = gth_map_view_unrealize;
 }
 
 
@@ -269,22 +258,10 @@ gth_map_view_init (GthMapView *self)
        gtk_container_set_border_width (GTK_CONTAINER (self), 2);
        gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
 
-       /* No GPS label */
-
-       self->priv->no_gps_label = gtk_label_new (_("The geographical position information is not available 
for this image."));
-       g_object_set (G_OBJECT (self->priv->no_gps_label),
-                     "wrap", TRUE,
-                     "wrap-mode", PANGO_WRAP_WORD_CHAR,
-                     "single-line-mode", FALSE,
-                     "justify", GTK_JUSTIFY_CENTER,
-                     "width-request", LABEL_MAX_WIDTH,
-                     NULL);
-       gtk_widget_show (self->priv->no_gps_label);
-       gtk_box_pack_start (GTK_BOX (self), self->priv->no_gps_label, TRUE, TRUE, 0);
-
        /* The map widget */
 
        self->priv->embed = gtk_champlain_embed_new ();
+       gtk_widget_set_size_request (self->priv->embed, -1, MAP_HEIGHT);
 
        self->priv->map_view = gtk_champlain_embed_get_view (GTK_CHAMPLAIN_EMBED (self->priv->embed));
        g_object_set (G_OBJECT (self->priv->map_view),
@@ -302,7 +279,6 @@ gth_map_view_init (GthMapView *self)
        champlain_scale_connect_view (CHAMPLAIN_SCALE (scale), self->priv->map_view);
        clutter_actor_add_child (CLUTTER_ACTOR (self->priv->map_view), scale);
 
-
        self->priv->marker_layer = champlain_marker_layer_new ();
        champlain_view_add_layer (self->priv->map_view, CHAMPLAIN_LAYER (self->priv->marker_layer));
        clutter_actor_show (CLUTTER_ACTOR (self->priv->marker_layer));
@@ -312,7 +288,6 @@ gth_map_view_init (GthMapView *self)
        champlain_marker_layer_add_marker (self->priv->marker_layer, CHAMPLAIN_MARKER (self->priv->marker));
 
        gtk_widget_show_all (self->priv->embed);
-       gtk_widget_hide (self->priv->embed);
 
        gtk_box_pack_start (GTK_BOX (self), self->priv->embed, TRUE, TRUE, 0);
 }
@@ -323,5 +298,6 @@ gth_map_view_gth_property_view_interface_init (GthPropertyViewInterface *iface)
 {
        iface->get_name = gth_map_view_real_get_name;
        iface->get_icon = gth_map_view_real_get_icon;
+       iface->can_view = gth_map_view_real_can_view;
        iface->set_file = gth_map_view_real_set_file;
 }
diff --git a/gthumb/gth-file-comment.c b/gthumb/gth-file-comment.c
index 0dc32c2c..e19df246 100644
--- a/gthumb/gth-file-comment.c
+++ b/gthumb/gth-file-comment.c
@@ -48,6 +48,28 @@ G_DEFINE_TYPE_WITH_CODE (GthFileComment,
                                                gth_file_comment_gth_property_view_interface_init))
 
 
+static gboolean
+gth_file_comment_real_can_view (GthPropertyView *base,
+                               GthFileData     *file_data)
+{
+       GthMetadata *value;
+       gboolean     value_available = FALSE;
+
+       if (file_data == NULL)
+               return FALSE;
+
+       value_available = FALSE;
+       value = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::description");
+       if (value != NULL) {
+               const char *formatted = gth_metadata_get_formatted (value);
+               if ((formatted != NULL) && (*formatted != '\0'))
+                       value_available = TRUE;
+       }
+
+       return value_available;
+}
+
+
 static char *
 get_comment (GthFileData *file_data)
 {
@@ -72,7 +94,7 @@ get_comment (GthFileData *file_data)
 }
 
 
-static gboolean
+static void
 gth_file_comment_real_set_file (GthPropertyView *base,
                                   GthFileData     *file_data)
 {
@@ -87,10 +109,8 @@ gth_file_comment_real_set_file (GthPropertyView *base,
                self->priv->last_file_data = gth_file_data_dup (file_data);
        }
 
-       if (file_data == NULL) {
-               gtk_widget_hide (self->priv->comment_win);
-               return FALSE;
-       }
+       if (file_data == NULL)
+               return;
 
        text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->priv->comment_view));
        comment = get_comment (file_data);
@@ -105,14 +125,8 @@ gth_file_comment_real_set_file (GthPropertyView *base,
                vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->priv->comment_win));
                gtk_adjustment_set_value (vadj, 0.0);
 
-               gtk_widget_show (self->priv->comment_win);
-
                g_free (comment);
        }
-       else
-               gtk_widget_hide (self->priv->comment_win);
-
-       return (comment != NULL);
 }
 
 
@@ -167,6 +181,7 @@ gth_file_comment_init (GthFileComment *self)
        //gtk_widget_set_size_request (self->priv->comment_win, -1, COMMENT_DEFAULT_HEIGHT);
        gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->comment_win), 
GTH_STYLE_CLASS_COMMENT);
        gtk_box_pack_start (GTK_BOX (self), self->priv->comment_win, TRUE, TRUE, 0);
+       gtk_widget_show (self->priv->comment_win);
 
        self->priv->comment_view = gtk_text_view_new ();
        gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->comment_view), 
GTH_STYLE_CLASS_COMMENT);
@@ -184,5 +199,6 @@ gth_file_comment_gth_property_view_interface_init (GthPropertyViewInterface *ifa
 {
        iface->get_name = gth_file_comment_real_get_name;
        iface->get_icon = gth_file_comment_real_get_icon;
+       iface->can_view = gth_file_comment_real_can_view;
        iface->set_file = gth_file_comment_real_set_file;
 }
diff --git a/gthumb/gth-file-properties.c b/gthumb/gth-file-properties.c
index bba658f9..c65d5a0d 100644
--- a/gthumb/gth-file-properties.c
+++ b/gthumb/gth-file-properties.c
@@ -78,11 +78,60 @@ G_DEFINE_TYPE_WITH_CODE (GthFileProperties,
 
 
 static gboolean
+gth_file_properties_real_can_view (GthPropertyView *base,
+                                  GthFileData     *file_data)
+{
+       GthFileProperties *self = GTH_FILE_PROPERTIES (base);
+       gboolean           data_available;
+       GList             *metadata_info;
+       GList             *scan;
+
+       if (file_data == NULL)
+               return FALSE;
+
+       if (! self->priv->show_details)
+               return TRUE;
+
+       data_available = FALSE;
+       metadata_info = gth_main_get_all_metadata_info ();
+       for (scan = metadata_info; scan; scan = scan->next) {
+               GthMetadataInfo *info = scan->data;
+               char            *value;
+
+               if ((info->flags & GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW) != 
GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW)
+                       continue;
+
+               value = gth_file_data_get_attribute_as_string (file_data, info->id);
+               if ((value == NULL) || (*value == '\0')) {
+                       g_free (value);
+                       continue;
+               }
+
+               if (info->id != NULL) {
+                       if (g_str_has_prefix (info->id, "Exif")) {
+                               data_available = TRUE;
+                               break;
+                       }
+                       else if (g_str_has_prefix (info->id, "Iptc")) {
+                               data_available = TRUE;
+                               break;
+                       }
+                       else if (g_str_has_prefix (info->id, "Xmp")) {
+                               data_available = TRUE;
+                               break;
+                       }
+               }
+       }
+
+       return data_available;
+}
+
+
+static void
 gth_file_properties_real_set_file (GthPropertyView *base,
                                   GthFileData     *file_data)
 {
        GthFileProperties *self;
-       gboolean           data_available;
        GHashTable        *category_hash;
        GList             *metadata_info;
        GList             *scan;
@@ -96,14 +145,11 @@ gth_file_properties_real_set_file (GthPropertyView *base,
 
        gtk_list_store_clear (self->priv->tree_model);
 
-       if (file_data == NULL) {
-               gtk_widget_hide (self->priv->main_container);
-               return FALSE;
-       }
+       if (file_data == NULL)
+               return;
 
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->priv->tree_model), 
GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, 0);
 
-       data_available = FALSE;
        category_hash = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
        metadata_info = gth_main_get_all_metadata_info ();
        for (scan = metadata_info; scan; scan = scan->next) {
@@ -183,18 +229,13 @@ gth_file_properties_real_set_file (GthPropertyView *base,
 
                g_free (tooltip);
                g_free (value);
-
-               data_available = TRUE;
        }
        g_list_free (metadata_info);
 
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->priv->tree_model), POS_COLUMN, 
GTK_SORT_ASCENDING);
        gtk_tree_view_expand_all (GTK_TREE_VIEW (self->priv->tree_view));
-       gtk_widget_set_visible (self->priv->main_container, data_available);
 
        g_hash_table_destroy (category_hash);
-
-       return data_available;
 }
 
 
@@ -459,5 +500,6 @@ gth_file_properties_gth_property_view_interface_init (GthPropertyViewInterface *
 {
        iface->get_name = gth_file_properties_real_get_name;
        iface->get_icon = gth_file_properties_real_get_icon;
+       iface->can_view = gth_file_properties_real_can_view;
        iface->set_file = gth_file_properties_real_set_file;
 }
diff --git a/gthumb/gth-sidebar-section.c b/gthumb/gth-sidebar-section.c
index 21bfa2d6..3ad0bfd1 100644
--- a/gthumb/gth-sidebar-section.c
+++ b/gthumb/gth-sidebar-section.c
@@ -27,11 +27,8 @@
 #include "gtk-utils.h"
 
 
-#define MIN_SECTION_WIDTH 365
-
-
 struct _GthSidebarSectionPrivate {
-       GtkWidget       *container;
+       GtkWidget       *void_view;
        GtkWidget       *expander;
        GthPropertyView *view;
        GthFileData     *file_data;
@@ -69,7 +66,7 @@ static void
 gth_sidebar_section_init (GthSidebarSection *self)
 {
        self->priv = gth_sidebar_section_get_instance_private (self);
-       self->priv->container = NULL;
+       self->priv->void_view = NULL;
        self->priv->expander = NULL;
        self->priv->view = NULL;
        self->priv->dirty = FALSE;
@@ -79,11 +76,7 @@ gth_sidebar_section_init (GthSidebarSection *self)
 static void
 _gth_sidebar_section_update_view (GthSidebarSection *self)
 {
-       gboolean success;
-
-       success = gth_property_view_set_file (self->priv->view, self->priv->file_data);
-       gtk_widget_set_visible (GTK_WIDGET (self->priv->view), success);
-       gtk_widget_set_sensitive (self->priv->expander, success);
+       gth_property_view_set_file (self->priv->view, self->priv->file_data);
        self->priv->dirty = FALSE;
 }
 
@@ -108,14 +101,13 @@ _gth_sidebar_section_add_view (GthSidebarSection *self,
 {
        GtkWidget *exp;
        GtkWidget *exp_label;
+       GtkWidget *exp_content;
        GtkWidget *icon;
        GtkWidget *label;
 
-       gtk_widget_set_size_request (GTK_WIDGET (self), MIN_SECTION_WIDTH, -1);
-
        self->priv->view = view;
-       _gtk_widget_set_margin (GTK_WIDGET (view), 3, 2, 3, 2);
-       gtk_widget_hide (GTK_WIDGET (view));
+       _gtk_widget_set_margin (GTK_WIDGET (view), 1, 2, 1, 2);
+       gtk_widget_show (GTK_WIDGET (view));
 
        self->priv->expander = exp = gtk_expander_new (NULL);
        exp_label = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
@@ -128,10 +120,27 @@ _gth_sidebar_section_add_view (GthSidebarSection *self,
        gtk_widget_show_all (exp_label);
        gtk_expander_set_label_widget (GTK_EXPANDER (exp), exp_label);
 
+       self->priv->void_view = gtk_frame_new (NULL);
+       gtk_frame_set_shadow_type (GTK_FRAME (self->priv->void_view), GTK_SHADOW_IN);
+       gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->void_view), 
GTK_STYLE_CLASS_VIEW);
+       _gtk_widget_set_margin (self->priv->void_view, 0, 2, 0, 2);
+       gtk_widget_hide (self->priv->void_view);
+
+       icon = gtk_image_new_from_icon_name ("action-unavailable-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR);
+       gtk_widget_set_sensitive (icon, FALSE);
+       _gtk_widget_set_margin (icon, 10, 0, 10, 0);
+       gtk_style_context_add_class (gtk_widget_get_style_context (icon), "void-view");
+       gtk_widget_show (icon);
+       gtk_container_add (GTK_CONTAINER (self->priv->void_view), icon);
+
+       exp_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+       gtk_box_pack_start (GTK_BOX (exp_content), GTK_WIDGET (view), FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (exp_content), self->priv->void_view, FALSE, FALSE, 0);
+       gtk_widget_show (exp_content);
+
        gtk_expander_set_expanded (GTK_EXPANDER (exp), TRUE);
-       gtk_container_add (GTK_CONTAINER (exp), GTK_WIDGET (view));
+       gtk_container_add (GTK_CONTAINER (exp), exp_content);
        gtk_widget_show (exp);
-
        gtk_box_pack_start (GTK_BOX (self), exp, FALSE, FALSE, 0);
 
        g_signal_connect (exp,
@@ -148,6 +157,7 @@ gth_sidebar_section_new (GthPropertyView *view)
 
        sidebar = g_object_new (GTH_TYPE_SIDEBAR_SECTION,
                                "orientation", GTK_ORIENTATION_VERTICAL,
+                               "vexpand", FALSE,
                                NULL);
        _gth_sidebar_section_add_view (sidebar, view);
 
@@ -162,21 +172,28 @@ _gth_sidebar_section_visible (GthSidebarSection *self)
 }
 
 
-void
+gboolean
 gth_sidebar_section_set_file (GthSidebarSection  *self,
                              GthFileData        *file_data)
 {
+       gboolean can_view;
+
        _g_object_unref (self->priv->file_data);
        self->priv->file_data = NULL;
        if (file_data != NULL)
                self->priv->file_data = _g_object_ref (file_data);
 
-       if (! _gth_sidebar_section_visible (self)) {
+       can_view = (self->priv->file_data != NULL) && gth_property_view_can_view (self->priv->view, 
self->priv->file_data);
+       gtk_widget_set_visible (GTK_WIDGET (self), can_view);
+
+       if (! can_view)
+               self->priv->dirty = FALSE;
+       else if (! _gth_sidebar_section_visible (self))
                self->priv->dirty = TRUE;
-               return;
-       }
+       else
+               _gth_sidebar_section_update_view (self);
 
-       _gth_sidebar_section_update_view (self);
+       return can_view;
 }
 
 
diff --git a/gthumb/gth-sidebar-section.h b/gthumb/gth-sidebar-section.h
index 938b26de..396c6f75 100644
--- a/gthumb/gth-sidebar-section.h
+++ b/gthumb/gth-sidebar-section.h
@@ -50,7 +50,7 @@ struct _GthSidebarSectionClass {
 
 GType          gth_sidebar_section_get_type    (void);
 GtkWidget *    gth_sidebar_section_new         (GthPropertyView        *view);
-void           gth_sidebar_section_set_file    (GthSidebarSection      *section,
+gboolean       gth_sidebar_section_set_file    (GthSidebarSection      *section,
                                                 GthFileData            *file_data);
 void           gth_sidebar_section_set_expanded(GthSidebarSection      *section,
                                                 gboolean                expanded);
diff --git a/gthumb/gth-sidebar.c b/gthumb/gth-sidebar.c
index 192daf0d..68f26033 100644
--- a/gthumb/gth-sidebar.c
+++ b/gthumb/gth-sidebar.c
@@ -31,13 +31,17 @@
 
 #define GTH_SIDEBAR_PAGE_PROPERTIES "GthSidebar.Properties"
 #define GTH_SIDEBAR_PAGE_TOOLS "GthSidebar.Tools"
+#define GTH_SIDEBAR_PAGE_EMPTY "GthSidebar.Empty"
+#define MIN_SIDEBAR_WIDTH 365
 
 
 struct _GthSidebarPrivate {
        GtkWidget   *properties;
        GtkWidget   *toolbox;
        GthFileData *file_data;
+       const char  *selected_page;
        GList       *sections;
+       int          n_visibles;
 };
 
 
@@ -74,6 +78,8 @@ gth_sidebar_init (GthSidebar *sidebar)
        sidebar->priv = gth_sidebar_get_instance_private (sidebar);
        sidebar->priv->file_data = NULL;
        sidebar->priv->sections = NULL;
+       sidebar->priv->selected_page = GTH_SIDEBAR_PAGE_EMPTY;
+       sidebar->priv->n_visibles = 0;
 }
 
 
@@ -165,7 +171,6 @@ _gth_sidebar_add_sections (GthSidebar  *sidebar,
                if (status != NULL) {
                        gth_sidebar_section_set_expanded (GTH_SIDEBAR_SECTION (section), status->expanded);
                }
-               gtk_widget_show (section);
 
                sidebar->priv->sections = g_list_prepend (sidebar->priv->sections, section);
                gtk_box_pack_start (GTK_BOX (sidebar->priv->properties),
@@ -184,6 +189,8 @@ static void
 _gth_sidebar_construct (GthSidebar *sidebar)
 {
        GtkWidget *properties_win;
+       GtkWidget *empty_view;
+       GtkWidget *icon;
 
        properties_win = gtk_scrolled_window_new (NULL, NULL);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (properties_win), GTK_POLICY_NEVER, 
GTK_POLICY_AUTOMATIC);
@@ -193,14 +200,25 @@ _gth_sidebar_construct (GthSidebar *sidebar)
        gtk_stack_add_named (GTK_STACK (sidebar), properties_win, GTH_SIDEBAR_PAGE_PROPERTIES);
 
        sidebar->priv->properties = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+       gtk_widget_set_size_request (GTK_WIDGET (sidebar->priv->properties), MIN_SIDEBAR_WIDTH, -1);
        gtk_widget_show (sidebar->priv->properties);
        gtk_container_add (GTK_CONTAINER (properties_win), sidebar->priv->properties);
 
        sidebar->priv->toolbox = gth_toolbox_new ("file-tools");
        gtk_style_context_add_class (gtk_widget_get_style_context (sidebar->priv->toolbox), 
GTK_STYLE_CLASS_SIDEBAR);
        gtk_widget_set_vexpand (sidebar->priv->toolbox, TRUE);
+       gtk_widget_set_size_request (GTK_WIDGET (sidebar->priv->toolbox), MIN_SIDEBAR_WIDTH, -1);
        gtk_widget_show (sidebar->priv->toolbox);
        gtk_stack_add_named (GTK_STACK (sidebar), sidebar->priv->toolbox, GTH_SIDEBAR_PAGE_TOOLS);
+
+       empty_view = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+       gtk_widget_show (empty_view);
+       gtk_stack_add_named (GTK_STACK (sidebar), empty_view, GTH_SIDEBAR_PAGE_EMPTY);
+
+       icon = gtk_image_new_from_icon_name("action-unavailable-symbolic", GTK_ICON_SIZE_DIALOG);
+       gtk_style_context_add_class (gtk_widget_get_style_context (icon), "void-view");
+       gtk_widget_show (icon);
+       gtk_box_pack_start (GTK_BOX (empty_view), icon, TRUE, FALSE, 0);
 }
 
 
@@ -224,6 +242,12 @@ gth_sidebar_get_toolbox (GthSidebar *sidebar)
 }
 
 
+static void
+_gth_sidebar_update_view (GthSidebar  *sidebar)
+{
+       gtk_stack_set_visible_child_name (GTK_STACK (sidebar), (sidebar->priv->n_visibles == 0) ? 
GTH_SIDEBAR_PAGE_EMPTY : sidebar->priv->selected_page);
+}
+
 void
 gth_sidebar_set_file (GthSidebar  *sidebar,
                      GthFileData *file_data)
@@ -236,24 +260,39 @@ gth_sidebar_set_file (GthSidebar  *sidebar,
        _g_object_unref (sidebar->priv->file_data);
        sidebar->priv->file_data = gth_file_data_dup (file_data);
 
+       sidebar->priv->n_visibles = 0;
        for (scan = sidebar->priv->sections; scan; scan = scan->next) {
                GtkWidget *child = scan->data;
-               gth_sidebar_section_set_file (GTH_SIDEBAR_SECTION (child), sidebar->priv->file_data);
+               if (gth_sidebar_section_set_file (GTH_SIDEBAR_SECTION (child), sidebar->priv->file_data))
+                       sidebar->priv->n_visibles++;
        }
+
+       _gth_sidebar_update_view (sidebar);
+}
+
+
+static void
+_gth_sidebar_set_visible_page (GthSidebar *sidebar,
+                              const char *page)
+{
+       sidebar->priv->selected_page = page;
+       gtk_stack_set_visible_child_name (GTK_STACK (sidebar), sidebar->priv->selected_page);
+
+       _gth_sidebar_update_view (sidebar);
 }
 
 
 void
 gth_sidebar_show_properties (GthSidebar *sidebar)
 {
-       gtk_stack_set_visible_child_name (GTK_STACK (sidebar), GTH_SIDEBAR_PAGE_PROPERTIES);
+       _gth_sidebar_set_visible_page (sidebar, GTH_SIDEBAR_PAGE_PROPERTIES);
 }
 
 
 void
 gth_sidebar_show_tools (GthSidebar *sidebar)
 {
-       gtk_stack_set_visible_child_name (GTK_STACK (sidebar), GTH_SIDEBAR_PAGE_TOOLS);
+       _gth_sidebar_set_visible_page (sidebar, GTH_SIDEBAR_PAGE_TOOLS);
 }
 
 
@@ -335,8 +374,16 @@ gth_property_view_get_icon (GthPropertyView *self)
 
 
 gboolean
+gth_property_view_can_view (GthPropertyView *self,
+                                   GthFileData     *file_data)
+{
+       return GTH_PROPERTY_VIEW_GET_INTERFACE (self)->can_view (self, file_data);
+}
+
+
+void
 gth_property_view_set_file (GthPropertyView *self,
                            GthFileData     *file_data)
 {
-       return GTH_PROPERTY_VIEW_GET_INTERFACE (self)->set_file (self, file_data);
+       GTH_PROPERTY_VIEW_GET_INTERFACE (self)->set_file (self, file_data);
 }
diff --git a/gthumb/gth-sidebar.h b/gthumb/gth-sidebar.h
index 8a63e613..d7733673 100644
--- a/gthumb/gth-sidebar.h
+++ b/gthumb/gth-sidebar.h
@@ -65,7 +65,9 @@ struct _GthPropertyViewInterface {
        GTypeInterface parent_iface;
        const char *    (*get_name)     (GthPropertyView *self);
        const char *    (*get_icon)     (GthPropertyView *self);
-       gboolean        (*set_file)     (GthPropertyView *self,
+       gboolean        (*can_view)     (GthPropertyView *self,
+                                        GthFileData     *file_data);
+       void            (*set_file)     (GthPropertyView *self,
                                         GthFileData     *file_data);
 };
 
@@ -84,7 +86,9 @@ char **        gth_sidebar_get_sections_status (GthSidebar      *sidebar);
 GType          gth_property_view_get_type      (void);
 const char *   gth_property_view_get_name      (GthPropertyView *self);
 const char *   gth_property_view_get_icon      (GthPropertyView *self);
-gboolean       gth_property_view_set_file      (GthPropertyView *self,
+gboolean       gth_property_view_can_view      (GthPropertyView *self,
+                                               GthFileData     *file_data);
+void           gth_property_view_set_file      (GthPropertyView *self,
                                                GthFileData     *file_data);
 
 G_END_DECLS
diff --git a/gthumb/resources/gthumb.css b/gthumb/resources/gthumb.css
index a7d569d8..4294fe32 100644
--- a/gthumb/resources/gthumb.css
+++ b/gthumb/resources/gthumb.css
@@ -162,3 +162,9 @@ GthToolbox .header-bar,
        border-radius: 20px;
        -gtk-outline-radius: 20px;
 }
+
+/* --  void sibebar section-- */
+
+.void-view {
+       opacity: 0.12;
+}


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