<commit_before>#include "private.h"

#include <Elementary.h>
#include "config.h"
#include "termio.h"
#include "options.h"
#include "options_keys.h"
#include "keyin.h"

/*XXX: can have only one widget at a time… */
static Config *_config;
static Evas_Object *_fr;
static Evas_Object *_layout;

static void _hover_del(Evas_Object *o);

static void
_shortcut_delete(void *data, Evas_Object *obj EINA_UNUSED,
                 void *event_info EINA_UNUSED)
{
   Evas_Object *hs, *bx;
   Config_Keys *cfg_key;
   Evas_Coord w, min_w, min_h;

   hs = data;
   bx = evas_object_data_get(hs, "bx");
   cfg_key = evas_object_data_get(hs, "cfg");

   _config->keys = eina_list_remove(_config->keys, cfg_key);
   evas_object_size_hint_min_get(hs, &w, NULL);
   evas_object_size_hint_min_get(bx, &min_w, &min_h);
   min_w -= w;
   evas_object_size_hint_min_set(bx, min_w, min_h);

   evas_object_del(hs);
   keyin_remove_config(cfg_key);

   eina_stringshare_del(cfg_key->keyname);
   eina_stringshare_del(cfg_key->cb);
   free(cfg_key);

   config_save(_config, NULL);
}

static Evas_Object *
_shortcut_button_add(Evas_Object *bx, const Config_Keys *key)
{
   const char *txt;
   Evas_Object *hs;

   txt = eina_stringshare_printf("%s%s%s%s%s%s%s",
                                 key->ctrl ? _("Ctrl+") : "",
                                 key->alt ? _("Alt+") : "",
                                 key->shift ? _("Shift+") : "",
                                 key->win ? _("Win+") : "",
                                 key->meta ? _("Meta+") : "",
                                 key->hyper ? _("Hyper+") : "",
                                 key->keyname);
   hs = elm_hoversel_add(_fr);
   elm_hoversel_hover_parent_set(hs, _fr);

   evas_object_data_set(hs, "bx", bx);
   evas_object_data_set(hs, "cfg", key);
   elm_layout_text_set(hs, NULL, txt);

   elm_hoversel_item_add(hs, _("Delete"), "delete", ELM_ICON_STANDARD,
                         _shortcut_delete, hs);

   eina_stringshare_del(txt);
   return hs;
}

static void
_cb_key_up(void *data, Evas *e EINA_UNUSED,
           Evas_Object *obj, void *event)
{
   Evas_Event_Key_Up *ev = event;
   int ctrl, alt, shift, win, meta, hyper, res;
   Config_Keys *cfg_key;
   Shortcut_Action *action;
   Evas_Object *bx = data;

   if (key_is_modifier(ev->keyname))
     return;

   ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
   alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
   shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
   win = evas_key_modifier_is_set(ev->modifiers, "Super");
   meta = evas_key_modifier_is_set(ev->modifiers, "Meta") ||
          evas_key_modifier_is_set(ev->modifiers, "AltGr") ||
          evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift");
   hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper");

   _hover_del(obj);

   action = evas_object_data_get(bx, "action");
   if (!action)
     {
        ERR("can't find any action to associate with.");
        return;
     }

   cfg_key = calloc(1, sizeof(Config_Keys));
   if (!cfg_key)
     return;
   cfg_key->keyname = eina_stringshare_add(ev->keyname);
   cfg_key->ctrl = ctrl;
   cfg_key->alt = alt;
   cfg_key->shift = shift;
   cfg_key->win = win;
   cfg_key->meta = meta;
   cfg_key->hyper = hyper;
   cfg_key->cb = eina_stringshare_add(action->action);

   res = keyin_add_config(cfg_key);
   if (res == 0)
     {
        Evas_Object *bt, *last;
        Evas_Coord w, h, min_w, min_h;

        last = evas_object_data_get(bx, "last");
        _config->keys = eina_list_append(_config->keys, cfg_key);
        bt = _shortcut_button_add(bx, cfg_key);
        evas_object_show(bt);
        evas_object_size_hint_min_get(bt, &w, &h);
        evas_object_size_hint_min_get(bx, &min_w, &min_h);
        min_w += w;
        if (h > min_h) min_h = h;
        evas_object_size_hint_min_set(bx, min_w, min_h);
        elm_box_pack_before(bx, bt, last);

        config_save(_config, NULL);
     }
   else
     {
        eina_stringshare_del(cfg_key->keyname);
        eina_stringshare_del(cfg_key->cb);
        free(cfg_key);
     }
}

static void
_cb_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
               Evas_Object *obj, void *event EINA_UNUSED)
{
   _hover_del(obj);
}


static void
_hover_sizing_eval(void)
{
   Evas_Coord x = 0, y = 0, w = 0, h = 0, min_w, min_h, new_x, new_y;
   evas_object_geometry_get(_fr, &x, &y, &w, &h);
#if (ECORE_VERSION_MAJOR > 1) || (ECORE_VERSION_MINOR >= 8)
   evas_object_geometry_set(_layout, x, y, w, h);
#else
   evas_object_move(_layout, x, y);
   evas_object_resize(_layout, w, h);
#endif
}

static void
_parent_move_cb(void *data EINA_UNUSED,
                Evas *e EINA_UNUSED,
                Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   _hover_sizing_eval();
}
static void
_parent_resize_cb(void *data EINA_UNUSED,
                  Evas *e EINA_UNUSED,
                  Evas_Object *obj EINA_UNUSED,
                  void *event_info EINA_UNUSED)
{
   _hover_sizing_eval();
}

static void
_parent_hide_cb(void *data,
                Evas *e EINA_UNUSED,
                Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)<commit_msg>open keys - fix compiler warnings<commit_after>#include "private.h"

#include <Elementary.h>
#include "config.h"
#include "termio.h"
#include "options.h"
#include "options_keys.h"
#include "keyin.h"
#include "utils.h"

/*XXX: can have only one widget at a time… */
static Config *_config;
static Evas_Object *_fr;
static Evas_Object *_layout;

static void _hover_del(Evas_Object *o);

static void
_shortcut_delete(void *data, Evas_Object *obj EINA_UNUSED,
                 void *event_info EINA_UNUSED)
{
   Evas_Object *hs, *bx;
   Config_Keys *cfg_key;
   Evas_Coord w, min_w, min_h;

   hs = data;
   bx = evas_object_data_get(hs, "bx");
   cfg_key = evas_object_data_get(hs, "cfg");

   _config->keys = eina_list_remove(_config->keys, cfg_key);
   evas_object_size_hint_min_get(hs, &w, NULL);
   evas_object_size_hint_min_get(bx, &min_w, &min_h);
   min_w -= w;
   evas_object_size_hint_min_set(bx, min_w, min_h);

   evas_object_del(hs);
   keyin_remove_config(cfg_key);

   eina_stringshare_del(cfg_key->keyname);
   eina_stringshare_del(cfg_key->cb);
   free(cfg_key);

   config_save(_config, NULL);
}

static Evas_Object *
_shortcut_button_add(Evas_Object *bx, const Config_Keys *key)
{
   const char *txt;
   Evas_Object *hs;

   txt = eina_stringshare_printf("%s%s%s%s%s%s%s",
                                 key->ctrl ? _("Ctrl+") : "",
                                 key->alt ? _("Alt+") : "",
                                 key->shift ? _("Shift+") : "",
                                 key->win ? _("Win+") : "",
                                 key->meta ? _("Meta+") : "",
                                 key->hyper ? _("Hyper+") : "",
                                 key->keyname);
   hs = elm_hoversel_add(_fr);
   elm_hoversel_hover_parent_set(hs, _fr);

   evas_object_data_set(hs, "bx", bx);
   evas_object_data_set(hs, "cfg", key);
   elm_layout_text_set(hs, NULL, txt);

   elm_hoversel_item_add(hs, _("Delete"), "delete", ELM_ICON_STANDARD,
                         _shortcut_delete, hs);

   eina_stringshare_del(txt);
   return hs;
}

static void
_cb_key_up(void *data, Evas *e EINA_UNUSED,
           Evas_Object *obj, void *event)
{
   Evas_Event_Key_Up *ev = event;
   int ctrl, alt, shift, win, meta, hyper, res;
   Config_Keys *cfg_key;
   Shortcut_Action *action;
   Evas_Object *bx = data;

   if (key_is_modifier(ev->keyname))
     return;

   ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
   alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
   shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
   win = evas_key_modifier_is_set(ev->modifiers, "Super");
   meta = evas_key_modifier_is_set(ev->modifiers, "Meta") ||
          evas_key_modifier_is_set(ev->modifiers, "AltGr") ||
          evas_key_modifier_is_set(ev->modifiers, "ISO_Level3_Shift");
   hyper = evas_key_modifier_is_set(ev->modifiers, "Hyper");

   _hover_del(obj);

   action = evas_object_data_get(bx, "action");
   if (!action)
     {
        ERR("can't find any action to associate with.");
        return;
     }

   cfg_key = calloc(1, sizeof(Config_Keys));
   if (!cfg_key)
     return;
   cfg_key->keyname = eina_stringshare_add(ev->keyname);
   cfg_key->ctrl = ctrl;
   cfg_key->alt = alt;
   cfg_key->shift = shift;
   cfg_key->win = win;
   cfg_key->meta = meta;
   cfg_key->hyper = hyper;
   cfg_key->cb = eina_stringshare_add(action->action);

   res = keyin_add_config(cfg_key);
   if (res == 0)
     {
        Evas_Object *bt, *last;
        Evas_Coord w, h, min_w, min_h;

        last = evas_object_data_get(bx, "last");
        _config->keys = eina_list_append(_config->keys, cfg_key);
        bt = _shortcut_button_add(bx, cfg_key);
        evas_object_show(bt);
        evas_object_size_hint_min_get(bt, &w, &h);
        evas_object_size_hint_min_get(bx, &min_w, &min_h);
        min_w += w;
        if (h > min_h) min_h = h;
        evas_object_size_hint_min_set(bx, min_w, min_h);
        elm_box_pack_before(bx, bt, last);

        config_save(_config, NULL);
     }
   else
     {
        eina_stringshare_del(cfg_key->keyname);
        eina_stringshare_del(cfg_key->cb);
        free(cfg_key);
     }
}

static void
_cb_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
               Evas_Object *obj, void *event EINA_UNUSED)
{
   _hover_del(obj);
}


static void
_hover_sizing_eval(void)
{
   Evas_Coord x = 0, y = 0, w = 0, h = 0;
   evas_object_geometry_get(_fr, &x, &y, &w, &h);
#if (ECORE_VERSION_MAJOR > 1) || (ECORE_VERSION_MINOR >= 8)
   evas_object_geometry_set(_layout, x, y, w, h);
#else
   evas_object_move(_layout, x, y);
   evas_object_resize(_layout, w, h);
#endif
}

static void
_parent_move_cb(void *data EINA_UNUSED,
                Evas *e EINA_UNUSED,
                Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   _hover_sizing_eval();
}
static void
_parent_resize_cb(void *data EINA_UNUSED,
                  Evas *e EINA_UNUSED,
                  Evas_Object *obj EINA_UNUSED,
                  void *event_info EINA_UNUSED)
{
   _hover_sizing_eval();
}

static void
_parent_hide_cb(void *data,
                Evas *e EINA_UNUSED,
                Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{'fraction_non_alphanumeric': 0.12603759183284038, 'fraction_numerical': 0.0017173933784944185, 'mean_word_length': 2.8283418553688824, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4403202', 'n_tokens_mistral': 4094, 'n_tokens_neox': 3990, 'n_words': 735}