ajwillia-ms pushed a commit to branch master. http://git.enlightenment.org/tools/edi.git/commit/?id=a10c4aacb664e6cec0bb6cf6a09a833151ef1caf
commit a10c4aacb664e6cec0bb6cf6a09a833151ef1caf Author: Andy Williams <a...@andywilliams.me> Date: Thu Jun 8 18:31:45 2017 -0700 ui: Speed up screen load and remember current tab This is a pretty simple type of backgrounding - only load files for tabs as they become visible :) --- src/bin/edi_config.c | 9 +++- src/bin/edi_config.h | 5 +- src/bin/edi_main.c | 11 +++- src/bin/editor/edi_editor.c | 4 +- src/bin/mainview/edi_mainview.c | 101 ++++++++++++++++++++++++++++------- src/bin/mainview/edi_mainview.h | 2 + src/bin/mainview/edi_mainview_item.h | 3 +- src/lib/edi_path.h | 1 + 8 files changed, 109 insertions(+), 27 deletions(-) diff --git a/src/bin/edi_config.c b/src/bin/edi_config.c index 20ef53c..93339bd 100644 --- a/src/bin/edi_config.c +++ b/src/bin/edi_config.c @@ -132,6 +132,7 @@ _edi_project_config_cb_free(void) EINA_LIST_FREE(_edi_project_config->tabs, tab) { if (tab->path) eina_stringshare_del(tab->path); + if (tab->type) eina_stringshare_del(tab->type); free(tab); } @@ -231,6 +232,7 @@ _edi_config_init(void) #define T Edi_Project_Config_Tab #define D _edi_proj_cfg_tab_edd EDI_CONFIG_VAL(D, T, path, EET_T_STRING); + EDI_CONFIG_VAL(D, T, type, EET_T_STRING); EDI_CONFIG_VAL(D, T, windowed, EET_T_UCHAR); _edi_proj_cfg_edd = EDI_CONFIG_DD_NEW("Project_Config", Edi_Project_Config); @@ -256,6 +258,7 @@ _edi_config_init(void) EDI_CONFIG_VAL(D, T, gui.tab_inserts_spaces, EET_T_UCHAR); EDI_CONFIG_LIST(D, T, tabs, _edi_proj_cfg_tab_edd); + EDI_CONFIG_VAL(D, T, current_tab, EET_T_UINT); EDI_CONFIG_VAL(D, T, launch.path, EET_T_STRING); EDI_CONFIG_VAL(D, T, launch.args, EET_T_STRING); @@ -499,7 +502,8 @@ _edi_project_config_save() } void -_edi_project_config_tab_add(const char *path, Eina_Bool windowed) +_edi_project_config_tab_add(const char *path, const char *type, + Eina_Bool windowed) { Edi_Project_Config_Tab *tab; Eina_List *list, *next; @@ -518,6 +522,7 @@ _edi_project_config_tab_add(const char *path, Eina_Bool windowed) else tab->path = eina_stringshare_add(path); + tab->type = eina_stringshare_add(type); tab->windowed = windowed; _edi_project_config->tabs = eina_list_append(_edi_project_config->tabs, tab); _edi_project_config_save_no_notify(); @@ -542,5 +547,7 @@ _edi_project_config_tab_remove(const char *path) _edi_project_config_save_no_notify(); eina_stringshare_del(tab->path); + if (tab->type) + eina_stringshare_del(tab->type); free(tab); } diff --git a/src/bin/edi_config.h b/src/bin/edi_config.h index b8e42cd..249f0b6 100644 --- a/src/bin/edi_config.h +++ b/src/bin/edi_config.h @@ -48,6 +48,7 @@ struct _Edi_Config struct _Edi_Project_Config_Tab { const char *path; + const char *type; Eina_Bool windowed; }; @@ -81,6 +82,7 @@ struct _Edi_Project_Config } gui; Eina_List *tabs; + unsigned int current_tab; Edi_Project_Config_Launch launch; Eina_Stringshare *user_fullname; Eina_Stringshare *user_email; @@ -111,7 +113,8 @@ const char* _edi_config_mime_search(const char *mime); void _edi_project_config_load(void); void _edi_project_config_save(void); -void _edi_project_config_tab_add(const char *path, Eina_Bool windowed); +void _edi_project_config_tab_add(const char *path, const char *type, + Eina_Bool windowed); void _edi_project_config_tab_remove(const char *path); #ifdef __cplusplus diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index cb66905..6f3a6fd 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -1262,6 +1262,7 @@ void _edi_open_tabs() { Edi_Project_Config_Tab *tab; + Edi_Path_Options *options; Eina_List *tabs, *list; char *path; @@ -1274,10 +1275,13 @@ _edi_open_tabs() else path = edi_path_append(edi_project_get(), tab->path); + options = edi_path_options_create(path); + options->type = eina_stringshare_add(tab->type); + options->background = EINA_TRUE; if (tab->windowed) - edi_mainview_open_window_path(eina_stringshare_add(path)); + edi_mainview_open_window(options); else - edi_mainview_open_path(eina_stringshare_add(path)); + edi_mainview_open(options); free(path); } @@ -1285,6 +1289,9 @@ _edi_open_tabs() { free(tab); } + + if (_edi_project_config->current_tab != 0) + edi_mainview_tab_select(_edi_project_config->current_tab); } static void diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c index afab1c5..d7a8e10 100644 --- a/src/bin/editor/edi_editor.c +++ b/src/bin/editor/edi_editor.c @@ -1159,9 +1159,9 @@ edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item) (void)!evas_object_key_grab(widget, "g", ctrl, shift | alt, 1); (void)!evas_object_key_grab(widget, "space", ctrl, shift | alt, 1); - evas_object_data_set(vbox, "editor", editor); + evas_object_data_set(item->view, "editor", editor); ev_handler = ecore_event_handler_add(EDI_EVENT_CONFIG_CHANGED, _edi_editor_config_changed, widget); - evas_object_event_callback_add(vbox, EVAS_CALLBACK_DEL, _editor_del_cb, ev_handler); + evas_object_event_callback_add(item->view, EVAS_CALLBACK_DEL, _editor_del_cb, ev_handler); if (edi_language_provider_has(editor)) { diff --git a/src/bin/mainview/edi_mainview.c b/src/bin/mainview/edi_mainview.c index 6652376..c088435 100644 --- a/src/bin/mainview/edi_mainview.c +++ b/src/bin/mainview/edi_mainview.c @@ -37,14 +37,30 @@ edi_mainview_item_current_get() EINA_LIST_FOREACH(_edi_mainview_items, item, it) { if (it && it->view == _current_view) - { - return it; - } + return it; } return NULL; } +unsigned int +edi_mainview_item_current_tab_get() +{ + Eina_List *item; + Edi_Mainview_Item *it; + unsigned int i = 0; + + EINA_LIST_FOREACH(_edi_mainview_items, item, it) + { + if (!it->win) + i++; + if (it && it->view == _current_view) + break; + } + + return i; +} + static void _edi_mainview_view_show(Evas_Object *view) { @@ -101,7 +117,6 @@ edi_mainview_item_next() EINA_LIST_FOREACH(_edi_mainview_items, item, it) { - if (it && open_next) { edi_mainview_item_select(it); @@ -114,6 +129,44 @@ edi_mainview_item_next() } void +edi_mainview_tab_select(unsigned int id) +{ + Eina_List *item; + Edi_Mainview_Item *it; + unsigned int i = 0; + + EINA_LIST_FOREACH(_edi_mainview_items, item, it) + { + if (!it->win) + i++; + if (i == id) + edi_mainview_item_select(it); + } +} + +static void +_content_load(Edi_Mainview_Item *item) +{ + Edi_Content_Provider *provider; + Evas_Object *child; + + provider = edi_content_provider_for_id_get(item->editortype); + if (!provider) + { + ERR("No content provider found for type %s", item->editortype); + return; + } + child = provider->content_ui_add(item->container, item); + + evas_object_size_hint_weight_set(child, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(child, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(item->container, child); + evas_object_show(child); + + item->loaded = EINA_TRUE; +} + +void edi_mainview_item_select(Edi_Mainview_Item *item) { Eina_List *list; @@ -134,11 +187,16 @@ edi_mainview_item_select(Edi_Mainview_Item *item) total_w += w; } + if (!item->loaded) + _content_load(item); + _edi_mainview_view_show(item->view); elm_object_signal_emit(item->tab, "mouse,down,1", "base"); evas_object_geometry_get(item->tab, NULL, NULL, &tabw, NULL); elm_scroller_region_bring_in(_tab_scroller, region_x, 0, tabw, 0); + _edi_project_config->current_tab = edi_mainview_item_current_tab_get(); + _edi_project_config_save(); } ecore_event_add(EDI_EVENT_TAB_CHANGED, NULL, NULL, NULL); @@ -193,7 +251,7 @@ _get_item_for_path(const char *path) } static Edi_Mainview_Item * -_edi_mainview_item_add(Edi_Path_Options *path, const char *mime, Elm_Object_Item *tab, Elm_Object_Item *view, +_edi_mainview_item_add(Edi_Path_Options *path, const char *mime, Elm_Object_Item *tab, Evas_Object *win) { Edi_Mainview_Item *item; @@ -203,7 +261,6 @@ _edi_mainview_item_add(Edi_Path_Options *path, const char *mime, Elm_Object_Item item->editortype = path->type; item->mimetype = mime; item->tab = tab; - item->view = view; item->win = win; _edi_mainview_items = eina_list_append(_edi_mainview_items, item); @@ -214,13 +271,17 @@ _edi_mainview_item_add(Edi_Path_Options *path, const char *mime, Elm_Object_Item static Evas_Object * _edi_mainview_content_create(Edi_Mainview_Item *item, Evas_Object *parent) { - Edi_Content_Provider *provider; + Evas_Object *container; - provider = edi_content_provider_for_id_get(item->editortype); - if (!provider) - return NULL; + container = elm_box_add(parent); + evas_object_size_hint_weight_set(container, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(container, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(container); + + item->loaded = EINA_FALSE; + item->container = container; - return provider->content_ui_add(parent, item); + return container; } static void @@ -229,12 +290,9 @@ _edi_mainview_item_tab_add(Edi_Path_Options *options, const char *mime) Evas_Object *content, *tab;//, *icon; Edi_Mainview_Item *item; Edi_Editor *editor; -// Edi_Content_Provider *provider; - item = _edi_mainview_item_add(options, mime, NULL, NULL, NULL); -// provider = edi_content_provider_for_id_get(item->editortype); + item = _edi_mainview_item_add(options, mime, NULL, NULL); content = _edi_mainview_content_create(item, _content_frame); - _edi_mainview_view_show(content); item->view = content; @@ -256,7 +314,9 @@ _edi_mainview_item_tab_add(Edi_Path_Options *options, const char *mime) evas_object_show(tab); elm_box_recalculate(tb); item->tab = tab; - edi_mainview_item_select(item); + + if (!options->background) + edi_mainview_item_select(item); // Set focus on the newly opening window so that one can just start typing editor = (Edi_Editor *)evas_object_data_get(content, "editor"); @@ -266,7 +326,7 @@ _edi_mainview_item_tab_add(Edi_Path_Options *options, const char *mime) if (options->line) edi_mainview_goto(options->line); - _edi_project_config_tab_add(options->path, EINA_FALSE); + _edi_project_config_tab_add(options->path, options->type, EINA_FALSE); } static void @@ -311,11 +371,12 @@ _edi_mainview_item_win_add(Edi_Path_Options *options, const char *mime) elm_win_focus_highlight_enabled_set(win, EINA_TRUE); evas_object_smart_callback_add(win, "delete,request", _edi_mainview_win_exit, NULL); - item = _edi_mainview_item_add(options, mime, NULL, NULL, win); + item = _edi_mainview_item_add(options, mime, NULL, win); evas_object_data_set(win, "edi_mainview_item", item); content = _edi_mainview_content_create(item, win); elm_win_resize_object_add(win, content); + _content_load(item); // Set focus on the newly opening window so that one can just start typing editor = (Edi_Editor *)evas_object_data_get(content, "editor"); @@ -325,7 +386,7 @@ _edi_mainview_item_win_add(Edi_Path_Options *options, const char *mime) evas_object_resize(win, 380 * elm_config_scale_get(), 260 * elm_config_scale_get()); evas_object_show(win); - _edi_project_config_tab_add(options->path, EINA_TRUE); + _edi_project_config_tab_add(options->path, options->type, EINA_TRUE); } static void @@ -803,7 +864,7 @@ edi_mainview_project_search_popup_show(void) input = elm_entry_add(box); elm_entry_single_line_set(input, EINA_TRUE); evas_object_event_callback_add(input, EVAS_CALLBACK_KEY_UP, _edi_mainview_goto_popup_key_up_cb, NULL); - evas_object_size_hint_weight_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(input, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(input); elm_box_pack_end(box, input); diff --git a/src/bin/mainview/edi_mainview.h b/src/bin/mainview/edi_mainview.h index d98b601..e268b45 100644 --- a/src/bin/mainview/edi_mainview.h +++ b/src/bin/mainview/edi_mainview.h @@ -267,6 +267,8 @@ void edi_mainview_item_prev(); */ void edi_mainview_item_next(); +void edi_mainview_tab_select(unsigned int id); + /** * @} * diff --git a/src/bin/mainview/edi_mainview_item.h b/src/bin/mainview/edi_mainview_item.h index 0fde7ef..2cc5d5b 100644 --- a/src/bin/mainview/edi_mainview_item.h +++ b/src/bin/mainview/edi_mainview_item.h @@ -32,7 +32,8 @@ typedef struct _Edi_Mainview_Item /* Private */ - /* Add new members here. */ + Evas_Object *container; /**< The visual container that the item will display within */ + Eina_Bool loaded; } Edi_Mainview_Item; #ifdef __cplusplus diff --git a/src/lib/edi_path.h b/src/lib/edi_path.h index a11251e..d2840f9 100644 --- a/src/lib/edi_path.h +++ b/src/lib/edi_path.h @@ -15,6 +15,7 @@ typedef struct _Edi_Path_Options const char *path; const char *type; int line, character; + Eina_Bool background; } Edi_Path_Options; /** --