ocarina: Add keyboard shortcuts to the library treeview

Delete deletes the selected library path, plus opens the chooser to add
a new path.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-08-13 08:18:13 -04:00
parent 448acf1181
commit 01d8eb15d8
2 changed files with 39 additions and 6 deletions

View File

@ -49,6 +49,19 @@ static libsaria::library::Path *find_path(gchar *path)
return lib_path;
}
static libsaria::library::Path *get_selected_path(GtkWidget *treeview)
{
GtkTreeIter iter;
GtkTreeModel *model = GTK_TREE_MODEL(get_list());
GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
libsaria::library::Path *path;
if (!gtk_tree_selection_get_selected(sel, &model, &iter))
return NULL;
gtk_tree_model_get(model, &iter, 0, &path, -1);
return path;
}
void LibraryDriver::path_updated(libsaria::library::Path *path)
{
GtkTreeIter iter;
@ -104,9 +117,29 @@ static void path_toggled(GtkCellRendererToggle *toggle, gchar *path, gpointer d)
libsaria::library::hide_path(lib_path);
}
static gboolean key_pressed(GtkWidget *treeview, GdkEvent *event, gpointer data)
{
libsaria::library::Path *path;
string key = gdk_keyval_name(event->key.keyval);
println("Library settings handling key press: " + key);
path = get_selected_path(treeview);
if (!path)
return FALSE;
if (key == "Delete")
libsaria::library::delete_path(path);
else if (key == "plus" || key == "KP_Add")
add_library(NULL, NULL);
else
return FALSE;
return TRUE;
}
void init_library()
{
connect_signal("AddLibrary", "clicked", G_CALLBACK(add_library), NULL);
connect_signal("UpdateLibraries", "clicked", G_CALLBACK(libsaria::library::update_all), NULL);
connect_signal("LibraryToggle", "toggled", G_CALLBACK(path_toggled), NULL);
connect_signal("LibraryView", "key-press-event", G_CALLBACK(key_pressed), NULL);
}

View File

@ -81,6 +81,11 @@
<action-widget response="-5">button2</action-widget>
</action-widgets>
</object>
<object class="GtkAdjustment" id="PauseAdjustment">
<property name="upper">256</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="MainWindow">
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -451,7 +456,7 @@
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="GtkTreeView" id="treeview1">
<object class="GtkTreeView" id="LibraryView">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">LibraryList</property>
@ -653,9 +658,4 @@
</object>
</child>
</object>
<object class="GtkAdjustment" id="PauseAdjustment">
<property name="upper">256</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
</interface>