[gtk+/wip/csoriano/pathbar-prototype] GtkPathBar: add hide direction property



commit 6bc2b4e242f94e062ad5e7692bc9dec8a8abb02c
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Nov 6 14:19:16 2015 +0100

    GtkPathBar: add hide direction property

 gtk/gtkpathbar.c    |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkpathbar.h    |    7 +++++++
 tests/testpathbar.c |   11 ++++++++++-
 3 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index f68490d..14d5979 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -41,6 +41,7 @@ struct _GtkPathBarPrivate
   GtkWidget *path_chunk_popover_container;
 
   gchar *path;
+  gboolean hide_direction;
 
   gboolean selecting_path;
 };
@@ -56,6 +57,7 @@ enum {
 enum {
   PROP_0,
   PROP_PATH,
+  PROP_HIDE_DIRECTION,
   LAST_PROP
 };
 
@@ -345,6 +347,39 @@ gtk_path_bar_select_path (GtkPathBar  *self,
   g_list_free (children);
 }
 
+void
+gtk_path_bar_set_hide_direction (GtkPathBar       *self,
+                                 GtkDirectionType  hide_direction)
+{
+  GtkPathBarPrivate *priv ;
+
+  g_return_if_fail (GTK_IS_PATH_BAR (self));
+  g_return_if_fail (hide_direction == GTK_DIR_LEFT || hide_direction == GTK_DIR_RIGHT);
+
+  priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+
+  if (gtk_hiding_box_get_hide_direction (GTK_HIDING_BOX (priv->path_box)) != hide_direction)
+    {
+      gtk_hiding_box_set_hide_direction (GTK_HIDING_BOX (priv->path_box), hide_direction);
+
+      g_object_notify (G_OBJECT (self), "hide-direction");
+
+      gtk_widget_queue_resize (GTK_WIDGET (self));
+    }
+}
+
+GtkDirectionType
+gtk_path_bar_get_hide_direction (GtkPathBar *self)
+{
+  GtkPathBarPrivate *priv ;
+
+  g_return_val_if_fail (GTK_IS_PATH_BAR (self), 0);
+
+  priv = gtk_path_bar_get_instance_private (GTK_PATH_BAR (self));
+
+  return gtk_hiding_box_get_hide_direction (GTK_HIDING_BOX (priv->path_box));
+}
+
 GtkWidget *
 gtk_path_bar_new (void)
 {
@@ -376,6 +411,9 @@ gtk_path_bar_get_property (GObject    *object,
     case PROP_PATH:
       g_value_set_string (value, priv->path);
       break;
+    case PROP_HIDE_DIRECTION:
+      g_value_set_int (value, priv->hide_direction);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -394,6 +432,9 @@ gtk_path_bar_set_property (GObject      *object,
     case PROP_PATH:
       gtk_path_bar_set_path (self, g_value_get_string (value));
       break;
+    case PROP_HIDE_DIRECTION:
+      gtk_path_bar_set_hide_direction (self, g_value_get_int (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -739,6 +780,13 @@ gtk_path_bar_class_init (GtkPathBarClass *klass)
                                NULL,
                                G_PARAM_READWRITE);
 
+  path_bar_properties[PROP_HIDE_DIRECTION] =
+          g_param_spec_string ("hide-direction",
+                               P_("Hide direction"),
+                               P_("From where the container will start hiding widgets when there is not 
enough space"),
+                               NULL,
+                               G_PARAM_READWRITE);
+
   g_object_class_install_properties (object_class, LAST_PROP, path_bar_properties);
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkpathbar.ui");
@@ -760,4 +808,5 @@ gtk_path_bar_init (GtkPathBar *self)
   gtk_widget_init_template (GTK_WIDGET (self));
 
   priv->selecting_path = FALSE;
+  priv->hide_direction = GTK_DIR_RIGHT;
 }
diff --git a/gtk/gtkpathbar.h b/gtk/gtkpathbar.h
index b0d3599..1f7be88 100644
--- a/gtk/gtkpathbar.h
+++ b/gtk/gtkpathbar.h
@@ -74,6 +74,13 @@ void                  gtk_path_bar_select_path        (GtkPathBar       *path_ba
                                                        const gchar      *path);
 GDK_AVAILABLE_IN_3_20
 const gchar*          gtk_path_bar_get_path           (GtkPathBar       *path_bar);
+GDK_AVAILABLE_IN_3_20
+void                  gtk_path_bar_set_hide_direction (GtkPathBar       *path_bar,
+                                                       GtkDirectionType  hide_direction);
+GDK_AVAILABLE_IN_3_20
+GtkDirectionType      gtk_path_bar_get_hide_direction (GtkPathBar       *path_bar);
+
+
 
 G_END_DECLS
 
diff --git a/tests/testpathbar.c b/tests/testpathbar.c
index 1861a7f..be25f80 100644
--- a/tests/testpathbar.c
+++ b/tests/testpathbar.c
@@ -80,6 +80,7 @@ main (int argc, char *argv[])
 {
   GtkWidget *window;
   GtkWidget *path_bar;
+  GtkWidget *box;
 
   gtk_init (&argc, &argv);
 
@@ -98,10 +99,18 @@ main (int argc, char *argv[])
 
   gtk_widget_insert_action_group (window, "action_group", action_group);
 
+  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
   g_type_ensure (GTK_TYPE_PATH_BAR);
   path_bar = gtk_path_bar_new ();
-  gtk_container_add (GTK_CONTAINER (window), path_bar);
+  gtk_container_add (GTK_CONTAINER (box), path_bar);
   gtk_path_bar_set_path (GTK_PATH_BAR (path_bar), "/test/test 2/test 3/asda lkasdl//pppppppppppppppp/ 
alskd/");
+
+  path_bar = gtk_path_bar_new ();
+  gtk_container_add (GTK_CONTAINER (box), path_bar);
+  gtk_path_bar_set_hide_direction (GTK_PATH_BAR (path_bar), GTK_DIR_LEFT);
+  gtk_path_bar_set_path (GTK_PATH_BAR (path_bar), "/test/test 2/test 3/asda lkasdl//pppppppppppppppp/ 
alskd/");
+
+  gtk_container_add (GTK_CONTAINER (window), box);
   gtk_widget_show_all (window);
 
   g_signal_connect (GTK_PATH_BAR (path_bar), "populate-popup",


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