yakov pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=1c24eff1035b5049cc0606a4fec8a5198d383860

commit 1c24eff1035b5049cc0606a4fec8a5198d383860
Author: Yakov Goldberg <yako...@samsung.com>
Date:   Tue May 26 16:22:14 2015 +0300

    Add multicontext support
    
    Now it is possible to open up to 15 projects simultaneously
---
 NEWS                         |  3 +-
 src/bin/gui/editor.c         | 92 +++++++++++++++++++++++++++++++++++++++-----
 src/bin/gui/egui_layout.json | 19 ++++++++-
 src/bin/gui/egui_logic.c     | 36 ++++++++++++-----
 src/lib/gui_widget.c         | 31 ++++++++++++---
 src/lib/gui_widget.h         |  8 ++++
 6 files changed, 163 insertions(+), 26 deletions(-)

diff --git a/NEWS b/NEWS
index 2bb0d56..833a130 100644
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,8 @@ https://phab.enlightenment.org/w/projects/gui_builder/
 Changes since 1.0.0
 -------------------
 Features:
-   * Add supoort for widgets: Hoversel
+   * Add support for widgets: Hoversel
+   * Add multicontext support: up to 15 contexts can be opened.
 
 Fixes:
   * Don't show empty hoversel in Property view when there is no resources.
diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c
index b7c9dea..8197904 100644
--- a/src/bin/gui/editor.c
+++ b/src/bin/gui/editor.c
@@ -2825,9 +2825,8 @@ _editor_undo(const Gui_Context *ctx)
 
    gui_context_memento_prev((Gui_Context *) ctx);
 
-   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, 
gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE);
-   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, 
gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE);
-
+   eo_do(g->main_win->toolbar_redo_it, 
elm_wdg_item_disabled_set(gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE));
+   eo_do(g->main_win->toolbar_undo_it, 
elm_wdg_item_disabled_set(gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE));
    return EINA_TRUE;
 }
 
@@ -3024,9 +3023,8 @@ _editor_redo(const Gui_Context *ctx)
    /* Update propview. */
    _editor_undo_redo_post(head_memento);
 
-   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, 
gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE);
-   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, 
gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE);
-
+   eo_do(g->main_win->toolbar_redo_it, 
elm_wdg_item_disabled_set(gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE));
+   eo_do(g->main_win->toolbar_undo_it, 
elm_wdg_item_disabled_set(gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE));
    return EINA_TRUE;
 }
 
@@ -4228,6 +4226,54 @@ _widget_selected_from_objtree(void *data EINA_UNUSED, 
Evas_Object *obj EINA_UNUS
 }
 
 static void
+_context_main_widgets_visibility_set(Gui_Context *ctx, Eina_Bool visible)
+{
+   Eina_List *widgets = gui_context_main_widgets_get(ctx);
+   Eina_List *l = NULL;
+   Eid *eid;
+
+   EINA_LIST_FOREACH(widgets, l, eid)
+     {
+        Gui_Widget *wdg = wdg_get(eid);
+        /* When main widget was selected, while switching context,
+         * need to force hiding its border. */
+        if (!visible)
+          _wdg_border_draw(wdg, EINA_FALSE, BORDER_SELECTION);
+        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
+        Eo *fr = main_wdg_info_frame_get(wi);
+        eo_do(fr, efl_gfx_visible_set(visible));
+     }
+}
+
+static void
+_switch_to_context(Gui_Context *ctx)
+{
+   Gui_Context *prev_ctx = _active_context_get();
+   if (prev_ctx)
+     {
+        _context_main_widgets_visibility_set(prev_ctx, EINA_FALSE);
+     }
+
+   _context_main_widgets_visibility_set(ctx, EINA_TRUE);
+
+   _active_context_set(ctx);
+   objtree_context_set(ctx);
+
+   eo_do(g->main_win->toolbar_redo_it, 
elm_wdg_item_disabled_set(gui_context_can_redo(ctx) ? EINA_FALSE : EINA_TRUE));
+   eo_do(g->main_win->toolbar_undo_it, 
elm_wdg_item_disabled_set(gui_context_can_undo(ctx) ? EINA_FALSE : EINA_TRUE));
+
+   Gui_Widget *wdg = gui_context_data_get(ctx, SELECTED_WDG);
+   _editor_wdg_selected_set(wdg);
+   objtree_item_selected_set(wdg);
+}
+
+static void
+_context_toolbar_clicked(void *data, Evas_Object *obj EINA_UNUSED, void 
*event_info EINA_UNUSED)
+{
+   _switch_to_context(data);
+}
+
+static void
 _project_close(const Gui_Context *ctx)
 {
    /* Clear lists. */
@@ -4274,10 +4320,29 @@ _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)
+               {
+                  elm_toolbar_item_selected_set(itnext, EINA_TRUE);
+                  _switch_to_context(elm_object_item_data_get(itnext));
+               }
+          }
+
         session_del((Gui_Session *) gui_context_editor_session_get(ctx));
         gui_context_del((Gui_Context *) ctx);
      }
-   _active_context_set(NULL);
+   if (!gui_contexts_count_get())
+     _active_context_set(NULL);
 }
 
 static Eina_Bool
@@ -4334,6 +4399,10 @@ _project_new(const char *filename)
           }
      }
 
+   /* Hide main widgets of currently edited context. */
+   if (_active_context_get())
+     _context_main_widgets_visibility_set(_active_context_get(), EINA_FALSE);
+
    /* FIXME: handle return values */
    _active_context_set(ctx);
    objtree_context_set(ctx);
@@ -4344,6 +4413,11 @@ _project_new(const char *filename)
    _editor_ctx_call(ctx);
 
    _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_data_set(glit, ctx);
+   elm_toolbar_item_selected_set(glit, EINA_TRUE);
    return EINA_TRUE;
 }
 
@@ -4361,8 +4435,8 @@ _wdg_border_draw_on_idle(void *data EINA_UNUSED)
 static void
 _update_undo_redo_buttons(void *data EINA_UNUSED)
 {
-   elm_object_item_disabled_set(g->main_win->toolbar_redo_it, EINA_TRUE);
-   elm_object_item_disabled_set(g->main_win->toolbar_undo_it, EINA_FALSE);
+   eo_do(g->main_win->toolbar_redo_it, elm_wdg_item_disabled_set(EINA_TRUE));
+   eo_do(g->main_win->toolbar_undo_it, elm_wdg_item_disabled_set(EINA_FALSE));
 }
 
 static void
diff --git a/src/bin/gui/egui_layout.json b/src/bin/gui/egui_layout.json
index a266dad..6b6b5bd 100644
--- a/src/bin/gui/egui_layout.json
+++ b/src/bin/gui/egui_layout.json
@@ -931,7 +931,7 @@
         "Evas.Object.size_hint_weight":[1, 1],
         "Efl.Gfx.Base.visible":[true]
       },
-      "Contains":["toolbar", "hor_box"]
+      "Contains":["toolbar", "context_toolbar", "hor_box"]
     },
     "toolbar":
     {
@@ -1050,6 +1050,23 @@
         }
       }
     },
+    "context_toolbar":
+    {
+       "Desc":
+       {
+          "parent":"main_box",
+          "class":"Elm.Toolbar",
+          "public":true
+       },
+       "Properties":
+       {
+          "Elm.Toolbar.select_mode":["ELM_OBJECT_SELECT_MODE_DEFAULT"],
+          "Elm.Toolbar.shrink_mode":["ELM_TOOLBAR_SHRINK_NONE"],
+          "Evas.Object.size_hint_weight":[1, 0],
+          "Evas.Object.size_hint_align":[-1, 0],
+          "Efl.Gfx.Base.visible":[true]
+       }
+    },
     "hor_box":
     {
       "Desc":
diff --git a/src/bin/gui/egui_logic.c b/src/bin/gui/egui_logic.c
index 679c3ee..8bf20a8 100644
--- a/src/bin/gui/egui_logic.c
+++ b/src/bin/gui/egui_logic.c
@@ -174,8 +174,12 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void 
*event)
                 {
                    ctx = _active_context_get();
                    _canvas_name_update(ctx);
-                   _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_TRUE);
-                   _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_TRUE);
+                   /* 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);
@@ -201,8 +205,12 @@ _on_fs_done(void *data, Evas_Object *obj EINA_UNUSED, void 
*event)
                 {
                    ctx = _active_context_get();
                    _canvas_name_update(ctx);
-                   _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_TRUE);
-                   _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_TRUE);
+                   /* 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);
@@ -440,10 +448,14 @@ _project_menu_item_sel_cb(void *data, Evas_Object *obj 
EINA_UNUSED, void *event_
              _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);
-             _menu_item_disabled_set(project_menu, ITEM_CLOSE, EINA_TRUE);
-             _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_TRUE);
-             _menu_item_disabled_set(project_menu, ITEM_SAVEAS, EINA_TRUE);
-             _menu_item_disabled_set(project_menu, ITEM_EXPORT, EINA_TRUE);
+             /* If no more opened contexts, disable items. */
+             if (!gui_contexts_count_get())
+               {
+                  _menu_item_disabled_set(project_menu, ITEM_CLOSE, EINA_TRUE);
+                  _menu_item_disabled_set(project_menu, ITEM_SAVE, EINA_TRUE);
+                  _menu_item_disabled_set(project_menu, ITEM_SAVEAS, 
EINA_TRUE);
+                  _menu_item_disabled_set(project_menu, ITEM_EXPORT, 
EINA_TRUE);
+               }
               break;
            }
       case ITEM_SAVE:
@@ -1103,8 +1115,12 @@ egui_project_open(char *path)
         if (post_open)
           {
              _canvas_name_update(_active_context_get());
-             _menu_item_disabled_set(project_menu, ITEM_OPEN, EINA_TRUE);
-             _menu_item_disabled_set(project_menu, ITEM_NEW, EINA_TRUE);
+             /* 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);
diff --git a/src/lib/gui_widget.c b/src/lib/gui_widget.c
index a39cdb0..b91027c 100644
--- a/src/lib/gui_widget.c
+++ b/src/lib/gui_widget.c
@@ -315,27 +315,27 @@ gui_context_new()
 {
    unsigned int i = 0;
    /* Looking for free context. */
-   for (i = 0; i < (BITS_PER_CONTEXT); i++)
+   for (i = 0; i < (1 << BITS_PER_CONTEXT); i++)
      {
         if (context_array[i] == NULL)
           break;
      }
-   if (i == BITS_PER_CONTEXT)
+   if (i == (1 << BITS_PER_CONTEXT))
      {
         ERR("no free context");
         return NULL;
      }
 
    Gui_Context *ctx = (Gui_Context*) calloc(1, sizeof(Gui_Context));
-   ctx->id = i;
-   context_array[i] = ctx;
-
    if (!ctx)
      {
         ERR("ctx == NULL");
         return NULL;
      }
 
+   ctx->id = i;
+   context_array[i] = ctx;
+
    ctx->wdg_list = NULL;
    ctx->main_widgets = NULL;
    ctx->names_hash = eina_hash_string_superfast_new(NULL);
@@ -351,6 +351,27 @@ gui_context_new()
    return ctx;
 }
 
+int
+gui_contexts_count_get()
+{
+   int i;
+   int ret = 0;
+   /* i is starting with 1 because there is global context undex index 0 */
+   for (i = 1; i < (1 << BITS_PER_CONTEXT); i++)
+     if (context_array[i]) ret++;
+   return ret;
+}
+
+Eina_Bool
+gui_context_free_is()
+{
+   int i;
+   /* i is starting with 1 because there is global context undex index 0 */
+   for (i = 1; i < (1 << BITS_PER_CONTEXT); i++)
+     if (!context_array[i]) return EINA_TRUE;
+   return EINA_FALSE;
+}
+
 Eina_List *
 gui_context_wdg_list_get(const Gui_Context *ctx)
 {
diff --git a/src/lib/gui_widget.h b/src/lib/gui_widget.h
index 9e4fa9a..e5d4839 100644
--- a/src/lib/gui_widget.h
+++ b/src/lib/gui_widget.h
@@ -123,6 +123,14 @@ global_context_get();
 Gui_Context *
 gui_context_new();
 
+/* Get count of opened contexts (not including global context) */
+int
+gui_contexts_count_get();
+
+/* Check if there free context exists */
+Eina_Bool
+gui_context_free_is();
+
 /* Get list of widgets of context */
 Eina_List *
 gui_context_wdg_list_get(const Gui_Context *ctx);

-- 


Reply via email to