[libadwaita/wip/exalm/tooltips: 3/4] split-button: Add :dropdown-tooltip




commit 3aef0c4792353b87e90b05fa1ba3fe742e847e63
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Jul 31 06:43:49 2022 +0400

    split-button: Add :dropdown-tooltip
    
    Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/528

 src/adw-split-button.c    | 69 +++++++++++++++++++++++++++++++++++++++++++++++
 src/adw-split-button.h    |  6 +++++
 tests/test-split-button.c | 28 +++++++++++++++++++
 3 files changed, 103 insertions(+)
---
diff --git a/src/adw-split-button.c b/src/adw-split-button.c
index ddc2c4a7..6660a974 100644
--- a/src/adw-split-button.c
+++ b/src/adw-split-button.c
@@ -63,6 +63,7 @@ enum {
   PROP_MENU_MODEL,
   PROP_POPOVER,
   PROP_DIRECTION,
+  PROP_DROPDOWN_TOOLTIP,
 
   /* actionable properties */
   PROP_ACTION_NAME,
@@ -192,6 +193,9 @@ adw_split_button_get_property (GObject    *object,
   case PROP_DIRECTION:
     g_value_set_enum (value, adw_split_button_get_direction (self));
     break;
+  case PROP_DROPDOWN_TOOLTIP:
+    g_value_set_string (value, adw_split_button_get_dropdown_tooltip (self));
+    break;
   case PROP_ACTION_NAME:
     g_value_set_string (value, gtk_actionable_get_action_name (GTK_ACTIONABLE (self)));
     break;
@@ -234,6 +238,9 @@ adw_split_button_set_property (GObject      *object,
   case PROP_DIRECTION:
     adw_split_button_set_direction (self, g_value_get_enum (value));
     break;
+  case PROP_DROPDOWN_TOOLTIP:
+    adw_split_button_set_dropdown_tooltip (self, g_value_get_string (value));
+    break;
   case PROP_ACTION_NAME:
     gtk_actionable_set_action_name (GTK_ACTIONABLE (self), g_value_get_string (value));
     break;
@@ -391,6 +398,20 @@ adw_split_button_class_init (AdwSplitButtonClass *klass)
                        GTK_ARROW_DOWN,
                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * AdwSplitButton:dropdown-tooltip: (attributes org.gtk.Property.get=adw_split_button_get_dropdown_tooltip 
org.gtk.Property.set=adw_split_button_set_dropdown_tooltip)
+   *
+   * The tooltip of the dropdown button.
+   *
+   * The tooltip can be marked up with the Pango text markup language.
+   *
+   * Since: 1.2
+   */
+  props[PROP_DROPDOWN_TOOLTIP] =
+    g_param_spec_string ("dropdown-tooltip", NULL, NULL,
+                         "",
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, LAST_PROP, props);
 
   g_object_class_override_property (object_class, PROP_ACTION_NAME, "action-name");
@@ -896,6 +917,54 @@ adw_split_button_set_direction (AdwSplitButton *self,
   update_style_classes (self);
 }
 
+/**
+ * adw_split_button_get_dropdown_tooltip: (attributes org.gtk.Method.get_property=dropdown-tooltip)
+ * @self: a split button
+ *
+ * Gets the tooltip of the dropdown button of @self.
+ *
+ * Returns: (transfer none): the dropdown tooltip of @self
+ *
+ * Since: 1.2
+ */
+const char *
+adw_split_button_get_dropdown_tooltip (AdwSplitButton *self)
+{
+  const char *tooltip;
+
+  g_return_val_if_fail (ADW_IS_SPLIT_BUTTON (self), NULL);
+
+  tooltip = gtk_widget_get_tooltip_markup (self->menu_button);
+
+  return tooltip ? tooltip : "";
+}
+
+/**
+ * adw_split_button_set_dropdown_tooltip: (attributes org.gtk.Method.set_property=dropdown-tooltip)
+ * @self: a split button
+ * @tooltip: the dropdown tooltip of @self
+ *
+ * Sets the tooltip of the dropdown button of @self.
+ *
+ * The tooltip can be marked up with the Pango text markup language.
+ *
+ * Since: 1.2
+ */
+void
+adw_split_button_set_dropdown_tooltip (AdwSplitButton *self,
+                                       const char     *tooltip)
+{
+  g_return_if_fail (ADW_IS_SPLIT_BUTTON (self));
+  g_return_if_fail (tooltip != NULL);
+
+  if (!g_strcmp0 (tooltip, adw_split_button_get_dropdown_tooltip (self)))
+    return;
+
+  gtk_widget_set_tooltip_markup (self->menu_button, tooltip);
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_DROPDOWN_TOOLTIP]);
+}
+
 /**
  * adw_split_button_popup:
  * @self: a split button
diff --git a/src/adw-split-button.h b/src/adw-split-button.h
index 55686e2e..e023ac2a 100644
--- a/src/adw-split-button.h
+++ b/src/adw-split-button.h
@@ -66,6 +66,12 @@ ADW_AVAILABLE_IN_ALL
 void         adw_split_button_set_direction (AdwSplitButton *self,
                                              GtkArrowType    direction);
 
+ADW_AVAILABLE_IN_1_2
+const char *adw_split_button_get_dropdown_tooltip (AdwSplitButton *self);
+ADW_AVAILABLE_IN_1_2
+void        adw_split_button_set_dropdown_tooltip (AdwSplitButton *self,
+                                                   const char     *tooltip);
+
 ADW_AVAILABLE_IN_ALL
 void adw_split_button_popup (AdwSplitButton *self);
 ADW_AVAILABLE_IN_ALL
diff --git a/tests/test-split-button.c b/tests/test-split-button.c
index 0348f5d4..1c214a78 100644
--- a/tests/test-split-button.c
+++ b/tests/test-split-button.c
@@ -272,6 +272,33 @@ test_adw_split_button_direction (void)
   g_assert_finalize_object (button);
 }
 
+static void
+test_adw_split_button_dropdown_tooltip (void)
+{
+  AdwSplitButton *button = g_object_ref_sink (ADW_SPLIT_BUTTON (adw_split_button_new ()));
+  char *tooltip;
+
+  g_assert_nonnull (button);
+
+  notified = 0;
+  g_signal_connect (button, "notify::dropdown-tooltip", G_CALLBACK (notify_cb), NULL);
+
+  g_object_get (button, "dropdown-tooltip", &tooltip, NULL);
+  g_assert_cmpstr (tooltip, ==, "");
+  g_assert_cmpint (notified, ==, 0);
+
+  adw_split_button_set_dropdown_tooltip (button, "Some tooltip");
+  g_assert_cmpstr (adw_split_button_get_dropdown_tooltip (button), ==, "Some tooltip");
+  g_assert_cmpint (notified, ==, 1);
+
+  g_object_set (button, "dropdown-tooltip", "Some other tooltip", NULL);
+  g_assert_cmpstr (adw_split_button_get_dropdown_tooltip (button), ==, "Some other tooltip");
+  g_assert_cmpint (notified, ==, 2);
+
+  g_free (tooltip);
+  g_assert_finalize_object (button);
+}
+
 int
 main (int   argc,
       char *argv[])
@@ -286,6 +313,7 @@ main (int   argc,
   g_test_add_func ("/Adwaita/SplitButton/menu_model", test_adw_split_button_menu_model);
   g_test_add_func ("/Adwaita/SplitButton/popover", test_adw_split_button_popover);
   g_test_add_func ("/Adwaita/SplitButton/direction", test_adw_split_button_direction);
+  g_test_add_func ("/Adwaita/SplitButton/dropdown_tooltip", test_adw_split_button_dropdown_tooltip);
 
   return g_test_run ();
 }


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