From 9ee00f99971192c3da53667467033463a0e5f50d Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 4 Jan 2016 08:27:30 -0500 Subject: [PATCH] gui/sidebar: Add a function for deselecting treeviews I'm using multiple treeviews, but only one should be selected at any time. Use this function to coordinate that. Signed-off-by: Anna Schumaker --- gui/collection.c | 3 +++ gui/playlist.c | 2 ++ gui/sidebar.c | 16 ++++++++++++++++ include/gui/sidebar.h | 8 ++++++++ 4 files changed, 29 insertions(+) diff --git a/gui/collection.c b/gui/collection.c index 14a9a071..1336f231 100644 --- a/gui/collection.c +++ b/gui/collection.c @@ -6,6 +6,7 @@ #include #include #include +#include enum collection_sidebar_columns { C_SB_IMAGE, @@ -126,6 +127,8 @@ void __collection_selection_changed(GtkTreeSelection *selection, if (gtk_tree_selection_get_selected(selection, &c_model, &iter)) { gtk_notebook_set_current_page(notebook, tempq_count() + 3); library = __collection_get_library(&iter); + + gui_sidebar_selected(SB_COLLECTION); if (library) gtk_file_chooser_set_current_folder(chooser, library->li_path); diff --git a/gui/playlist.c b/gui/playlist.c index 665c52f6..25e095f7 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -4,6 +4,7 @@ #include #include #include +#include enum playlist_sidebar_columns { P_SB_IMAGE, @@ -43,6 +44,7 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data) gtk_tree_model_get(model, &iter, P_SB_PLAYLIST, &p_cur, -1); gtk_notebook_set_current_page(notebook, tempq_count() + 2); + gui_sidebar_selected(SB_PLAYLIST); playlist_select(p_cur); } } diff --git a/gui/sidebar.c b/gui/sidebar.c index d5dbe3f8..7bb41893 100644 --- a/gui/sidebar.c +++ b/gui/sidebar.c @@ -12,6 +12,14 @@ void __sidebar_resize(GtkPaned *pane, GParamSpec *pspec, gpointer data) gui_settings_set(SIDEBAR_SETTING, gtk_paned_get_position(pane)); } +void __sidebar_deselect(const gchar *widget) +{ + GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget(widget)); + GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); + + gtk_tree_selection_unselect_all(selection); +} + void gui_sidebar_init() { GtkPaned *pane = GTK_PANED(gui_builder_widget("o_sidebar")); @@ -20,3 +28,11 @@ void gui_sidebar_init() if (pos > 0) gtk_paned_set_position(pane, pos); } + +void gui_sidebar_selected(enum sidebar_selection_t selected) +{ + if (selected != SB_COLLECTION) + __sidebar_deselect("o_collection_view"); + if (selected != SB_PLAYLIST) + __sidebar_deselect("o_playlist_view"); +} diff --git a/include/gui/sidebar.h b/include/gui/sidebar.h index add25c61..43088e5a 100644 --- a/include/gui/sidebar.h +++ b/include/gui/sidebar.h @@ -4,7 +4,15 @@ #ifndef OCARINA_GUI_SIDEBAR_H #define OCARINA_GUI_SIDEBAR_H +enum sidebar_selection_t { + SB_COLLECTION, + SB_PLAYLIST, +}; + /* Called to initialize the sidebar. */ void gui_sidebar_init(); +/* Called to tell the sidebar that the selection has changed. */ +void gui_sidebar_selected(enum sidebar_selection_t); + #endif /* OCARINA_GUI_SIDEBAR_H */