yakov pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=096cdfe0fd393e19330dfea944aa43b990d8f455

commit 096cdfe0fd393e19330dfea944aa43b990d8f455
Author: Yakov Goldberg <yako...@samsung.com>
Date:   Mon Jun 29 10:36:04 2015 +0300

    Fix update canvas name
---
 src/bin/gui/editor.c             | 64 ++++++++++++++++++++++------------------
 src/bin/gui/egui_logic.c         | 59 ++++++++++++++++++++++--------------
 src/bin/gui/egui_logic_private.h |  3 ++
 src/lib/gui_widget.c             | 17 ++++-------
 4 files changed, 82 insertions(+), 61 deletions(-)

diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c
index 24d03e9..b959fbb 100644
--- a/src/bin/gui/editor.c
+++ b/src/bin/gui/editor.c
@@ -88,6 +88,34 @@ _active_context_get()
    return _active_ctx;
 }
 
+void
+_canvas_name_update(const Gui_Context *ctx)
+{
+   const char* project_name = NULL;
+   char name[100];
+   if (!ctx)
+     {
+        sprintf(name, "Erigo - EFL GUI Builder");
+     }
+   else
+     {
+        project_name = gui_context_project_name_get(ctx);
+        if (!project_name) project_name = "untitled";
+        sprintf(name, "Erigo - %s", project_name);
+     }
+   eo_do(g->main_win->main_win, elm_obj_win_title_set(name));
+
+   /* Find item according to context. */
+   Elm_Object_Item *glit = 
elm_toolbar_first_item_get(g->main_win->context_toolbar);
+   for ( ; glit; glit = elm_toolbar_item_next_get(glit))
+     if (elm_object_item_data_get(glit) == ctx) break;
+
+   if (glit)
+     {
+        eo_do(glit, elm_wdg_item_part_text_set(NULL, project_name));
+     }
+}
+
 typedef enum {
      BORDER_OUT =    0,
      BORDER_LEFT =   1 << 0,
@@ -3943,7 +3971,7 @@ _field_update_from_itemview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Desc
           }
         else
           {
-             Eid *name_id = gui_context_eid_get_by_name(_active_ctx, 
new_value);
+             Eid *name_id = gui_context_eid_get_by_name(_active_context_get(), 
new_value);
              gui_value_name_id_set(val, type, name_id);
              if (type == GUI_TYPE_OBJECT)
                {
@@ -3956,7 +3984,7 @@ _field_update_from_itemview(void *data EINA_UNUSED, Eo 
*obj, const Eo_Event_Desc
           {
              if (type == GUI_TYPE_OBJECT)
                {
-                  Eid *old_name_id = gui_context_eid_get_by_name(_active_ctx, 
old_value);
+                  Eid *old_name_id = 
gui_context_eid_get_by_name(_active_context_get(), old_value);
                   Gui_Widget *w = wdg_get(old_name_id);
                   wdg_parent_set(w, wdg_name_get(wdg_main_wdg_get(wdg)));
                }
@@ -4518,6 +4546,7 @@ _switch_to_context(Gui_Context *ctx)
    _editor_wdg_selected_set(wdg);
    objtree_item_selected_set(wdg);
    _canvas_resize_cb(NULL, g->main_win->canvas_scroller, NULL, NULL);
+   _canvas_name_update(ctx);
 }
 
 static void
@@ -4556,12 +4585,12 @@ _project_close(const Gui_Context *ctx)
 
         /* Set selected widget to NULL, in order to hide border. */
         _editor_wdg_selected_set(NULL);
-        _editor_layout_clear(_active_ctx);
+        _editor_layout_clear(_active_context_get());
 
         /* Iterate over windows and delete Main_Wdg_Info */
         Eina_List *list, *itr, *itr2;
         Eid *wdg_id;
-        list = gui_context_main_widgets_get(_active_ctx);
+        list = gui_context_main_widgets_get(_active_context_get());
         EINA_LIST_FOREACH_SAFE(list, itr, itr2, wdg_id)
           {
              Gui_Widget *wdg = wdg_get(wdg_id);
@@ -4573,31 +4602,9 @@ _project_close(const Gui_Context *ctx)
                }
           }
 
-        /* Remove context from context_toolbar */
-        Elm_Object_Item *glit = 
elm_toolbar_first_item_get(g->main_win->context_toolbar);
-        for ( ; glit; glit = elm_toolbar_item_next_get(glit))
-           if (elm_object_item_data_get(glit) == ctx) break;
-
-        if (glit)
-          {
-             Elm_Object_Item *itnext = elm_toolbar_item_prev_get(glit);
-             itnext = (itnext) ? itnext : elm_toolbar_item_next_get(glit);
-             elm_object_item_del(glit);
-
-             if (itnext)
-               {
-                  /* This will call toolbar item clicked. */
-                  elm_toolbar_item_selected_set(itnext, EINA_TRUE);
-               }
-          }
-
         session_del((Gui_Session *) gui_context_editor_session_get(ctx));
         gui_context_del((Gui_Context *) ctx);
      }
-   if (!gui_contexts_count_get())
-     {
-        _active_context_set(NULL);
-     }
 }
 
 static Eina_Bool
@@ -4670,9 +4677,10 @@ _project_new(const char *filename)
    _observers_init(ctx);
 
    const char *projname = gui_context_project_name_get(ctx);
-   Elm_Object_Item *glit = 
elm_toolbar_item_append(g->main_win->context_toolbar, NULL, projname, 
_context_toolbar_clicked, ctx);
+   Elm_Object_Item *glit;
+   eo_do(g->main_win->context_toolbar, glit = 
elm_obj_toolbar_item_append(NULL, projname, _context_toolbar_clicked, ctx));
    elm_object_item_data_set(glit, ctx);
-   elm_toolbar_item_selected_set(glit, EINA_TRUE);
+   eo_do(glit, elm_obj_toolbar_item_selected_set(EINA_TRUE));
    return EINA_TRUE;
 }
 
diff --git a/src/bin/gui/egui_logic.c b/src/bin/gui/egui_logic.c
index 1b548be..192069a 100644
--- a/src/bin/gui/egui_logic.c
+++ b/src/bin/gui/egui_logic.c
@@ -68,14 +68,41 @@ canvas_get()
    return g_main_wdgs->main_win->canvas_grid;
 }
 
+/* Deletes item according to context, and switches to the next context. */
+static void
+_context_toolbar_item_delete(const Gui_Context *ctx)
+{
+   /* Remove context from context_toolbar */
+   Elm_Object_Item *glit = 
elm_toolbar_first_item_get(g_main_wdgs->main_win->context_toolbar);
+   for ( ; glit; glit = elm_toolbar_item_next_get(glit))
+     if (elm_object_item_data_get(glit) == ctx) break;
+
+   if (glit)
+     {
+        Elm_Object_Item *itnext;
+        eo_do(glit, itnext = elm_obj_toolbar_item_prev_get());
+        itnext = (itnext) ? itnext : elm_toolbar_item_next_get(glit);
+        eo_do(glit, elm_wdg_item_del());
+
+        if (itnext)
+          {
+             /* This will call toolbar item clicked. */
+             eo_do(itnext, elm_obj_toolbar_item_selected_set(EINA_TRUE));
+          }
+     }
+}
+
 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()))
+   Gui_Context *close_ctx = _active_context_get();
+   while ((close_ctx = _active_context_get()))
      {
-        _guilogic_cbs->_project_close(ctx);
+        _guilogic_cbs->_project_close(close_ctx);
+        _active_context_set(NULL);
+        _context_toolbar_item_delete(close_ctx);
      }
+
    printf("win del\n");
    elm_exit();
 }
@@ -108,24 +135,6 @@ _menu_item_disabled_set(Eo *menu, intptr_t _item_type, 
Eina_Bool disabled)
      elm_object_item_disabled_set(it, disabled);
 }
 
-static void
-_canvas_name_update(const Gui_Context *ctx)
-{
-   const char* project_name;
-   char name[100];
-   if (!ctx)
-     {
-        sprintf(name, "Erigo - EFL GUI Builder");
-     }
-   else
-     {
-        project_name = gui_context_project_name_get(ctx);
-        if (!project_name) project_name = "untitled";
-        sprintf(name, "Erigo - %s", project_name);
-     }
-   eo_do(g_main_wdgs->main_win->main_win, elm_obj_win_title_set(name));
-}
-
 /* Callback to be called after clicking popup button */
 static void
 _popup_cb(Popup_Button_Type button_type, void *data)
@@ -450,7 +459,11 @@ _project_menu_item_sel_cb(void *data, Evas_Object *obj 
EINA_UNUSED, void *event_
            }
       case ITEM_CLOSE:
            {
-              _guilogic_cbs->_project_close(_active_context_get());
+              Gui_Context *close_ctx = _active_context_get();
+              _guilogic_cbs->_project_close(close_ctx);
+              _active_context_set(NULL);
+              _context_toolbar_item_delete(close_ctx);
+
              _canvas_name_update(_active_context_get());
              _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_FALSE);
              _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_FALSE);
@@ -475,6 +488,7 @@ _project_menu_item_sel_cb(void *data, Evas_Object *obj 
EINA_UNUSED, void *event_
                    return;
                 }
               generator_ctx_source_generate(ctx, GENERATE_JSON);
+              _canvas_name_update(ctx);
               break;
            }
       case ITEM_SAVEAS:
@@ -913,6 +927,7 @@ _key_binding_save_cb(void *data)
              return;
           }
         generator_ctx_source_generate(ctx, GENERATE_JSON);
+        _canvas_name_update(ctx);
      }
    else if (action == ITEM_SAVEAS)
      {
diff --git a/src/bin/gui/egui_logic_private.h b/src/bin/gui/egui_logic_private.h
index 5763719..1d921bc 100644
--- a/src/bin/gui/egui_logic_private.h
+++ b/src/bin/gui/egui_logic_private.h
@@ -27,6 +27,9 @@ _active_context_set(Gui_Context *ctx);
 Gui_Context *
 _active_context_get();
 
+void
+_canvas_name_update(const Gui_Context *ctx);
+
 Eo *
 canvas_get();
 
diff --git a/src/lib/gui_widget.c b/src/lib/gui_widget.c
index be9b95a..0b31eff 100644
--- a/src/lib/gui_widget.c
+++ b/src/lib/gui_widget.c
@@ -864,24 +864,19 @@ gui_context_eid_get_by_name(const Gui_Context *ctx, const 
char *name)
    Eid *eid = eina_hash_find(ctx->eids_by_name, name);
    return eid;
 }
-/*
+
 Eina_Bool
 gui_all_contexts_del()
 {
-   Gui_Context *ctx;
-   Eina_List *ctx_list_tmp = eina_list_clone(ctx_list);
-   Eina_List *lst;
-
-   EINA_LIST_FOREACH(ctx_list_tmp, lst, ctx)
+   unsigned int i = 0;
+   /* Looking for free context. */
+   for (i = 1; i < (1 << BITS_PER_CONTEXT); i++)
      {
-        gui_context_del(ctx);
+        if (context_array[i] != NULL)
+          gui_context_del(context_array[i]);
      }
-
-   eina_list_free(ctx_list);
-   eina_list_free(ctx_list_tmp);
    return EINA_TRUE;
 }
-*/
 
 Eina_Bool
 egui_init(const char *db_path, const char *all_eo_path, const char *black_list)

-- 


Reply via email to