gui: Configure more keyboard shortcuts

- Number keys to switch pages
- c, h, p, m to switch to collection, history, playlist and collection
  manager tabs.
- Slash key to focus on the search entry

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2014-02-07 21:27:47 -05:00 committed by Anna Schumaker
parent 2957ea01d4
commit 38c0009acd
3 changed files with 41 additions and 0 deletions

View File

@ -335,6 +335,7 @@ public:
void on_sidebar_cursor_changed();
bool on_sidebar_clicked(GdkEventButton *);
bool on_view_button_pressed(GdkEventButton *);
void on_focus_search();
};
@ -750,6 +751,11 @@ bool OcarinaPage::on_view_button_pressed(GdkEventButton *button)
return true;
}
void OcarinaPage::on_focus_search()
{
page_entry.grab_focus();
}
/*
@ -873,6 +879,17 @@ static void init_menu_item(const std::string &name, unsigned int num)
sigc::ptr_fun(on_add_to_queue), num));
}
void focus_tab_search()
{
std::map<Playqueue *, OcarinaPage *>::iterator it;
for (it = tab_map.begin(); it != tab_map.end(); it++) {
if (it->second->is_current_tab()) {
it->second->on_focus_search();
return;
}
}
}
void init_tabs()
{
Gtk::Notebook *notebook;

View File

@ -3,6 +3,7 @@
*/
#include <audio.h>
#include <callback.h>
#include <deck.h>
#include <idle.h>
#include <library.h>
#include <playlist.h>
@ -145,16 +146,38 @@ static void on_fav_toggled()
*/
static bool on_window_key_pressed(GdkEventKey *event)
{
Gtk::Notebook *notebook;
Gtk::Window *window;
std::string key = gdk_keyval_name(event->keyval);
builder->get_widget("o_window", window);
builder->get_widget("o_notebook", notebook);
if (key.size() >= 3) {
if (key.substr(0, 3) == "KP_")
key = key.substr(3);
}
if (key == "Escape")
window->set_focus(*window);
else if (key == "slash")
focus_tab_search();
else if (key >= "0" && key <= "9") {
unsigned int n = atoi(key.c_str());
if (n < deck::size())
notebook->set_current_page(n);
} else if (key == "c")
notebook->set_current_page(deck::size());
else if (key == "h")
notebook->set_current_page(deck::size() + 1);
else if (key == "m")
notebook->set_current_page(deck::size() + 3);
else if (key == "n")
on_next();
else if (key == "N")
audio :: previous();
else if (key == "p")
notebook->set_current_page(deck::size() + 2);
else if (key == "q")
queue_selected(false);
else if (key == "s")

View File

@ -50,6 +50,7 @@ public:
/* tabs.cpp */
void queue_selected(bool);
void focus_tab_search();
void init_tabs();
void init_tabs2();
void cleanup_tabs();