47 lines
928 B
C++
47 lines
928 B
C++
|
|
#include <gdk/gdk.h>
|
|
#include <ocarina/shortcut.h>
|
|
#include <ocarina/window.h>
|
|
#include <ocarina/header.h>
|
|
#include <libsaria/print.h>
|
|
|
|
#include <map>
|
|
#include <string>
|
|
using namespace std;
|
|
|
|
static map<string, void (*)()> shortcut_map;
|
|
|
|
void register_shortcut(string key, void (*func)())
|
|
{
|
|
shortcut_map[key] = func;
|
|
}
|
|
|
|
/*
|
|
* Returns FALSE to allow other functions to run
|
|
* Returns TRUE if other handlers should not be run
|
|
*/
|
|
gboolean handle_shortcut(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|
{
|
|
string key = gdk_keyval_name(event->key.keyval);
|
|
map<string, void (*)()>::iterator it;
|
|
|
|
if (key == "Escape") {
|
|
window_focus();
|
|
return TRUE;
|
|
}
|
|
|
|
/* Don't run shortcuts if user is filtering */
|
|
if (entry_focused() == true)
|
|
return FALSE;
|
|
|
|
it = shortcut_map.find(key);
|
|
if (it == shortcut_map.end()) {
|
|
print("No function registered for key: ");
|
|
println(key);
|
|
return FALSE;
|
|
}
|
|
|
|
it->second();
|
|
return TRUE;
|
|
}
|