[libadwaita/wip/exalm/view-switcher-cleanup: 1/12] view-switcher-bar: Remove policy




commit 5b1eeb38d1fa9334dabbb136856b195d8ff930f1
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Aug 31 14:45:20 2021 +0500

    view-switcher-bar: Remove policy
    
    We never use it and don't recommend it. People can easily reimplement it
    themselves if they need to.
    
    Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/167

 doc/migrating-libhandy-1-4-to-libadwaita.md |  5 ++
 src/adw-view-switcher-bar.c                 | 71 -----------------------------
 src/adw-view-switcher-bar.h                 |  6 ---
 src/adw-view-switcher-bar.ui                |  2 +-
 tests/test-view-switcher-bar.c              | 22 ---------
 5 files changed, 6 insertions(+), 100 deletions(-)
---
diff --git a/doc/migrating-libhandy-1-4-to-libadwaita.md b/doc/migrating-libhandy-1-4-to-libadwaita.md
index 956afc99..8abb9842 100644
--- a/doc/migrating-libhandy-1-4-to-libadwaita.md
+++ b/doc/migrating-libhandy-1-4-to-libadwaita.md
@@ -242,6 +242,11 @@ You should stop using [property@Gtk.Stack:transition-type] and
 [property@Gtk.Stack:transition-duration] properties before switching to
 [class@Adw.ViewStack].
 
+### Adapt to [class@Adw.ViewSwitcherBar] API Changes
+
+The "policy" property has been removed. If you had used it, use a plain
+[class@Adw.ViewSwitcher] in a [class@Gtk.ActionBar] instead.
+
 ### Adapt to [class@Adw.Avatar] API Changes
 
 The `HdyAvatar:loadable-icon` property has been removed along with its getter
diff --git a/src/adw-view-switcher-bar.c b/src/adw-view-switcher-bar.c
index 657d7d80..7b4b8782 100644
--- a/src/adw-view-switcher-bar.c
+++ b/src/adw-view-switcher-bar.c
@@ -66,7 +66,6 @@
 
 enum {
   PROP_0,
-  PROP_POLICY,
   PROP_STACK,
   PROP_REVEAL,
   LAST_PROP,
@@ -80,7 +79,6 @@ struct _AdwViewSwitcherBar
   GtkRevealer *revealer;
   AdwViewSwitcher *view_switcher;
 
-  AdwViewSwitcherPolicy policy;
   GtkSelectionModel *pages;
   gboolean reveal;
 };
@@ -120,9 +118,6 @@ adw_view_switcher_bar_get_property (GObject    *object,
   AdwViewSwitcherBar *self = ADW_VIEW_SWITCHER_BAR (object);
 
   switch (prop_id) {
-  case PROP_POLICY:
-    g_value_set_enum (value, adw_view_switcher_bar_get_policy (self));
-    break;
   case PROP_STACK:
     g_value_set_object (value, adw_view_switcher_bar_get_stack (self));
     break;
@@ -144,9 +139,6 @@ adw_view_switcher_bar_set_property (GObject      *object,
   AdwViewSwitcherBar *self = ADW_VIEW_SWITCHER_BAR (object);
 
   switch (prop_id) {
-  case PROP_POLICY:
-    adw_view_switcher_bar_set_policy (self, g_value_get_enum (value));
-    break;
   case PROP_STACK:
     adw_view_switcher_bar_set_stack (self, g_value_get_object (value));
     break;
@@ -180,21 +172,6 @@ adw_view_switcher_bar_class_init (AdwViewSwitcherBarClass *klass)
   object_class->set_property = adw_view_switcher_bar_set_property;
   object_class->dispose = adw_view_switcher_bar_dispose;
 
-  /**
-   * AdwViewSwitcherBar:policy: (attributes org.gtk.Property.get=adw_view_switcher_bar_get_policy 
org.gtk.Property.set=adw_view_switcher_bar_set_policy)
-   *
-   * The policy to determine which mode to use.
-   *
-   * Since: 1.0
-   */
-  props[PROP_POLICY] =
-    g_param_spec_enum ("policy",
-                       "Policy",
-                       "The policy to determine the mode to use",
-                       ADW_TYPE_VIEW_SWITCHER_POLICY,
-                       ADW_VIEW_SWITCHER_POLICY_NARROW,
-                       G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
   /**
    * AdwViewSwitcherBar:stack: (attributes org.gtk.Property.get=adw_view_switcher_bar_get_stack 
org.gtk.Property.set=adw_view_switcher_bar_set_stack)
    *
@@ -237,11 +214,6 @@ adw_view_switcher_bar_class_init (AdwViewSwitcherBarClass *klass)
 static void
 adw_view_switcher_bar_init (AdwViewSwitcherBar *self)
 {
-  /* This must be initialized before the template so the embedded view switcher
-   * can pick up the correct default value.
-   */
-  self->policy = ADW_VIEW_SWITCHER_POLICY_NARROW;
-
   gtk_widget_init_template (GTK_WIDGET (self));
 
   self->revealer = GTK_REVEALER (gtk_widget_get_first_child (GTK_WIDGET (self->action_bar)));
@@ -264,49 +236,6 @@ adw_view_switcher_bar_new (void)
   return g_object_new (ADW_TYPE_VIEW_SWITCHER_BAR, NULL);
 }
 
-/**
- * adw_view_switcher_bar_get_policy: (attributes org.gtk.Method.get_property=policy)
- * @self: a `AdwViewSwitcherBar`
- *
- * Gets the policy of @self.
- *
- * Returns: the policy of @self
- *
- * Since: 1.0
- */
-AdwViewSwitcherPolicy
-adw_view_switcher_bar_get_policy (AdwViewSwitcherBar *self)
-{
-  g_return_val_if_fail (ADW_IS_VIEW_SWITCHER_BAR (self), ADW_VIEW_SWITCHER_POLICY_NARROW);
-
-  return self->policy;
-}
-
-/**
- * adw_view_switcher_bar_set_policy: (attributes org.gtk.Method.set_property=policy)
- * @self: a `AdwViewSwitcherBar`
- * @policy: the new policy
- *
- * Sets the policy of @self.
- *
- * Since: 1.0
- */
-void
-adw_view_switcher_bar_set_policy (AdwViewSwitcherBar    *self,
-                                  AdwViewSwitcherPolicy  policy)
-{
-  g_return_if_fail (ADW_IS_VIEW_SWITCHER_BAR (self));
-
-  if (self->policy == policy)
-    return;
-
-  self->policy = policy;
-
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_POLICY]);
-
-  gtk_widget_queue_resize (GTK_WIDGET (self));
-}
-
 /**
  * adw_view_switcher_bar_get_stack: (attributes org.gtk.Method.get_property=stack)
  * @self: a `AdwViewSwitcherBar`
diff --git a/src/adw-view-switcher-bar.h b/src/adw-view-switcher-bar.h
index 52d84e2f..ebda1e33 100644
--- a/src/adw-view-switcher-bar.h
+++ b/src/adw-view-switcher-bar.h
@@ -27,12 +27,6 @@ G_DECLARE_FINAL_TYPE (AdwViewSwitcherBar, adw_view_switcher_bar, ADW, VIEW_SWITC
 ADW_AVAILABLE_IN_ALL
 GtkWidget *adw_view_switcher_bar_new (void) G_GNUC_WARN_UNUSED_RESULT;
 
-ADW_AVAILABLE_IN_ALL
-AdwViewSwitcherPolicy adw_view_switcher_bar_get_policy (AdwViewSwitcherBar *self);
-ADW_AVAILABLE_IN_ALL
-void                  adw_view_switcher_bar_set_policy (AdwViewSwitcherBar    *self,
-                                                        AdwViewSwitcherPolicy  policy);
-
 ADW_AVAILABLE_IN_ALL
 AdwViewStack *adw_view_switcher_bar_get_stack (AdwViewSwitcherBar *self);
 ADW_AVAILABLE_IN_ALL
diff --git a/src/adw-view-switcher-bar.ui b/src/adw-view-switcher-bar.ui
index 95b4aae9..5a442dad 100644
--- a/src/adw-view-switcher-bar.ui
+++ b/src/adw-view-switcher-bar.ui
@@ -9,7 +9,7 @@
             <property name="margin-start">10</property>
             <property name="margin-end">10</property>
             <property name="narrow-ellipsize">end</property>
-            <property name="policy" bind-source="AdwViewSwitcherBar" bind-property="policy" 
bind-flags="sync-create|bidirectional" />
+            <property name="policy">narrow</property>
           </object>
         </child>
       </object>
diff --git a/tests/test-view-switcher-bar.c b/tests/test-view-switcher-bar.c
index dcc568ff..e44ee5bd 100644
--- a/tests/test-view-switcher-bar.c
+++ b/tests/test-view-switcher-bar.c
@@ -7,27 +7,6 @@
 #include <adwaita.h>
 
 
-static void
-test_adw_view_switcher_bar_policy (void)
-{
-  g_autoptr (AdwViewSwitcherBar) bar = NULL;
-
-  bar = g_object_ref_sink (ADW_VIEW_SWITCHER_BAR (adw_view_switcher_bar_new ()));
-  g_assert_nonnull (bar);
-
-  g_assert_cmpint (adw_view_switcher_bar_get_policy (bar), ==, ADW_VIEW_SWITCHER_POLICY_NARROW);
-
-  adw_view_switcher_bar_set_policy (bar, ADW_VIEW_SWITCHER_POLICY_AUTO);
-  g_assert_cmpint (adw_view_switcher_bar_get_policy (bar), ==, ADW_VIEW_SWITCHER_POLICY_AUTO);
-
-  adw_view_switcher_bar_set_policy (bar, ADW_VIEW_SWITCHER_POLICY_WIDE);
-  g_assert_cmpint (adw_view_switcher_bar_get_policy (bar), ==, ADW_VIEW_SWITCHER_POLICY_WIDE);
-
-  adw_view_switcher_bar_set_policy (bar, ADW_VIEW_SWITCHER_POLICY_NARROW);
-  g_assert_cmpint (adw_view_switcher_bar_get_policy (bar), ==, ADW_VIEW_SWITCHER_POLICY_NARROW);
-}
-
-
 static void
 test_adw_view_switcher_bar_stack (void)
 {
@@ -75,7 +54,6 @@ main (int   argc,
   gtk_test_init (&argc, &argv, NULL);
   adw_init ();
 
-  g_test_add_func("/Adwaita/ViewSwitcherBar/policy", test_adw_view_switcher_bar_policy);
   g_test_add_func("/Adwaita/ViewSwitcherBar/stack", test_adw_view_switcher_bar_stack);
   g_test_add_func("/Adwaita/ViewSwitcherBar/reveal", test_adw_view_switcher_bar_reveal);
 


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