billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=a0b7fae2dd51480df0fd7c5213adf27b789c3141

commit a0b7fae2dd51480df0fd7c5213adf27b789c3141
Author: Boris Faure <bill...@gmail.com>
Date:   Fri Mar 18 19:08:58 2016 +0100

    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 14982e9..581a6ea 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 fb9e148..05e75f0 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 3f6e36f..3203be1 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 95ca85d..b70035f 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);
 }

-- 


Reply via email to