rimmed pushed a commit to branch master.

http://git.enlightenment.org/tools/eflete.git/commit/?id=63157a99fdf90c8111944d7a5e846641a904382f

commit 63157a99fdf90c8111944d7a5e846641a904382f
Author: Vitalii Vorobiov <[email protected]>
Date:   Wed Oct 5 17:19:11 2016 +0300

    editor: part_item_add/del of items by using INDEX
---
 src/bin/editor/diff.c                             | 18 ++++++++++++
 src/bin/editor/diff.h                             |  7 +++++
 src/bin/editor/editor.h                           |  2 +-
 src/bin/editor/editor_part.c                      | 35 +++++++++++++----------
 src/bin/resource_manager/resource_manager_load.c  | 19 ++++++++++--
 src/bin/resource_manager/resource_manager_react.c |  3 +-
 src/bin/ui/workspace/group_navigator.c            | 17 +++++++++--
 7 files changed, 78 insertions(+), 23 deletions(-)

diff --git a/src/bin/editor/diff.c b/src/bin/editor/diff.c
index 6990b8b..7f1032d 100644
--- a/src/bin/editor/diff.c
+++ b/src/bin/editor/diff.c
@@ -74,6 +74,8 @@ typedef Eina_Bool (* function_type_string_uint_ushort) 
(Evas_Object *, Change*,
                                                         const char *, unsigned 
int, unsigned short);
 typedef Eina_Bool (* function_type_string_string_string) (Evas_Object *, 
Change*, Eina_Bool, Eina_Bool,
                                                           const char *, const 
char *, const char *);
+typedef Eina_Bool (* function_type_string_string_string_uint) (Evas_Object *, 
Change*, Eina_Bool, Eina_Bool,
+                                                          const char *, const 
char *, const char *, unsigned int);
 typedef Eina_Bool (* function_type_string_uint_uint) (Evas_Object *, Change*, 
Eina_Bool, Eina_Bool,
                                                           const char *, 
unsigned int, unsigned int);
 typedef Eina_Bool (* function_type_string_uint_string) (Evas_Object *, 
Change*, Eina_Bool, Eina_Bool,
@@ -184,6 +186,9 @@ _apply(Evas_Object *obj, Function_Info *fi)
       case FUNCTION_TYPE_STRING_STRING_STRING:
          return ((function_type_string_string_string)fi->function)(obj, NULL, 
false, true,
                   fi->args.type_sss.s1, fi->args.type_sss.s2, 
fi->args.type_sss.s3);
+      case FUNCTION_TYPE_STRING_STRING_STRING_UINT:
+         return ((function_type_string_string_string_uint)fi->function)(obj, 
NULL, false, true,
+                  fi->args.type_sssui.s1, fi->args.type_sssui.s2, 
fi->args.type_sssui.s3, fi->args.type_sssui.ui4);
       case FUNCTION_TYPE_STRING_UINT_UINT:
          return ((function_type_string_uint_uint)fi->function)(obj, NULL, 
false, true,
                   fi->args.type_suiui.s1, fi->args.type_suiui.ui2, 
fi->args.type_suiui.ui3);
@@ -404,6 +409,14 @@ diff_update(Diff *diff, Diff *new_diff)
          eina_stringshare_ref(new_diff->redo.args.type_sss.s2);
          eina_stringshare_ref(new_diff->redo.args.type_sss.s3);
          break;
+      case FUNCTION_TYPE_STRING_STRING_STRING_UINT:
+         eina_stringshare_del(diff->redo.args.type_sss.s1);
+         eina_stringshare_del(diff->redo.args.type_sss.s2);
+         eina_stringshare_del(diff->redo.args.type_sss.s3);
+         eina_stringshare_ref(new_diff->redo.args.type_sss.s1);
+         eina_stringshare_ref(new_diff->redo.args.type_sss.s2);
+         eina_stringshare_ref(new_diff->redo.args.type_sss.s3);
+         break;
       case FUNCTION_TYPE_STRING_UINT_UINT:
          eina_stringshare_del(diff->redo.args.type_suiui.s1);
          eina_stringshare_ref(new_diff->redo.args.type_suiui.s1);
@@ -565,6 +578,11 @@ diff_free(Diff *diff)
          eina_stringshare_del(diff->redo.args.type_sss.s2);
          eina_stringshare_del(diff->redo.args.type_sss.s3);
          break;
+      case FUNCTION_TYPE_STRING_STRING_STRING_UINT:
+         eina_stringshare_del(diff->redo.args.type_sss.s1);
+         eina_stringshare_del(diff->redo.args.type_sss.s2);
+         eina_stringshare_del(diff->redo.args.type_sss.s3);
+         break;
       case FUNCTION_TYPE_STRING_UINT_UINT:
          eina_stringshare_del(diff->redo.args.type_suiui.s1);
          break;
diff --git a/src/bin/editor/diff.h b/src/bin/editor/diff.h
index fe82dac..0de3d4b 100644
--- a/src/bin/editor/diff.h
+++ b/src/bin/editor/diff.h
@@ -51,6 +51,7 @@ typedef enum {
    FUNCTION_TYPE_STRING_STRING_USHORT,
    FUNCTION_TYPE_STRING_UINT_USHORT,
    FUNCTION_TYPE_STRING_STRING_STRING,
+   FUNCTION_TYPE_STRING_STRING_STRING_UINT,
    FUNCTION_TYPE_STRING_UINT_UINT,
    FUNCTION_TYPE_STRING_UINT_STRING,
    FUNCTION_TYPE_STRING_STRING_INT_INT_INT_INT,
@@ -200,6 +201,12 @@ struct _Function_Info {
       } type_sss;
       struct {
          Eina_Stringshare *s1;
+         Eina_Stringshare *s2;
+         Eina_Stringshare *s3;
+         unsigned int ui4;
+      } type_sssui;
+      struct {
+         Eina_Stringshare *s1;
          unsigned int ui2;
          unsigned int ui3;
       } type_suiui;
diff --git a/src/bin/editor/editor.h b/src/bin/editor/editor.h
index 1569708..4baaaa3 100644
--- a/src/bin/editor/editor.h
+++ b/src/bin/editor/editor.h
@@ -625,7 +625,7 @@ editor_part_item_index_restack_below(Evas_Object 
*edit_object, Change *change, E
                                      const char *part_name, unsigned int 
index) EINA_WARN_UNUSED_RESULT;
 Eina_Bool
 editor_part_item_index_append(Evas_Object *edit_object, Change *change, 
Eina_Bool merge, Eina_Bool apply,
-                        const char *part_name, const char *item_name, const 
char *source_group) EINA_WARN_UNUSED_RESULT;
+                        const char *part_name, const char *item_name, const 
char *source_group, unsigned int index) EINA_WARN_UNUSED_RESULT;
 Eina_Bool
 editor_part_item_index_del(Evas_Object *edit_object, Change *change, Eina_Bool 
merge, Eina_Bool apply,
                      const char *part_name, unsigned int index) 
EINA_WARN_UNUSED_RESULT;
diff --git a/src/bin/editor/editor_part.c b/src/bin/editor/editor_part.c
index d13d72b..9446d10 100644
--- a/src/bin/editor/editor_part.c
+++ b/src/bin/editor/editor_part.c
@@ -686,28 +686,28 @@ editor_part_item_index_reset(Evas_Object *edit_object, 
Change *change, Eina_Bool
 
 Eina_Bool
 editor_part_item_index_append(Evas_Object *edit_object, Change *change, 
Eina_Bool merge __UNUSED__, Eina_Bool apply,
-                              const char *part_name, const char *item_name, 
const char *source_group)
+                              const char *part_name, const char *item_name, 
const char *source_group, unsigned int index)
 {
    Diff *diff;
    Editor_Item event_info;
-   int count;
+   unsigned int count;
 
    assert(edit_object != NULL);
 
    count = edje_edit_part_items_count_get(edit_object, part_name);
-
    if (change)
      {
         diff = mem_calloc(1, sizeof(Diff));
-        diff->redo.type = FUNCTION_TYPE_STRING_STRING_STRING;
+        diff->redo.type = FUNCTION_TYPE_STRING_STRING_STRING_UINT;
         diff->redo.function = editor_part_item_index_append;
-        diff->redo.args.type_sss.s1 = eina_stringshare_add(part_name);
-        diff->redo.args.type_sss.s2 = eina_stringshare_add(item_name);
-        diff->redo.args.type_sss.s3 = eina_stringshare_add(source_group);
+        diff->redo.args.type_sssui.s1 = eina_stringshare_add(part_name);
+        diff->redo.args.type_sssui.s2 = eina_stringshare_add(item_name);
+        diff->redo.args.type_sssui.s3 = eina_stringshare_add(source_group);
+        diff->redo.args.type_sssui.ui4 = index;
         diff->undo.type = FUNCTION_TYPE_STRING_UINT;
         diff->undo.function = editor_part_item_index_del;
         diff->undo.args.type_sui.s1 = eina_stringshare_add(part_name);
-        diff->undo.args.type_sui.ui2 = count;
+        diff->undo.args.type_sui.ui2 = index;
 
         change_diff_add(change, diff);
      }
@@ -715,13 +715,16 @@ editor_part_item_index_append(Evas_Object *edit_object, 
Change *change, Eina_Boo
      {
         Edje_Part_Type type = edje_edit_part_type_get(edit_object, part_name);
 
-        CRIT_ON_FAIL(edje_edit_part_item_insert_after_index(edit_object, 
part_name, item_name, count - 1, source_group));
+        if (index != count)
+          CRIT_ON_FAIL(edje_edit_part_item_insert_before_index(edit_object, 
part_name, item_name, index, source_group));
+        else
+          CRIT_ON_FAIL(edje_edit_part_item_insert_after_index(edit_object, 
part_name, item_name, index, source_group));
 
         if (type == EDJE_PART_TYPE_TABLE)
           {
              /* fixing incorrect default item position */
-             
CRIT_ON_FAIL(edje_edit_part_item_index_position_row_set(edit_object, part_name, 
count, 0));
-             
CRIT_ON_FAIL(edje_edit_part_item_index_position_col_set(edit_object, part_name, 
count, 0));
+             
CRIT_ON_FAIL(edje_edit_part_item_index_position_row_set(edit_object, part_name, 
index, 0));
+             
CRIT_ON_FAIL(edje_edit_part_item_index_position_col_set(edit_object, part_name, 
index, 0));
           }
 
         CRIT_ON_FAIL(editor_save(edit_object));
@@ -730,6 +733,7 @@ editor_part_item_index_append(Evas_Object *edit_object, 
Change *change, Eina_Boo
         event_info.part_name = eina_stringshare_add(part_name);
         event_info.item_name = eina_stringshare_add(item_name);
         event_info.source = eina_stringshare_add(source_group);
+        event_info.item_index = index;
         if (!_editor_signals_blocked)
           evas_object_smart_callback_call(ap.win, 
SIGNAL_EDITOR_PART_ITEM_ADDED, (void *)&event_info);
         eina_stringshare_del(event_info.part_name);
@@ -772,11 +776,12 @@ editor_part_item_index_del(Evas_Object *edit_object, 
Change *change, Eina_Bool m
         diff->redo.function = editor_part_item_index_del;
         diff->redo.args.type_sui.s1 = eina_stringshare_add(part_name);
         diff->redo.args.type_sui.ui2 = index;
-        diff->undo.type = FUNCTION_TYPE_STRING_UINT_STRING;
+        diff->undo.type = FUNCTION_TYPE_STRING_STRING_STRING_UINT;
         diff->undo.function = editor_part_item_index_append;
-        diff->undo.args.type_sss.s1 = eina_stringshare_add(part_name);
-        diff->undo.args.type_sss.s2 = eina_stringshare_add(item_name);
-        diff->undo.args.type_sss.s3 = eina_stringshare_add(source_group);
+        diff->undo.args.type_sssui.s1 = eina_stringshare_add(part_name);
+        diff->undo.args.type_sssui.s2 = eina_stringshare_add(item_name);
+        diff->undo.args.type_sssui.s3 = eina_stringshare_add(source_group);
+        diff->undo.args.type_sssui.ui4 = index;
 
         change_diff_add(change, diff);
      }
diff --git a/src/bin/resource_manager/resource_manager_load.c 
b/src/bin/resource_manager/resource_manager_load.c
index 92b0be3..a8eedb9 100644
--- a/src/bin/resource_manager/resource_manager_load.c
+++ b/src/bin/resource_manager/resource_manager_load.c
@@ -412,7 +412,8 @@ _state_add(Project *pro, Group2 *group, Part2 *part, const 
char *state_name, dou
 Part_Item2 *
 _part_item_add(Part2 *part, Eina_Stringshare *item_name, unsigned int i)
 {
-   Part_Item2 *item;
+   Eina_List *l, *item_list;
+   Part_Item2 *item, *item_data;
 
    item = mem_calloc(1, sizeof(Part_Item2));
    item->common.id = i;
@@ -423,7 +424,21 @@ _part_item_add(Part2 *part, Eina_Stringshare *item_name, 
unsigned int i)
         edje_edit_string_free(item_name);
      }
    item->part = part;
-   part->items = eina_list_append(part->items, item);
+
+   if (i != eina_list_count(part->items))
+     {
+        l = eina_list_nth_list(part->items, i);
+        part->items = eina_list_prepend_relative_list(part->items, item, l);
+        item_list = eina_list_data_find_list(part->items, item);
+        EINA_LIST_FOREACH(eina_list_next(item_list), l, item_data)
+          {
+             item_data->common.id++;
+          }
+     }
+   else
+     {
+        part->items = eina_list_append(part->items, item);
+     }
 
    return item;
 }
diff --git a/src/bin/resource_manager/resource_manager_react.c 
b/src/bin/resource_manager/resource_manager_react.c
index 3af7aa2..f9c19da 100644
--- a/src/bin/resource_manager/resource_manager_react.c
+++ b/src/bin/resource_manager/resource_manager_react.c
@@ -776,10 +776,9 @@ _editor_part_item_added_cb(void *data,
    Project *pro = (Project *)data;
    Group2 *group = tabs_current_group_get();
    Part2 *part = (Part2 *)resource_manager_find(group->parts, 
editor_item->part_name);
-   unsigned int count = eina_list_count(part->items);
 
    /* we can use _item_dependency_load here, but let's avoid using edje edit */
-   item = _part_item_add(part, editor_item->item_name, count);
+   item = _part_item_add(part, editor_item->item_name, 
editor_item->item_index);
    used = resource_manager_find(pro->RM.groups, editor_item->source);
    if (used)
      _resource_usage_resource_add((Resource2 *)item, used);
diff --git a/src/bin/ui/workspace/group_navigator.c 
b/src/bin/ui/workspace/group_navigator.c
index c47d2b7..bace6ae 100644
--- a/src/bin/ui/workspace/group_navigator.c
+++ b/src/bin/ui/workspace/group_navigator.c
@@ -886,7 +886,7 @@ _item_validate(void *data,
 
    EINA_LIST_FOREACH(pl->part->items, l, item)
      {
-       if (!strcmp(item->common.name, name))
+       if (item->common.name && !strcmp(item->common.name, name))
          goto item_data_invalidated;
      }
 
@@ -1455,8 +1455,14 @@ _popup_add_item_close_cb(void *data,
 
    msg = eina_stringshare_printf(_("added new item \"%s\" to part \"%s\""), 
name, pl->part->common.name);
    change = change_add(msg);
-   CRIT_ON_FAIL(editor_part_item_index_append(pl->group->edit_object, change, 
false, true, pl->part->common.name, name, pl->popup.item_selected->data));
-
+   CRIT_ON_FAIL(editor_part_item_index_append(pl->group->edit_object,
+                                              change,
+                                              false,
+                                              true,
+                                              pl->part->common.name,
+                                              name,
+                                              pl->popup.item_selected->data,
+                                              
eina_list_count(pl->part->items)));
    history_change_add(pl->group->history, change);
    eina_stringshare_del(msg);
 }
@@ -2149,6 +2155,11 @@ group_navigator_part_item_del(Evas_Object *obj, 
Part_Item2 *item)
         it = elm_object_item_data_get(item_glit);
      }
    assert(item_glit != NULL);
+   while (eina_list_next(part_items))
+     {
+        part_items = eina_list_next(part_items);
+        elm_genlist_item_update(eina_list_data_get(part_items));
+     }
 
    to_select = elm_genlist_item_next_get(item_glit);
 

-- 


Reply via email to