forked from enlightenment/enventor
setting: code refactoring.
clean up code. this is one step for setting extension.
This commit is contained in:
parent
2be4e6c3d3
commit
8a837c3b4a
|
@ -4,7 +4,12 @@
|
|||
#include "common.h"
|
||||
#include "text_setting.h"
|
||||
|
||||
struct setting_s
|
||||
typedef enum {
|
||||
SETTING_VIEW_GENERAL = 0,
|
||||
SETTING_VIEW_TEXT
|
||||
} setting_view;
|
||||
|
||||
typedef struct setting_s
|
||||
{
|
||||
Evas_Object *setting_layout;
|
||||
|
||||
|
@ -31,12 +36,17 @@ struct setting_s
|
|||
Evas_Object *apply_btn;
|
||||
Evas_Object *reset_btn;
|
||||
Evas_Object *cancel_btn;
|
||||
};
|
||||
|
||||
typedef struct setting_s setting_data;
|
||||
setting_view current_view;
|
||||
} setting_data;
|
||||
|
||||
static setting_data *g_sd = NULL;
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Internal method implementation */
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
img_path_entry_update(Evas_Object *entry, Eina_List *edc_img_paths)
|
||||
{
|
||||
|
@ -194,7 +204,6 @@ setting_reset_btn_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
|
|||
text_setting_linenumber_set(config_linenumber_get());
|
||||
text_setting_auto_indent_set(config_auto_indent_get());
|
||||
text_setting_auto_complete_set(config_auto_complete_get());
|
||||
|
||||
text_setting_syntax_color_reset();
|
||||
}
|
||||
|
||||
|
@ -464,26 +473,22 @@ general_layout_create(setting_data *sd, Evas_Object *parent)
|
|||
}
|
||||
|
||||
static void
|
||||
general_tab_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
||||
void *event_info EINA_UNUSED)
|
||||
general_setting_focus_set(void)
|
||||
{
|
||||
setting_data *sd = data;
|
||||
Evas_Object *content;
|
||||
|
||||
if (!sd->setting_layout) return;
|
||||
|
||||
content = elm_object_part_content_get(sd->setting_layout,
|
||||
"elm.swallow.content");
|
||||
|
||||
if (content == sd->general_layout) return;
|
||||
|
||||
elm_object_part_content_unset(sd->setting_layout, "elm.swallow.content");
|
||||
evas_object_hide(content);
|
||||
|
||||
elm_object_part_content_set(sd->setting_layout, "elm.swallow.content",
|
||||
sd->general_layout);
|
||||
setting_data *sd = g_sd;
|
||||
elm_object_focus_set(sd->img_path_entry, EINA_TRUE);
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
general_setting_content_get(Evas_Object *parent EINA_UNUSED)
|
||||
{
|
||||
setting_data *sd = g_sd;
|
||||
return sd->general_layout;
|
||||
}
|
||||
|
||||
static void
|
||||
focus_custom_chain_set(setting_data *sd, Evas_Object *content)
|
||||
{
|
||||
//Set a custom chain to set the focus order.
|
||||
Eina_List *custom_chain = NULL;
|
||||
custom_chain = eina_list_append(custom_chain, sd->tabbar);
|
||||
|
@ -495,14 +500,52 @@ general_tab_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
}
|
||||
|
||||
static void
|
||||
text_setting_tab_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
||||
void *event_info EINA_UNUSED)
|
||||
toolbar_general_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
||||
void *event_info EINA_UNUSED)
|
||||
{
|
||||
setting_data *sd = data;
|
||||
text_setting_layout_show(sd->setting_layout, sd->tabbar, sd->apply_btn,
|
||||
sd->reset_btn, sd->cancel_btn);
|
||||
|
||||
if (sd->current_view == SETTING_VIEW_GENERAL) return;
|
||||
|
||||
//Hide previous tab view
|
||||
Evas_Object *pcontent = elm_object_part_content_unset(sd->setting_layout,
|
||||
"elm.swallow.content");
|
||||
evas_object_hide(pcontent);
|
||||
|
||||
Evas_Object *content = general_setting_content_get(obj);
|
||||
elm_object_part_content_set(sd->setting_layout, "elm.swallow.content",
|
||||
content);
|
||||
focus_custom_chain_set(sd, content);
|
||||
general_setting_focus_set();
|
||||
|
||||
sd->current_view = SETTING_VIEW_GENERAL;
|
||||
}
|
||||
|
||||
static void
|
||||
toolbar_text_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
|
||||
{
|
||||
setting_data *sd = data;
|
||||
|
||||
if (sd->current_view == SETTING_VIEW_TEXT) return;
|
||||
|
||||
//Hide previous tab view
|
||||
Evas_Object *pcontent = elm_object_part_content_unset(sd->setting_layout,
|
||||
"elm.swallow.content");
|
||||
evas_object_hide(pcontent);
|
||||
|
||||
Evas_Object *content = text_setting_content_get(obj);
|
||||
elm_object_part_content_set(sd->setting_layout, "elm.swallow.content",
|
||||
content);
|
||||
focus_custom_chain_set(sd, content);
|
||||
text_setting_focus_set();
|
||||
|
||||
sd->current_view = SETTING_VIEW_TEXT;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Externally accessible calls */
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
setting_open(void)
|
||||
{
|
||||
|
@ -538,8 +581,8 @@ setting_open(void)
|
|||
elm_toolbar_select_mode_set(tabbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
|
||||
evas_object_size_hint_weight_set(tabbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
|
||||
elm_toolbar_item_append(tabbar, NULL, _("General"), general_tab_cb, sd);
|
||||
elm_toolbar_item_append(tabbar, NULL, _("Text Editor"), text_setting_tab_cb, sd);
|
||||
elm_toolbar_item_append(tabbar, NULL, _("General"), toolbar_general_cb, sd);
|
||||
elm_toolbar_item_append(tabbar, NULL, _("Text Editor"), toolbar_text_cb, sd);
|
||||
|
||||
elm_object_part_content_set(layout, "elm.swallow.tabbar", tabbar);
|
||||
|
||||
|
@ -547,11 +590,6 @@ setting_open(void)
|
|||
Evas_Object *general_layout = general_layout_create(sd, layout);
|
||||
elm_object_part_content_set(layout, "elm.swallow.content", general_layout);
|
||||
|
||||
//Text setting layout
|
||||
Evas_Object *text_setting_layout;
|
||||
text_setting_layout = text_setting_layout_create(layout);
|
||||
evas_object_hide(text_setting_layout);
|
||||
|
||||
//Apply Button
|
||||
Evas_Object *apply_btn = elm_button_add(layout);
|
||||
elm_object_text_set(apply_btn, _("Apply"));
|
||||
|
@ -578,6 +616,7 @@ setting_open(void)
|
|||
sd->apply_btn = apply_btn;
|
||||
sd->reset_btn = reset_btn;
|
||||
sd->cancel_btn = cancel_btn;
|
||||
sd->current_view = SETTING_VIEW_GENERAL;
|
||||
|
||||
menu_activate_request();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
#include "common.h"
|
||||
#include "text_setting.h"
|
||||
|
||||
#define UNSUPPORTED_FONT_CNT 28
|
||||
#define UNSUPPORTED_FONT_MAX_LEN 32
|
||||
|
@ -11,6 +10,35 @@
|
|||
#define SYNTAX_TEMPLATE_FONT_SIZE 10
|
||||
#define SYNTAX_COLOR_LEN 7
|
||||
|
||||
typedef struct color_keyword_s
|
||||
{
|
||||
int pos_begin;
|
||||
int pos_end;
|
||||
int color_type;
|
||||
} color_keyword;
|
||||
|
||||
typedef struct text_setting_s
|
||||
{
|
||||
Evas_Object *layout;
|
||||
Evas_Object *text_edit_entry;
|
||||
Evas_Object *color_ctxpopup;
|
||||
|
||||
Evas_Object *slider_font;
|
||||
Evas_Object *toggle_linenum;
|
||||
Evas_Object *toggle_indent;
|
||||
Evas_Object *toggle_autocomp;
|
||||
Evas_Object *toggle_smart_undo_redo;
|
||||
Evas_Object *list_font_name;
|
||||
|
||||
color_keyword *color_keyword_list;
|
||||
char *syntax_template_format;
|
||||
char *syntax_template_str;
|
||||
|
||||
const char *font_name;
|
||||
const char *font_style;
|
||||
double font_scale;
|
||||
} text_setting_data;
|
||||
|
||||
static char unsupported_font_list[UNSUPPORTED_FONT_CNT][UNSUPPORTED_FONT_MAX_LEN] =
|
||||
{
|
||||
"Dingbats", "KacstArt", "KacstBook", "KacstDecorative", "KacstDigital",
|
||||
|
@ -67,13 +95,18 @@ static int color_type_list[COLOR_KEYWORD_MAX_CNT] =
|
|||
|
||||
static text_setting_data *g_tsd = NULL;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Internal method implementation */
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
syntax_template_set(char *syntax_template_str, char *syntax_template_format,
|
||||
double font_scale)
|
||||
{
|
||||
if (!syntax_template_str || !syntax_template_format) return;
|
||||
|
||||
snprintf(syntax_template_str, SYNTAX_TEMPLATE_MAX_LEN, syntax_template_format,
|
||||
snprintf(syntax_template_str, SYNTAX_TEMPLATE_MAX_LEN,
|
||||
syntax_template_format,
|
||||
(int) ((SYNTAX_TEMPLATE_FONT_SIZE * font_scale) + 0.5),
|
||||
color_val[color_type_list[0]], color_val[color_type_list[1]],
|
||||
color_val[color_type_list[2]], color_val[color_type_list[3]],
|
||||
|
@ -119,7 +152,7 @@ static void
|
|||
syntax_template_apply(void)
|
||||
{
|
||||
text_setting_data *tsd = g_tsd;
|
||||
Evas_Object *layout = tsd->text_setting_layout;
|
||||
Evas_Object *layout = tsd->layout;
|
||||
if (!layout) return;
|
||||
|
||||
Evas_Object *entry = elm_object_part_content_get(layout,
|
||||
|
@ -204,7 +237,7 @@ color_ctxpopup_del_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
|
|||
color_keyword *selected_color_keyword;
|
||||
selected_color_keyword = evas_object_data_get(obj, "color_keyword");
|
||||
|
||||
elm_object_disabled_set(tsd->text_setting_layout, EINA_FALSE);
|
||||
elm_object_disabled_set(tsd->layout, EINA_FALSE);
|
||||
elm_object_focus_set(tsd->slider_font, EINA_TRUE);
|
||||
|
||||
text_setting_syntax_color_update(obj, selected_color_keyword);
|
||||
|
@ -529,7 +562,7 @@ text_setting_double_clicked_cb(void *data, Evas_Object *obj,
|
|||
if ((pos >= selected_color_keyword->pos_begin) &&
|
||||
(pos <= selected_color_keyword->pos_end))
|
||||
{
|
||||
ctxpopup = color_ctxpopup_create(tsd->text_setting_layout,
|
||||
ctxpopup = color_ctxpopup_create(tsd->layout,
|
||||
selected_color_keyword);
|
||||
if (!ctxpopup) return;
|
||||
|
||||
|
@ -695,10 +728,15 @@ is_supported_font(const char *font_name)
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Externally accessible calls */
|
||||
/*****************************************************************************/
|
||||
|
||||
Evas_Object *
|
||||
text_setting_layout_create(Evas_Object *parent)
|
||||
text_setting_content_get(Evas_Object *parent)
|
||||
{
|
||||
text_setting_data *tsd = g_tsd;
|
||||
if (tsd->layout) return tsd->layout;
|
||||
|
||||
//Layout
|
||||
Evas_Object *layout = elm_layout_add(parent);
|
||||
|
@ -882,7 +920,7 @@ text_setting_layout_create(Evas_Object *parent)
|
|||
elm_list_go(list_font_name);
|
||||
if (font_name_it) elm_list_item_selected_set(font_name_it, EINA_TRUE);
|
||||
|
||||
tsd->text_setting_layout = layout;
|
||||
tsd->layout = layout;
|
||||
tsd->text_edit_entry = entry;
|
||||
tsd->slider_font = slider_font;
|
||||
tsd->toggle_linenum = toggle_linenum;
|
||||
|
@ -890,39 +928,15 @@ text_setting_layout_create(Evas_Object *parent)
|
|||
tsd->toggle_autocomp = toggle_autocomp;
|
||||
tsd->toggle_smart_undo_redo = toggle_smart_undo_redo;
|
||||
tsd->list_font_name = list_font_name;
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
void
|
||||
text_setting_layout_show(Evas_Object *setting_layout, Evas_Object *tabbar,
|
||||
Evas_Object *apply_btn, Evas_Object *reset_btn,
|
||||
Evas_Object *cancel_btn)
|
||||
text_setting_focus_set(void)
|
||||
{
|
||||
text_setting_data *tsd = g_tsd;
|
||||
Evas_Object *content;
|
||||
|
||||
if (!setting_layout) return;
|
||||
|
||||
content = elm_object_part_content_get(setting_layout,
|
||||
"elm.swallow.content");
|
||||
|
||||
if (content == tsd->text_setting_layout) return;
|
||||
|
||||
elm_object_part_content_unset(setting_layout, "elm.swallow.content");
|
||||
evas_object_hide(content);
|
||||
|
||||
elm_object_part_content_set(setting_layout, "elm.swallow.content",
|
||||
tsd->text_setting_layout);
|
||||
elm_object_focus_set(tsd->slider_font, EINA_TRUE);
|
||||
|
||||
//Set a custom chain to set the focus order.
|
||||
Eina_List *custom_chain = NULL;
|
||||
custom_chain = eina_list_append(custom_chain, tabbar);
|
||||
custom_chain = eina_list_append(custom_chain, tsd->text_setting_layout);
|
||||
custom_chain = eina_list_append(custom_chain, apply_btn);
|
||||
custom_chain = eina_list_append(custom_chain, reset_btn);
|
||||
custom_chain = eina_list_append(custom_chain, cancel_btn);
|
||||
elm_object_focus_custom_chain_set(setting_layout, custom_chain);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1020,15 +1034,10 @@ text_setting_term(void)
|
|||
text_setting_data *tsd = g_tsd;
|
||||
if (!tsd) return;
|
||||
|
||||
if (tsd->color_ctxpopup)
|
||||
evas_object_del(tsd->color_ctxpopup);
|
||||
|
||||
if (tsd->color_keyword_list)
|
||||
free(tsd->color_keyword_list);
|
||||
if (tsd->syntax_template_format)
|
||||
free(tsd->syntax_template_format);
|
||||
if (tsd->syntax_template_str)
|
||||
free(tsd->syntax_template_str);
|
||||
evas_object_del(tsd->color_ctxpopup);
|
||||
free(tsd->color_keyword_list);
|
||||
free(tsd->syntax_template_format);
|
||||
free(tsd->syntax_template_str);
|
||||
eina_stringshare_del(tsd->font_name);
|
||||
eina_stringshare_del(tsd->font_style);
|
||||
free(tsd);
|
||||
|
|
|
@ -1,36 +1,4 @@
|
|||
typedef struct color_keyword_s
|
||||
{
|
||||
int pos_begin;
|
||||
int pos_end;
|
||||
int color_type;
|
||||
} color_keyword;
|
||||
|
||||
struct text_setting_s
|
||||
{
|
||||
Evas_Object *text_setting_layout;
|
||||
Evas_Object *text_edit_entry;
|
||||
Evas_Object *color_ctxpopup;
|
||||
|
||||
Evas_Object *slider_font;
|
||||
Evas_Object *toggle_linenum;
|
||||
Evas_Object *toggle_indent;
|
||||
Evas_Object *toggle_autocomp;
|
||||
Evas_Object *toggle_smart_undo_redo;
|
||||
Evas_Object *list_font_name;
|
||||
|
||||
color_keyword *color_keyword_list;
|
||||
char *syntax_template_format;
|
||||
char *syntax_template_str;
|
||||
|
||||
const char *font_name;
|
||||
const char *font_style;
|
||||
double font_scale;
|
||||
};
|
||||
|
||||
typedef struct text_setting_s text_setting_data;
|
||||
|
||||
Evas_Object *text_setting_layout_create(Evas_Object *parent);
|
||||
void text_setting_layout_show(Evas_Object *setting_layout, Evas_Object *tabbar, Evas_Object *apply_btn, Evas_Object *reset_btn, Evas_Object *cancel_btn);
|
||||
Evas_Object *text_setting_content_get(Evas_Object *parent);
|
||||
void text_setting_syntax_color_reset(void);
|
||||
void text_setting_syntax_color_save(void);
|
||||
void text_setting_config_set(void);
|
||||
|
@ -42,3 +10,4 @@ void text_setting_auto_complete_set(Eina_Bool enabled);
|
|||
void text_setting_smart_undo_redo_set(Eina_Bool enabled);
|
||||
void text_setting_term(void);
|
||||
void text_setting_init(void);
|
||||
void text_setting_focus_set(void);
|
||||
|
|
Loading…
Reference in New Issue