[gnome-photos] main-toolbar: Add a Select All / Select None menu



commit 05707dd276fac1b7d0c2c03fc746332171ead066
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Mar 24 00:01:50 2013 +0100

    main-toolbar: Add a Select All / Select None menu
    
    Original patch from Cosimo Cecchi for gnome-documents.

 src/Makefile.am              |    1 +
 src/photos-application.c     |   30 +++++++++++++++++++++++++++++-
 src/photos-main-toolbar.c    |   10 ++++++++++
 src/photos-selection-menu.ui |   15 +++++++++++++++
 src/photos-view-container.c  |   15 ++++++++++++++-
 src/photos.gresource.xml     |    1 +
 6 files changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index aef6cc3..e197dfa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -152,6 +152,7 @@ EXTRA_DIST = \
        photos.gresource.xml \
        photos-app-menu.ui \
        photos-marshalers.list \
+       photos-selection-menu.ui \
        photos-tracker-resources.xml \
        $(null)
 
diff --git a/src/photos-application.c b/src/photos-application.c
index 9e01c36..76a462a 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -41,6 +41,8 @@ struct _PhotosApplicationPrivate
 {
   GResource *resource;
   GSimpleAction *fs_action;
+  GSimpleAction *sel_all_action;
+  GSimpleAction *sel_none_action;
   GtkWidget *main_window;
   PhotosModeController *mode_cntrlr;
 };
@@ -82,6 +84,18 @@ photos_application_quit (GSimpleAction *simple, GVariant *parameter, gpointer us
 
 
 static void
+photos_application_window_mode_changed (PhotosApplication *self, PhotosWindowMode mode, PhotosWindowMode 
old_mode)
+{
+  PhotosApplicationPrivate *priv = self->priv;
+  gboolean enable;
+
+  enable = (mode == PHOTOS_WINDOW_MODE_OVERVIEW || mode == PHOTOS_WINDOW_MODE_FAVORITES);
+  g_simple_action_set_enabled (priv->sel_all_action, enable);
+  g_simple_action_set_enabled (priv->sel_none_action, enable);
+}
+
+
+static void
 photos_application_activate (GApplication *application)
 {
   PhotosApplication *self = PHOTOS_APPLICATION (application);
@@ -112,7 +126,6 @@ photos_application_startup (GApplication *application)
   settings = gtk_settings_get_default ();
   g_object_set (settings, "gtk-application-prefer-dark-theme", TRUE, NULL);
 
-  priv->main_window = photos_main_window_new (GTK_APPLICATION (self));
   priv->mode_cntrlr = photos_mode_controller_new ();
 
   action = g_simple_action_new ("about", NULL);
@@ -134,6 +147,17 @@ photos_application_startup (GApplication *application)
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
   g_object_unref (action);
 
+  priv->sel_all_action = g_simple_action_new ("select-all", NULL);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->sel_all_action));
+
+  priv->sel_none_action = g_simple_action_new ("select-none", NULL);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->sel_none_action));
+
+  g_signal_connect_swapped (priv->mode_cntrlr,
+                            "window-mode-changed",
+                            G_CALLBACK (photos_application_window_mode_changed),
+                            self);
+
   builder = gtk_builder_new ();
   gtk_builder_add_from_resource (builder, "/org/gnome/photos/app-menu.ui", NULL);
 
@@ -143,7 +167,9 @@ photos_application_startup (GApplication *application)
 
   gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>q", "app.quit", NULL);
   gtk_application_add_accelerator (GTK_APPLICATION (self), "F11", "app.fullscreen", NULL);
+  gtk_application_add_accelerator (GTK_APPLICATION (self), "<Primary>a", "app.select-all", NULL);
 
+  priv->main_window = photos_main_window_new (GTK_APPLICATION (self));
   photos_mode_controller_set_window_mode (priv->mode_cntrlr, PHOTOS_WINDOW_MODE_OVERVIEW);
 }
 
@@ -180,6 +206,8 @@ photos_application_dispose (GObject *object)
     }
 
   g_clear_object (&priv->fs_action);
+  g_clear_object (&priv->sel_all_action);
+  g_clear_object (&priv->sel_none_action);
   g_clear_object (&priv->mode_cntrlr);
 
   G_OBJECT_CLASS (photos_application_parent_class)
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 21527ef..874676f 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -240,6 +240,7 @@ photos_main_toolbar_clear_toolbar (PhotosMainToolbar *self)
   PhotosMainToolbarPrivate *priv = self->priv;
   GtkStyleContext *context;
 
+  gd_main_toolbar_set_labels_menu (GD_MAIN_TOOLBAR (priv->toolbar), NULL);
   photos_main_toolbar_clear_state_data (self);
   context = gtk_widget_get_style_context (priv->toolbar);
   gtk_style_context_remove_class (context, "selection-mode");
@@ -337,6 +338,8 @@ static void
 photos_main_toolbar_populate_for_selection_mode (PhotosMainToolbar *self)
 {
   PhotosMainToolbarPrivate *priv = self->priv;
+  GMenu *selection_menu;
+  GtkBuilder *builder;
   GtkStyleContext *context;
   GtkWidget *selection_button;
 
@@ -346,6 +349,13 @@ photos_main_toolbar_populate_for_selection_mode (PhotosMainToolbar *self)
   gtk_style_context_add_class (context, "selection-mode");
   gtk_widget_reset_style (priv->toolbar);
 
+  builder = gtk_builder_new ();
+  gtk_builder_add_from_resource (builder, "/org/gnome/photos/selection-menu.ui", NULL);
+
+  selection_menu = G_MENU (gtk_builder_get_object (builder, "selection-menu"));
+  gd_main_toolbar_set_labels_menu (GD_MAIN_TOOLBAR (priv->toolbar), G_MENU_MODEL (selection_menu));
+  g_object_unref (builder);
+
   selection_button = gd_main_toolbar_add_button (GD_MAIN_TOOLBAR (priv->toolbar), NULL, _("Done"), FALSE);
   context = gtk_widget_get_style_context (selection_button);
   gtk_style_context_add_class (context, "suggested-action");
diff --git a/src/photos-selection-menu.ui b/src/photos-selection-menu.ui
new file mode 100644
index 0000000..51cb412
--- /dev/null
+++ b/src/photos-selection-menu.ui
@@ -0,0 +1,15 @@
+<interface>
+  <menu id="selection-menu">
+    <section>
+      <item>
+        <attribute name="action">app.select-all</attribute>
+        <attribute name="label" translatable="yes">Select All</attribute>
+        <attribute name="accel">&lt;Primary&gt;a</attribute>
+      </item>
+      <item>
+        <attribute name="action">app.select-none</attribute>
+        <attribute name="label" translatable="yes">Select None</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/src/photos-view-container.c b/src/photos-view-container.c
index dd837e2..9d2d89c 100644
--- a/src/photos-view-container.c
+++ b/src/photos-view-container.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 Red Hat, Inc.
+ * Copyright © 2012, 2013 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -26,6 +26,7 @@
 #include "config.h"
 #include <libgd/gd.h>
 
+#include "photos-application.h"
 #include "photos-enums.h"
 #include "photos-item-manager.h"
 #include "photos-load-more-button.h"
@@ -242,6 +243,8 @@ photos_view_container_constructed (GObject *object)
 {
   PhotosViewContainer *self = PHOTOS_VIEW_CONTAINER (object);
   PhotosViewContainerPrivate *priv = self->priv;
+  GAction *action;
+  GtkApplication *app;
   gboolean status;
 
   G_OBJECT_CLASS (photos_view_container_parent_class)->constructed (object);
@@ -300,6 +303,16 @@ photos_view_container_constructed (GObject *object)
       break;
     }
 
+  app = photos_application_new ();
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "select-all");
+  g_signal_connect_swapped (action, "activate", G_CALLBACK (gd_main_view_select_all), priv->view);
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "select-none");
+  g_signal_connect_swapped (action, "activate", G_CALLBACK (gd_main_view_unselect_all), priv->view);
+
+  g_object_unref (app);
+
   g_signal_connect (priv->trk_cntrlr,
                     "query-status-changed",
                     G_CALLBACK (photos_view_container_query_status_changed),
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index 3722e36..ff23572 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gnome/photos">
     <file alias="app-menu.ui" preprocess="xml-stripblanks">photos-app-menu.ui</file>
+    <file alias="selection-menu.ui" preprocess="xml-stripblanks">photos-selection-menu.ui</file>
   </gresource>
 </gresources>


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