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



commit c2e443c17794a405dc88fdca8f9ab20a765a09ca
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 2c34409..169a3a0 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -1615,8 +1615,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;
@@ -1834,6 +1836,11 @@ photos_application_startup (GApplication *application)
   self->sharpen_action = g_simple_action_new ("sharpen-current", G_VARIANT_TYPE_DOUBLE);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->sharpen_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 0f305d5..430fb49 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -49,6 +49,7 @@ struct _PhotosPreviewView
   GAction *draw;
   GCancellable *cancellable;
   GeglNode *node;
+  GSettings *settings;
   GtkWidget *palette;
   GtkWidget *properties;
   GtkWidget *edit_revealer;
@@ -472,6 +473,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)
@@ -590,12 +599,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_show (self->nav_buttons);
@@ -624,6 +635,7 @@ photos_preview_view_dispose (GObject *object)
   g_clear_object (&self->item_mngr);
   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);
 }
@@ -700,6 +712,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]