summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2014-12-16 15:44:34 +0200
committerYakov Goldberg <yakov.g@samsung.com>2014-12-21 11:59:52 +0200
commit188ad46baca60e2da95f583007987a63a9603710 (patch)
tree0a61a4f740105b706bc700a0779b1022f0bfe4c4 /src/bin
parent8700fa0c5aa9de9c28717c234bbb442861ef631e (diff)
Adding key bindings
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/egui_gui/CMakeLists.txt1
-rw-r--r--src/bin/egui_gui/editor.c30
-rw-r--r--src/bin/egui_gui/key_bindings.c135
-rw-r--r--src/bin/egui_gui/key_bindings.h15
4 files changed, 178 insertions, 3 deletions
diff --git a/src/bin/egui_gui/CMakeLists.txt b/src/bin/egui_gui/CMakeLists.txt
index 8c6fe62..b784c9c 100644
--- a/src/bin/egui_gui/CMakeLists.txt
+++ b/src/bin/egui_gui/CMakeLists.txt
@@ -69,6 +69,7 @@ add_executable(${TARGET}
69 settings_view.c 69 settings_view.c
70 editor.c 70 editor.c
71 dnd.c 71 dnd.c
72 key_bindings.c
72 ) 73 )
73 74
74add_dependencies(${TARGET} erigo_cmd) 75add_dependencies(${TARGET} erigo_cmd)
diff --git a/src/bin/egui_gui/editor.c b/src/bin/egui_gui/editor.c
index e6d2658..ed34557 100644
--- a/src/bin/egui_gui/editor.c
+++ b/src/bin/egui_gui/editor.c
@@ -12,6 +12,7 @@
12#include "itemview.h" 12#include "itemview.h"
13#include "propview.h" 13#include "propview.h"
14#include "cbview.h" 14#include "cbview.h"
15#include "key_bindings.h"
15 16
16#include "dnd.h" 17#include "dnd.h"
17 18
@@ -2433,6 +2434,7 @@ _editor_undo(const Gui_Context *ctx)
2433 const Gui_Memento *memento, *head_memento, *tmp; 2434 const Gui_Memento *memento, *head_memento, *tmp;
2434 /* Save head memento for post function. */ 2435 /* Save head memento for post function. */
2435 head_memento = memento = gui_context_current_memento_get(ctx); 2436 head_memento = memento = gui_context_current_memento_get(ctx);
2437 if (!memento) return EINA_FALSE;
2436 2438
2437 /* Find last element of the list */ 2439 /* Find last element of the list */
2438 tmp = gui_memento_next(memento); 2440 tmp = gui_memento_next(memento);
@@ -2641,9 +2643,7 @@ _editor_redo(const Gui_Context *ctx)
2641{ 2643{
2642 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE); 2644 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, EINA_FALSE);
2643 const Gui_Memento *memento, *head_memento; 2645 const Gui_Memento *memento, *head_memento;
2644 gui_context_memento_next((Gui_Context *) ctx); 2646 head_memento = memento = gui_context_memento_next((Gui_Context *) ctx);
2645 /* Save head memento for post function. */
2646 head_memento = memento = gui_context_current_memento_get(ctx);
2647 2647
2648 while (memento) 2648 while (memento)
2649 { 2649 {
@@ -3089,6 +3089,7 @@ editor_shutdown()
3089 free(di); 3089 free(di);
3090 drop_target_wdg_del(NULL, g->main_win->canvas_bg); 3090 drop_target_wdg_del(NULL, g->main_win->canvas_bg);
3091 3091
3092 key_bindings_shutdown();
3092 target_db_shutdown(); 3093 target_db_shutdown();
3093 proplayout_shutdown(); 3094 proplayout_shutdown();
3094 objtree_shutdown(); 3095 objtree_shutdown();
@@ -4115,6 +4116,24 @@ _update_undo_redo_buttons(void *data EINA_UNUSED)
4115 elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE); 4116 elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);
4116} 4117}
4117 4118
4119static void
4120_key_binding_undo_cb(void *data EINA_UNUSED)
4121{
4122 _editor_undo(_active_context_get());
4123}
4124
4125static void
4126_key_binding_redo_cb(void *data EINA_UNUSED)
4127{
4128 _editor_redo(_active_context_get());
4129}
4130
4131static void
4132_key_binding_wdg_del_cb(void *data EINA_UNUSED)
4133{
4134 _editor_selected_wdg_del_cb();
4135}
4136
4118void 4137void
4119editor_init(GuiLogicCbs *_guilogic_cbs) 4138editor_init(GuiLogicCbs *_guilogic_cbs)
4120{ 4139{
@@ -4169,5 +4188,10 @@ editor_init(GuiLogicCbs *_guilogic_cbs)
4169 _drop_target_pos, NULL, 4188 _drop_target_pos, NULL,
4170 _drop_target_drop, NULL 4189 _drop_target_drop, NULL
4171 ); 4190 );
4191
4192 key_bindings_init();
4193 key_binding_new(_key_binding_undo_cb, NULL, "ctrl", "z", NULL);
4194 key_binding_new(_key_binding_redo_cb, NULL, "ctrl", "shift", "z", NULL);
4195 key_binding_new(_key_binding_wdg_del_cb, NULL, "delete", NULL);
4172} 4196}
4173 4197
diff --git a/src/bin/egui_gui/key_bindings.c b/src/bin/egui_gui/key_bindings.c
new file mode 100644
index 0000000..019df2a
--- /dev/null
+++ b/src/bin/egui_gui/key_bindings.c
@@ -0,0 +1,135 @@
1
2
3#include "egui_log.h"
4#include <Eo.h>
5#include <Eina.h>
6#include <Ecore.h>
7#include <Ecore_Input.h>
8#include "key_bindings.h"
9
10typedef struct _Key_Binding_Data Key_Binding_Data;
11
12struct _Key_Binding_Data
13{
14 /*
15 int ctrl : 1;
16 int alt : 1;
17 int shift : 1;
18 int win : 1;
19 const char *keyname;
20 */
21
22 Key_Binding_Cb cb;
23 void *data;
24};
25
26static Eina_Hash *_bindings;
27
28static Key_Binding_Data *
29_key_binding_lookup(const char *keyname, Eina_Bool ctrl, Eina_Bool alt, Eina_Bool shift, Eina_Bool win)
30{
31 Key_Binding_Data *ret;
32 int len = strlen(keyname);
33 char *buf = calloc(4 + len + 1 , 1);
34 sprintf(buf, "%d%d%d%d%s", ctrl, alt, shift, win, keyname);
35 eina_str_tolower(&buf);
36 ret = eina_hash_find(_bindings, buf);
37 free(buf);
38 return ret;
39}
40
41static Eina_Bool
42_key_down_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *ev)
43{
44 Ecore_Event_Key *event = ev;
45 Eina_Bool ctrl = !!(event->modifiers & ECORE_EVENT_MODIFIER_CTRL);
46 int alt = !!(event->modifiers & ECORE_EVENT_MODIFIER_ALT);
47 int shift =!!(event->modifiers & ECORE_EVENT_MODIFIER_SHIFT);
48 int win = !!(event->modifiers & ECORE_EVENT_MODIFIER_WIN);
49
50 Key_Binding_Data *kbd = _key_binding_lookup(event->key, ctrl, alt, shift, win);
51
52 if (kbd && kbd->cb)
53 {
54 kbd->cb(kbd->data);
55 }
56 return ECORE_CALLBACK_PASS_ON;
57}
58
59static Eina_Bool
60_key_up_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
61{
62 //Ecore_Event_Key *event = ev;
63 return ECORE_CALLBACK_PASS_ON;
64}
65
66void
67key_bindings_init()
68{
69 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _key_down_cb, NULL);
70 ecore_event_handler_add(ECORE_EVENT_KEY_UP, _key_up_cb, NULL);
71 _bindings = eina_hash_string_superfast_new(free);
72}
73
74void
75key_bindings_shutdown()
76{
77 eina_hash_free(_bindings);
78}
79
80void
81key_binding_new(Key_Binding_Cb cb, void *data, ...)
82{
83 va_list vl;
84 va_start(vl, data);
85 char *val, *str;
86 int ctrl = 0, alt = 0, shift = 0, win = 0;
87 val = va_arg(vl, char *);
88
89 Eina_Strbuf *einabuf = eina_strbuf_new();
90 const char *einabuf_str = NULL;
91 while (val)
92 {
93 str = strdup(val);
94 eina_str_tolower(&str);
95 if (!strcmp(str, "ctrl"))
96 {
97 ctrl = 1;
98 }
99 else if (!strcmp(str, "alt"))
100 {
101 alt = 1;
102 }
103 else if (!strcmp(str, "shift"))
104 {
105 shift = 1;
106 }
107 else if (!strcmp(str, "win"))
108 {
109 win = 1;
110 }
111 else
112 {
113 eina_strbuf_append(einabuf, str);
114 }
115 val = va_arg(vl, char *);
116 free(str);
117 }
118 einabuf_str = eina_strbuf_string_get(einabuf);
119
120 int len = strlen(einabuf_str);
121 char *buf = calloc(4 + len + 1 , 1);
122 sprintf(buf, "%d%d%d%d%s", ctrl, alt, shift, win, einabuf_str);
123 eina_str_tolower(&buf);
124
125 Key_Binding_Data *kb = calloc(1, sizeof(Key_Binding_Data)), *kb_old;
126 kb->cb = cb;
127 kb->data = data;
128 kb_old = eina_hash_set(_bindings, buf, kb);
129 if (kb_old) free(kb_old);
130
131 free(buf);
132 eina_strbuf_free(einabuf);
133 va_end(vl);
134}
135
diff --git a/src/bin/egui_gui/key_bindings.h b/src/bin/egui_gui/key_bindings.h
new file mode 100644
index 0000000..bd3dde7
--- /dev/null
+++ b/src/bin/egui_gui/key_bindings.h
@@ -0,0 +1,15 @@
1
2#ifndef _KEY_BINDINGS_H
3#define _KEY_BINDINGS_H
4
5typedef void (*Key_Binding_Cb)(void *);
6
7void
8key_bindings_init();
9
10void
11key_bindings_shutdown();
12
13void
14key_binding_new(Key_Binding_Cb cb, void *data, ...);
15#endif