summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2015-08-24 23:09:24 +0200
committerBoris Faure <billiob@gmail.com>2015-08-24 23:09:24 +0200
commitcf58c1ee76582a4465cf282426b591dcab349e51 (patch)
treee10539c3db0a296f9e1c0ab3eb8b936486a5bd0d
parent144e0b5068aa25b7fce822a94101586f374aa236 (diff)
add context menu to open a selection as an url. Closes T584
-rw-r--r--src/bin/termio.c58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 6eb1c8d..f9300e3 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -2306,6 +2306,7 @@ _take_selection_text(Termio *sd, Elm_Sel_Type type, const char *text)
2306 sd->reset_sel = EINA_FALSE; 2306 sd->reset_sel = EINA_FALSE;
2307 sd->set_sel_at = ecore_time_get(); // hack 2307 sd->set_sel_at = ecore_time_get(); // hack
2308 sd->sel_type = type; 2308 sd->sel_type = type;
2309
2309 elm_cnp_selection_set(sd->win, type, 2310 elm_cnp_selection_set(sd->win, type,
2310 ELM_SEL_FORMAT_TEXT, 2311 ELM_SEL_FORMAT_TEXT,
2311 text, 2312 text,
@@ -4029,11 +4030,62 @@ _cb_ctxp_sel_copy(void *data, Evas_Object *obj, void *event EINA_UNUSED)
4029 Evas_Object *term = data; 4030 Evas_Object *term = data;
4030 Termio *sd = evas_object_smart_data_get(term); 4031 Termio *sd = evas_object_smart_data_get(term);
4031 4032
4033 EINA_SAFETY_ON_NULL_RETURN(sd);
4034
4032 termio_take_selection(data, ELM_SEL_TYPE_CLIPBOARD); 4035 termio_take_selection(data, ELM_SEL_TYPE_CLIPBOARD);
4036
4037 sd->ctxpopup = NULL;
4038 evas_object_del(obj);
4039}
4040
4041static void
4042_cb_ctxp_sel_open_as_url(void *data, Evas_Object *obj, void *event EINA_UNUSED)
4043{
4044 Evas_Object *term = data;
4045 Termio *sd = evas_object_smart_data_get(term);
4046 char buf[PATH_MAX], *s, *escaped;
4047 const char *cmd;
4048 const char *prefix = "http://";
4049 Config *config;
4050
4051 EINA_SAFETY_ON_NULL_RETURN(sd);
4052 config = sd->config;
4053
4054 termio_take_selection(data, ELM_SEL_TYPE_PRIMARY);
4055
4056 if (!sd->have_sel || !sd->sel_str)
4057 goto end;
4058
4059 if (!(config->helper.url.general) ||
4060 !(config->helper.url.general[0]))
4061 goto end;
4062 cmd = config->helper.url.general;
4063
4064 s = eina_str_escape(sd->sel_str);
4065 if (!s)
4066 goto end;
4067 if (casestartswith(s, "http://") ||
4068 casestartswith(s, "https://") ||
4069 casestartswith(s, "ftp://") ||
4070 casestartswith(s, "mailto:"))
4071 prefix = "";
4072
4073 escaped = ecore_file_escape_name(s);
4074 if (!escaped)
4075 goto end;
4076
4077 snprintf(buf, sizeof(buf), "%s %s%s", cmd, prefix, escaped);
4078 free(escaped);
4079
4080 WRN("trying to launch '%s'", buf);
4081 ecore_exe_run(buf, NULL);
4082
4083end:
4033 sd->ctxpopup = NULL; 4084 sd->ctxpopup = NULL;
4034 evas_object_del(obj); 4085 evas_object_del(obj);
4035} 4086}
4036 4087
4088
4037static void 4089static void
4038_handle_right_click(Evas_Object *obj, Evas_Event_Mouse_Down *ev, Termio *sd, 4090_handle_right_click(Evas_Object *obj, Evas_Event_Mouse_Down *ev, Termio *sd,
4039 int cx, int cy) 4091 int cx, int cy)
@@ -4044,8 +4096,10 @@ _handle_right_click(Evas_Object *obj, Evas_Event_Mouse_Down *ev, Termio *sd,
4044 ctxp = elm_ctxpopup_add(sd->win); 4096 ctxp = elm_ctxpopup_add(sd->win);
4045 sd->ctxpopup = ctxp; 4097 sd->ctxpopup = ctxp;
4046 4098
4047 elm_ctxpopup_item_append(ctxp, _("Copy"), NULL, _cb_ctxp_sel_copy, 4099 elm_ctxpopup_item_append(ctxp, _("Copy"), NULL,
4048 sd->self); 4100 _cb_ctxp_sel_copy, sd->self);
4101 elm_ctxpopup_item_append(ctxp, _("Open as URL"), NULL,
4102 _cb_ctxp_sel_open_as_url, sd->self);
4049 evas_object_move(ctxp, ev->canvas.x, ev->canvas.y); 4103 evas_object_move(ctxp, ev->canvas.x, ev->canvas.y);
4050 evas_object_show(ctxp); 4104 evas_object_show(ctxp);
4051 evas_object_smart_callback_add(ctxp, "dismissed", 4105 evas_object_smart_callback_add(ctxp, "dismissed",