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 <Anna@OcarinaProject.net>
This commit is contained in:
parent
70dca79b41
commit
066d27a240
34
gui/tabs.cpp
34
gui/tabs.cpp
|
@ -434,8 +434,39 @@ static void init_menu_item(const std::string &pq, unsigned int n)
|
||||||
sigc::bind<unsigned int> (sigc::ptr_fun(on_add_to_queue), n));
|
sigc::bind<unsigned int> (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()
|
void init_tabs()
|
||||||
{
|
{
|
||||||
|
Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false);
|
||||||
/* Notebook signals */
|
/* Notebook signals */
|
||||||
struct Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false);
|
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));
|
notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page));
|
||||||
|
@ -458,6 +489,9 @@ void init_tabs()
|
||||||
init_history_tab();
|
init_history_tab();
|
||||||
init_collection_tab();
|
init_collection_tab();
|
||||||
init_queue_tabs();
|
init_queue_tabs();
|
||||||
|
|
||||||
|
/* Setup keyboard shortcuts */
|
||||||
|
window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed));
|
||||||
}
|
}
|
||||||
|
|
||||||
void post_init_tabs()
|
void post_init_tabs()
|
||||||
|
|
|
@ -12,47 +12,12 @@ extern "C" {
|
||||||
|
|
||||||
const std::string appname = "Ocarina ";
|
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_init()
|
||||||
{
|
{
|
||||||
Gtk::Window *window = Glib :: wrap(GTK_WINDOW(gui_builder_widget("o_window")), false);
|
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_title(appname + get_version());
|
||||||
window->set_icon_from_file(gui :: share_file("ocarina.png"));
|
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;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.18.3 -->
|
<!-- Generated with glade 3.19.0 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.12"/>
|
<requires lib="gtk+" version="3.12"/>
|
||||||
<object class="GtkBox" id="QueueToolbar">
|
<object class="GtkBox" id="QueueToolbar">
|
||||||
|
@ -26,7 +26,6 @@
|
||||||
<object class="GtkSwitch" id="q_switch">
|
<object class="GtkSwitch" id="q_switch">
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="active">True</property>
|
<property name="active">True</property>
|
||||||
<property name="state">True</property>
|
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
|
|
@ -212,7 +212,7 @@
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkWindow" id="o_window">
|
<object class="GtkWindow" id="o_window">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="title" translatable="yes">Ocarina 6.1.3</property>
|
<property name="title" translatable="yes">Ocarina 6.1.3</property>
|
||||||
<property name="default_width">1024</property>
|
<property name="default_width">1024</property>
|
||||||
<property name="default_height">683</property>
|
<property name="default_height">683</property>
|
||||||
|
@ -1011,5 +1011,6 @@ Manager</property>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<accelerator key="Escape" signal="grab-focus"/>
|
||||||
</object>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
Loading…
Reference in New Issue