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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-04 08:27:30 -05:00
parent 7439a2a73d
commit 9ee00f9997
4 changed files with 29 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include <core/tempq.h>
#include <gui/builder.h>
#include <gui/collection.h>
#include <gui/sidebar.h>
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);

View File

@ -4,6 +4,7 @@
#include <core/tempq.h>
#include <gui/builder.h>
#include <gui/playlist.h>
#include <gui/sidebar.h>
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);
}
}

View File

@ -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");
}

View File

@ -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 */