forked from enlightenment/terminology
termio: add popup on right click on color to copy it
This commit is contained in:
parent
6761f05d06
commit
2be609daab
|
@ -1096,6 +1096,32 @@ termio_paste_selection(Evas_Object *obj, Elm_Sel_Type type)
|
|||
_getsel_cb, obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_ctxp_color_copy(void *data,
|
||||
Evas_Object *obj,
|
||||
void *_event EINA_UNUSED)
|
||||
{
|
||||
Termio *sd = data;
|
||||
const char *txt;
|
||||
EINA_SAFETY_ON_NULL_RETURN(sd);
|
||||
|
||||
if (sd->link.color.a == 255)
|
||||
txt = eina_stringshare_printf("#%.2x%.2x%.2x",
|
||||
sd->link.color.r,
|
||||
sd->link.color.g,
|
||||
sd->link.color.b);
|
||||
else
|
||||
txt = eina_stringshare_printf("#%.2x%.2x%.2x%.2x",
|
||||
sd->link.color.r,
|
||||
sd->link.color.g,
|
||||
sd->link.color.b,
|
||||
sd->link.color.a);
|
||||
|
||||
termio_take_selection_text(sd, ELM_SEL_TYPE_CLIPBOARD, txt);
|
||||
|
||||
sd->ctxpopup = NULL;
|
||||
evas_object_del(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_link_down(void *data,
|
||||
|
@ -1123,9 +1149,42 @@ _cb_link_down(void *data,
|
|||
sd->link.down.x = ev->canvas.x;
|
||||
sd->link.down.y = ev->canvas.y;
|
||||
}
|
||||
else if (ev->button == 3)
|
||||
else if (ev->button == 3) /* right click */
|
||||
{
|
||||
Evas_Object *ctxp;
|
||||
|
||||
ctxp = elm_ctxpopup_add(sd->win);
|
||||
sd->ctxpopup = ctxp;
|
||||
|
||||
if (sd->link.is_color)
|
||||
{
|
||||
const char *fmt, *txt;
|
||||
if (sd->link.color.a == 255)
|
||||
{
|
||||
fmt = eina_stringshare_printf(_("Copy '%s'"),
|
||||
"#%.2x%.2x%.2x");
|
||||
txt = eina_stringshare_printf(fmt,
|
||||
sd->link.color.r,
|
||||
sd->link.color.g,
|
||||
sd->link.color.b);
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt = eina_stringshare_printf(_("Copy '%s'"),
|
||||
"#%.2x%.2x%.2x%.2x");
|
||||
txt = eina_stringshare_printf(fmt,
|
||||
sd->link.color.r,
|
||||
sd->link.color.g,
|
||||
sd->link.color.b,
|
||||
sd->link.color.a);
|
||||
}
|
||||
elm_ctxpopup_item_append(ctxp, txt, NULL,
|
||||
_cb_ctxp_color_copy, sd);
|
||||
eina_stringshare_del(txt);
|
||||
eina_stringshare_del(fmt);
|
||||
}
|
||||
else
|
||||
{
|
||||
Eina_Bool absolut = EINA_FALSE;
|
||||
const char *raw_link;
|
||||
size_t len;
|
||||
|
@ -1139,8 +1198,6 @@ _cb_link_down(void *data,
|
|||
return;
|
||||
}
|
||||
|
||||
ctxp = elm_ctxpopup_add(sd->win);
|
||||
sd->ctxpopup = ctxp;
|
||||
|
||||
if (hl)
|
||||
{
|
||||
|
@ -1191,14 +1248,16 @@ _cb_link_down(void *data,
|
|||
{
|
||||
elm_ctxpopup_item_append(ctxp, _("Copy"), NULL, _cb_ctxp_link_copy, sd->self);
|
||||
}
|
||||
if (!hl)
|
||||
free((void*)raw_link);
|
||||
}
|
||||
|
||||
evas_object_move(ctxp, ev->canvas.x, ev->canvas.y);
|
||||
evas_object_show(ctxp);
|
||||
evas_object_smart_callback_add(ctxp, "dismissed",
|
||||
_cb_ctxp_dismissed, sd);
|
||||
evas_object_event_callback_add(ctxp, EVAS_CALLBACK_DEL,
|
||||
_cb_ctxp_del, sd);
|
||||
if (!hl)
|
||||
free((void*)raw_link);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2631,7 +2690,7 @@ termio_handle_right_click(Evas_Event_Mouse_Down *ev, Termio *sd,
|
|||
_cb_ctxp_del, sd);
|
||||
return;
|
||||
}
|
||||
if (!sd->link.string)
|
||||
if (!sd->link.string && !sd->link.is_color)
|
||||
evas_object_smart_callback_call(sd->self, "options", NULL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue