Loading the panel from the filesystem. organise out a little and commit where i've got to

This commit is contained in:
Andy Williams 2014-02-14 23:50:25 +00:00
parent 4e0c68a540
commit 5d8981d09d
5 changed files with 190 additions and 57 deletions

View File

@ -35,6 +35,7 @@ PKG_CHECK_MODULES([EFL],
ecore >= 1.8.0
edje >= 1.8.0
elementary >= 1.8.0
eio >= 1.8.0
])
# Check for tests and coverage

View File

@ -9,7 +9,10 @@ AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
-I$(top_srcdir)/src/lib/ \
@EFL_CFLAGS@
edi_SOURCES = edi_main.c
edi_SOURCES = \
edi_filepanel.c \
edi_main.c
edi_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libedi.la
localedir = $(datadir)/locale

131
src/bin/edi_filepanel.c Normal file
View File

@ -0,0 +1,131 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <libgen.h>
#include <Eio.h>
#include "edi_filepanel.h"
#include "edi_private.h"
static void stat_done(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *st);
// TODO take this from the command line!
static char *PROJECT_ROOT = "/home/andy/Code/edi";
static Elm_Genlist_Item_Class itc, itc2;
static Evas_Object *list;
static void
dummy()
{}
static void
ls_done(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *path)
{
eio_file_direct_stat(path, stat_done, dummy, eina_stringshare_add(path));
}
static Eina_Bool
ls_filter(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *file)
{
struct stat st;
if (stat(file, &st)) return EINA_FALSE;
return !(eina_str_has_prefix(basename(file), "."));
}
static void
stat_done(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *st)
{
if (S_ISREG(st->mode))
{
elm_genlist_item_append(list, &itc, data,
NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
}
else if (S_ISDIR(st->mode))
{
if (strcmp(data, PROJECT_ROOT))
{
elm_genlist_item_append(list, &itc2, data,
NULL, ELM_GENLIST_ITEM_TREE, NULL, NULL);
// TODO remove this and recurse
return;
}
eio_file_ls(data, ls_filter, ls_done, dummy, dummy, data);
}
else
printf("WAT %s\n", data);
eina_stringshare_del(data);
}
static char *
_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED)
{
return strdup(basename(data));
}
static Evas_Object *
_content_get(void *data, Evas_Object *obj, const char *source)
{
if (!strcmp(source, "elm.swallow.icon"))
{
Evas_Object *ic;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "file");
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
evas_object_show(ic);
return ic;
}
return NULL;
}
static void
_item_del(void *data, Evas_Object *obj EINA_UNUSED)
{
}
static Evas_Object *
_content_dir_get(void *data, Evas_Object *obj, const char *source)
{
if (!strcmp(source, "elm.swallow.icon"))
{
Evas_Object *ic;
ic = elm_icon_add(obj);
elm_icon_standard_set(ic, "folder");
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
evas_object_show(ic);
return ic;
}
return NULL;
}
void
edi_filepanel_add(Evas_Object *parent)
{
list = elm_genlist_add(parent);
evas_object_size_hint_min_set(list, 100, -1);
evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(list);
itc.item_style = "default";
itc.func.text_get = _text_get;
itc.func.content_get = _content_get;
// itc.func.state_get = _state_get;
itc.func.del = _item_del;
itc2.item_style = "default";
itc2.func.text_get = _text_get;
itc2.func.content_get = _content_dir_get;
itc2.func.del = _item_del;
eio_file_direct_stat(PROJECT_ROOT, stat_done, dummy, eina_stringshare_add(PROJECT_ROOT));
elm_box_pack_end(parent, list);
}

44
src/bin/edi_filepanel.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef EDI_H_
# define EDI_H_
#include <Elementary.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file
* @brief These routines are used for managing the Edi file panel.
*/
/**
* @brief UI management functions.
* @defgroup UI
*
* @{
*
* Initialisation and management of the file panel UI
*
*/
/**
* Initialize a new Edi filepanel and add it to the parent panel.
*
* @param win The window into which the panel will be loaded.
*
* @ingroup UI
*/
void edi_filepanel_add(Evas_Object *parent);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* EDI_H_ */

View File

@ -8,85 +8,39 @@
#include <Ecore_Getopt.h>
#include <Elementary.h>
#include <Eio.h>
#include "gettext.h"
#include "Edi.h"
#include "edi_filepanel.h"
#include "edi_private.h"
#define COPYRIGHT "Copyright © 2014 Andy Williams <andy@andyilliams.me> and various contributors (see AUTHORS)."
static Elm_Genlist_Item_Class itc;
static void
_edi_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
elm_exit();
}
static char *
_text_get(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED)
{
return strdup(data);
}
static Evas_Object *
_content_get(void *data, Evas_Object *obj, const char *source)
{
if (!strcmp(source, "elm.swallow.icon"))
{
Evas_Object *ic;
ic = elm_icon_add(obj);
if (!strcmp(data, "Dir"))
elm_icon_standard_set(ic, "folder");
else
elm_icon_standard_set(ic, "file");
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
evas_object_show(ic);
return ic;
}
return NULL;
}
static Evas_Object *
edi_filetree_setup(Evas_Object *win)
{
Evas_Object *list;
list = elm_genlist_add(win);
evas_object_size_hint_min_set(list, 100, -1);
evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(list);
itc.item_style = "default";
itc.func.text_get = _text_get;
itc.func.content_get = _content_get;
// itc.func.state_get = _state_get;
// itc.func.del = _item_del;
elm_genlist_item_append(list, &itc, "File 1",
NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
elm_genlist_item_append(list, &itc, "File 2",
NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
elm_genlist_item_append(list, &itc, "Dir",
NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
return list;
}
static Evas_Object *
edi_content_setup(Evas_Object *win)
{
Evas_Object *panes, *panes_h, *txt;
Evas_Object *panes, *panes_h, *panel, *txt;
panes = elm_panes_add(win);
evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
// add file list
elm_object_part_content_set(panes, "left", edi_filetree_setup(win));
panel = elm_box_add(win);
evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(panel);
edi_filepanel_add(panel);
elm_object_part_content_set(panes, "left", panel);
elm_panes_content_left_size_set(panes, 0.2);
// add panes