forked from enlightenment/edi
Adding (blind) loading of files as text for editing. Use a naviframe for holding the content and a callback from filepanel through main to open new files
This commit is contained in:
parent
db5f776939
commit
6e27500f68
|
@ -11,6 +11,7 @@ AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
|
||||||
|
|
||||||
edi_SOURCES = \
|
edi_SOURCES = \
|
||||||
edi_filepanel.c \
|
edi_filepanel.c \
|
||||||
|
edi_mainview.c \
|
||||||
edi_main.c
|
edi_main.c
|
||||||
|
|
||||||
edi_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libedi.la
|
edi_LDADD = @EFL_LIBS@ $(top_builddir)/src/lib/libedi.la
|
||||||
|
|
|
@ -15,6 +15,7 @@ static char *PROJECT_ROOT = "/home/andy/Code/E/edi";
|
||||||
|
|
||||||
static Elm_Genlist_Item_Class itc, itc2;
|
static Elm_Genlist_Item_Class itc, itc2;
|
||||||
static Evas_Object *list;
|
static Evas_Object *list;
|
||||||
|
static edi_filepanel_item_clicked_cb _open_cb;
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED)
|
_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *source EINA_UNUSED)
|
||||||
|
@ -39,9 +40,16 @@ _content_get(void *data, Evas_Object *obj, const char *source)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_item_del(void *data, Evas_Object *obj EINA_UNUSED)
|
_item_del(void *data, Evas_Object *obj)
|
||||||
{
|
{
|
||||||
eina_stringshare_del(data);
|
eina_stringshare_del(data);
|
||||||
|
eina_stringshare_del(elm_object_item_data_get(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_item_sel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
|
{
|
||||||
|
_open_cb((const char*)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Evas_Object *
|
static Evas_Object *
|
||||||
|
@ -96,20 +104,21 @@ load_tree(char *path, Elm_Object_Item *parent)
|
||||||
if (info->type == EINA_FILE_DIR)
|
if (info->type == EINA_FILE_DIR)
|
||||||
{
|
{
|
||||||
newParent = elm_genlist_item_sorted_insert(list, &itc2, eina_stringshare_add(name),
|
newParent = elm_genlist_item_sorted_insert(list, &itc2, eina_stringshare_add(name),
|
||||||
parent, ELM_GENLIST_ITEM_NONE, _item_sort, NULL, NULL);
|
parent, ELM_GENLIST_ITEM_NONE, _item_sort, _item_sel, eina_stringshare_add(info->path));
|
||||||
load_tree(info->path, newParent);
|
load_tree(info->path, newParent);
|
||||||
}
|
}
|
||||||
else if (info->type == EINA_FILE_REG)
|
else if (info->type == EINA_FILE_REG)
|
||||||
{
|
{
|
||||||
elm_genlist_item_sorted_insert(list, &itc, eina_stringshare_add(name),
|
elm_genlist_item_sorted_insert(list, &itc, eina_stringshare_add(name),
|
||||||
parent, ELM_GENLIST_ITEM_NONE, _item_sort, NULL, NULL);
|
parent, ELM_GENLIST_ITEM_NONE, _item_sort, _item_sel, eina_stringshare_add(info->path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
edi_filepanel_add(Evas_Object *parent)
|
edi_filepanel_add(Evas_Object *parent,
|
||||||
|
edi_filepanel_item_clicked_cb cb)
|
||||||
{
|
{
|
||||||
list = elm_genlist_add(parent);
|
list = elm_genlist_add(parent);
|
||||||
evas_object_size_hint_min_set(list, 100, -1);
|
evas_object_size_hint_min_set(list, 100, -1);
|
||||||
|
@ -128,6 +137,7 @@ edi_filepanel_add(Evas_Object *parent)
|
||||||
// itc2.func.state_get = _state_get;
|
// itc2.func.state_get = _state_get;
|
||||||
itc2.func.del = _item_del;
|
itc2.func.del = _item_del;
|
||||||
|
|
||||||
|
_open_cb = cb;
|
||||||
load_tree(PROJECT_ROOT, NULL);
|
load_tree(PROJECT_ROOT, NULL);
|
||||||
|
|
||||||
elm_box_pack_end(parent, list);
|
elm_box_pack_end(parent, list);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef EDI_H_
|
#ifndef EDI_FILEPANEL_H_
|
||||||
# define EDI_H_
|
# define EDI_FILEPANEL_H_
|
||||||
|
|
||||||
#include <Elementary.h>
|
#include <Elementary.h>
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ extern "C" {
|
||||||
* @brief These routines are used for managing the Edi file panel.
|
* @brief These routines are used for managing the Edi file panel.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typedef void (*edi_filepanel_item_clicked_cb)(const char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief UI management functions.
|
* @brief UI management functions.
|
||||||
* @defgroup UI
|
* @defgroup UI
|
||||||
|
@ -29,7 +31,8 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* @ingroup UI
|
* @ingroup UI
|
||||||
*/
|
*/
|
||||||
void edi_filepanel_add(Evas_Object *parent);
|
void edi_filepanel_add(Evas_Object *parent,
|
||||||
|
edi_filepanel_item_clicked_cb cb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
@ -41,4 +44,4 @@ void edi_filepanel_add(Evas_Object *parent);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* EDI_H_ */
|
#endif /* EDI_FILEPANEL_H_ */
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "Edi.h"
|
#include "Edi.h"
|
||||||
#include "edi_filepanel.h"
|
#include "edi_filepanel.h"
|
||||||
|
#include "edi_mainview.h"
|
||||||
|
|
||||||
#include "edi_private.h"
|
#include "edi_private.h"
|
||||||
|
|
||||||
|
@ -25,6 +26,12 @@ _edi_win_del(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_i
|
||||||
elm_exit();
|
elm_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_edi_file_open_cb(const char *path)
|
||||||
|
{
|
||||||
|
edi_mainview_open(path);
|
||||||
|
}
|
||||||
|
|
||||||
static Evas_Object *
|
static Evas_Object *
|
||||||
edi_content_setup(Evas_Object *win)
|
edi_content_setup(Evas_Object *win)
|
||||||
{
|
{
|
||||||
|
@ -38,7 +45,7 @@ edi_content_setup(Evas_Object *win)
|
||||||
evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
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_size_hint_align_set(panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
evas_object_show(panel);
|
evas_object_show(panel);
|
||||||
edi_filepanel_add(panel);
|
edi_filepanel_add(panel, _edi_file_open_cb);
|
||||||
|
|
||||||
elm_object_part_content_set(panes, "left", panel);
|
elm_object_part_content_set(panes, "left", panel);
|
||||||
elm_panes_content_left_size_set(panes, 0.2);
|
elm_panes_content_left_size_set(panes, 0.2);
|
||||||
|
@ -53,13 +60,13 @@ edi_content_setup(Evas_Object *win)
|
||||||
elm_object_part_content_set(panes, "right", panes_h);
|
elm_object_part_content_set(panes, "right", panes_h);
|
||||||
|
|
||||||
// add main content
|
// add main content
|
||||||
txt = elm_entry_add(win);
|
panel = elm_box_add(win);
|
||||||
elm_entry_scrollable_set(txt, EINA_TRUE);
|
evas_object_size_hint_weight_set(panel, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||||
elm_object_text_set(txt, "Main");
|
evas_object_size_hint_align_set(panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
evas_object_show(panel);
|
||||||
evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
edi_mainview_add(panel);
|
||||||
evas_object_show(txt);
|
|
||||||
elm_object_part_content_set(panes_h, "top", txt);
|
elm_object_part_content_set(panes_h, "top", panel);
|
||||||
|
|
||||||
// add lower panel
|
// add lower panel
|
||||||
txt = elm_label_add(win);
|
txt = elm_label_add(win);
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#include <Eina.h>
|
||||||
|
|
||||||
|
#include "edi_mainview.h"
|
||||||
|
|
||||||
|
#include "edi_private.h"
|
||||||
|
|
||||||
|
static Evas_Object *nf, *tb;
|
||||||
|
|
||||||
|
static void
|
||||||
|
_promote(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
|
{
|
||||||
|
elm_naviframe_item_promote(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
EAPI void
|
||||||
|
edi_mainview_open(const char *path)
|
||||||
|
{
|
||||||
|
Evas_Object *txt;
|
||||||
|
Elm_Object_Item *it, *tab;
|
||||||
|
|
||||||
|
txt = elm_entry_add(nf);
|
||||||
|
elm_entry_scrollable_set(txt, EINA_TRUE);
|
||||||
|
elm_entry_file_set(txt, path, ELM_TEXT_FORMAT_PLAIN_UTF8);
|
||||||
|
elm_entry_autosave_set(txt, EINA_TRUE);
|
||||||
|
evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||||
|
evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
|
evas_object_show(txt);
|
||||||
|
|
||||||
|
it = elm_naviframe_item_simple_push(nf, txt);
|
||||||
|
tab = elm_toolbar_item_append(tb, NULL, basename(path), _promote, it);
|
||||||
|
elm_toolbar_item_selected_set(tab, EINA_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
EAPI void
|
||||||
|
edi_mainview_add(Evas_Object *parent)
|
||||||
|
{
|
||||||
|
Evas_Object *box, *txt;
|
||||||
|
Elm_Object_Item *it;
|
||||||
|
|
||||||
|
box = elm_box_add(parent);
|
||||||
|
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||||
|
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
|
evas_object_show(box);
|
||||||
|
elm_box_pack_end(parent, box);
|
||||||
|
|
||||||
|
tb = elm_toolbar_add(parent);
|
||||||
|
evas_object_size_hint_weight_set(tb, EVAS_HINT_EXPAND, 0.0);
|
||||||
|
evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
|
elm_toolbar_homogeneous_set(tb, EINA_FALSE);
|
||||||
|
elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_SCROLL);
|
||||||
|
elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_ALWAYS);
|
||||||
|
elm_box_pack_end(box, tb);
|
||||||
|
evas_object_show(tb);
|
||||||
|
|
||||||
|
nf = elm_naviframe_add(parent);
|
||||||
|
evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||||
|
evas_object_size_hint_align_set(nf, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
|
elm_box_pack_end(box, nf);
|
||||||
|
evas_object_show(nf);
|
||||||
|
|
||||||
|
txt = elm_label_add(parent);
|
||||||
|
elm_object_text_set(txt, "Welcome - tap a file to edit");
|
||||||
|
evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||||
|
evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||||
|
evas_object_show(txt);
|
||||||
|
|
||||||
|
it = elm_naviframe_item_simple_push(nf, txt);
|
||||||
|
elm_toolbar_item_append(tb, NULL, "Welcome", _promote, it);
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
#ifndef EDI_MAINVIEW_H_
|
||||||
|
# define EDI_MAINVIEW_H_
|
||||||
|
|
||||||
|
#include <Elementary.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief These routines are used for managing the main area of the Edi interface.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief UI management functions.
|
||||||
|
* @defgroup UI
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* Initialisation and management of the main view UI
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a new Edi main view and add it to the parent panel.
|
||||||
|
*
|
||||||
|
* @param win The window into which the panel will be loaded.
|
||||||
|
*
|
||||||
|
* @ingroup UI
|
||||||
|
*/
|
||||||
|
EAPI void edi_mainview_add(Evas_Object *parent);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @brief Content management functions.
|
||||||
|
* @defgroup Content
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* Opening and managing content within the view.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
EAPI void edi_mainview_open(const char *path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* EDI_MAINVIEW_H_ */
|
Loading…
Reference in New Issue