From 11f9ba86094b13b82db5814953c29adbce14a5c1 Mon Sep 17 00:00:00 2001 From: Al Poole Date: Sat, 2 Dec 2017 10:25:54 +0000 Subject: [PATCH] theme: add a title to theme edcs and use that. This makes it a little neater. --- data/themes/black.edc | 5 ++++- data/themes/solarized.edc | 5 ++++- data/themes/solarized_dark.edc | 4 ++++ data/themes/white.edc | 5 ++++- src/bin/edi_theme.c | 23 ++++++++++++++++++++++- src/bin/edi_theme.h | 11 +++++++++++ src/bin/screens/edi_settings.c | 19 ++++++++----------- 7 files changed, 57 insertions(+), 15 deletions(-) diff --git a/data/themes/black.edc b/data/themes/black.edc index addadeb..88ed149 100644 --- a/data/themes/black.edc +++ b/data/themes/black.edc @@ -1,5 +1,8 @@ -collections { +data { + item: "title" "Black theme"; +} +collections { /* simple layout to pack our scrolling content into an elm_layout */ group { name: "elm/code/layout/default"; data { diff --git a/data/themes/solarized.edc b/data/themes/solarized.edc index 25142e2..cfcf9e5 100644 --- a/data/themes/solarized.edc +++ b/data/themes/solarized.edc @@ -1,5 +1,8 @@ -collections { +data { + item: "title" "Solarized"; +} +collections { /* simple layout to pack our scrolling content into an elm_layout */ group { name: "elm/code/layout/default"; data { diff --git a/data/themes/solarized_dark.edc b/data/themes/solarized_dark.edc index 6da9572..a3b728c 100644 --- a/data/themes/solarized_dark.edc +++ b/data/themes/solarized_dark.edc @@ -1,3 +1,7 @@ +data { + item: "title" "Solarized Dark"; +} + collections { /* simple layout to pack our scrolling content into an elm_layout */ diff --git a/data/themes/white.edc b/data/themes/white.edc index fa55108..a8c4389 100644 --- a/data/themes/white.edc +++ b/data/themes/white.edc @@ -1,5 +1,8 @@ -collections { +data { + item: "title" "Black on White"; +} +collections { /* simple layout to pack our scrolling content into an elm_layout */ group { name: "elm/code/layout/default"; data { diff --git a/src/bin/edi_theme.c b/src/bin/edi_theme.c index a2ba60a..2872400 100644 --- a/src/bin/edi_theme.c +++ b/src/bin/edi_theme.c @@ -35,6 +35,25 @@ edi_theme_elm_code_set(Evas_Object *obj, const char *name) } } +Edi_Theme * +edi_theme_theme_by_name(const char *name) +{ + Eina_List *l; + Edi_Theme *theme; + + if (!name) return NULL; + + edi_theme_themes_get(); + + EINA_LIST_FOREACH(_edi_themes, l, theme) + { + if (!strcmp(theme->name, name)) + return theme; + } + + return NULL; +} + Eina_List * edi_theme_themes_get(void) { @@ -49,6 +68,8 @@ edi_theme_themes_get(void) theme = malloc(sizeof(Edi_Theme)); theme->name = strdup("default"); theme->path = edi_path_append(elm_theme_system_dir_get(), "default.edj"); + theme->title = strdup("Default"); + _edi_themes = eina_list_append(_edi_themes, theme); files = ecore_file_ls(directory); @@ -60,8 +81,8 @@ edi_theme_themes_get(void) name = strdup(file); name[strlen(name) - 4] = '\0'; theme->name = name; - theme->path = edi_path_append(directory, file); + theme->title = edje_file_data_get(theme->path, "title"); _edi_themes = eina_list_append(_edi_themes, theme); } free(file); diff --git a/src/bin/edi_theme.h b/src/bin/edi_theme.h index 552a91f..6d02315 100644 --- a/src/bin/edi_theme.h +++ b/src/bin/edi_theme.h @@ -7,6 +7,7 @@ typedef struct _Edi_Theme { char *name; char *path; + char *title; } Edi_Theme; #ifdef __cplusplus @@ -47,6 +48,16 @@ void edi_theme_elm_code_set(Evas_Object *obj, const char *name); */ Eina_List *edi_theme_themes_get(void); +/** + * Get theme obj by its name. + * + * @return the theme obj matching the name. + * + * @ingroup Theme + */ +Edi_Theme *edi_theme_theme_by_name(const char *name); + + /** * @} */ diff --git a/src/bin/screens/edi_settings.c b/src/bin/screens/edi_settings.c index c2f890a..34ec76b 100644 --- a/src/bin/screens/edi_settings.c +++ b/src/bin/screens/edi_settings.c @@ -146,12 +146,15 @@ _edi_settings_font_preview_add(Evas_Object *parent, const char *font_name, int f static void _edi_settings_display_theme_pressed_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info) { + Edi_Theme *theme; const char *text = elm_object_item_text_get(event_info); + theme = elm_object_item_data_get(event_info); + if (_edi_project_config->gui.theme) eina_stringshare_del(_edi_project_config->gui.theme); - _edi_project_config->gui.theme = eina_stringshare_add(text); + _edi_project_config->gui.theme = eina_stringshare_add(theme->name); _edi_project_config_save(); elm_object_text_set(obj, text); @@ -162,14 +165,10 @@ static char * _edi_settings_display_theme_text_get_cb(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED) { Edi_Theme *current; - int i; - i = (int)(uintptr_t) data; - current = eina_list_nth(edi_theme_themes_get(), i); + current = data; - if (!current) return NULL; - - return strdup(current->name); + return strdup(current->title); } static Evas_Object * @@ -180,7 +179,6 @@ _edi_settings_display_create(Evas_Object *parent) Elm_Genlist_Item_Class *itc; Edi_Theme *theme; Eina_List *themes, *l; - int i = 0; frame = _edi_settings_panel_create(parent, _("Display")); box = elm_object_part_content_get(frame, "default"); @@ -227,7 +225,7 @@ _edi_settings_display_create(Evas_Object *parent) if (!_edi_project_config->gui.theme) elm_object_text_set(combobox, _("default")); else - elm_object_text_set(combobox, _edi_project_config->gui.theme); + elm_object_text_set(combobox, edi_theme_theme_by_name(_edi_project_config->gui.theme)->title); elm_table_pack(table, combobox, 1, 1, 1, 1); elm_box_pack_end(box, table); @@ -239,8 +237,7 @@ _edi_settings_display_create(Evas_Object *parent) EINA_LIST_FOREACH(themes, l, theme) { - elm_genlist_item_append(combobox, itc, (void *)(uintptr_t) i, NULL, ELM_GENLIST_ITEM_NONE, NULL, (void *)(uintptr_t) i); - i++; + elm_genlist_item_append(combobox, itc, theme, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); } elm_genlist_realized_items_update(combobox);