e_conf_env: Display variable and assignment.

When setting a custom environment variable display the variable
name and the value in NAME=VALUE format within the UI list. If
the value string is long then use an ellipsis. Adds some clarity.
enlightenment-0.24
Alastair Poole 3 years ago
parent 9cb83899b4
commit 8d72d36246
  1. 69
      src/modules/conf_paths/e_int_config_env.c

@ -10,10 +10,10 @@ struct _E_Config_Dialog_Data
E_Config_Dialog *cfd;
Eina_List *env_vars;
char *var_str, *val_str;
int unset;
struct {
Evas_Object *var_en, *val_en, *unset, *list;
} gui;
@ -27,15 +27,15 @@ e_int_config_env(Evas_Object *parent EINA_UNUSED, const char *params EINA_UNUSED
if (e_config_dialog_find("E", "advanced/environment_variables")) return NULL;
v = E_NEW(E_Config_Dialog_View, 1);
v->create_cfdata = _create_data;
v->free_cfdata = _free_data;
v->basic.create_widgets = _basic_create_widgets;
v->basic.apply_cfdata = _basic_apply_data;
cfd = e_config_dialog_new(NULL, _("Environment Variables"),
"E", "advanced/environment_variables",
"preferences-system", 0, v, NULL);
"E", "advanced/environment_variables",
"preferences-system", 0, v, NULL);
return cfd;
}
@ -44,7 +44,7 @@ _fill_data(E_Config_Dialog_Data *cfdata)
{
Eina_List *l;
E_Config_Env_Var *evr, *evr2;
EINA_LIST_FOREACH(e_config->env_vars, l, evr)
{
evr2 = E_NEW(E_Config_Env_Var, 1);
@ -70,7 +70,7 @@ static void
_free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
E_Config_Env_Var *evr;
EINA_LIST_FREE(cfdata->env_vars, evr)
{
eina_stringshare_del(evr->var);
@ -88,7 +88,7 @@ _basic_apply_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata
Eina_List *l, *l2;
E_Config_Env_Var *evr, *evr2;
int same;
// old env vars removed from new set - unset
EINA_LIST_FOREACH(e_config->env_vars, l, evr)
{
@ -112,7 +112,7 @@ _basic_apply_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata
EINA_LIST_FOREACH(cfdata->env_vars, l, evr)
{
evr2 = E_NEW(E_Config_Env_Var, 1);
evr2->var = eina_stringshare_add(evr->var);
if (evr->val) evr2->val = eina_stringshare_add(evr->val);
evr2->unset = evr->unset;
@ -147,6 +147,24 @@ _sel_cb(void *data)
e_widget_entry_text_set(cfdata->gui.val_en, "");
}
static const char *
_env_text(E_Config_Env_Var *evr)
{
static Eina_Slstr *text;
char *val;
val = strndup(evr->val, 64);
if (strlen(evr->val) > 64)
text = eina_slstr_printf("%s=%s...", evr->var, val);
else
text = eina_slstr_printf("%s=%s", evr->var, val);
free(val);
return text;
}
static void
_add_cb(void *data, void *data2 EINA_UNUSED)
{
@ -154,9 +172,9 @@ _add_cb(void *data, void *data2 EINA_UNUSED)
Eina_List *l;
E_Config_Env_Var *evr = NULL;
int i, sel = -1;
if (!cfdata->var_str) return;
i = 0;
EINA_LIST_FOREACH(cfdata->env_vars, l, evr)
{
@ -183,8 +201,8 @@ _add_cb(void *data, void *data2 EINA_UNUSED)
cfdata->unset = 0;
}
cfdata->env_vars = eina_list_append(cfdata->env_vars, evr);
e_widget_ilist_append(cfdata->gui.list, NULL,
evr->var, _sel_cb, cfdata, NULL);
e_widget_ilist_append(cfdata->gui.list, NULL,
_env_text(evr), _sel_cb, cfdata, NULL);
e_widget_ilist_go(cfdata->gui.list);
sel = e_widget_ilist_count(cfdata->gui.list) - 1;
e_widget_ilist_selected_set(cfdata->gui.list, sel);
@ -206,6 +224,7 @@ _add_cb(void *data, void *data2 EINA_UNUSED)
if (sel >= 0)
{
e_widget_ilist_selected_set(cfdata->gui.list, sel);
e_widget_ilist_nth_label_set(cfdata->gui.list, sel, _env_text(evr));
e_widget_ilist_nth_show(cfdata->gui.list, sel, 0);
}
}
@ -220,7 +239,7 @@ _del_cb(void *data, void *data2 EINA_UNUSED)
int sel_n;
/*
int i, sel = -1;
EINA_LIST_FOREACH(cfdata->env_vars, l, evr)
{
if (!strcmp(cfdata->var_str, evr->var))
@ -249,7 +268,7 @@ _del_cb(void *data, void *data2 EINA_UNUSED)
e_widget_ilist_freeze(cfdata->gui.list);
EINA_LIST_FOREACH(cfdata->env_vars, l, evr)
{
e_widget_ilist_append(cfdata->gui.list, NULL, evr->var,
e_widget_ilist_append(cfdata->gui.list, NULL, _env_text(evr),
_sel_cb, cfdata, NULL);
}
e_widget_ilist_go(cfdata->gui.list);
@ -278,36 +297,36 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf
Evas_Object *o, *ol, *oe, *ob, *oc;
Eina_List *l;
E_Config_Env_Var *evr;
e_dialog_resizable_set(cfd->dia, 1);
o = e_widget_table_add(e_win_evas_win_get(evas), 0);
ol = e_widget_ilist_add(evas, 0, 0, NULL);
cfdata->gui.list = ol;
e_widget_ilist_freeze(ol);
EINA_LIST_FOREACH(cfdata->env_vars, l, evr)
{
e_widget_ilist_append(ol, NULL, evr->var, _sel_cb, cfdata, NULL);
e_widget_ilist_append(ol, NULL, _env_text(evr), _sel_cb, cfdata, NULL);
}
e_widget_ilist_go(ol);
e_widget_ilist_thaw(ol);
e_widget_size_min_set(ol, 200, 160);
e_widget_table_object_append(o, ol, 0, 0, 3, 1, 1, 1, 1, 1);
oe = e_widget_entry_add(cfd->dia->win, &(cfdata->var_str), NULL, NULL, NULL);
cfdata->gui.var_en = oe;
e_widget_table_object_append(o, oe, 0, 1, 1, 1, 1, 1, 1, 0);
oe = e_widget_entry_add(cfd->dia->win, &(cfdata->val_str), NULL, NULL, NULL);
cfdata->gui.val_en = oe;
e_widget_table_object_append(o, oe, 1, 1, 1, 1, 1, 1, 1, 0);
oc = e_widget_check_add(evas, _("Unset"), &(cfdata->unset));
cfdata->gui.unset = oc;
e_widget_table_object_append(o, oc, 2, 1, 1, 1, 1, 1, 1, 0);
evas_object_smart_callback_add(oc, "changed", _unset_cb, cfdata);
ob = e_widget_button_add(evas, _("Add"), "list-add", _add_cb, cfdata, NULL);
e_widget_table_object_append(o, ob, 0, 2, 1, 1, 1, 1, 0, 0);
@ -316,6 +335,6 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf
ob = e_widget_button_add(evas, _("Delete"), "list-remove", _del_cb, cfdata, NULL);
e_widget_table_object_append(o, ob, 2, 2, 1, 1, 1, 1, 0, 0);
return o;
}

Loading…
Cancel
Save