forked from enlightenment/edi
If a file is open then re-focus the loaded file. Don't open directories or non-files
This commit is contained in:
parent
6e27500f68
commit
be30e5e24c
|
@ -29,7 +29,7 @@ _edi_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_i
|
||||||
static void
|
static void
|
||||||
_edi_file_open_cb(const char *path)
|
_edi_file_open_cb(const char *path)
|
||||||
{
|
{
|
||||||
edi_mainview_open(path);
|
edi_mainview_open_path(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Evas_Object *
|
static Evas_Object *
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
#include <Eina.h>
|
#include <Eina.h>
|
||||||
|
#include <Eio.h>
|
||||||
|
|
||||||
#include "edi_mainview.h"
|
#include "edi_mainview.h"
|
||||||
|
|
||||||
|
@ -12,17 +13,46 @@
|
||||||
|
|
||||||
static Evas_Object *nf, *tb;
|
static Evas_Object *nf, *tb;
|
||||||
|
|
||||||
|
static void
|
||||||
|
dummy()
|
||||||
|
{}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_promote(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
_promote(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
elm_naviframe_item_promote(data);
|
elm_naviframe_item_promote(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
static Elm_Object_Item *
|
||||||
edi_mainview_open(const char *path)
|
_get_item_for_path(const char *path)
|
||||||
|
{
|
||||||
|
Eina_List *list, *item;
|
||||||
|
Elm_Object_Item *it;
|
||||||
|
|
||||||
|
list = elm_naviframe_items_get(nf);
|
||||||
|
EINA_LIST_FOREACH(list, item, it)
|
||||||
|
{
|
||||||
|
const char *loaded;
|
||||||
|
loaded = elm_object_item_data_get(it);
|
||||||
|
|
||||||
|
if (loaded && !strcmp(loaded, path))
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_edi_mainview_open_file_text(const char *path)
|
||||||
{
|
{
|
||||||
Evas_Object *txt;
|
Evas_Object *txt;
|
||||||
Elm_Object_Item *it, *tab;
|
Elm_Object_Item *it, *tab;
|
||||||
|
|
||||||
|
it = _get_item_for_path(path);
|
||||||
|
if (it)
|
||||||
|
{
|
||||||
|
elm_naviframe_item_promote(it);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
txt = elm_entry_add(nf);
|
txt = elm_entry_add(nf);
|
||||||
elm_entry_scrollable_set(txt, EINA_TRUE);
|
elm_entry_scrollable_set(txt, EINA_TRUE);
|
||||||
|
@ -33,10 +63,33 @@ edi_mainview_open(const char *path)
|
||||||
evas_object_show(txt);
|
evas_object_show(txt);
|
||||||
|
|
||||||
it = elm_naviframe_item_simple_push(nf, txt);
|
it = elm_naviframe_item_simple_push(nf, txt);
|
||||||
|
elm_object_item_data_set(it, path);
|
||||||
|
elm_naviframe_item_style_set(it, "overlap");
|
||||||
tab = elm_toolbar_item_append(tb, NULL, basename(path), _promote, it);
|
tab = elm_toolbar_item_append(tb, NULL, basename(path), _promote, it);
|
||||||
elm_toolbar_item_selected_set(tab, EINA_TRUE);
|
elm_toolbar_item_selected_set(tab, EINA_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_edi_mainview_open_stat_done(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *stat)
|
||||||
|
{
|
||||||
|
const char *path;
|
||||||
|
|
||||||
|
path = data;
|
||||||
|
if (S_ISREG(stat->mode))
|
||||||
|
{
|
||||||
|
_edi_mainview_open_file_text(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
eina_stringshare_del(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
EAPI void
|
||||||
|
edi_mainview_open_path(const char *path)
|
||||||
|
{
|
||||||
|
eio_file_direct_stat(path, _edi_mainview_open_stat_done, dummy,
|
||||||
|
eina_stringshare_add(path));
|
||||||
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
edi_mainview_add(Evas_Object *parent)
|
edi_mainview_add(Evas_Object *parent)
|
||||||
{
|
{
|
||||||
|
@ -71,5 +124,6 @@ edi_mainview_add(Evas_Object *parent)
|
||||||
evas_object_show(txt);
|
evas_object_show(txt);
|
||||||
|
|
||||||
it = elm_naviframe_item_simple_push(nf, txt);
|
it = elm_naviframe_item_simple_push(nf, txt);
|
||||||
|
elm_naviframe_item_style_set(it, "overlap");
|
||||||
elm_toolbar_item_append(tb, NULL, "Welcome", _promote, it);
|
elm_toolbar_item_append(tb, NULL, "Welcome", _promote, it);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ EAPI void edi_mainview_add(Evas_Object *parent);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
EAPI void edi_mainview_open(const char *path);
|
EAPI void edi_mainview_open_path(const char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|
Loading…
Reference in New Issue