file_tab: ++implementation.

allow remove item from the tab.
This commit is contained in:
Hermet Park 2016-07-04 22:17:38 +09:00
parent 37770335ff
commit 5b00b70fc2
4 changed files with 94 additions and 8 deletions

View File

@ -351,15 +351,16 @@ group { name: "elm/list/h_item/enventor";
target: "label2";
target: "label3";
}
rect {"elm.swallow.icon";
swallow {"elm.swallow.icon";
scale: 1;
desc { "default";
fixed: 1 1;
align: 0 0.5;
rel1.relative: 0.0 0.5;
rel1.offset: 5 0;
rel1.offset: 5 -1;
rel2.relative: 0.0 0.5;
min: 12 12;
rel2.offset: 5 -2;
min: 15 15;
}
}
part { name: "sel_shine"; mouse_events: 0;

View File

@ -10,6 +10,7 @@ typedef struct file_tab_s
typedef struct file_tab_it_s
{
Enventor_Item *enventor_it;
Elm_Object_Item *it;
} file_tab_it;
file_data *g_fd = NULL;
@ -58,10 +59,51 @@ list_item_selected_cb(void *data, Evas_Object *obj EINA_UNUSED,
file_mgr_file_focus(fti->enventor_it);
}
static void
file_tab_it_del(file_tab_it *fti)
{
Evas_Object *list = elm_object_item_widget_get(fti->it);
//FIXME: If this item is main, then it needs to close project.
//If the focused item is removed, then enable next item.
if (elm_list_selected_item_get(list) == fti->it)
{
//Next?
Elm_Object_Item *it;
it = elm_list_item_next(fti->it);
//Prev?
if (!it) it = elm_list_item_prev(fti->it);
if (it)
{
file_tab_it *next_fti = elm_object_item_data_get(it);
file_mgr_file_focus(next_fti->enventor_it);
}
}
//Remove item.
elm_object_item_del(fti->it);
enventor_item_del(fti->enventor_it);
free(fti);
elm_list_go(list);
}
static void
close_btn_clicked_cb(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
file_tab_it *fti = data;
file_tab_it_del(fti);
}
/*****************************************************************************/
/* Externally accessible calls */
/*****************************************************************************/
Eina_Bool file_tab_it_select(Enventor_Item *enventor_it)
Eina_Bool
file_tab_it_select(Enventor_Item *enventor_it)
{
file_data *fd = g_fd;
EINA_SAFETY_ON_NULL_RETURN_VAL(fd, EINA_FALSE);
@ -83,7 +125,8 @@ Eina_Bool file_tab_it_select(Enventor_Item *enventor_it)
return EINA_FALSE;
}
void file_tab_clear(void)
void
file_tab_clear(void)
{
file_data *fd = g_fd;
EINA_SAFETY_ON_NULL_RETURN(fd);
@ -100,7 +143,8 @@ void file_tab_clear(void)
elm_list_clear(fd->list);
}
Eina_Bool file_tab_it_add(Enventor_Item *enventor_it)
Eina_Bool
file_tab_it_add(Enventor_Item *enventor_it)
{
if (!enventor_it)
{
@ -136,10 +180,21 @@ Eina_Bool file_tab_it_add(Enventor_Item *enventor_it)
fti->enventor_it = enventor_it;
elm_list_item_append(fd->list, filename, NULL, NULL, list_item_selected_cb,
fti);
//Close Button
Evas_Object *btn = elm_button_add(fd->list);
elm_object_style_set(btn, ENVENTOR_NAME);
elm_object_focus_allow_set(btn, EINA_FALSE);
Evas_Object *img = elm_image_add(btn);
elm_image_file_set(img, EDJE_PATH, "close");
elm_object_content_set(btn, img);
fti->it = elm_list_item_append(fd->list, filename, btn, NULL,
list_item_selected_cb, fti);
elm_list_go(fd->list);
evas_object_smart_callback_add(btn, "clicked", close_btn_clicked_cb, fti);
free(filename);
return EINA_TRUE;

View File

@ -26,5 +26,6 @@ EAPI Eina_Bool enventor_item_line_delete(Enventor_Item *it);
EAPI Eina_Bool enventor_item_file_save(Enventor_Item *it, const char *file);
EAPI Eina_Bool enventor_item_modified_get(const Enventor_Item *it);
EAPI void enventor_item_modified_set(Enventor_Item *it, Eina_Bool modified);
EAPI Eina_Bool enventor_item_del(Enventor_Item *it);
#include "enventor_object.eo.legacy.h"

View File

@ -85,6 +85,16 @@ static void
_enventor_main_item_free(Enventor_Object_Data *pd)
{
edit_term(pd->main_it.ed);
pd->main_it.ed = NULL;
}
static void
_enventor_sub_items_free(Enventor_Object_Data *pd)
{
Enventor_Item *it;
EINA_LIST_FREE(pd->sub_its, it)
enventor_item_del(it);
pd->sub_its = NULL;
}
static Eina_Bool
@ -272,6 +282,7 @@ _enventor_object_efl_canvas_group_group_del(Evas_Object *obj EINA_UNUSED, Envent
edj_mgr_term();
build_term();
_enventor_sub_items_free(pd);
_enventor_main_item_free(pd);
}
@ -1098,5 +1109,23 @@ enventor_item_modified_set(Enventor_Item *it, Eina_Bool modified)
edit_changed_set(it->ed, modified);
}
EAPI Eina_Bool
enventor_item_del(Enventor_Item *it)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(it, EINA_FALSE);
//Main Item?
if (it == &it->pd->main_it)
{
_enventor_main_item_free(it->pd);
}
//Sub Items
else
{
it->pd->sub_its = eina_list_remove(it->pd->sub_its, it);
edit_term(it->ed);
free(it);
}
}
#include "enventor_object.eo.c"