From 066d27a240e0a3de58ee56ffbb88b18af858fda2 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 26 Dec 2015 11:31:57 -0500 Subject: [PATCH] gui/window: Move keyboard shortcut handling into tabs.cpp I handle the Escape key through gtkbuilder, so let's move the tab-changing keys into the tabs source file. Signed-off-by: Anna Schumaker --- gui/tabs.cpp | 34 ++++++++++++++++++++++++++++++++++ gui/window.cpp | 35 ----------------------------------- share/ocarina/QueueToolbar.ui | 3 +-- share/ocarina/ocarina6.glade | 3 ++- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/gui/tabs.cpp b/gui/tabs.cpp index f1cfc488..78fd1960 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -434,8 +434,39 @@ static void init_menu_item(const std::string &pq, unsigned int n) sigc::bind (sigc::ptr_fun(on_add_to_queue), n)); } +static bool on_window_key_pressed(GdkEventKey *event) +{ + Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false); + std::string key = gdk_keyval_name(event->keyval); + + if (key.size() >= 3) { + if (key.substr(0, 3) == "KP_") + key = key.substr(3); + } + + if (key == "slash") + tab_focus_search(); + else if (key >= "0" && key <= "9") { + unsigned int n = atoi(key.c_str()); + if (n < tempq_count()) + notebook->set_current_page(n); + } else if (key == "c") + notebook->set_current_page(tempq_count()); + else if (key == "h") + notebook->set_current_page(tempq_count() + 1); + else if (key == "m") + notebook->set_current_page(tempq_count() + 3); + else if (key == "p") + notebook->set_current_page(tempq_count() + 2); + else + return false; + return true; +} + + void init_tabs() { + Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false); /* Notebook signals */ struct Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false); notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); @@ -458,6 +489,9 @@ void init_tabs() init_history_tab(); init_collection_tab(); init_queue_tabs(); + + /* Setup keyboard shortcuts */ + window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed)); } void post_init_tabs() diff --git a/gui/window.cpp b/gui/window.cpp index 91fbde3c..64c7d259 100644 --- a/gui/window.cpp +++ b/gui/window.cpp @@ -12,47 +12,12 @@ extern "C" { const std::string appname = "Ocarina "; -static bool on_window_key_pressed(GdkEventKey *event) -{ - Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false); - Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false); - std::string key = gdk_keyval_name(event->keyval); - - 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") - tab_focus_search(); - else if (key >= "0" && key <= "9") { - unsigned int n = atoi(key.c_str()); - if (n < tempq_count()) - notebook->set_current_page(n); - } else if (key == "c") - notebook->set_current_page(tempq_count()); - else if (key == "h") - notebook->set_current_page(tempq_count() + 1); - else if (key == "m") - notebook->set_current_page(tempq_count() + 3); - else if (key == "p") - notebook->set_current_page(tempq_count() + 2); - else - return false; - return true; -} - Gtk::Window *window_init() { Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false); - window->set_can_focus(); window->set_title(appname + get_version()); window->set_icon_from_file(gui :: share_file("ocarina.png")); - window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed)); - return window; } diff --git a/share/ocarina/QueueToolbar.ui b/share/ocarina/QueueToolbar.ui index efeb8ff5..625cc3cd 100644 --- a/share/ocarina/QueueToolbar.ui +++ b/share/ocarina/QueueToolbar.ui @@ -1,5 +1,5 @@ - + @@ -26,7 +26,6 @@ True True - True False diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index 71d1b5f9..81b562c5 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -212,7 +212,7 @@ True - False + True Ocarina 6.1.3 1024 683 @@ -1011,5 +1011,6 @@ Manager +