hermet pushed a commit to branch master.

http://git.enlightenment.org/tools/enventor.git/commit/?id=8d109970c6f3531cbcb1b35f7c0f2154fc8800aa

commit 8d109970c6f3531cbcb1b35f7c0f2154fc8800aa
Author: Hermet Park <her...@hermet.pe.kr>
Date:   Tue Apr 26 23:13:42 2016 +0900

    code refactoring.
    
    sanitize duplicated error message code.
---
 src/bin/live_edit.c | 29 ++++++++++++++---------------
 src/lib/auto_comp.c | 38 +++++++++++++++++++++++---------------
 src/lib/ctxpopup.c  | 25 +++++++++++++------------
 3 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/src/bin/live_edit.c b/src/bin/live_edit.c
index e837d24..5c6c9f4 100644
--- a/src/bin/live_edit.c
+++ b/src/bin/live_edit.c
@@ -935,6 +935,13 @@ info_text_init(live_data *ld)
 }
 
 static void
+key_grab_add(Evas_Object *keygrabber, const char *key)
+{
+   if (!evas_object_key_grab(keygrabber, key, 0, 0, EINA_TRUE))
+     EINA_LOG_ERR(_("Failed to grab key - %s"), key);
+}
+
+static void
 live_edit_layer_set(live_data *ld)
 {
    //Keygrabber
@@ -944,25 +951,17 @@ live_edit_layer_set(live_data *ld)
                                   keygrabber_key_down_cb, ld);
    evas_object_event_callback_add(ld->keygrabber, EVAS_CALLBACK_KEY_DOWN,
                                   keygrabber_direction_key_down_cb, ld);
-   if (!evas_object_key_grab(ld->keygrabber, "Return", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR(_("Failed to grab key - Return"));
-   if (!evas_object_key_grab(ld->keygrabber, "Delete", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR(_("Failed to grab key - Delete"));
-   if (!evas_object_key_grab(ld->keygrabber, "BackSpace", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR(_("Failed to grab key - BackSpace"));
-   if (!evas_object_key_grab(ld->keygrabber, "Up", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR(_("Failed to grab key - Up"));
-   if (!evas_object_key_grab(ld->keygrabber, "Down", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR(_("Failed to grab key - Down"));
-   if (!evas_object_key_grab(ld->keygrabber, "Left", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR(_("Failed to grab key - Left"));
-   if (!evas_object_key_grab(ld->keygrabber, "Right", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR(_("Failed to grab key - Right"));
-
    evas_object_event_callback_add(ld->live_view, EVAS_CALLBACK_RESIZE,
                                   live_view_geom_cb, ld);
    evas_object_event_callback_add(ld->live_view, EVAS_CALLBACK_MOVE,
                                   live_view_geom_cb, ld);
+   key_grab_add(ld->keygrabber, "Return");
+   key_grab_add(ld->keygrabber, "Delete");
+   key_grab_add(ld->keygrabber, "BackSpace");
+   key_grab_add(ld->keygrabber, "Up");
+   key_grab_add(ld->keygrabber, "Down");
+   key_grab_add(ld->keygrabber, "Left");
+   key_grab_add(ld->keygrabber, "Right");
 
    //Create Live View Layout
    Evas_Object *layout = elm_layout_add(ld->live_view);
diff --git a/src/lib/auto_comp.c b/src/lib/auto_comp.c
index 664db9e..ff2b186 100644
--- a/src/lib/auto_comp.c
+++ b/src/lib/auto_comp.c
@@ -362,6 +362,19 @@ init_thread_cancel_cb(void *data, Ecore_Thread *thread 
EINA_UNUSED)
 }
 
 static void
+key_grab_add(Evas_Object *keygrabber, const char *key)
+{
+   if (!evas_object_key_grab(keygrabber, key, 0, 0, EINA_TRUE))
+     EINA_LOG_ERR(_("Failed to grab key - %s"), key);
+}
+
+static void
+key_grab_del(Evas_Object *keygrabber, const char *key)
+{
+   evas_object_key_ungrab(keygrabber, key, 0, 0);
+}
+
+static void
 anchor_keygrab_set(autocomp_data *ad, Eina_Bool grab)
 {
    Evas_Object *anchor = ad->anchor;
@@ -369,26 +382,21 @@ anchor_keygrab_set(autocomp_data *ad, Eina_Bool grab)
    if (grab)
      {
         if (ad->on_keygrab) return;
-        if (!evas_object_key_grab(anchor, "BackSpace", 0, 0, EINA_TRUE))
-          EINA_LOG_ERR("Failed to grab key - BackSpace");
-        if (!evas_object_key_grab(anchor, "Return", 0, 0, EINA_TRUE))
-          EINA_LOG_ERR("Failed to grab key - Return");
-        if (!evas_object_key_grab(anchor, "Tab", 0, 0, EINA_TRUE))
-          EINA_LOG_ERR("Failed to grab key - Tab");
-        if (!evas_object_key_grab(anchor, "Up", 0, 0, EINA_TRUE))
-          EINA_LOG_ERR("Failed to grab key - Up");
-        if (!evas_object_key_grab(anchor, "Down", 0, 0, EINA_TRUE))
-          EINA_LOG_ERR("Failed to grab key - Down");
+        key_grab_add(anchor, "BackSpace");
+        key_grab_add(anchor, "Return");
+        key_grab_add(anchor, "Tab");
+        key_grab_add(anchor, "Up");
+        key_grab_add(anchor, "Down");
         ad->on_keygrab = EINA_TRUE;
      }
    else
      {
         if (!ad->on_keygrab) return;
-        evas_object_key_ungrab(anchor, "BackSpace", 0, 0);
-        evas_object_key_ungrab(anchor, "Return", 0, 0);
-        evas_object_key_ungrab(anchor, "Tab", 0, 0);
-        evas_object_key_ungrab(anchor, "Up", 0, 0);
-        evas_object_key_ungrab(anchor, "Down", 0, 0);
+        key_grab_del(anchor, "BackSpace");
+        key_grab_del(anchor, "Return");
+        key_grab_del(anchor, "Tab");
+        key_grab_del(anchor, "Up");
+        key_grab_del(anchor, "Down");
         ad->on_keygrab = EINA_FALSE;
      }
 }
diff --git a/src/lib/ctxpopup.c b/src/lib/ctxpopup.c
index 60af932..773def3 100644
--- a/src/lib/ctxpopup.c
+++ b/src/lib/ctxpopup.c
@@ -759,6 +759,13 @@ ctxpopup_key_down_cb(void *data, Evas *e EINA_UNUSED,
    else if (!strcmp(ev->key, "BackSpace")) candidate_reset(ctxdata);
 }
 
+static void
+key_grab_add(Evas_Object *keygrabber, const char *key)
+{
+   if (!evas_object_key_grab(keygrabber, key, 0, 0, EINA_TRUE))
+     EINA_LOG_ERR(_("Failed to grab key - %s"), key);
+}
+
 /*****************************************************************************/
 /* Externally accessible calls                                               */
 /*****************************************************************************/
@@ -825,12 +832,9 @@ ctxpopup_img_preview_create(edit_data *ed,
                                   ctxpopup_mouse_wheel_cb, ctxdata);
    evas_object_focus_set(ctxpopup, EINA_TRUE);
 
-   if (!evas_object_key_grab(ctxpopup, "Up", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR("Failed to grab key - Up");
-   if (!evas_object_key_grab(ctxpopup, "Down", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR("Failed to grab key - Down");
-   if (!evas_object_key_grab(ctxpopup, "BackSpace", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR("Failed to grab key - BackSpace");
+   key_grab_add(ctxpopup, "Up");
+   key_grab_add(ctxpopup, "Down");
+   key_grab_add(ctxpopup, "BackSpace");
 
    return ctxpopup;
 }
@@ -942,12 +946,9 @@ ctxpopup_candidate_list_create(edit_data *ed, attr_value 
*attr,
    evas_object_smart_callback_add(ctxpopup, "dismissed", ctxpopup_dismiss_cb,
                                   ed);
 
-   if (!evas_object_key_grab(ctxpopup, "Up", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR("Failed to grab key - Up");
-   if (!evas_object_key_grab(ctxpopup, "Down", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR("Failed to grab key - Down");
-   if (!evas_object_key_grab(ctxpopup, "BackSpace", 0, 0, EINA_TRUE))
-     EINA_LOG_ERR("Failed to grab key - BackSpace");
+   key_grab_add(ctxpopup, "Up");
+   key_grab_add(ctxpopup, "Down");
+   key_grab_add(ctxpopup, "BackSpace");
 
    return ctxpopup;
 

-- 


Reply via email to