[gtk+] shortcuts: Add support for standard gestures



commit 304c5ac226b5254e6ced7ad3f5e81b89481b694e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 22 02:24:12 2015 -0500

    shortcuts: Add support for standard gestures
    
    Add an enum for gestures that GtkShortcutsShortcut knows how
    to show an image and subtitle for.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758187

 docs/reference/gtk/gtk3-sections.txt |    1 +
 gtk/gtkshortcutsshortcut.c           |   93 +++++++++++++++++++++++++++-------
 gtk/gtkshortcutsshortcut.h           |   36 +++++++++++++
 3 files changed, 111 insertions(+), 19 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 767ad26..f1d6bc5 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -8517,6 +8517,7 @@ gtk_shortcuts_group_get_type
 <SECTION>
 <FILE>gtkshortcutsshortcut</FILE>
 GtkShortcutsShortcut
+GtkShortcutType
 <SUBSECTION Standard>
 GTK_TYPE_SHORTCUTS_SHORTCUT
 GTK_SHORTCUTS_SHORTCUT
diff --git a/gtk/gtkshortcutsshortcut.c b/gtk/gtkshortcutsshortcut.c
index 16f0cde..6825c6c 100644
--- a/gtk/gtkshortcutsshortcut.c
+++ b/gtk/gtkshortcutsshortcut.c
@@ -29,9 +29,8 @@
  * @Title: GtkShortcutsShortcut
  * @Short_description: Represents a keyboard shortcut in a GtkShortcutsWindow
  *
- * A GtkShortcutsShortcut represents a single keyboard shortcut with
- * a short text. This widget is only meant to be used with
- * #GtkShortcutsWindow.
+ * A GtkShortcutsShortcut represents a single keyboard shortcut or gesture
+ * with a short text. This widget is only meant to be used with #GtkShortcutsWindow.
  */
 
 struct _GtkShortcutsShortcut
@@ -48,6 +47,7 @@ struct _GtkShortcutsShortcut
   GtkSizeGroup *title_size_group;
 
   GtkTextDirection direction;
+  GtkShortcutType  shortcut_type;
 };
 
 struct _GtkShortcutsShortcutClass
@@ -66,6 +66,7 @@ enum {
   PROP_ACCEL_SIZE_GROUP,
   PROP_TITLE_SIZE_GROUP,
   PROP_DIRECTION,
+  PROP_SHORTCUT_TYPE,
   LAST_PROP
 };
 
@@ -108,19 +109,7 @@ gtk_shortcuts_shortcut_set_subtitle (GtkShortcutsShortcut *self,
 {
   gtk_label_set_label (self->subtitle, subtitle);
   gtk_widget_set_visible (GTK_WIDGET (self->subtitle), subtitle != NULL);
-}
-
-static void
-update_icon_visible (GtkShortcutsShortcut *self)
-{
-  const gchar *accelerator;
-  gboolean show_accel;
-
-  accelerator = gtk_shortcut_label_get_accelerator (self->accelerator);
-  show_accel = accelerator && accelerator[0] != '\0';
-
-  gtk_widget_set_visible (GTK_WIDGET (self->accelerator), show_accel);
-  gtk_widget_set_visible (GTK_WIDGET (self->image), !show_accel);
+  g_object_notify (G_OBJECT (self), "subtitle");
 }
 
 static void
@@ -128,7 +117,6 @@ gtk_shortcuts_shortcut_set_accelerator (GtkShortcutsShortcut *self,
                                         const gchar          *accelerator)
 {
   gtk_shortcut_label_set_accelerator (self->accelerator, accelerator);
-  update_icon_visible (self);
 }
 
 static void
@@ -136,7 +124,6 @@ gtk_shortcuts_shortcut_set_icon (GtkShortcutsShortcut *self,
                                  GIcon                *gicon)
 {
   gtk_image_set_from_gicon (self->image, gicon, GTK_ICON_SIZE_DIALOG);
-  update_icon_visible (self);
 }
 
 static void
@@ -173,6 +160,57 @@ gtk_shortcuts_shortcut_direction_changed (GtkWidget        *widget,
 }
 
 static void
+gtk_shortcuts_shortcut_set_type (GtkShortcutsShortcut *self,
+                                 GtkShortcutType       type)
+{
+  if (self->shortcut_type == type)
+    return;
+
+  self->shortcut_type = type;
+
+  switch (type)
+    {
+    case GTK_SHORTCUT_GESTURE_PINCH:
+      gtk_image_set_from_resource (self->image, "/org/gtk/libgtk/gesture/pinch.png");
+      gtk_shortcuts_shortcut_set_subtitle (self, _("Two finger pinch"));
+      break;
+
+    case GTK_SHORTCUT_GESTURE_STRETCH:
+      gtk_image_set_from_resource (self->image, "/org/gtk/libgtk/gesture/stretch.png");
+      gtk_shortcuts_shortcut_set_subtitle (self, _("Two finger stretch"));
+      break;
+
+    case GTK_SHORTCUT_GESTURE_ROTATE_CLOCKWISE:
+      gtk_image_set_from_resource (self->image, "/org/gtk/libgtk/gesture/rotate-clockwise.png");
+      gtk_shortcuts_shortcut_set_subtitle (self, _("Rotate clockwise"));
+      break;
+
+    case GTK_SHORTCUT_GESTURE_ROTATE_COUNTERCLOCKWISE:
+      gtk_image_set_from_resource (self->image, "/org/gtk/libgtk/gesture/rotate-anticlockwise.png");
+      gtk_shortcuts_shortcut_set_subtitle (self, _("Rotate counterclockwise"));
+      break;
+
+    case GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_LEFT:
+      gtk_image_set_from_resource (self->image, "/org/gtk/libgtk/gesture/two-finger-swipe-left.png");
+      gtk_shortcuts_shortcut_set_subtitle (self, _("Two finger swipe left"));
+      break;
+
+    case GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_RIGHT:
+      gtk_image_set_from_resource (self->image, "/org/gtk/libgtk/gesture/two-finger-swipe-right.png");
+      gtk_shortcuts_shortcut_set_subtitle (self, _("Two finger swipe right"));
+      break;
+
+    default: ;
+    }
+
+  gtk_widget_set_visible (GTK_WIDGET (self->accelerator), type == GTK_SHORTCUT_ACCELERATOR);
+  gtk_widget_set_visible (GTK_WIDGET (self->image), type != GTK_SHORTCUT_ACCELERATOR);
+
+
+  g_object_notify (G_OBJECT (self), "shortcut-type");
+}
+
+static void
 gtk_shortcuts_shortcut_get_property (GObject    *object,
                                      guint       prop_id,
                                      GValue     *value,
@@ -207,6 +245,10 @@ gtk_shortcuts_shortcut_get_property (GObject    *object,
       g_value_set_enum (value, self->direction);
       break;
 
+    case PROP_SHORTCUT_TYPE:
+      g_value_set_enum (value, self->shortcut_type);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -250,6 +292,10 @@ gtk_shortcuts_shortcut_set_property (GObject      *object,
       gtk_shortcuts_shortcut_set_direction (self, g_value_get_enum (value));
       break;
 
+    case PROP_SHORTCUT_TYPE:
+      gtk_shortcuts_shortcut_set_type (self, g_value_get_enum (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -398,11 +444,19 @@ gtk_shortcuts_shortcut_class_init (GtkShortcutsShortcutClass *klass)
   properties[PROP_DIRECTION] =
     g_param_spec_enum ("direction",
                        P_("Direction"),
-                       P_("Direction"),
+                       P_("Text direction for which this shortcut is active"),
                        GTK_TYPE_TEXT_DIRECTION,
                        GTK_TEXT_DIR_NONE,
                        (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
 
+  properties[PROP_SHORTCUT_TYPE] =
+    g_param_spec_enum ("shortcut-type",
+                       P_("Shortcut Type"),
+                       P_("The type of shortcut that is represented"),
+                       GTK_TYPE_SHORTCUT_TYPE,
+                       GTK_SHORTCUT_ACCELERATOR,
+                       (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
+
   g_object_class_install_properties (object_class, LAST_PROP, properties);
 }
 
@@ -413,6 +467,7 @@ gtk_shortcuts_shortcut_init (GtkShortcutsShortcut *self)
   gtk_box_set_spacing (GTK_BOX (self), 12);
 
   self->direction = GTK_TEXT_DIR_NONE;
+  self->shortcut_type = GTK_SHORTCUT_ACCELERATOR;
 
   self->image = g_object_new (GTK_TYPE_IMAGE,
                               "visible", FALSE,
diff --git a/gtk/gtkshortcutsshortcut.h b/gtk/gtkshortcutsshortcut.h
index 57d76ad..435e1bf 100644
--- a/gtk/gtkshortcutsshortcut.h
+++ b/gtk/gtkshortcutsshortcut.h
@@ -34,6 +34,42 @@ G_BEGIN_DECLS
 typedef struct _GtkShortcutsShortcut      GtkShortcutsShortcut;
 typedef struct _GtkShortcutsShortcutClass GtkShortcutsShortcutClass;
 
+/**
+ * GtkShortcutType:
+ * @GTK_SHORTCUT_ACCELERATOR:
+ *   The shortcut is a keyboard accelerator. The #GtkShortcutsShortcut:accelerator
+ *   property will be used.
+ * @GTK_SHORTCUT_GESTURE_PINCH:
+ *   The shortcut is a pinch gesture. GTK+ provides and icon and subtitle.
+ * @GTK_SHORTCUT_GESTURE_STRETCH:
+ *   The shortcut is a stretch gesture. GTK+ provides and icon and subtitle.
+ * @GTK_SHORTCUT_GESTURE_ROTATE_CLOCKWISE:
+ *   The shortcut is a clockwise rotation gesture. GTK+ provides and icon and subtitle.
+ * @GTK_SHORTCUT_GESTURE_ROTATE_COUNTERCLOCKWISE:
+ *   The shortcut is a counterclockwise rotation gesture. GTK+ provides and icon and subtitle.
+ * @GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_LEFT:
+ *   The shortcut is a two-finger swipe gesture. GTK+ provides and icon and subtitle.
+ * @GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_RIGHT:
+ *   The shortcut is a two-finger swipe gesture. GTK+ provides and icon and subtitle.
+ * @GTK_SHORTCUT_GESTURE:
+ *   The shortcut is a gesture. The #GtkShortcutsShortcut:icon property will be
+ *   used.
+ *
+ * GtkShortcutType specifies the kind of shortcut that is being described.
+ * More values may be added to this enumeration over time.
+ *
+ * Since: 3.20
+ */
+typedef enum {
+  GTK_SHORTCUT_ACCELERATOR,
+  GTK_SHORTCUT_GESTURE_PINCH,
+  GTK_SHORTCUT_GESTURE_STRETCH,
+  GTK_SHORTCUT_GESTURE_ROTATE_CLOCKWISE,
+  GTK_SHORTCUT_GESTURE_ROTATE_COUNTERCLOCKWISE,
+  GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_LEFT,
+  GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_RIGHT,
+  GTK_SHORTCUT_GESTURE
+} GtkShortcutType;
 
 GDK_AVAILABLE_IN_3_20
 GType        gtk_shortcuts_shortcut_get_type (void) G_GNUC_CONST;


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