gui/treeview: Add a row-activated signal handler

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-24 09:06:43 -04:00
parent 730395aeff
commit dbc1df154a
6 changed files with 34 additions and 25 deletions

View File

@ -7,6 +7,7 @@
#include <gui/artwork.h>
#include <gui/audio.h>
#include <gui/idle.h>
#include <gui/treeview.h>
#include <gui/view.h>
#include <gui/window.h>
@ -38,7 +39,7 @@ static void __audio_load(struct track *track)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")),
playlist_has(PL_SYSTEM, "Favorites", track));
gui_view_scroll();
gui_treeview_scroll();
gui_artwork_set_cover();
gui_idle_enable();
}

View File

@ -20,6 +20,7 @@ static const enum compare_t GUI_COL_MAP[GUI_MODEL_N_COLUMNS] = {
static unsigned int sort_count = 0;
static gchar *sort_text = NULL;
static bool can_scroll = true;
static int __gui_treeview_colum_match_sort(enum compare_t compare)
{
@ -138,6 +139,14 @@ static void __gui_treeview_column_clicked(GtkTreeViewColumn *col,
g_timeout_add_seconds(3, __gui_treeview_dec_sort, NULL);
}
void __gui_treeview_row_activated(GtkTreeView *treeview, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer data)
{
can_scroll = false;
gui_filter_path_load_track(path);
can_scroll = true;
}
void gui_treeview_init()
{
GtkTreeViewColumn *col;
@ -175,11 +184,13 @@ void gui_treeview_scroll()
{
struct playlist *playlist = gui_model_get_playlist();
GtkTreePath *path;
int pos;
if (!playlist || (int)playlist->pl_queue.q_cur.it_pos < 0)
pos = playlist ? playlist->pl_queue.q_cur.it_pos : -1;
if (!can_scroll || pos < 0)
return;
path = gui_filter_path_from_index(playlist->pl_queue.q_cur.it_pos);
path = gui_filter_path_from_index(pos);
if (!path)
return;

View File

@ -25,7 +25,6 @@ static const gchar *QUEUE_SETTINGS[GUI_MODEL_N_COLUMNS] = {
};
static GtkTreeView *view_treeview = NULL;
static bool view_no_scroll = false;
static unsigned int __view_get_column_index(GtkTreeViewColumn *col)
{
@ -42,16 +41,6 @@ static unsigned int __view_get_column_index(GtkTreeViewColumn *col)
return GUI_MODEL_N_COLUMNS;
}
void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer data)
{
view_no_scroll = true;
audio_load(gui_filter_path_get_track(path));
queue_selected(&gui_model_get_playlist()->pl_queue,
gtk_tree_path_get_indices(path)[0]);
view_no_scroll = false;
}
void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec,
gpointer data)
{
@ -302,9 +291,3 @@ void gui_view_set_playlist(struct playlist *playlist)
{
gui_treeview_set_playlist(playlist);
}
void gui_view_scroll()
{
if (!view_no_scroll)
gui_treeview_scroll();
}

View File

@ -9,9 +9,6 @@
/* Called to initialize structures needed by the treeview. */
void gui_view_init();
/* Called to scroll the GUI treeview to the queue's current position. */
void gui_view_scroll();
/* Called to set the currently displayed model. */
void gui_view_set_playlist(struct playlist *);

View File

@ -885,7 +885,7 @@ audio-volume-medium</property>
<property name="tooltip_column">9</property>
<signal name="button-press-event" handler="__view_button_press" swapped="no"/>
<signal name="key-press-event" handler="__view_keypress" swapped="no"/>
<signal name="row-activated" handler="__view_row_activated" swapped="no"/>
<signal name="row-activated" handler="__gui_treeview_row_activated" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection5">
<property name="mode">multiple</property>

View File

@ -1,6 +1,7 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/core.h>
#include <core/idle.h>
#include <gui/filter.h>
@ -8,7 +9,19 @@
#include <gui/treeview.h>
#include <tests/test.h>
struct core_init_data init_data = {};
static void test_load(struct track *track) { }
static void test_state_change(GstState state) {}
static void test_config_pause(int count) {}
struct audio_ops test_audio_ops = {
.on_load = test_load,
.on_state_change = test_state_change,
.on_config_pause = test_config_pause,
};
struct core_init_data init_data = {
.audio_ops = &test_audio_ops,
};
void test_treeview_init()
{
@ -39,6 +52,10 @@ void test_treeview_init()
gtk_tree_view_get_cursor(gui_treeview(), &path, NULL);
g_assert_nonnull(path);
g_assert_cmpuint(gui_filter_path_get_track(path)->tr_track, ==, 5);
gtk_tree_view_row_activated(gui_treeview(), path, NULL);
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 5);
gtk_tree_path_free(path);
}
void test_treeview_sort()