[libadwaita/wip/exalm/leaflet-shortcuts: 2/6] leaflet: Rename can-swipe-* to can-navigate-*




commit f34969701e8501545e706280b7cc5eed98afcdab
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Nov 12 14:28:28 2021 +0500

    leaflet: Rename can-swipe-* to can-navigate-*
    
    We'll add shortcut and mouse button support, so make the name more generic.

 demo/adw-demo-window.ui                       |   4 +-
 demo/adw-style-demo-window.ui                 |   2 +-
 doc/migrating-between-development-versions.md |   6 ++
 doc/migrating-libhandy-1-4-to-libadwaita.md   |   4 +
 src/adw-leaflet.c                             | 128 ++++++++++++++------------
 src/adw-leaflet.h                             |  12 +--
 src/adw-preferences-window.ui                 |   2 +-
 7 files changed, 88 insertions(+), 70 deletions(-)
---
diff --git a/demo/adw-demo-window.ui b/demo/adw-demo-window.ui
index aba5a73e..b6f2322f 100644
--- a/demo/adw-demo-window.ui
+++ b/demo/adw-demo-window.ui
@@ -42,13 +42,13 @@
       <object class="AdwToastOverlay" id="toast_overlay">
         <property name="child">
           <object class="AdwLeaflet" id="subpage_leaflet">
-            <property name="can-swipe-back">True</property>
+            <property name="can-navigate-back">True</property>
             <property name="width-request">360</property>
             <property name="can-unfold">False</property>
             <property name="transition-type" bind-source="content_box" bind-property="transition-type" 
bind-flags="sync-create"/>
             <child>
               <object class="AdwLeaflet" id="content_box">
-                <property name="can-swipe-back">True</property>
+                <property name="can-navigate-back">True</property>
                 <child>
                   <object class="GtkBox">
                     <property name="orientation">vertical</property>
diff --git a/demo/adw-style-demo-window.ui b/demo/adw-style-demo-window.ui
index 9a3e0d00..bafc0541 100644
--- a/demo/adw-style-demo-window.ui
+++ b/demo/adw-style-demo-window.ui
@@ -1184,7 +1184,7 @@ The "raised" style class can be used to make a button inside a toolbar use defau
     <property name="default-height">480</property>
     <property name="content">
       <object class="AdwLeaflet" id="sidebar_leaflet">
-        <property name="can-swipe-back">True</property>
+        <property name="can-navigate-back">True</property>
         <child>
           <object class="GtkBox">
             <property name="orientation">vertical</property>
diff --git a/doc/migrating-between-development-versions.md b/doc/migrating-between-development-versions.md
index 959f0963..0634ad77 100644
--- a/doc/migrating-between-development-versions.md
+++ b/doc/migrating-between-development-versions.md
@@ -281,3 +281,9 @@ throughout the window without the need to set shortcut widget.
 If some of these shortcuts conflict with another widget, the latter has
 priority, and it should work automatically if the widget correctly stops event
 propagation.
+
+### Adapt to [class@Adw.Leaflet] API changes
+
+The `can-swipe-back` and `can-swipe-forward` properties have been renamed to
+[property@AdwLeaflet:can-navigate-back] and
+[property@AdwLeaflet:can-navigate-forward], along with their accessors.
diff --git a/doc/migrating-libhandy-1-4-to-libadwaita.md b/doc/migrating-libhandy-1-4-to-libadwaita.md
index fe3b7691..e8c8655e 100644
--- a/doc/migrating-libhandy-1-4-to-libadwaita.md
+++ b/doc/migrating-libhandy-1-4-to-libadwaita.md
@@ -259,6 +259,10 @@ page objects, similarly to [class@Gtk.Stack]. For example,
 [method@Adw.SqueezerPage.set_enabled] should be used to replace
 `hdy_squeezer_set_child_enabled()`.
 
+The `can-swipe-back` and `can-swipe-forward` properties have been renamed to
+[property@AdwLeaflet:can-navigate-back] and
+[property@AdwLeaflet:can-navigate-forward], along with their accessors.
+
 The `hhomogeneous-folded`, `vhomogeneous-folded`, `hhomogeneous-unfolded`,
 and `vhomogeneous-unfolded` properties have been replaced by a single
 [property@Adw.Leaflet:homogeneous] property, set to `TRUE` by default,
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index bdad663c..ccd1b6ae 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -78,8 +78,8 @@ enum {
   PROP_MODE_TRANSITION_DURATION,
   PROP_CHILD_TRANSITION_DURATION,
   PROP_CHILD_TRANSITION_RUNNING,
-  PROP_CAN_SWIPE_BACK,
-  PROP_CAN_SWIPE_FORWARD,
+  PROP_CAN_NAVIGATE_BACK,
+  PROP_CAN_NAVIGATE_FORWARD,
   PROP_CAN_UNFOLD,
   PROP_PAGES,
 
@@ -175,8 +175,8 @@ struct _AdwLeaflet {
     int last_visible_widget_width;
     int last_visible_widget_height;
 
-    gboolean can_swipe_back;
-    gboolean can_swipe_forward;
+    gboolean can_navigate_back;
+    gboolean can_navigate_forward;
 
     GtkPanDirection active_direction;
     int swipe_direction;
@@ -1486,14 +1486,14 @@ leaflet_child_visibility_notify_cb (GObject    *obj,
 }
 
 static gboolean
-can_swipe_in_direction (AdwLeaflet             *self,
-                        AdwNavigationDirection  direction)
+can_navigate_in_direction (AdwLeaflet             *self,
+                           AdwNavigationDirection  direction)
 {
   switch (direction) {
   case ADW_NAVIGATION_DIRECTION_BACK:
-    return self->child_transition.can_swipe_back;
+    return self->child_transition.can_navigate_back;
   case ADW_NAVIGATION_DIRECTION_FORWARD:
-    return self->child_transition.can_swipe_forward;
+    return self->child_transition.can_navigate_forward;
   default:
     g_assert_not_reached ();
   }
@@ -1528,7 +1528,7 @@ prepare_cb (AdwSwipeTracker        *tracker,
   } else {
     AdwLeafletPage *page = NULL;
 
-    if (can_swipe_in_direction (self, direction) && self->folded)
+    if (can_navigate_in_direction (self, direction) && self->folded)
       page = find_swipeable_page (self, direction);
 
     if (page) {
@@ -2072,11 +2072,11 @@ adw_leaflet_get_property (GObject    *object,
   case PROP_CHILD_TRANSITION_RUNNING:
     g_value_set_boolean (value, adw_leaflet_get_child_transition_running (self));
     break;
-  case PROP_CAN_SWIPE_BACK:
-    g_value_set_boolean (value, adw_leaflet_get_can_swipe_back (self));
+  case PROP_CAN_NAVIGATE_BACK:
+    g_value_set_boolean (value, adw_leaflet_get_can_navigate_back (self));
     break;
-  case PROP_CAN_SWIPE_FORWARD:
-    g_value_set_boolean (value, adw_leaflet_get_can_swipe_forward (self));
+  case PROP_CAN_NAVIGATE_FORWARD:
+    g_value_set_boolean (value, adw_leaflet_get_can_navigate_forward (self));
     break;
   case PROP_CAN_UNFOLD:
     g_value_set_boolean (value, adw_leaflet_get_can_unfold (self));
@@ -2122,11 +2122,11 @@ adw_leaflet_set_property (GObject      *object,
   case PROP_CHILD_TRANSITION_DURATION:
     adw_leaflet_set_child_transition_duration (self, g_value_get_uint (value));
     break;
-  case PROP_CAN_SWIPE_BACK:
-    adw_leaflet_set_can_swipe_back (self, g_value_get_boolean (value));
+  case PROP_CAN_NAVIGATE_BACK:
+    adw_leaflet_set_can_navigate_back (self, g_value_get_boolean (value));
     break;
-  case PROP_CAN_SWIPE_FORWARD:
-    adw_leaflet_set_can_swipe_forward (self, g_value_get_boolean (value));
+  case PROP_CAN_NAVIGATE_FORWARD:
+    adw_leaflet_set_can_navigate_forward (self, g_value_get_boolean (value));
     break;
   case PROP_CAN_UNFOLD:
     adw_leaflet_set_can_unfold (self, g_value_get_boolean (value));
@@ -2347,36 +2347,44 @@ adw_leaflet_class_init (AdwLeafletClass *klass)
                             G_PARAM_READABLE);
 
   /**
-   * AdwLeaflet:can-swipe-back: (attributes org.gtk.Property.get=adw_leaflet_get_can_swipe_back 
org.gtk.Property.set=adw_leaflet_set_can_swipe_back)
+   * AdwLeaflet:can-navigate-back: (attributes org.gtk.Property.get=adw_leaflet_get_can_navigate_back 
org.gtk.Property.set=adw_leaflet_set_can_navigate_back)
    *
-   * Whether a swipe gesture can be used to navigate to the previous child.
+   * Whether gestures and shortcuts for navigating backward are enabled.
+   *
+   * The supported gestures are:
+   * - One-finger swipe on touchscreens
+   * - Horizontal scrolling on touchpads (usually two-finger swipe)
    *
    * Only children that have [property@Adw.LeafletPage:navigatable] set to
    * `TRUE` can be navigated to.
    *
    * Since: 1.0
    */
-  props[PROP_CAN_SWIPE_BACK] =
-      g_param_spec_boolean ("can-swipe-back",
-                            "Can swipe back",
-                            "Whether a swipe gesture can be used to navigate to the previous child",
+  props[PROP_CAN_NAVIGATE_BACK] =
+      g_param_spec_boolean ("can-navigate-back",
+                            "Can navigate back",
+                            "Whether gestures and shortcuts for navigating backward are enabled",
                             FALSE,
                             G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
   /**
-   * AdwLeaflet:can-swipe-forward: (attributes org.gtk.Property.get=adw_leaflet_get_can_swipe_forward 
org.gtk.Property.set=adw_leaflet_set_can_swipe_forward)
+   * AdwLeaflet:can-navigate-forward: (attributes org.gtk.Property.get=adw_leaflet_get_can_navigate_forward 
org.gtk.Property.set=adw_leaflet_set_can_navigate_forward)
+   *
+   * Whether gestures and shortcuts for navigating forward are enabled.
    *
-   * Whether a swipe gesture can be used to navigate to the next child.
+   * The supported gestures are:
+   * - One-finger swipe on touchscreens
+   * - Horizontal scrolling on touchpads (usually two-finger swipe)
    *
    * Only children that have [property@Adw.LeafletPage:navigatable] set to
    * `TRUE` can be navigated to.
    *
    * Since: 1.0
    */
-  props[PROP_CAN_SWIPE_FORWARD] =
-      g_param_spec_boolean ("can-swipe-forward",
-                            "Can swipe forward",
-                            "Whether a swipe gesture can be used to navigate to the next child",
+  props[PROP_CAN_NAVIGATE_FORWARD] =
+      g_param_spec_boolean ("can-navigate-forward",
+                            "Can navigate forward",
+                            "Whether gestures and shortcuts for navigating forward are enabled",
                             FALSE,
                             G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
@@ -2522,7 +2530,7 @@ adw_leaflet_get_snap_points (AdwSwipeable *swipeable,
   } else {
     AdwLeafletPage *page = NULL;
 
-    if (can_swipe_in_direction (self, self->child_transition.swipe_direction) && self->folded)
+    if (can_navigate_in_direction (self, self->child_transition.swipe_direction) && self->folded)
       page = find_swipeable_page (self, self->child_transition.swipe_direction);
 
     lower = MIN (0, page ? self->child_transition.swipe_direction : 0);
@@ -3316,91 +3324,91 @@ adw_leaflet_get_child_transition_running (AdwLeaflet *self)
 }
 
 /**
- * adw_leaflet_set_can_swipe_back: (attributes org.gtk.Method.set_property=can-swipe-back)
+ * adw_leaflet_set_can_navigate_back: (attributes org.gtk.Method.set_property=can-navigate-back)
  * @self: a `AdwLeaflet`
- * @can_swipe_back: the new value
+ * @can_navigate_back: the new value
  *
- * Sets whether a swipe gesture can be used to navigate to the previous child.
+ * Sets whether gestures and shortcuts for navigating backward are enabled.
  *
  * Since: 1.0
  */
 void
-adw_leaflet_set_can_swipe_back (AdwLeaflet *self,
-                                gboolean    can_swipe_back)
+adw_leaflet_set_can_navigate_back (AdwLeaflet *self,
+                                   gboolean    can_navigate_back)
 {
   g_return_if_fail (ADW_IS_LEAFLET (self));
 
-  can_swipe_back = !!can_swipe_back;
+  can_navigate_back = !!can_navigate_back;
 
-  if (self->child_transition.can_swipe_back == can_swipe_back)
+  if (self->child_transition.can_navigate_back == can_navigate_back)
     return;
 
-  self->child_transition.can_swipe_back = can_swipe_back;
-  adw_swipe_tracker_set_enabled (self->tracker, can_swipe_back || self->child_transition.can_swipe_forward);
+  self->child_transition.can_navigate_back = can_navigate_back;
+  adw_swipe_tracker_set_enabled (self->tracker, can_navigate_back || 
self->child_transition.can_navigate_forward);
 
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CAN_SWIPE_BACK]);
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CAN_NAVIGATE_BACK]);
 }
 
 /**
- * adw_leaflet_get_can_swipe_back: (attributes org.gtk.Method.get_property=can-swipe-back)
+ * adw_leaflet_get_can_navigate_back: (attributes org.gtk.Method.get_property=can-navigate-back)
  * @self: a `AdwLeaflet`
  *
- * Gets whether a swipe gesture can be used to navigate to the previous child.
+ * Gets whether gestures and shortcuts for navigating backward are enabled.
  *
- * Returns: whether back swipe is enabled.
+ * Returns: Whether gestures and shortcuts are enabled.
  *
  * Since: 1.0
  */
 gboolean
-adw_leaflet_get_can_swipe_back (AdwLeaflet *self)
+adw_leaflet_get_can_navigate_back (AdwLeaflet *self)
 {
   g_return_val_if_fail (ADW_IS_LEAFLET (self), FALSE);
 
-  return self->child_transition.can_swipe_back;
+  return self->child_transition.can_navigate_back;
 }
 
 /**
- * adw_leaflet_set_can_swipe_forward: (attributes org.gtk.Method.set_property=can-swipe-forward)
+ * adw_leaflet_set_can_navigate_forward: (attributes org.gtk.Method.set_property=can-navigate-forward)
  * @self: a `AdwLeaflet`
- * @can_swipe_forward: the new value
+ * @can_navigate_forward: the new value
  *
- * Sets whether a swipe gesture can be used to navigate to the next child.
+ * Sets whether gestures and shortcuts for navigating forward are enabled.
  *
  * Since: 1.0
  */
 void
-adw_leaflet_set_can_swipe_forward (AdwLeaflet *self,
-                                   gboolean    can_swipe_forward)
+adw_leaflet_set_can_navigate_forward (AdwLeaflet *self,
+                                      gboolean    can_navigate_forward)
 {
   g_return_if_fail (ADW_IS_LEAFLET (self));
 
-  can_swipe_forward = !!can_swipe_forward;
+  can_navigate_forward = !!can_navigate_forward;
 
-  if (self->child_transition.can_swipe_forward == can_swipe_forward)
+  if (self->child_transition.can_navigate_forward == can_navigate_forward)
     return;
 
-  self->child_transition.can_swipe_forward = can_swipe_forward;
-  adw_swipe_tracker_set_enabled (self->tracker, self->child_transition.can_swipe_back || can_swipe_forward);
+  self->child_transition.can_navigate_forward = can_navigate_forward;
+  adw_swipe_tracker_set_enabled (self->tracker, self->child_transition.can_navigate_back || 
can_navigate_forward);
 
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CAN_SWIPE_FORWARD]);
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CAN_NAVIGATE_FORWARD]);
 }
 
 /**
- * adw_leaflet_get_can_swipe_forward: (attributes org.gtk.Method.get_property=can-swipe-forward)
+ * adw_leaflet_get_can_navigate_forward: (attributes org.gtk.Method.get_property=can-navigate-forward)
  * @self: a `AdwLeaflet`
  *
- * Gets whether a swipe gesture can be used to navigate to the next child.
+ * Gets whether gestures and shortcuts for navigating forward are enabled.
  *
- * Returns: Whether forward swipe is enabled.
+ * Returns: Whether gestures and shortcuts are enabled.
  *
  * Since: 1.0
  */
 gboolean
-adw_leaflet_get_can_swipe_forward (AdwLeaflet *self)
+adw_leaflet_get_can_navigate_forward (AdwLeaflet *self)
 {
   g_return_val_if_fail (ADW_IS_LEAFLET (self), FALSE);
 
-  return self->child_transition.can_swipe_forward;
+  return self->child_transition.can_navigate_forward;
 }
 
 /**
diff --git a/src/adw-leaflet.h b/src/adw-leaflet.h
index 7b7a9799..7bdd89de 100644
--- a/src/adw-leaflet.h
+++ b/src/adw-leaflet.h
@@ -120,16 +120,16 @@ ADW_AVAILABLE_IN_ALL
 gboolean adw_leaflet_get_child_transition_running (AdwLeaflet *self);
 
 ADW_AVAILABLE_IN_ALL
-gboolean adw_leaflet_get_can_swipe_back (AdwLeaflet *self);
+gboolean adw_leaflet_get_can_navigate_back (AdwLeaflet *self);
 ADW_AVAILABLE_IN_ALL
-void     adw_leaflet_set_can_swipe_back (AdwLeaflet *self,
-                                         gboolean    can_swipe_back);
+void     adw_leaflet_set_can_navigate_back (AdwLeaflet *self,
+                                            gboolean    can_navigate_back);
 
 ADW_AVAILABLE_IN_ALL
-gboolean adw_leaflet_get_can_swipe_forward (AdwLeaflet *self);
+gboolean adw_leaflet_get_can_navigate_forward (AdwLeaflet *self);
 ADW_AVAILABLE_IN_ALL
-void     adw_leaflet_set_can_swipe_forward (AdwLeaflet *self,
-                                            gboolean    can_swipe_forward);
+void     adw_leaflet_set_can_navigate_forward (AdwLeaflet *self,
+                                               gboolean    can_navigate_forward);
 
 ADW_AVAILABLE_IN_ALL
 GtkWidget *adw_leaflet_get_adjacent_child (AdwLeaflet             *self,
diff --git a/src/adw-preferences-window.ui b/src/adw-preferences-window.ui
index f20bb7ba..b6f38906 100644
--- a/src/adw-preferences-window.ui
+++ b/src/adw-preferences-window.ui
@@ -15,7 +15,7 @@
       <object class="AdwToastOverlay" id="toast_overlay">
         <child>
           <object class="AdwLeaflet" id="subpages_leaflet">
-            <property name="can-swipe-back" bind-source="AdwPreferencesWindow" 
bind-property="can-swipe-back" bind-flags="sync-create"/>
+            <property name="can-navigate-back" bind-source="AdwPreferencesWindow" 
bind-property="can-swipe-back" bind-flags="sync-create"/>
             <property name="can-unfold">False</property>
             <property name="width-request">360</property>
             <signal name="notify::child-transition-running" 
handler="subpages_leaflet_child_transition_running_cb" swapped="yes"/>


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