add configuration on whether to activate links

- on email
- on file paths
- on URLs
- from escape codes (called hyper links in the code)

Closes T6339
This commit is contained in:
Boris Faure 2019-01-21 22:11:22 +01:00
parent a78c653b60
commit 2e34b8e962
7 changed files with 146 additions and 52 deletions

View File

@ -7,7 +7,7 @@
#include "col.h"
#include "utils.h"
#define CONF_VER 19
#define CONF_VER 20
#define LIM(v, min, max) {if (v >= max) v = max; else if (v <= min) v = min;}
@ -122,8 +122,16 @@ config_init(void)
(edd_base, Config, "cursor_shape", cursor_shape, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "disable_visual_bell", disable_visual_bell, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
EET_DATA_DESCRIPTOR_ADD_BASIC /* DEPRECATED */
(edd_base, Config, "active_links", active_links, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "active_links_email", active_links_email, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "active_links_file", active_links_file, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "active_links_url", active_links_url, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "active_links_escape", active_links_escape, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
(edd_base, Config, "translucent", translucent, EET_T_UCHAR);
EET_DATA_DESCRIPTOR_ADD_BASIC
@ -258,7 +266,10 @@ config_sync(const Config *config_src, Config *config)
config->cursor_shape = config_src->cursor_shape;
config->disable_visual_bell = config_src->disable_visual_bell;
config->bell_rings = config_src->bell_rings;
config->active_links = config_src->active_links;
config->active_links_email = config_src->active_links_email;
config->active_links_file = config_src->active_links_file;
config->active_links_url = config_src->active_links_url;
config->active_links_escape = config_src->active_links_escape;
config->mute = config_src->mute;
config->visualize = config_src->visualize;
config->urg_bell = config_src->urg_bell;
@ -519,7 +530,10 @@ config_new(void)
config->cursor_shape = CURSOR_SHAPE_BLOCK;
config->disable_visual_bell = EINA_FALSE;
config->bell_rings = EINA_TRUE;
config->active_links = EINA_TRUE;
config->active_links_email = EINA_TRUE;
config->active_links_file = EINA_TRUE;
config->active_links_url = EINA_TRUE;
config->active_links_escape = EINA_TRUE;
config->translucent = EINA_FALSE;
config->mute = EINA_FALSE;
config->visualize = EINA_TRUE;
@ -670,7 +684,14 @@ config_load(const char *key)
config->cursor_shape = CURSOR_SHAPE_BLOCK;
EINA_FALLTHROUGH;
/*pass through*/
case CONF_VER: /* 19 */
case 19:
config->active_links_email = config->active_links;
config->active_links_file = config->active_links;
config->active_links_url = config->active_links;
config->active_links_escape = config->active_links;
EINA_FALLTHROUGH;
/*pass through*/
case CONF_VER: /* 20 */
config->version = CONF_VER;
break;
default:
@ -745,7 +766,10 @@ config_fork(const Config *config)
CPY(cursor_shape);
CPY(disable_visual_bell);
CPY(bell_rings);
CPY(active_links);
CPY(active_links_email);
CPY(active_links_file);
CPY(active_links_url);
CPY(active_links_escape);
CPY(translucent);
CPY(opacity);
CPY(mute);

View File

@ -69,7 +69,11 @@ struct _Config
int cursor_shape;
Eina_Bool disable_visual_bell;
Eina_Bool bell_rings;
Eina_Bool active_links;
Eina_Bool active_links; /* DEPRECATED */
Eina_Bool active_links_email;
Eina_Bool active_links_file;
Eina_Bool active_links_url;
Eina_Bool active_links_escape;
Eina_Bool translucent;
Eina_Bool mute;
Eina_Bool visualize;

View File

@ -745,6 +745,10 @@ elm_main(int argc, char **argv)
if (active_links != 0xff)
{
config->active_links = !!active_links;
config->active_links_email = config->active_links;
config->active_links_file = config->active_links;
config->active_links_url = config->active_links;
config->active_links_escape = config->active_links;
config->temporary = EINA_TRUE;
}

View File

@ -41,7 +41,10 @@ CB(disable_visual_bell, 1);
CB(bell_rings, 0);
CB(flicker_on_key, 0);
CB(urg_bell, 0);
CB(active_links, 0);
CB(active_links_email, 0);
CB(active_links_file, 0);
CB(active_links_url, 0);
CB(active_links_escape, 0);
CB(multi_instance, 0);
CB(xterm_256color, 0);
CB(erase_is_del, 0);
@ -204,14 +207,7 @@ static void
_add_cursors_option(Evas_Object *bx,
Behavior_Ctx *ctx)
{
Evas_Object *o, *lbl, *rd, *rdg, *layout, *oe;
o = elm_separator_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_separator_horizontal_set(o, EINA_TRUE);
elm_box_pack_end(bx, o);
evas_object_show(o);
Evas_Object *lbl, *rd, *rdg, *layout, *oe;
lbl = elm_label_add(bx);
evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, 0.0);
@ -340,13 +336,6 @@ _add_cursors_option(Evas_Object *bx,
edje_object_signal_emit(oe, "focus,in,noblink", "terminology");
evas_object_smart_callback_add(rd, "changed", _cursors_changed_cb, ctx);
o = elm_separator_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_separator_horizontal_set(o, EINA_TRUE);
elm_box_pack_end(bx, o);
evas_object_show(o);
elm_radio_value_set(rdg,
1 + 2 * ctx->config->cursor_shape + (ctx->config->disable_cursor_blink ? 1 : 0));
}
@ -355,7 +344,7 @@ void
options_behavior(Evas_Object *opbox, Evas_Object *term)
{
Config *config = termio_config_get(term);
Evas_Object *o, *bx, *sc, *frame;
Evas_Object *o, *bx, *sc, *frame, *lbl;
int w, h;
const char *tooltip;
Behavior_Ctx *ctx;
@ -391,7 +380,18 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
elm_object_content_set(sc, o);
evas_object_show(o);
#define SEPARATOR \
do { \
o = elm_separator_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_separator_horizontal_set(o, EINA_TRUE); \
elm_box_pack_end(bx, o); \
evas_object_show(o); \
} while (0)
#define CX(_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); \
@ -400,18 +400,35 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
elm_box_pack_end(bx, o); \
evas_object_show(o); \
evas_object_smart_callback_add(o, "changed", \
_cb_op_behavior_##_cfg_name, ctx)
_cb_op_behavior_##_cfg_name, ctx); \
} while (0)
CX(_("Scroll to bottom on new content"), jump_on_change, 0);
CX(_("Scroll to bottom when a key is pressed"), jump_on_keypress, 0);
SEPARATOR;
_add_cursors_option(bx, ctx);
SEPARATOR;
lbl = elm_label_add(bx);
evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(lbl, 0.0, 0.0);
elm_layout_text_set(lbl, NULL, _("Active Links:"));
elm_box_pack_end(bx, lbl);
evas_object_show(lbl);
CX(_("On emails"), active_links_email, 0);
CX(_("On file paths"), active_links_file, 0);
CX(_("On URLs"), active_links_url, 0);
CX(_("Based on escape codes"), active_links_escape, 0);
SEPARATOR;
CX(_("React to key presses"), flicker_on_key, 0);
if (!multisense_available)
{
Evas_Object *lbl;
lbl = elm_label_add(bx);
evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(lbl, 0.0, 0.5);
@ -422,7 +439,6 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
CX(_("Visual Bell"), disable_visual_bell, 1);
CX(_("Bell rings"), bell_rings, 0);
CX(_("Urgent Bell"), urg_bell, 0);
CX(_("Active Links"), active_links, 0);
CX(_("Multiple instances, one process"), multi_instance, 0);
CX(_("Set TERM to xterm-256color"), xterm_256color, 0);
CX(_("BackArrow sends Del (instead of BackSpace)"), erase_is_del, 0);
@ -438,6 +454,7 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
#undef CX
SEPARATOR;
o = elm_check_add(bx);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
@ -504,12 +521,7 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
evas_object_smart_callback_add(o, "changed",
_cb_op_behavior_cg_height, ctx);
o = elm_separator_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_separator_horizontal_set(o, EINA_TRUE);
elm_box_pack_end(bx, o);
evas_object_show(o);
SEPARATOR;
o = elm_label_add(bx);
evas_object_size_hint_weight_set(o, 0.0, 0.0);
@ -572,4 +584,5 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
evas_object_size_hint_weight_set(opbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(opbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(o);
#undef SEPARATOR
}

View File

@ -821,7 +821,8 @@ _should_inline(const Evas_Object *obj)
/* Need to be freed */
const char *
termio_link_get(const Evas_Object *obj)
termio_link_get(const Evas_Object *obj,
Eina_Bool *from_escape_code)
{
Termio *sd = evas_object_smart_data_get(obj);
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL);
@ -829,6 +830,9 @@ termio_link_get(const Evas_Object *obj)
if (!sd->link.string && !sd->link.id)
return NULL;
if (from_escape_code)
*from_escape_code = EINA_FALSE;
link = sd->link.string;
if (sd->link.id)
{
@ -836,6 +840,8 @@ termio_link_get(const Evas_Object *obj)
if (!hl->url)
return NULL;
link = hl->url;
if (from_escape_code)
*from_escape_code = EINA_TRUE;
}
if (link_is_url(link))
{
@ -863,28 +869,47 @@ _activate_link(Evas_Object *obj, Eina_Bool may_inline)
char buf[PATH_MAX], *s, *escaped;
const char *path = NULL, *cmd = NULL;
const char *link = NULL;
Eina_Bool from_escape_code = EINA_FALSE;
Eina_Bool url = EINA_FALSE, email = EINA_FALSE, handled = EINA_FALSE;
EINA_SAFETY_ON_NULL_RETURN(sd);
config = sd->config;
if (!config) return;
if (!config->active_links) return;
if (!config)
return;
link = termio_link_get(obj);
link = termio_link_get(obj, &from_escape_code);
if (!link)
return;
if (link_is_url(link))
url = EINA_TRUE;
else if (link[0] == '/')
path = link;
else if (link_is_email(link))
email = EINA_TRUE;
if (from_escape_code && !config->active_links_escape)
return;
if (url && casestartswith(link, "mailto:"))
if (link_is_url(link))
{
if (casestartswith(link, "mailto:"))
{
email = EINA_TRUE;
if (!config->active_links_email)
return;
}
else
{
url = EINA_TRUE;
if (!config->active_links_url)
return;
}
}
else if (link[0] == '/')
{
path = link;
if (!config->active_links_file)
return;
}
else if (link_is_email(link))
{
email = EINA_TRUE;
url = EINA_FALSE;
if (!config->active_links_email)
return;
}
s = eina_str_escape(link);
@ -3778,8 +3803,6 @@ _smart_mouseover_apply(Evas_Object *obj)
EINA_SAFETY_ON_NULL_RETURN(sd);
config = sd->config;
if (!config->active_links)
return;
if ((sd->mouse.cx < 0) || (sd->mouse.cy < 0) ||
(sd->link.suspend) || (!evas_object_focus_get(obj)))
@ -3796,7 +3819,8 @@ _smart_mouseover_apply(Evas_Object *obj)
if (cell->att.link_id)
{
_hyperlink_mouseover(obj, sd, cell->att.link_id);
if (config->active_links_escape)
_hyperlink_mouseover(obj, sd, cell->att.link_id);
return;
}
@ -3808,6 +3832,30 @@ _smart_mouseover_apply(Evas_Object *obj)
return;
}
if (link_is_url(s))
{
if (casestartswith(s, "mailto:"))
{
if (!config->active_links_email)
return;
}
else
{
if (!config->active_links_url)
return;
}
}
else if (s[0] == '/')
{
if (!config->active_links_file)
return;
}
else if (link_is_email(s))
{
if (!config->active_links_email)
return;
}
if (sd->link.string)
eina_stringshare_del(sd->link.string);
sd->link.string = eina_stringshare_add(s);

View File

@ -27,7 +27,8 @@ void termio_font_update(Evas_Object *obj);
Config *termio_config_get(const Evas_Object *obj);
Eina_Bool termio_take_selection(Evas_Object *obj, Elm_Sel_Type);
void termio_paste_selection(Evas_Object *obj, Elm_Sel_Type);
const char *termio_link_get(const Evas_Object *obj);
const char *termio_link_get(const Evas_Object *obj,
Eina_Bool *from_escape_code);
void termio_mouseover_suspend_pushpop(Evas_Object *obj, int dir);
void termio_event_feed_mouse_in(Evas_Object *obj);
void termio_size_get(const Evas_Object *obj, int *w, int *h);

View File

@ -4452,7 +4452,7 @@ _cb_popup(void *data,
{
/* Popup a link, there was user interaction on it. */
from_user_interaction = EINA_TRUE;
src = termio_link_get(term->termio);
src = termio_link_get(term->termio, NULL);
}
if (!src)
return;
@ -4473,7 +4473,7 @@ _cb_popup_queue(void *data,
if (!src)
{
from_user_interaction = EINA_TRUE;
src = termio_link_get(term->termio);
src = termio_link_get(term->termio, NULL);
}
if (!src)
return;