yakov pushed a commit to branch master. http://git.enlightenment.org/tools/erigo.git/commit/?id=918289db03634f948b2b85a987692a8743e9adc7
commit 918289db03634f948b2b85a987692a8743e9adc7 Author: Yakov Goldberg <yako...@samsung.com> Date: Sun Jun 28 16:32:00 2015 +0300 Refactor and fix open/close multi contexts --- src/bin/gui/editor.c | 6 ++- src/bin/gui/egui_logic.c | 124 +++++++++++++++++++++++------------------------ src/bin/gui/egui_logic.h | 5 +- src/bin/main.c | 4 +- 4 files changed, 66 insertions(+), 73 deletions(-) diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c index 9119c49..24d03e9 100644 --- a/src/bin/gui/editor.c +++ b/src/bin/gui/editor.c @@ -4586,8 +4586,8 @@ _project_close(const Gui_Context *ctx) if (itnext) { + /* This will call toolbar item clicked. */ elm_toolbar_item_selected_set(itnext, EINA_TRUE); - _switch_to_context(elm_object_item_data_get(itnext)); } } @@ -4595,7 +4595,9 @@ _project_close(const Gui_Context *ctx) gui_context_del((Gui_Context *) ctx); } if (!gui_contexts_count_get()) - _active_context_set(NULL); + { + _active_context_set(NULL); + } } static Eina_Bool diff --git a/src/bin/gui/egui_logic.c b/src/bin/gui/egui_logic.c index 5b825fa..1b548be 100644 --- a/src/bin/gui/egui_logic.c +++ b/src/bin/gui/egui_logic.c @@ -71,6 +71,11 @@ canvas_get() static void _main_win_del_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED) { + Gui_Context *ctx; + while ((ctx = _active_context_get())) + { + _guilogic_cbs->_project_close(ctx); + } printf("win del\n"); elm_exit(); } @@ -915,8 +920,61 @@ _key_binding_save_cb(void *data) } } +static void +_egui_project_open(const char *path) +{ + if (path) + { + Eina_Bool post_open = EINA_FALSE; + /* If file exists try open it. */ + if (ecore_file_exists(path)) + { + if (_guilogic_cbs->_project_new(path)) + { + post_open = EINA_TRUE; + } + } + /* If not, create new file. */ + else + { + if (_guilogic_cbs->_project_new(NULL)) + { + const Gui_Context *ctx = _active_context_get(); + + char *_dir = ecore_file_dir_get(path); + const char *filename = ecore_file_file_get(path); + + gui_context_project_name_set((Gui_Context *) ctx, filename); + gui_context_project_path_set((Gui_Context *) ctx, _dir); + gui_context_project_filename_set((Gui_Context *) ctx, filename); + generator_ctx_source_generate(ctx, GENERATE_JSON); + _canvas_name_update(ctx); + + free(_dir); + post_open = EINA_TRUE; + } + } + + if (post_open) + { + _canvas_name_update(_active_context_get()); + /* If no more free contexts, disable items. */ + if (!gui_context_free_is()) + { + _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_TRUE); + _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_TRUE); + } + _menu_item_disabled_set(project_menu, ITEM_CLOSE, EINA_FALSE); + _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_FALSE); + _menu_item_disabled_set(project_menu, ITEM_SAVEAS, EINA_FALSE); + _menu_item_disabled_set(project_menu, ITEM_EXPORT, EINA_FALSE); + _guilogic_cbs->_theme_hoversel_fill(); + } + } +} + void -egui_start() +egui_start(const char *filename) { g_main_wdgs = egui_layout_gui_get(); @@ -1070,6 +1128,7 @@ egui_start() /*FIXME: Need to unpack inline image, so pass it into delete callback*/ evas_object_smart_callback_add(g_main_wdgs->main_win->main_win, "delete,request", _main_win_del_cb, NULL); _factory_vertical_pack(EINA_FALSE); + _egui_project_open(filename); } void @@ -1079,66 +1138,3 @@ egui_stop() editor_shutdown(); key_bindings_shutdown(); } - -void -egui_project_open(char *path) -{ - if (path) - { - Eina_Bool post_open = EINA_FALSE; - /* If file exists try open it. */ - if (ecore_file_exists(path)) - { - if (_guilogic_cbs->_project_new(path)) - { - post_open = EINA_TRUE; - } - } - /* If not, create new file. */ - else - { - if (_guilogic_cbs->_project_new(NULL)) - { - const Gui_Context *ctx = _active_context_get(); - - char *_dir = ecore_file_dir_get(path); - const char *filename = ecore_file_file_get(path); - - gui_context_project_name_set((Gui_Context *) ctx, filename); - gui_context_project_path_set((Gui_Context *) ctx, _dir); - gui_context_project_filename_set((Gui_Context *) ctx, filename); - generator_ctx_source_generate(ctx, GENERATE_JSON); - _canvas_name_update(ctx); - - free(_dir); - post_open = EINA_TRUE; - } - } - - if (post_open) - { - _canvas_name_update(_active_context_get()); - /* If no more free contexts, disable items. */ - if (!gui_context_free_is()) - { - _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_TRUE); - _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_TRUE); - } - _menu_item_disabled_set(project_menu, ITEM_CLOSE, EINA_FALSE); - _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_FALSE); - _menu_item_disabled_set(project_menu, ITEM_SAVEAS, EINA_FALSE); - _menu_item_disabled_set(project_menu, ITEM_EXPORT, EINA_FALSE); - _guilogic_cbs->_theme_hoversel_fill(); - } - } -} - -void -egui_project_close() -{ - const Gui_Context *ctx = _active_context_get(); - if (ctx) - { - _guilogic_cbs->_project_close(ctx); - } -} diff --git a/src/bin/gui/egui_logic.h b/src/bin/gui/egui_logic.h index b363d72..258d012 100644 --- a/src/bin/gui/egui_logic.h +++ b/src/bin/gui/egui_logic.h @@ -4,10 +4,7 @@ #include "egui_layout.h" -void egui_start(); +void egui_start(const char *filename); void egui_stop(); -void egui_project_open(char *filename); -void egui_project_close(); - #endif diff --git a/src/bin/main.c b/src/bin/main.c index b63c6db..a6ae243 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -253,10 +253,8 @@ main(int argc, char **argv) if (mode == MODE_GUI) { #ifdef GUI_MODE - egui_start(); - egui_project_open(filename); + egui_start(filename); elm_run(); - egui_project_close(); egui_stop(); #else printf("You are trying to use \"erigo_cmd\" in graphic mode. Nothing is going to happen :)\n"); --