From a0b7fae2dd51480df0fd7c5213adf27b789c3141 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Fri, 18 Mar 2016 19:08:58 +0100 Subject: [PATCH] add a reset button to reset the key bindings --- src/bin/config.c | 15 +++++++++++++++ src/bin/config.h | 1 + src/bin/options.h | 30 ++++++++++++++++++++++++++++++ src/bin/options_keys.c | 18 +++++++++++++++++- 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/bin/config.c b/src/bin/config.c index 14982e97..581a6ea7 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -361,6 +361,21 @@ _add_default_keys(Config *config) ADD_KB("KP_Divide", 0, 0, 1, 0, "copy_clipboard"); } +void +config_reset_keys(Config *config) +{ + Config_Keys *key; + + EINA_LIST_FREE(config->keys, key) + { + eina_stringshare_del(key->keyname); + eina_stringshare_del(key->cb); + free(key); + } + _add_default_keys(config); +} + + static void _add_key(Config *config, const char *name, int ctrl, int alt, int shift, int win, const char *cb_name) diff --git a/src/bin/config.h b/src/bin/config.h index fb9e148a..05e75f06 100644 --- a/src/bin/config.h +++ b/src/bin/config.h @@ -94,6 +94,7 @@ Config *config_fork(Config *config); Config *config_new(); void config_del(Config *config); void config_default_font_set(Config *config, Evas *evas); +void config_reset_keys(Config *config); const char *config_theme_path_get(const Config *config); const char *config_theme_path_default_get(const Config *config); diff --git a/src/bin/options.h b/src/bin/options.h index 3f6e36fa..3203be13 100644 --- a/src/bin/options.h +++ b/src/bin/options.h @@ -5,4 +5,34 @@ void options_toggle(Evas_Object *win, Evas_Object *bg, Evas_Object *term, void (*donecb) (void *data), void *donedata); Eina_Bool options_active_get(void); +#define OPTIONS_CB(_cfg_name, _inv) \ +static void \ +_cb_op_behavior_##_cfg_name(void *data, Evas_Object *obj, \ + void *event EINA_UNUSED) \ +{ \ + Evas_Object *term = data; \ + Config *config = termio_config_get(term); \ + if (_inv) \ + config->_cfg_name = !elm_check_state_get(obj); \ + else \ + config->_cfg_name = elm_check_state_get(obj); \ + termio_config_update(term); \ + windows_update(); \ + config_save(config, NULL); \ +} + +#define OPTIONS_CX(_bx, _lbl, _cfg_name, _inv) \ + do { \ + o = elm_check_add(_bx); \ + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); \ + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); \ + elm_object_text_set(o, _lbl); \ + elm_check_state_set(o, _inv ? !config->_cfg_name : config->_cfg_name); \ + elm_box_pack_end(_bx, o); \ + evas_object_show(o); \ + evas_object_smart_callback_add(o, "changed", \ + _cb_op_behavior_##_cfg_name, term) \ + } while (0) + + #endif diff --git a/src/bin/options_keys.c b/src/bin/options_keys.c index 95ca85d5..b70035f6 100644 --- a/src/bin/options_keys.c +++ b/src/bin/options_keys.c @@ -337,6 +337,16 @@ char *gl_group_text_get(void *data, Evas_Object *obj EINA_UNUSED, return strdup(action->description); } +static void +_cb_reset_keys(void *data, Evas_Object *obj EINA_UNUSED, + void *event EINA_UNUSED) +{ + Evas_Object *gl = data; + + config_reset_keys(_config); + elm_genlist_realized_items_update(gl); +} + void options_keys(Evas_Object *opbox, Evas_Object *term) { @@ -409,5 +419,11 @@ options_keys(Evas_Object *opbox, Evas_Object *term) action++; } - /* TODO: reset button ? */ + o = elm_button_add(bx); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_object_text_set(o, _("Reset bindings")); + elm_box_pack_end(bx, o); + evas_object_show(o); + evas_object_smart_callback_add(o, "clicked", _cb_reset_keys, gl); }