[gnome-photos/wip/rishi/collection: 12/51] selection-toolbar: Explicitly set the visibility of the buttons



commit 5615630cca86a9a86cb5e3b4f21be1ec64c97c33
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Jan 23 12:53:45 2018 +0100

    selection-toolbar: Explicitly set the visibility of the buttons
    
    In order to use SelectionToolbar for importing, it is necessary to hide
    all the buttons that are currently present, and only show the one that
    will trigger the import. Therefore, it will no longer be sufficient to
    only adjust their sensitivity to match the context.
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/29

 src/photos-selection-toolbar.c  | 61 +++++++++++++++++++++++++++++++++++++++++
 src/photos-selection-toolbar.ui | 22 +++++++--------
 2 files changed, 72 insertions(+), 11 deletions(-)
---
diff --git a/src/photos-selection-toolbar.c b/src/photos-selection-toolbar.c
index d9140e48..7851c486 100644
--- a/src/photos-selection-toolbar.c
+++ b/src/photos-selection-toolbar.c
@@ -44,9 +44,16 @@ struct _PhotosSelectionToolbar
   GAction *selection_mode_action;
   GHashTable *item_listeners;
   GtkWidget *toolbar_collection;
+  GtkWidget *toolbar_export;
   GtkWidget *toolbar_favorite;
   GtkWidget *toolbar_open;
+  GtkWidget *toolbar_print;
+  GtkWidget *toolbar_properties;
+  GtkWidget *toolbar_separator;
+  GtkWidget *toolbar_share;
+  GtkWidget *toolbar_trash;
   PhotosBaseManager *item_mngr;
+  PhotosModeController *mode_cntrlr;
   PhotosSelectionController *sel_cntrlr;
   gboolean inside_refresh;
 };
@@ -191,9 +198,19 @@ photos_selection_toolbar_set_item_visibility (PhotosSelectionToolbar *self)
   GList *l;
   GList *selection;
   GtkWidget *image;
+  PhotosWindowMode mode;
   gboolean has_selection;
   gboolean enable_collection;
   gboolean enable_favorite;
+  gboolean show_collection;
+  gboolean show_export;
+  gboolean show_favorite;
+  gboolean show_open;
+  gboolean show_print;
+  gboolean show_properties;
+  gboolean show_separator;
+  gboolean show_share;
+  gboolean show_trash;
   gchar *favorite_label;
   gchar *open_label;
   guint fav_count = 0;
@@ -201,6 +218,33 @@ photos_selection_toolbar_set_item_visibility (PhotosSelectionToolbar *self)
 
   self->inside_refresh = TRUE;
 
+  mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
+  switch (mode)
+    {
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+    case PHOTOS_WINDOW_MODE_SEARCH:
+      show_collection = TRUE;
+      show_export = TRUE;
+      show_favorite = TRUE;
+      show_open = TRUE;
+      show_print = TRUE;
+      show_properties = TRUE;
+      show_separator = TRUE;
+      show_share = TRUE;
+      show_trash = TRUE;
+      break;
+
+    case PHOTOS_WINDOW_MODE_NONE:
+    case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
   selection = photos_selection_controller_get_selection (self->sel_cntrlr);
   has_selection = selection != NULL;
 
@@ -260,6 +304,16 @@ photos_selection_toolbar_set_item_visibility (PhotosSelectionToolbar *self)
   gtk_widget_set_sensitive (self->toolbar_collection, enable_collection);
   gtk_widget_set_sensitive (self->toolbar_favorite, enable_favorite);
 
+  gtk_widget_set_visible (self->toolbar_collection, show_collection);
+  gtk_widget_set_visible (self->toolbar_export, show_export);
+  gtk_widget_set_visible (self->toolbar_favorite, show_favorite);
+  gtk_widget_set_visible (self->toolbar_open, show_open);
+  gtk_widget_set_visible (self->toolbar_print, show_print);
+  gtk_widget_set_visible (self->toolbar_properties, show_properties);
+  gtk_widget_set_visible (self->toolbar_separator, show_separator);
+  gtk_widget_set_visible (self->toolbar_share, show_share);
+  gtk_widget_set_visible (self->toolbar_trash, show_trash);
+
   self->inside_refresh = FALSE;
 }
 
@@ -349,6 +403,7 @@ photos_selection_toolbar_init (PhotosSelectionToolbar *self)
   gtk_widget_init_template (GTK_WIDGET (self));
 
   self->item_mngr = g_object_ref (state->item_mngr);
+  self->mode_cntrlr = g_object_ref (state->mode_cntrlr);
 
   self->sel_cntrlr = photos_selection_controller_dup_singleton ();
   g_signal_connect_object (self->sel_cntrlr,
@@ -375,8 +430,14 @@ photos_selection_toolbar_class_init (PhotosSelectionToolbarClass *class)
   object_class->dispose = photos_selection_toolbar_dispose;
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/selection-toolbar.ui");
+  gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_export);
   gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_favorite);
   gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_open);
+  gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_print);
+  gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_properties);
+  gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_separator);
+  gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_share);
+  gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_trash);
   gtk_widget_class_bind_template_child (widget_class, PhotosSelectionToolbar, toolbar_collection);
   gtk_widget_class_bind_template_callback (widget_class, photos_selection_toolbar_favorite_clicked);
   gtk_widget_class_bind_template_callback (widget_class, photos_selection_toolbar_collection_clicked);
diff --git a/src/photos-selection-toolbar.ui b/src/photos-selection-toolbar.ui
index 9ac16cc3..bb7522a5 100644
--- a/src/photos-selection-toolbar.ui
+++ b/src/photos-selection-toolbar.ui
@@ -5,7 +5,7 @@
     <property name="visible">0</property>
       <child>
         <object class="GtkButton" id="toolbar_favorite">
-          <property name="visible">1</property>
+          <property name="no-show-all">1</property>
           <signal name="clicked" object="PhotosSelectionToolbar" swapped="no"
                   handler="photos_selection_toolbar_favorite_clicked" />
         </object>
@@ -14,10 +14,10 @@
         </packing>
       </child>
       <child>
-        <object class="GtkButton">
-          <property name="visible">1</property>
+        <object class="GtkButton" id="toolbar_export">
           <property name="action_name">app.save-current</property>
           <property name="label" translatable="yes">Export</property>
+          <property name="no-show-all">1</property>
         </object>
         <packing>
           <property name="pack_type">start</property>
@@ -25,8 +25,8 @@
       </child>
       <child>
         <object class="GtkButton" id="toolbar_open">
-          <property name="visible">1</property>
           <property name="label" translatable="yes">Open</property>
+          <property name="no-show-all">1</property>
           <property name="action_name">app.open-current</property>
         </object>
         <packing>
@@ -34,8 +34,8 @@
         </packing>
       </child>
       <child>
-        <object class="GtkSeparator">
-          <property name="visible">1</property>
+        <object class="GtkSeparator" id="toolbar_separator">
+          <property name="no-show-all">1</property>
           <property name="orientation">vertical</property>
         </object>
         <packing>
@@ -44,8 +44,8 @@
       </child>
       <child>
         <object class="GtkButton" id="toolbar_share">
-          <property name="visible">1</property>
           <property name="action_name">app.share-current</property>
+          <property name="no-show-all">1</property>
           <style>
             <class name="image-button"/>
           </style>
@@ -62,8 +62,8 @@
       </child>
       <child>
         <object class="GtkButton" id="toolbar_print">
-          <property name="visible">1</property>
           <property name="action_name">app.print-current</property>
+          <property name="no-show-all">1</property>
           <style>
             <class name="image-button"/>
           </style>
@@ -80,8 +80,8 @@
       </child>
       <child>
         <object class="GtkButton" id="toolbar_trash">
-          <property name="visible">1</property>
           <property name="action_name">app.delete</property>
+          <property name="no-show-all">1</property>
           <style>
             <class name="image-button"/>
           </style>
@@ -98,8 +98,8 @@
       </child>
       <child>
         <object class="GtkButton" id="toolbar_properties">
-          <property name="visible">1</property>
           <property name="label" translatable="yes">Properties</property>
+          <property name="no-show-all">1</property>
           <property name="action_name">app.properties</property>
         </object>
         <packing>
@@ -108,8 +108,8 @@
       </child>
       <child>
         <object class="GtkButton" id="toolbar_collection">
-          <property name="visible">1</property>
           <property name="label" translatable="yes">Add to Album</property>
+          <property name="no-show-all">1</property>
           <signal name="clicked" object="PhotosSelectionToolbar" swapped="no"
                   handler="photos_selection_toolbar_collection_clicked" />
         </object>


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