[gimp/wip/animation: 115/145] plug-ins: single-click on track title selects all, and double-click...



commit ce8183b583a785166bb586f4227c5856d740867c
Author: Jehan <jehan girinstud io>
Date:   Mon May 29 12:14:57 2017 +0200

    plug-ins: single-click on track title selects all, and double-click...
    
    ... to edit the title.
    In order to not trigger a select-all action on double click as well, I
    delay it though I'm really not sure it's a good experience to do so.
    Maybe I will review this later.

 .../widgets/animation-editable-label.c             |   48 +++++++++++--
 plug-ins/animation-play/widgets/animation-xsheet.c |   74 ++++++++++++++++++++
 2 files changed, 117 insertions(+), 5 deletions(-)
---
diff --git a/plug-ins/animation-play/widgets/animation-editable-label.c 
b/plug-ins/animation-play/widgets/animation-editable-label.c
index f8023bf..85d6bd8 100644
--- a/plug-ins/animation-play/widgets/animation-editable-label.c
+++ b/plug-ins/animation-play/widgets/animation-editable-label.c
@@ -34,6 +34,7 @@ enum
 
 enum
 {
+  ALTERNATE_ACTION,
   PREPARE_EDITING,
   EDITING,
   LAST_SIGNAL
@@ -63,6 +64,7 @@ static void animation_editable_label_get_property  (GObject              *object
                                                     GValue               *value,
                                                     GParamSpec           *pspec);
 
+static gboolean animation_editable_label_alternate_click (gpointer        user_data);
 static gboolean animation_editable_label_clicked   (GtkWidget            *widget,
                                                     GdkEvent             *event,
                                                     gpointer              user_data);
@@ -78,6 +80,15 @@ animation_editable_label_class_init (AnimationEditableLabelClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  animation_editable_label_signals[ALTERNATE_ACTION] =
+    g_signal_new ("alternate-action",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_FIRST,
+                  0,
+                  NULL, NULL,
+                  NULL,
+                  G_TYPE_NONE,
+                  0);
   animation_editable_label_signals[PREPARE_EDITING] =
     g_signal_new ("prepare-editing",
                   G_TYPE_FROM_CLASS (klass),
@@ -238,17 +249,44 @@ animation_editable_label_get_property (GObject    *object,
 }
 
 static gboolean
+animation_editable_label_alternate_click (gpointer user_data)
+{
+  AnimationEditableLabel *label = ANIMATION_EDITABLE_LABEL (user_data);
+
+  if (! label->priv->is_editing)
+    g_signal_emit (label, animation_editable_label_signals[ALTERNATE_ACTION],
+                   0, NULL);
+
+  return FALSE;
+}
+
+static gboolean
 animation_editable_label_clicked (GtkWidget *widget,
                                   GdkEvent  *event,
                                   gpointer   user_data)
 {
   AnimationEditableLabel *label = ANIMATION_EDITABLE_LABEL (user_data);
 
-  g_signal_emit (label, animation_editable_label_signals[PREPARE_EDITING],
-                 0, NULL);
-  animation_editable_label_set_editing (label, TRUE);
-  g_signal_emit (label, animation_editable_label_signals[EDITING],
-                 0, NULL);
+  if (event->type == GDK_BUTTON_PRESS)
+    {
+      gint time;
+
+      g_object_get (gtk_settings_get_for_screen (gdk_screen_get_default ()),
+                    "gtk-double-click-time", &time,
+                    NULL);
+      /* Do not run the alternate action immediately because we want
+       * it to be ignored on a double click. */
+      g_timeout_add (time, animation_editable_label_alternate_click,
+                             label);
+    }
+  else if (event->type == GDK_2BUTTON_PRESS)
+    {
+      g_signal_emit (label, animation_editable_label_signals[PREPARE_EDITING],
+                     0, NULL);
+      animation_editable_label_set_editing (label, TRUE);
+      g_signal_emit (label, animation_editable_label_signals[EDITING],
+                     0, NULL);
+    }
 
   return TRUE;
 }
diff --git a/plug-ins/animation-play/widgets/animation-xsheet.c 
b/plug-ins/animation-play/widgets/animation-xsheet.c
index a60abb4..87820ef 100755
--- a/plug-ins/animation-play/widgets/animation-xsheet.c
+++ b/plug-ins/animation-play/widgets/animation-xsheet.c
@@ -228,6 +228,11 @@ static gboolean merge_suites                         (gint                    *k
 static gint     compare_keys                         (gint                    *key1,
                                                       gint                    *key2);
 
+static void     animation_xsheet_select_all          (AnimationXSheet         *xsheet,
+                                                      gint                     level);
+static gboolean animation_xsheet_title_clicked       (GtkWidget               *title,
+                                                      gpointer                 user_data);
+
 G_DEFINE_TYPE (AnimationXSheet, animation_xsheet, GTK_TYPE_SCROLLED_WINDOW)
 
 #define parent_class animation_xsheet_parent_class
@@ -486,6 +491,9 @@ animation_xsheet_add_headers (AnimationXSheet *xsheet,
                     "notify::text",
                     G_CALLBACK (animation_xsheet_track_title_updated),
                     xsheet);
+  g_signal_connect (frame, "alternate-action",
+                    G_CALLBACK (animation_xsheet_title_clicked),
+                    xsheet);
   gtk_widget_show (frame);
 
   /* Style a bit the title label. */
@@ -2360,3 +2368,69 @@ compare_keys (gint *key1,
 
   return retval;
 }
+
+static void
+animation_xsheet_select_all (AnimationXSheet *xsheet,
+                             gint             level)
+{
+  GList *track_iter;
+  GList *frame_iter;
+  gint   i;
+
+  if (xsheet->priv->selected_track >= 0 &&
+      xsheet->priv->selected_track != level)
+    {
+      /* Reset current selection. */
+      GList *track_iter;
+      GList *frame_iter;
+
+      for (track_iter = xsheet->priv->cels; track_iter; track_iter = track_iter->next)
+        {
+          for (frame_iter = track_iter->data; frame_iter; frame_iter = frame_iter->next)
+            {
+              gtk_toggle_button_set_active (frame_iter->data, FALSE);
+            }
+        }
+    }
+  g_queue_clear (xsheet->priv->selected_frames);
+  xsheet->priv->selected_track = level;
+
+  track_iter = g_list_nth (xsheet->priv->cels, level);
+  frame_iter = track_iter->data;
+  for (i = 0; frame_iter; frame_iter = frame_iter->next, i++)
+    {
+      g_queue_push_head (xsheet->priv->selected_frames,
+                         GINT_TO_POINTER (i));
+      gtk_toggle_button_set_active (frame_iter->data, TRUE);
+    }
+
+  /* Finally update the layer view. */
+  if (g_queue_is_empty (xsheet->priv->selected_frames))
+    {
+      animation_layer_view_select (ANIMATION_LAYER_VIEW (xsheet->priv->layer_view),
+                                   NULL);
+    }
+  else
+    {
+      const GList *layers;
+
+      /* Show layers of position 0. */
+      layers = animation_cel_animation_get_layers (xsheet->priv->animation,
+                                                   level, 0);
+      animation_layer_view_select (ANIMATION_LAYER_VIEW (xsheet->priv->layer_view),
+                                   layers);
+    }
+}
+
+static gboolean
+animation_xsheet_title_clicked (GtkWidget *title_label,
+                                gpointer   user_data)
+{
+  gpointer track_num;
+
+  track_num = g_object_get_data (G_OBJECT (title_label), "track-num");
+  animation_xsheet_select_all (ANIMATION_XSHEET (user_data),
+                               GPOINTER_TO_INT (track_num));
+
+  return TRUE;
+}


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