[gnome-photos/wip/abono/sidebar: 628/635] application: Add action to show/hide properties sidebar



commit 74363e7bd702fa99e093e00a4f0ce5ecf346e1d3
Author: Alessandro Bono <abono gnome org>
Date:   Thu Oct 27 13:15:46 2016 +0200

    application: Add action to show/hide properties sidebar
    
    The state of the action is tied to its gsetting key
    value to make it persistent

 data/org.gnome.photos.gschema.xml |    7 ++++++-
 src/photos-application.c          |    7 +++++++
 src/photos-preview-menu.ui        |    4 ++--
 src/photos-preview-view.c         |   17 +++++++++++++++++
 4 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/data/org.gnome.photos.gschema.xml b/data/org.gnome.photos.gschema.xml
index 7bbd903..d4da2ba 100644
--- a/data/org.gnome.photos.gschema.xml
+++ b/data/org.gnome.photos.gschema.xml
@@ -1,6 +1,11 @@
 <schemalist gettext-domain="gnome-photos">
   <schema id="org.gnome.photos" path="/org/gnome/photos/">
-    <key name="window-size" type="ai">
+    <key name="show-properties-sidebar" type="b">
+      <default>false</default>
+      <summary>Show the properties sidebar</summary>
+      <description>Show the properties sidebar while viewing an image</description>
+    </key>
+      <key name="window-size" type="ai">
       <default>[960, 600]</default>
       <summary>Window size</summary>
       <description>Window size (width and height).</description>
diff --git a/src/photos-application.c b/src/photos-application.c
index 9e00b8f..a631f98 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -1798,8 +1798,10 @@ static void
 photos_application_startup (GApplication *application)
 {
   PhotosApplication *self = PHOTOS_APPLICATION (application);
+  GAction *action;
   GError *error;
   GrlRegistry *registry;
+  GSettings *settings;
   GSimpleAction *simple_action;
   GtkIconTheme *icon_theme;
   GtkSettings *gtk_settings;
@@ -2040,6 +2042,11 @@ photos_application_startup (GApplication *application)
   self->zoom_out_action = g_simple_action_new ("zoom-out", G_VARIANT_TYPE_VARDICT);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->zoom_out_action));
 
+  settings = g_settings_new ("org.gnome.photos");
+  action = g_settings_create_action (G_SETTINGS (settings), "show-properties-sidebar");
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
+  g_clear_object (&settings);
+
   g_signal_connect_swapped (self->state->mode_cntrlr,
                             "window-mode-changed",
                             G_CALLBACK (photos_application_window_mode_changed),
diff --git a/src/photos-preview-menu.ui b/src/photos-preview-menu.ui
index b72ff3b..69163a4 100644
--- a/src/photos-preview-menu.ui
+++ b/src/photos-preview-menu.ui
@@ -33,8 +33,8 @@
     </section>
     <section>
       <item>
-        <attribute name="action">app.properties</attribute>
-        <attribute name="label" translatable="yes">Properties</attribute>
+        <attribute name="action">app.show-properties-sidebar</attribute>
+        <attribute name="label" translatable="yes">Show Properties</attribute>
       </item>
     </section>
   </menu>
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index c70a8cd..40a2039 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -56,6 +56,7 @@ struct _PhotosPreviewView
   GAction *zoom_out_action;
   GCancellable *cancellable;
   GeglNode *node;
+  GSettings *settings;
   GtkWidget *palette;
   GtkWidget *properties;
   GtkWidget *edit_revealer;
@@ -768,6 +769,14 @@ photos_preview_view_sharpen (PhotosPreviewView *self, GVariant *parameter)
                                         NULL);
 }
 
+static void
+photos_preview_set_properties_sidebar_visibility_from_settings (PhotosPreviewView *self)
+{
+  gboolean value;
+
+  value = g_settings_get_boolean (self->settings, "show-properties-sidebar");
+  gtk_revealer_set_reveal_child (GTK_REVEALER (self->properties_revealer), value);
+}
 
 static void
 photos_preview_view_tool_activated (PhotosTool *tool, gpointer user_data)
@@ -889,12 +898,14 @@ photos_preview_view_window_mode_changed (PhotosPreviewView *self, PhotosWindowMo
       break;
 
     case PHOTOS_WINDOW_MODE_EDIT:
+      gtk_revealer_set_reveal_child (GTK_REVEALER (self->properties_revealer), FALSE);
       gtk_revealer_set_reveal_child (GTK_REVEALER (self->edit_revealer), TRUE);
       photos_edit_palette_show (PHOTOS_EDIT_PALETTE (self->palette));
       photos_preview_nav_buttons_hide (self->nav_buttons);
       break;
 
     case PHOTOS_WINDOW_MODE_PREVIEW:
+      photos_preview_set_properties_sidebar_visibility_from_settings (self);
       gtk_revealer_set_reveal_child (GTK_REVEALER (self->edit_revealer), FALSE);
       photos_edit_palette_hide_details (PHOTOS_EDIT_PALETTE (self->palette));
       photos_preview_nav_buttons_set_auto_hide (self->nav_buttons, TRUE);
@@ -1167,6 +1178,7 @@ photos_preview_view_dispose (GObject *object)
   g_clear_object (&self->gesture_zoom);
   g_clear_object (&self->mode_cntrlr);
   g_clear_object (&self->nav_buttons);
+  g_clear_object (&self->settings);
 
   G_OBJECT_CLASS (photos_preview_view_parent_class)->dispose (object);
 }
@@ -1278,6 +1290,11 @@ photos_preview_view_init (PhotosPreviewView *self)
 
   self->properties = photos_properties_sidebar_new ();
   gtk_container_add (GTK_CONTAINER (self->properties_revealer), self->properties);
+  self->settings = g_settings_new ("org.gnome.photos");
+  g_signal_connect_swapped (self->settings,
+                            "changed::show-properties-sidebar",
+                            G_CALLBACK (photos_preview_set_properties_sidebar_visibility_from_settings),
+                            self);
 
   sw = gtk_scrolled_window_new (NULL, NULL);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);


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