[sound-juicer] Add SjTreeView::play-cursor-row and SjTreeView::play-row



commit efd8fb1464b9e6d3f92dae6876de23551baec0d0
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Mon Aug 4 10:54:37 2014 +0100

    Add SjTreeView::play-cursor-row and SjTreeView::play-row
    
    As SjTreeView::move-cursor restricts keyboard cursor movements to
    activatable/editable columns it's no longer possible to play the track
    under the treeview cursor with the keyboard. Add two signals to fix
    this: 'play-row' for playing the specified path and 'play-cursor-row'
    for playing the cursor row. 'play-cursor-row' is bound to
    Control-Space.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=151469

 data/sound-juicer.ui |    1 +
 src/sj-tree-view.c   |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 src/sj-tree-view.h   |    2 ++
 3 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/data/sound-juicer.ui b/data/sound-juicer.ui
index 13d288a..72cd14c 100644
--- a/data/sound-juicer.ui
+++ b/data/sound-juicer.ui
@@ -428,6 +428,7 @@
                     </child>
                     <signal name="cursor_changed" handler="on_tracklist_row_selected"/>
                     <signal name="row_activated" handler="on_tracklist_row_activate"/>
+                    <signal name="play_row" handler="on_tracklist_row_activate"/>
                   </object>
                 </child>
               </object>
diff --git a/src/sj-tree-view.c b/src/sj-tree-view.c
index 472e5f9..9cc23ab 100644
--- a/src/sj-tree-view.c
+++ b/src/sj-tree-view.c
@@ -21,8 +21,27 @@
 
 static GtkTreeViewClass *parent_class;
 
+enum {
+  PLAY_ROW,
+  PLAY_CURSOR_ROW,
+  SIGNAL_LAST
+};
+
+static guint signals[SIGNAL_LAST];
+
 G_DEFINE_TYPE (SjTreeView, sj_tree_view, GTK_TYPE_TREE_VIEW);
 
+static void
+sj_tree_view_play_curent_row (SjTreeView *self)
+{
+  GtkTreePath *path;
+
+  gtk_tree_view_get_cursor (GTK_TREE_VIEW (self), &path, NULL);
+  if (path != NULL)
+    g_signal_emit (self, signals[PLAY_ROW], 0, path);
+  gtk_tree_path_free (path);
+}
+
 /**
  * Find out if the focused cell is being edited
  */
@@ -434,8 +453,28 @@ sj_tree_view_class_init (SjTreeViewClass *class)
 
   widget_class->key_press_event = sj_tree_view_key_press;
   tree_class->move_cursor = sj_tree_view_move_cursor;
-
-  /* Keybindings - Ctrl-Tab moves focus */
+  class->play_cursor_row = sj_tree_view_play_curent_row;
+
+  signals[PLAY_ROW] =
+    g_signal_new ("play-row",
+                  G_TYPE_FROM_CLASS (class),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (SjTreeViewClass, play_row),
+                  NULL, NULL,
+                  g_cclosure_marshal_generic,
+                  G_TYPE_NONE, 1,
+                  GTK_TYPE_TREE_PATH);
+
+  signals[PLAY_CURSOR_ROW] =
+    g_signal_new ("play-cursor-row",
+                  G_TYPE_FROM_CLASS (class),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                  G_STRUCT_OFFSET (SjTreeViewClass, play_cursor_row),
+                  NULL, NULL,
+                  g_cclosure_marshal_generic,
+                  G_TYPE_NONE, 0);
+
+  /* Keybindings - Ctrl-Tab moves focus, Ctrl-Spaces plays current row */
 
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, GDK_CONTROL_MASK,
                                 "move-focus", 1,
@@ -460,6 +499,12 @@ sj_tree_view_class_init (SjTreeViewClass *class)
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Left_Tab, GDK_CONTROL_MASK,
                                 "move-focus", 1,
                                 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
+
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
+                                "play-cursor-row", 0);
+
+  gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
+                                "play-cursor-row", 0);
 }
 
 GtkWidget*
diff --git a/src/sj-tree-view.h b/src/sj-tree-view.h
index ff3729c..da72fd6 100644
--- a/src/sj-tree-view.h
+++ b/src/sj-tree-view.h
@@ -38,6 +38,8 @@ typedef struct _SjTreeView SjTreeView;
 struct _SjTreeViewClass
 {
   GtkTreeViewClass parent_class;
+  void             (*play_row)(SjTreeView*, GtkTreePath*);
+  void             (*play_cursor_row)(SjTreeView*);
 };
 
 struct _SjTreeView


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