forked from enlightenment/edi
mainview_panel: fix focus issue and panel closing.
This fixes an issue with focus and also makes closing panels and tabs much friendlier to the user.
This commit is contained in:
parent
1841082de8
commit
d1052de44b
|
@ -19,6 +19,13 @@
|
|||
#include "edi_private.h"
|
||||
#include "edi_config.h"
|
||||
|
||||
typedef struct _Edi_Mainview_State {
|
||||
Edi_Mainview_Panel *panel;
|
||||
Edi_Mainview_Item *item;
|
||||
} Edi_Mainview_State;
|
||||
|
||||
static Edi_Mainview_State *_cached = NULL;
|
||||
|
||||
static Evas_Object *_main_win;
|
||||
static Evas_Object *_edi_mainview_goto_popup;
|
||||
|
||||
|
@ -26,6 +33,41 @@ static void
|
|||
dummy()
|
||||
{}
|
||||
|
||||
static void
|
||||
_edi_mainview_panel_cache_set(void)
|
||||
{
|
||||
if (!_cached)
|
||||
_cached = calloc(1, sizeof(Edi_Mainview_State));
|
||||
|
||||
_cached->panel = edi_mainview_panel_current_get();
|
||||
_cached->item = edi_mainview_item_current_get();
|
||||
}
|
||||
|
||||
static Edi_Mainview_State *
|
||||
_edi_mainview_panel_cache_get(void)
|
||||
{
|
||||
if (!_cached || !_cached->panel || !_cached->item)
|
||||
return NULL;
|
||||
|
||||
return _cached;
|
||||
}
|
||||
|
||||
static Edi_Mainview_Item *
|
||||
_get_item_for_path(Edi_Mainview_Panel *panel, const char *path)
|
||||
{
|
||||
Eina_List *item;
|
||||
Edi_Mainview_Item *it;
|
||||
|
||||
if (!panel || !path) return NULL;
|
||||
|
||||
EINA_LIST_FOREACH(panel->items, item, it)
|
||||
{
|
||||
if (it && !strcmp(it->path, path))
|
||||
return it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
edi_mainview_panel_item_count(Edi_Mainview_Panel *panel)
|
||||
{
|
||||
|
@ -64,6 +106,9 @@ _edi_mainview_panel_current_tab_hide(Edi_Mainview_Panel *panel)
|
|||
|
||||
edi_mainview_panel_focus(panel);
|
||||
|
||||
if (!panel || !panel->current)
|
||||
return;
|
||||
|
||||
editor = (Edi_Editor *)evas_object_data_get(panel->current->view, "editor");
|
||||
if (editor)
|
||||
{
|
||||
|
@ -323,9 +368,11 @@ _promote(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
|
||||
panel = edi_mainview_panel_for_item_get(item);
|
||||
|
||||
_edi_mainview_panel_cache_set();
|
||||
|
||||
_edi_mainview_panel_current_tab_hide(panel);
|
||||
|
||||
edi_mainview_panel_item_select(panel, (Edi_Mainview_Item *)data);
|
||||
edi_mainview_panel_item_select(panel, item);
|
||||
|
||||
_edi_mainview_panel_current_tab_show(panel);
|
||||
|
||||
|
@ -337,10 +384,14 @@ _closetab(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
|
||||
{
|
||||
Edi_Mainview_Panel *panel;
|
||||
Edi_Mainview_Item *item;
|
||||
Edi_Mainview_State *last;
|
||||
int index;
|
||||
|
||||
panel = edi_mainview_panel_for_item_get((Edi_Mainview_Item *)data);
|
||||
edi_mainview_panel_item_close(panel, data);
|
||||
item = (Edi_Mainview_Item *) data;
|
||||
|
||||
panel = edi_mainview_panel_for_item_get(item);
|
||||
edi_mainview_panel_item_close(panel, item);
|
||||
if (eina_list_count(panel->items)== 0 && edi_mainview_panel_count() > 1)
|
||||
{
|
||||
edi_mainview_panel_remove(panel);
|
||||
|
@ -350,6 +401,18 @@ _closetab(void *data, Evas_Object *obj EINA_UNUSED,
|
|||
|
||||
edi_mainview_panel_focus(panel);
|
||||
|
||||
/* When closing tabs keep current tab */
|
||||
last = _edi_mainview_panel_cache_get();
|
||||
if (last && last->panel == panel && last->item)
|
||||
{
|
||||
item = _get_item_for_path(panel, last->item->path);
|
||||
if (item)
|
||||
{
|
||||
_edi_mainview_panel_current_tab_hide(panel);
|
||||
edi_mainview_panel_item_select(panel, item);
|
||||
}
|
||||
}
|
||||
|
||||
if (eina_list_count(panel->items))
|
||||
_edi_mainview_panel_current_tab_show(panel);
|
||||
}
|
||||
|
@ -438,22 +501,6 @@ _edi_mainview_panel_item_tab_add(Edi_Mainview_Panel *panel, Edi_Path_Options *op
|
|||
_edi_project_config_tab_add(options->path, mime?mime:options->type, EINA_FALSE, id);
|
||||
}
|
||||
|
||||
static Edi_Mainview_Item *
|
||||
_get_item_for_path(Edi_Mainview_Panel *panel, const char *path)
|
||||
{
|
||||
Eina_List *item;
|
||||
Edi_Mainview_Item *it;
|
||||
|
||||
if (!panel) return NULL;
|
||||
|
||||
EINA_LIST_FOREACH(panel->items, item, it)
|
||||
{
|
||||
if (it && !strcmp(it->path, path))
|
||||
return it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
_edi_popup_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED,
|
||||
void *event_info EINA_UNUSED)
|
||||
|
@ -504,6 +551,7 @@ _edi_mainview_panel_mime_content_safe_popup(void)
|
|||
elm_object_part_content_set(popup, "button1", button);
|
||||
evas_object_smart_callback_add(button, "clicked", _edi_popup_cancel_cb, popup);
|
||||
|
||||
_edi_mainview_panel_current_tab_show(edi_mainview_panel_current_get());
|
||||
evas_object_show(popup);
|
||||
}
|
||||
|
||||
|
@ -824,7 +872,6 @@ edi_mainview_panel_open(Edi_Mainview_Panel *panel, Edi_Path_Options *options)
|
|||
|
||||
current = panel;
|
||||
|
||||
|
||||
for (i = 0; i < edi_mainview_panel_count(); i++)
|
||||
{
|
||||
panel = edi_mainview_panel_by_index(i);
|
||||
|
@ -832,6 +879,7 @@ edi_mainview_panel_open(Edi_Mainview_Panel *panel, Edi_Path_Options *options)
|
|||
it = _get_item_for_path(panel, options->path);
|
||||
if (it)
|
||||
{
|
||||
_edi_mainview_panel_current_tab_hide(panel);
|
||||
edi_mainview_panel_focus(panel);
|
||||
|
||||
editor = evas_object_data_get(panel->current->view, "editor");
|
||||
|
@ -851,7 +899,6 @@ edi_mainview_panel_open(Edi_Mainview_Panel *panel, Edi_Path_Options *options)
|
|||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
panel = current;
|
||||
|
|
Loading…
Reference in New Issue