[libadwaita/wip/exalm/shortcut-widget: 1/2] tab-view: Remove shortcut-widget




commit 92c19d440e53775fc9216d662381e75cfe8e8b57
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Nov 10 20:31:24 2021 +0500

    tab-view: Remove shortcut-widget

 demo/adw-tab-view-demo-window.ui              |   1 -
 doc/migrating-between-development-versions.md |  11 +++
 doc/migrating-libhandy-1-4-to-libadwaita.md   |  11 +++
 src/adw-tab-view.c                            | 135 ++++----------------------
 src/adw-tab-view.h                            |   6 --
 tests/test-tab-view.c                         |  31 ------
 6 files changed, 39 insertions(+), 156 deletions(-)
---
diff --git a/demo/adw-tab-view-demo-window.ui b/demo/adw-tab-view-demo-window.ui
index 5e4b5354..70b793c4 100644
--- a/demo/adw-tab-view-demo-window.ui
+++ b/demo/adw-tab-view-demo-window.ui
@@ -35,7 +35,6 @@
           <object class="AdwTabView" id="view">
             <property name="vexpand">True</property>
             <property name="menu-model">tab_menu</property>
-            <property name="shortcut-widget">AdwTabViewDemoWindow</property>
             <signal name="page-detached" handler="page_detached_cb" swapped="true"/>
             <signal name="setup-menu" handler="setup_menu_cb" swapped="true"/>
             <signal name="create-window" handler="create_window_cb" swapped="true"/>
diff --git a/doc/migrating-between-development-versions.md b/doc/migrating-between-development-versions.md
index 735d56db..959f0963 100644
--- a/doc/migrating-between-development-versions.md
+++ b/doc/migrating-between-development-versions.md
@@ -270,3 +270,14 @@ The [signal@Adw.SwipeTracker::begin-swipe] signal is now emitted immediately
 before the swipe starts, after the drag threshold has been reached, and it has
 lost its `direction` parameter. The new [signal@Adw.SwipeTracker::prepare]
 signal behaves exactly like `begin-swipe` was, and can be used instead of it.
+
+### Adapt to [class@Adw.TabView] API changes
+
+The `HdyTabVoew:shortcut-widget` property has been removed with no replacement;
+[class@AdwTabView] automatically installs shortcuts with the
+`GTK_SHORTCUT_SCOPE_MANAGED` scope, so they are automatically available
+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.
diff --git a/doc/migrating-libhandy-1-4-to-libadwaita.md b/doc/migrating-libhandy-1-4-to-libadwaita.md
index aeddba02..fe3b7691 100644
--- a/doc/migrating-libhandy-1-4-to-libadwaita.md
+++ b/doc/migrating-libhandy-1-4-to-libadwaita.md
@@ -329,6 +329,17 @@ before the swipe starts, after the drag threshold has been reached, and it has
 lost its `direction` parameter. The new [signal@Adw.SwipeTracker::prepare]
 signal behaves exactly like `begin-swipe` was, and can be used instead of it.
 
+### Adapt to [class@Adw.TabView] API changes
+
+The `HdyTabVoew:shortcut-widget` property has been removed with no replacement;
+[class@AdwTabView] automatically installs shortcuts with the
+`GTK_SHORTCUT_SCOPE_MANAGED` scope, so they are automatically available
+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 Stylesheet Changes
 
 Most widgets don't have a backdrop state anymore, and the following public
diff --git a/src/adw-tab-view.c b/src/adw-tab-view.c
index e028bdfd..e38d37ca 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -40,6 +40,21 @@ static GSList *tab_view_list;
  * As such, it does not support disabling page reordering or detaching, or
  * adding children via [class@Gtk.Builder].
  *
+ * `AdwTabView` adds the following shortcuts in the managed scope:
+ *
+ * * Ctrl+Page Up - switch to the previous page
+ * * Ctrl+Page Down - switch to the next page
+ * * Ctrl+Home - switch to the first page
+ * * Ctrl+End - switch to the last page
+ * * Ctrl+Shift+Page Up - move the current page backward
+ * * Ctrl+Shift+Page Down - move the current page forward
+ * * Ctrl+Shift+Home - move the current page at the start
+ * * Ctrl+Shift+End - move the current page at the end
+ * * Ctrl+Tab - switch to the next page, with looping
+ * * Ctrl+Shift+Tab - switch to the previous page, with looping
+ * * Alt+1-9 - switch to pages 1-9
+ * * Alt+0 - switch to page 10
+ *
  * ## CSS nodes
  *
  * `AdwTabView` has a main CSS node with the name `tabview`.
@@ -107,9 +122,6 @@ struct _AdwTabView
 
   int transfer_count;
 
-  GtkWidget *shortcut_widget;
-  GtkEventController *shortcut_controller;
-
   GtkSelectionModel *pages;
 };
 
@@ -123,7 +135,6 @@ enum {
   PROP_SELECTED_PAGE,
   PROP_DEFAULT_ICON,
   PROP_MENU_MODEL,
-  PROP_SHORTCUT_WIDGET,
   PROP_PAGES,
   LAST_PROP
 };
@@ -1259,23 +1270,11 @@ init_shortcuts (AdwTabView         *self,
                                   (i + 9) % 10); /* Alt+0 means page 10, not 0 */
 }
 
-static void
-shortcut_widget_notify_cb (AdwTabView *self)
-{
-  gtk_widget_remove_controller (self->shortcut_widget, self->shortcut_controller);
-  self->shortcut_controller = NULL;
-  self->shortcut_widget = NULL;
-
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SHORTCUT_WIDGET]);
-}
-
 static void
 adw_tab_view_dispose (GObject *object)
 {
   AdwTabView *self = ADW_TAB_VIEW (object);
 
-  adw_tab_view_set_shortcut_widget (self, NULL);
-
   if (self->pages)
     g_list_model_items_changed (G_LIST_MODEL (self->pages), 0, self->n_pages, 0);
 
@@ -1342,10 +1341,6 @@ adw_tab_view_get_property (GObject    *object,
     g_value_set_object (value, adw_tab_view_get_menu_model (self));
     break;
 
-  case PROP_SHORTCUT_WIDGET:
-    g_value_set_object (value, adw_tab_view_get_shortcut_widget (self));
-    break;
-
   case PROP_PAGES:
     g_value_take_object (value, adw_tab_view_get_pages (self));
     break;
@@ -1376,10 +1371,6 @@ adw_tab_view_set_property (GObject      *object,
     adw_tab_view_set_menu_model (self, g_value_get_object (value));
     break;
 
-  case PROP_SHORTCUT_WIDGET:
-    adw_tab_view_set_shortcut_widget (self, g_value_get_object (value));
-    break;
-
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   }
@@ -1504,37 +1495,6 @@ adw_tab_view_class_init (AdwTabViewClass *klass)
                          G_TYPE_MENU_MODEL,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
-  /**
-   * AdwTabView:shortcut-widget: (attributes org.gtk.Property.get=adw_tab_view_get_shortcut_widget 
org.gtk.Property.set=adw_tab_view_set_shortcut_widget)
-   *
-   * The shortcut widget.
-   *
-   * It has the following shortcuts:
-   * * Ctrl+Page Up - switch to the previous page
-   * * Ctrl+Page Down - switch to the next page
-   * * Ctrl+Home - switch to the first page
-   * * Ctrl+End - switch to the last page
-   * * Ctrl+Shift+Page Up - move the current page backward
-   * * Ctrl+Shift+Page Down - move the current page forward
-   * * Ctrl+Shift+Home - move the current page at the start
-   * * Ctrl+Shift+End - move the current page at the end
-   * * Ctrl+Tab - switch to the next page, with looping
-   * * Ctrl+Shift+Tab - switch to the previous page, with looping
-   * * Alt+1-9 - switch to pages 1-9
-   * * Alt+0 - switch to page 10
-   *
-   * These shortcuts are always available on the tab view itself, this property
-   * is useful if they should be available globally.
-   *
-   * Since: 1.0
-   */
-  props[PROP_SHORTCUT_WIDGET] =
-    g_param_spec_object ("shortcut-widget",
-                         "Shortcut widget",
-                         "Tab shortcut widget",
-                         GTK_TYPE_WIDGET,
-                         G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
-
   /**
    * AdwTabView:pages: (attributes org.gtk.Property.get=adw_tab_view_get_pages)
    *
@@ -1770,6 +1730,8 @@ adw_tab_view_init (AdwTabView *self)
   tab_view_list = g_slist_prepend (tab_view_list, self);
 
   controller = gtk_shortcut_controller_new ();
+  gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (controller),
+                                     GTK_SHORTCUT_SCOPE_MANAGED);
 
   init_shortcuts (self, controller);
 
@@ -2470,69 +2432,6 @@ adw_tab_view_set_menu_model (AdwTabView *self,
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_MENU_MODEL]);
 }
 
-/**
- * adw_tab_view_get_shortcut_widget: (attributes org.gtk.Method.get_property=shortcut-widget)
- * @self: a `AdwTabView`
- *
- * Gets the shortcut widget for @self.
- *
- * Returns: (transfer none) (nullable): the shortcut widget for @self
- *
- * Since: 1.0
- */
-GtkWidget *
-adw_tab_view_get_shortcut_widget (AdwTabView *self)
-{
-  g_return_val_if_fail (ADW_IS_TAB_VIEW (self), NULL);
-
-  return self->shortcut_widget;
-}
-
-/**
- * adw_tab_view_set_shortcut_widget: (attributes org.gtk.Method.set_property=shortcut-widget)
- * @self: a `AdwTabView`
- * @widget: (nullable): a shortcut widget
- *
- * Sets the shortcut widget for @self.
- *
- * Since: 1.0
- */
-void
-adw_tab_view_set_shortcut_widget (AdwTabView *self,
-                                  GtkWidget  *widget)
-{
-  g_return_if_fail (ADW_IS_TAB_VIEW (self));
-  g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
-
-  if (widget == self->shortcut_widget)
-    return;
-
-  if (self->shortcut_widget) {
-    gtk_widget_remove_controller (self->shortcut_widget, self->shortcut_controller);
-    self->shortcut_controller = NULL;
-
-    g_object_weak_unref (G_OBJECT (self->shortcut_widget),
-                         (GWeakNotify) shortcut_widget_notify_cb,
-                         self);
-  }
-
-  self->shortcut_widget = widget;
-
-  if (self->shortcut_widget) {
-    g_object_weak_ref (G_OBJECT (self->shortcut_widget),
-                       (GWeakNotify) shortcut_widget_notify_cb,
-                       self);
-
-    self->shortcut_controller = gtk_shortcut_controller_new ();
-
-    init_shortcuts (self, self->shortcut_controller);
-
-    gtk_widget_add_controller (self->shortcut_widget, self->shortcut_controller);
-  }
-
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SHORTCUT_WIDGET]);
-}
-
 /**
  * adw_tab_view_set_page_pinned:
  * @self: a `AdwTabView`
diff --git a/src/adw-tab-view.h b/src/adw-tab-view.h
index b57bc932..b1af9eb8 100644
--- a/src/adw-tab-view.h
+++ b/src/adw-tab-view.h
@@ -116,12 +116,6 @@ ADW_AVAILABLE_IN_ALL
 void        adw_tab_view_set_menu_model (AdwTabView *self,
                                          GMenuModel *menu_model);
 
-ADW_AVAILABLE_IN_ALL
-GtkWidget *adw_tab_view_get_shortcut_widget (AdwTabView *self);
-ADW_AVAILABLE_IN_ALL
-void       adw_tab_view_set_shortcut_widget (AdwTabView *self,
-                                             GtkWidget  *widget);
-
 ADW_AVAILABLE_IN_ALL
 void adw_tab_view_set_page_pinned (AdwTabView *self,
                                    AdwTabPage *page,
diff --git a/tests/test-tab-view.c b/tests/test-tab-view.c
index 70d21531..04687867 100644
--- a/tests/test-tab-view.c
+++ b/tests/test-tab-view.c
@@ -214,36 +214,6 @@ test_adw_tab_view_menu_model (void)
   g_assert_finalize_object (model2);
 }
 
-static void
-test_adw_tab_view_shortcut_widget (void)
-{
-  AdwTabView *view = g_object_ref_sink (ADW_TAB_VIEW (adw_tab_view_new ()));
-  GtkWidget *widget;
-  GtkWidget *widget1 = g_object_ref_sink (gtk_button_new ());
-  GtkWidget *widget2 = g_object_ref_sink (gtk_button_new ());
-
-  g_assert_nonnull (view);
-
-  notified = 0;
-  g_signal_connect (view, "notify::shortcut-widget", G_CALLBACK (notify_cb), NULL);
-
-  g_object_get (view, "shortcut-widget", &widget, NULL);
-  g_assert_null (widget);
-  g_assert_cmpint (notified, ==, 0);
-
-  adw_tab_view_set_shortcut_widget (view, widget1);
-  g_assert_true (adw_tab_view_get_shortcut_widget (view) == widget1);
-  g_assert_cmpint (notified, ==, 1);
-
-  g_object_set (view, "shortcut-widget", widget2, NULL);
-  g_assert_true (adw_tab_view_get_shortcut_widget (view) == widget2);
-  g_assert_cmpint (notified, ==, 2);
-
-  g_assert_finalize_object (view);
-  g_assert_finalize_object (widget1);
-  g_assert_finalize_object (widget2);
-}
-
 static void
 test_adw_tab_view_get_page (void)
 {
@@ -1257,7 +1227,6 @@ main (int   argc,
   g_test_add_func ("/Adwaita/TabView/n_pinned_pages", test_adw_tab_view_n_pinned_pages);
   g_test_add_func ("/Adwaita/TabView/default_icon", test_adw_tab_view_default_icon);
   g_test_add_func ("/Adwaita/TabView/menu_model", test_adw_tab_view_menu_model);
-  g_test_add_func ("/Adwaita/TabView/shortcut_widget", test_adw_tab_view_shortcut_widget);
   g_test_add_func ("/Adwaita/TabView/get_page", test_adw_tab_view_get_page);
   g_test_add_func ("/Adwaita/TabView/select", test_adw_tab_view_select);
   g_test_add_func ("/Adwaita/TabView/add_basic", test_adw_tab_view_add_basic);


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