2009-10-22 15:10:23 -07:00
|
|
|
/*
|
2009-08-12 09:08:53 -07:00
|
|
|
* TODO
|
|
|
|
* userdefined icon/label cb
|
|
|
|
* show/hide/add buttons ???
|
|
|
|
* need a background ???
|
|
|
|
* show/Hide hidden files
|
|
|
|
* double click to choose a file
|
|
|
|
* multiselection
|
|
|
|
* write docs
|
|
|
|
*/
|
|
|
|
|
2009-08-27 22:28:44 -07:00
|
|
|
#include <Elementary.h>
|
2009-08-12 09:08:53 -07:00
|
|
|
#include "elm_priv.h"
|
|
|
|
|
|
|
|
typedef struct _Widget_Data Widget_Data;
|
|
|
|
|
|
|
|
struct _Widget_Data
|
|
|
|
{
|
2009-09-06 17:00:33 -07:00
|
|
|
Evas_Object *vbox, *entry, *entry2, *list, *scr2;
|
2009-08-12 09:08:53 -07:00
|
|
|
const char *path;
|
2009-09-06 17:00:33 -07:00
|
|
|
const char *selection;
|
2009-10-22 15:10:23 -07:00
|
|
|
Eina_Bool only_folder;
|
2009-08-12 09:08:53 -07:00
|
|
|
Eina_Bool expand;
|
2009-10-22 15:10:23 -07:00
|
|
|
|
2010-03-31 13:19:55 -07:00
|
|
|
struct
|
2009-10-22 15:10:23 -07:00
|
|
|
{
|
|
|
|
Evas_Object *bx;
|
|
|
|
Evas_Object *ok;
|
|
|
|
Evas_Object *cancel;
|
|
|
|
} buttons;
|
2009-08-12 09:08:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
Elm_Genlist_Item_Class itc;
|
|
|
|
|
2010-03-08 22:15:39 -08:00
|
|
|
static const char *widtype = NULL;
|
2010-04-05 12:18:36 -07:00
|
|
|
|
|
|
|
static const char SIG_DIRECTORY_OPEN[]= "directory,open";
|
|
|
|
static const char SIG_DONE[] = "done";
|
|
|
|
static const char SIG_SELECTED[] = "selected";
|
|
|
|
static const Evas_Smart_Cb_Description _signals[] = {
|
|
|
|
{SIG_DIRECTORY_OPEN, ""}, /* FIXME: all three may be called with a
|
|
|
|
path arg. */
|
|
|
|
{SIG_DONE, ""},
|
|
|
|
{SIG_SELECTED, ""},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2009-08-12 09:08:53 -07:00
|
|
|
static void _populate(Evas_Object *obj, const char *path, Elm_Genlist_Item *parent);
|
2009-10-12 13:51:26 -07:00
|
|
|
static void _do_anchors(Evas_Object *obj, const char *path);
|
2009-08-12 09:08:53 -07:00
|
|
|
|
|
|
|
/*** ELEMENTARY WIDGET ***/
|
|
|
|
static void
|
|
|
|
_del_hook(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-08-12 09:08:53 -07:00
|
|
|
if (wd->path) eina_stringshare_del(wd->path);
|
2009-09-06 17:00:33 -07:00
|
|
|
if (wd->selection) eina_stringshare_del(wd->selection);
|
2009-08-12 09:08:53 -07:00
|
|
|
free(wd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_sizing_eval(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Coord minw = -1, minh = -1;
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-08-12 09:08:53 -07:00
|
|
|
evas_object_size_hint_min_get(wd->vbox, &minw, &minh);
|
|
|
|
evas_object_size_hint_min_set(obj, minw, minh);
|
2009-08-26 10:59:41 -07:00
|
|
|
// printf("***** SIZING EVAL [min %d %d] *************\n", minw, minh);
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** GENLIST "MODEL" ***/
|
|
|
|
static char*
|
2010-03-09 09:51:30 -08:00
|
|
|
_itc_label_get(const void *data, Evas_Object *obj __UNUSED__, const char *source __UNUSED__)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
|
|
|
//~ printf("LABEL_GET: %s\n", (char*) data);
|
|
|
|
return strdup(ecore_file_file_get(data)); // NOTE this will be free() by the caller
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object*
|
|
|
|
_itc_icon_get(const void *data, Evas_Object *obj, const char *source)
|
|
|
|
{
|
|
|
|
Evas_Object *ic;
|
|
|
|
|
|
|
|
//~ printf("ICON GET for %s (source: %s)\n", (char*)data, source);
|
|
|
|
if (!strcmp(source, "elm.swallow.icon"))
|
|
|
|
{
|
|
|
|
ic = elm_icon_add(obj);
|
|
|
|
if (ecore_file_is_dir((char*)data))
|
2009-09-06 17:00:33 -07:00
|
|
|
elm_icon_standard_set(ic, "folder");
|
2009-08-12 09:08:53 -07:00
|
|
|
else
|
2009-08-26 10:59:41 -07:00
|
|
|
elm_icon_standard_set(ic, "file");
|
2009-08-12 09:08:53 -07:00
|
|
|
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
|
|
|
|
evas_object_show(ic);
|
|
|
|
return ic;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-22 15:10:23 -07:00
|
|
|
static Eina_Bool
|
2010-03-09 09:51:30 -08:00
|
|
|
_itc_state_get(const void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *source __UNUSED__)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_itc_del(const void *data, Evas_Object *obj __UNUSED__)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
|
|
|
//~ printf("DEL DATA [%s]\n", (char*)data);
|
|
|
|
eina_stringshare_del(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_expand_done(void *data, Evas_Object *obj __UNUSED__, void *event_info)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
|
|
|
Elm_Genlist_Item *it = event_info;
|
|
|
|
const char *path = elm_genlist_item_data_get(it);
|
2009-08-26 10:59:41 -07:00
|
|
|
// printf("EXPAND %s\n", path);
|
2009-08-12 09:08:53 -07:00
|
|
|
_populate(data, path, it);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_contract_done(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
|
|
|
Elm_Genlist_Item *it = event_info;
|
2010-03-09 19:47:33 -08:00
|
|
|
// const char *path = elm_genlist_item_data_get(it);
|
2009-08-26 10:59:41 -07:00
|
|
|
// printf("CONTRACT %s\n", path);
|
2009-08-12 09:08:53 -07:00
|
|
|
elm_genlist_item_subitems_clear(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_expand_req(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
|
|
|
Elm_Genlist_Item *it = event_info;
|
|
|
|
elm_genlist_item_expanded_set(it, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_contract_req(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
|
|
|
Elm_Genlist_Item *it = event_info;
|
|
|
|
elm_genlist_item_expanded_set(it, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** PRIVATES ***/
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_sel(void *data, Evas_Object *obj __UNUSED__, void *event_info)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
2009-09-06 17:00:33 -07:00
|
|
|
Evas_Object *fs = data;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(fs);
|
2009-08-12 09:08:53 -07:00
|
|
|
const char *path = elm_genlist_item_data_get(event_info);
|
|
|
|
const char *p;
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-08-12 09:08:53 -07:00
|
|
|
if (ecore_file_is_dir(path))
|
|
|
|
{
|
2009-08-26 10:59:41 -07:00
|
|
|
// printf("SELECTED DIR: %s\n", path);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (wd->expand)
|
|
|
|
{
|
|
|
|
_do_anchors(fs, path);
|
|
|
|
if (wd->entry2) elm_entry_entry_set(wd->entry2, "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// keep a ref to path 'couse it will be destroyed by _populate
|
|
|
|
p = eina_stringshare_add(path);
|
|
|
|
_populate(fs, p, NULL);
|
|
|
|
eina_stringshare_del(p);
|
|
|
|
}
|
|
|
|
return;
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
2009-09-06 17:00:33 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// printf("SELECTED FILE: %s\n", path);
|
|
|
|
if (wd->entry2)
|
|
|
|
elm_entry_entry_set(wd->entry2, ecore_file_file_get(path));
|
|
|
|
}
|
2010-03-31 13:19:55 -07:00
|
|
|
|
2010-04-05 12:18:36 -07:00
|
|
|
evas_object_smart_callback_call(fs, SIG_SELECTED, (void*)path);
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_up(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
2009-09-06 17:00:33 -07:00
|
|
|
Evas_Object *fs = data;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(fs);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-08-12 09:08:53 -07:00
|
|
|
char *parent = ecore_file_dir_get(wd->path);
|
2009-09-06 17:00:33 -07:00
|
|
|
_populate(fs, parent, NULL);
|
2009-08-12 09:08:53 -07:00
|
|
|
free(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_home(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
2009-09-06 17:00:33 -07:00
|
|
|
Evas_Object *fs = data;
|
|
|
|
_populate(fs, getenv("HOME"), NULL);
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_ok(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
2009-09-06 17:00:33 -07:00
|
|
|
Evas_Object *fs = data;
|
2010-04-05 12:18:36 -07:00
|
|
|
evas_object_smart_callback_call(fs, SIG_DONE,
|
2009-09-06 17:00:33 -07:00
|
|
|
(void*)elm_fileselector_selected_get(fs));
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_canc(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
2009-09-06 17:00:33 -07:00
|
|
|
Evas_Object *fs = data;
|
2010-04-05 12:18:36 -07:00
|
|
|
evas_object_smart_callback_call(fs, SIG_DONE, NULL);
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-09 09:51:30 -08:00
|
|
|
_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
2009-09-06 17:00:33 -07:00
|
|
|
Evas_Object *fs = data;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(fs);
|
2009-08-12 09:08:53 -07:00
|
|
|
Elm_Entry_Anchor_Info *info = event_info;
|
|
|
|
const char *p;
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-09-06 17:00:33 -07:00
|
|
|
//~ printf("ANCHOR CLICKED %s\n", info->name);
|
|
|
|
// keep a ref to path 'couse it will be destroyed by _populate
|
|
|
|
p = eina_stringshare_add(info->name);
|
|
|
|
_populate(fs, p, NULL);
|
2010-04-05 12:18:36 -07:00
|
|
|
evas_object_smart_callback_call(data, SIG_SELECTED, (void*)p);
|
2009-09-06 17:00:33 -07:00
|
|
|
eina_stringshare_del(p);
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
|
|
|
|
2009-10-22 15:10:23 -07:00
|
|
|
static void
|
2009-08-12 09:08:53 -07:00
|
|
|
_do_anchors(Evas_Object *obj, const char *path)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
char **tok, buf[PATH_MAX*3];
|
|
|
|
int i, j;
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-08-12 09:08:53 -07:00
|
|
|
//~ printf("ANCHORIZE...\n");
|
|
|
|
buf[0] = '\0';
|
2010-01-30 14:22:46 -08:00
|
|
|
tok = eina_str_split(path, "/", 0);
|
2009-08-12 09:08:53 -07:00
|
|
|
for (i = 0; tok[i]; i++)
|
|
|
|
{
|
|
|
|
if (strlen(tok[i]) < 1) continue;
|
|
|
|
//~ printf("TOK: %s\n", tok[i]);
|
2010-01-30 14:22:46 -08:00
|
|
|
eina_strlcat(buf, "/<a href=", sizeof(buf));
|
2009-08-12 09:08:53 -07:00
|
|
|
for (j = 0; j <= i; j++)
|
|
|
|
{
|
|
|
|
if (strlen(tok[j]) < 1) continue;
|
|
|
|
//~ printf("REV: %s\n",tok[j]);
|
2010-01-30 14:22:46 -08:00
|
|
|
eina_strlcat(buf, "/", sizeof(buf));
|
|
|
|
eina_strlcat(buf, tok[j], sizeof(buf));
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
2010-01-30 14:22:46 -08:00
|
|
|
eina_strlcat(buf, ">", sizeof(buf));
|
|
|
|
eina_strlcat(buf, tok[i], sizeof(buf));
|
|
|
|
eina_strlcat(buf, "</a>", sizeof(buf));
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
|
|
|
free(tok[0]);
|
|
|
|
free(tok);
|
2009-10-22 15:10:23 -07:00
|
|
|
|
2009-08-12 09:08:53 -07:00
|
|
|
//~ printf("ANCHOR: %s\n", buf);
|
|
|
|
elm_entry_entry_set(wd->entry, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_populate(Evas_Object *obj, const char *path, Elm_Genlist_Item *parent)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dp;
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
char *real;
|
2009-08-12 15:43:50 -07:00
|
|
|
Eina_List *files = NULL, *dirs = NULL, *l;
|
2009-08-12 09:08:53 -07:00
|
|
|
|
2009-10-12 13:51:26 -07:00
|
|
|
if ((!wd) || (!ecore_file_is_dir(path))) return;
|
2009-08-12 09:08:53 -07:00
|
|
|
dir = opendir(path);
|
|
|
|
if (!dir) return;
|
2010-04-05 12:18:36 -07:00
|
|
|
evas_object_smart_callback_call(obj, SIG_DIRECTORY_OPEN, (void*)path);
|
2009-08-12 09:08:53 -07:00
|
|
|
if (!parent)
|
|
|
|
{
|
|
|
|
elm_genlist_clear(wd->list);
|
2010-03-13 13:01:26 -08:00
|
|
|
eina_stringshare_replace(&wd->path, path);
|
2009-08-12 09:08:53 -07:00
|
|
|
_do_anchors(obj, path);
|
|
|
|
}
|
2009-10-22 15:10:23 -07:00
|
|
|
|
2010-03-09 19:47:33 -08:00
|
|
|
if (wd->entry2) elm_entry_entry_set(wd->entry2, "");
|
2009-08-12 09:08:53 -07:00
|
|
|
while ((dp = readdir(dir)) != NULL)
|
|
|
|
{
|
2009-08-12 15:43:50 -07:00
|
|
|
if (dp->d_name[0] == '.') continue; // TODO make this configurable
|
|
|
|
|
2009-08-12 09:08:53 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", path, dp->d_name);
|
|
|
|
real = ecore_file_realpath(buf); //TODO this will resolv symlinks...I dont like it
|
2009-08-12 15:43:50 -07:00
|
|
|
if (ecore_file_is_dir(real))
|
|
|
|
dirs = eina_list_append(dirs, real);
|
2009-10-22 15:10:23 -07:00
|
|
|
else if(!wd->only_folder)
|
2009-08-12 15:43:50 -07:00
|
|
|
files = eina_list_append(files, real);
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
|
2010-01-16 05:54:55 -08:00
|
|
|
files = eina_list_sort(files, eina_list_count(files), EINA_COMPARE_CB(strcoll));
|
|
|
|
dirs = eina_list_sort(dirs, eina_list_count(dirs), EINA_COMPARE_CB(strcoll));
|
2009-08-12 15:43:50 -07:00
|
|
|
EINA_LIST_FOREACH(dirs, l, real)
|
2009-09-06 17:00:33 -07:00
|
|
|
{
|
|
|
|
//~ printf("DIR: %s\n", real);
|
2009-08-12 09:08:53 -07:00
|
|
|
elm_genlist_item_append(wd->list, &itc,
|
|
|
|
eina_stringshare_add(real), /* item data */
|
|
|
|
parent,
|
2009-08-12 15:43:50 -07:00
|
|
|
wd->expand ? ELM_GENLIST_ITEM_SUBITEMS :
|
2010-03-09 19:47:33 -08:00
|
|
|
ELM_GENLIST_ITEM_NONE,
|
2009-08-12 09:08:53 -07:00
|
|
|
NULL, NULL);
|
|
|
|
free(real);
|
2009-09-06 17:00:33 -07:00
|
|
|
}
|
2009-08-12 15:43:50 -07:00
|
|
|
eina_list_free(dirs);
|
2009-10-22 15:10:23 -07:00
|
|
|
|
2009-08-12 15:43:50 -07:00
|
|
|
EINA_LIST_FOREACH(files, l, real)
|
2009-09-06 17:00:33 -07:00
|
|
|
{
|
|
|
|
//~ printf("FILE: %s [%p]\n", real, wd->list);
|
2009-08-12 15:43:50 -07:00
|
|
|
elm_genlist_item_append(wd->list, &itc,
|
|
|
|
eina_stringshare_add(real), /* item data */
|
|
|
|
parent, ELM_GENLIST_ITEM_NONE,
|
|
|
|
NULL, NULL);
|
|
|
|
free(real);
|
2009-09-06 17:00:33 -07:00
|
|
|
}
|
2009-08-12 15:43:50 -07:00
|
|
|
eina_list_free(files);
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** API ***/
|
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_fileselector_add(Evas_Object *parent)
|
|
|
|
{
|
|
|
|
Evas_Object *obj, *ic, *bt, *box;
|
|
|
|
Widget_Data *wd;
|
|
|
|
|
|
|
|
// Elementary Widget
|
|
|
|
wd = ELM_NEW(Widget_Data);
|
|
|
|
wd->expand = EINA_FALSE;
|
2009-09-06 17:00:33 -07:00
|
|
|
obj = elm_widget_add(evas_object_evas_get(parent));
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_SET_WIDTYPE(widtype, "fileselector");
|
2009-08-12 09:08:53 -07:00
|
|
|
elm_widget_type_set(obj, "fileselector");
|
|
|
|
elm_widget_sub_object_add(parent, obj);
|
|
|
|
elm_widget_data_set(obj, wd);
|
|
|
|
elm_widget_del_hook_set(obj, _del_hook);
|
|
|
|
|
|
|
|
// TODO Do we need a bg object? a frame?
|
|
|
|
// vbox
|
|
|
|
wd->vbox = elm_box_add(parent);
|
2009-10-09 17:32:27 -07:00
|
|
|
evas_object_size_hint_weight_set(wd->vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
2009-08-12 09:08:53 -07:00
|
|
|
elm_widget_resize_object_set(obj, wd->vbox);
|
|
|
|
evas_object_show(wd->vbox);
|
|
|
|
|
|
|
|
// buttons box
|
|
|
|
box = elm_box_add(parent);
|
|
|
|
elm_box_horizontal_set(box, 1);
|
|
|
|
elm_widget_sub_object_add(obj, box);
|
|
|
|
elm_box_pack_end(wd->vbox, box);
|
|
|
|
evas_object_size_hint_align_set(box, 0.0, 0.0);
|
|
|
|
evas_object_show(box);
|
2009-10-22 15:10:23 -07:00
|
|
|
|
2009-08-12 09:08:53 -07:00
|
|
|
// up btn
|
|
|
|
ic = elm_icon_add(parent);
|
|
|
|
elm_icon_standard_set(ic, "arrow_up");
|
|
|
|
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
|
|
|
|
bt = elm_button_add(parent);
|
|
|
|
elm_button_icon_set(bt, ic);
|
|
|
|
elm_button_label_set(bt, "Up");
|
|
|
|
evas_object_size_hint_align_set(bt, 0.0, 0.0);
|
|
|
|
elm_widget_sub_object_add(obj, bt);
|
|
|
|
elm_box_pack_end(box, bt);
|
|
|
|
evas_object_smart_callback_add(bt, "clicked", _up, obj);
|
|
|
|
evas_object_show(bt);
|
2009-10-22 15:10:23 -07:00
|
|
|
|
2009-08-12 09:08:53 -07:00
|
|
|
// home btn
|
|
|
|
ic = elm_icon_add(parent);
|
|
|
|
elm_icon_standard_set(ic, "home");
|
|
|
|
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
|
|
|
|
bt = elm_button_add(parent);
|
|
|
|
elm_button_icon_set(bt, ic);
|
|
|
|
elm_button_label_set(bt, "Home");
|
|
|
|
evas_object_size_hint_align_set(bt, 0.0, 0.0);
|
|
|
|
elm_widget_sub_object_add(obj, bt);
|
|
|
|
elm_box_pack_end(box, bt);
|
|
|
|
evas_object_smart_callback_add(bt, "clicked", _home, obj);
|
|
|
|
evas_object_show(bt);
|
|
|
|
|
|
|
|
// genlist
|
2009-10-12 13:51:26 -07:00
|
|
|
itc.item_style = "default";
|
2009-08-12 09:08:53 -07:00
|
|
|
itc.func.label_get = _itc_label_get;
|
2009-10-12 13:51:26 -07:00
|
|
|
itc.func.icon_get = _itc_icon_get;
|
2009-08-12 09:08:53 -07:00
|
|
|
itc.func.state_get = _itc_state_get;
|
2009-10-12 13:51:26 -07:00
|
|
|
itc.func.del = _itc_del;
|
2009-08-12 09:08:53 -07:00
|
|
|
|
|
|
|
wd->list = elm_genlist_add(parent);
|
2009-10-09 17:32:27 -07:00
|
|
|
evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
2009-08-12 09:08:53 -07:00
|
|
|
evas_object_size_hint_min_set(wd->list, 100, 100);
|
|
|
|
elm_widget_sub_object_add(obj, wd->list);
|
|
|
|
elm_box_pack_end(wd->vbox, wd->list);
|
|
|
|
evas_object_show(wd->list);
|
|
|
|
|
|
|
|
evas_object_smart_callback_add(wd->list, "selected", _sel, obj);
|
|
|
|
evas_object_smart_callback_add(wd->list, "expand,request", _expand_req, obj);
|
|
|
|
evas_object_smart_callback_add(wd->list, "contract,request", _contract_req, obj);
|
2009-08-26 16:39:17 -07:00
|
|
|
evas_object_smart_callback_add(wd->list, "expanded", _expand_done, obj);
|
|
|
|
evas_object_smart_callback_add(wd->list, "contracted", _contract_done, obj);
|
2009-08-12 09:08:53 -07:00
|
|
|
|
2009-09-06 17:00:33 -07:00
|
|
|
// path entry
|
|
|
|
wd->entry = elm_entry_add(parent);
|
|
|
|
elm_widget_sub_object_add(obj, wd->entry);
|
|
|
|
elm_entry_editable_set(wd->entry, 0);
|
2009-10-22 15:10:23 -07:00
|
|
|
elm_entry_single_line_set(wd->entry, EINA_FALSE);
|
|
|
|
elm_entry_line_char_wrap_set(wd->entry, EINA_TRUE);
|
2009-10-09 17:32:27 -07:00
|
|
|
evas_object_size_hint_weight_set(wd->entry, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
evas_object_size_hint_align_set(wd->entry, EVAS_HINT_FILL, 0.0);
|
2009-09-06 17:00:33 -07:00
|
|
|
elm_box_pack_end(wd->vbox, wd->entry);
|
|
|
|
evas_object_show(wd->entry);
|
|
|
|
evas_object_smart_callback_add(wd->entry, "anchor,clicked", _anchor_clicked, obj);
|
|
|
|
|
|
|
|
// name entry scroller
|
|
|
|
wd->scr2 = elm_scroller_add(parent);
|
|
|
|
elm_scroller_content_min_limit(wd->scr2, 0, 1);
|
|
|
|
elm_scroller_policy_set(wd->scr2, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
|
2009-10-09 17:32:27 -07:00
|
|
|
evas_object_size_hint_weight_set(wd->scr2, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
evas_object_size_hint_align_set(wd->scr2, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
2009-09-06 17:00:33 -07:00
|
|
|
elm_box_pack_end(wd->vbox, wd->scr2);
|
|
|
|
evas_object_show(wd->scr2);
|
2009-08-12 09:08:53 -07:00
|
|
|
|
2009-10-22 15:10:23 -07:00
|
|
|
elm_fileselector_buttons_ok_cancel_set(obj, 1);
|
2010-03-31 13:19:55 -07:00
|
|
|
|
2009-08-12 15:43:50 -07:00
|
|
|
// Is this the right way to show sub-objs ?? or use the show/hide cbs ??
|
2009-08-12 09:08:53 -07:00
|
|
|
//~ evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, obj);
|
|
|
|
//~ evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
|
2010-03-09 19:47:33 -08:00
|
|
|
//~ _changed_size_hints, obj);
|
2009-08-12 09:08:53 -07:00
|
|
|
_sizing_eval(obj);
|
2010-04-05 12:18:36 -07:00
|
|
|
|
|
|
|
// TODO: convert Elementary to subclassing of Evas_Smart_Class
|
|
|
|
// TODO: and save some bytes, making descriptions per-class and not instance!
|
|
|
|
evas_object_smart_callbacks_descriptions_set(obj, _signals);
|
2009-08-12 09:08:53 -07:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2009-09-06 17:00:33 -07:00
|
|
|
EAPI void
|
|
|
|
elm_fileselector_is_save_set(Evas_Object *obj, Eina_Bool is_save)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2009-09-06 17:00:33 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-09-06 17:00:33 -07:00
|
|
|
if (is_save)
|
|
|
|
{
|
|
|
|
if (wd->entry2) return;
|
|
|
|
wd->entry2 = elm_entry_add(elm_widget_parent_get(obj));
|
|
|
|
elm_widget_sub_object_add(obj, wd->entry2);
|
|
|
|
elm_entry_editable_set(wd->entry2, 1);
|
|
|
|
elm_entry_single_line_set(wd->entry2, EINA_TRUE);
|
2009-10-09 17:35:05 -07:00
|
|
|
evas_object_size_hint_weight_set(wd->entry2, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
evas_object_size_hint_align_set(wd->entry2, EVAS_HINT_FILL, 0.0);
|
2009-09-06 17:00:33 -07:00
|
|
|
elm_scroller_content_set(wd->scr2, wd->entry2);
|
|
|
|
evas_object_show(wd->entry2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_object_del(wd->entry2);
|
|
|
|
wd->entry2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2010-03-23 20:06:00 -07:00
|
|
|
elm_fileselector_is_save_get(const Evas_Object *obj)
|
2009-09-06 17:00:33 -07:00
|
|
|
{
|
2010-03-09 19:47:33 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
2009-09-06 17:00:33 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return EINA_FALSE;
|
2009-09-06 17:00:33 -07:00
|
|
|
return wd->entry2 ? EINA_TRUE : EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-22 15:10:23 -07:00
|
|
|
EAPI void
|
|
|
|
elm_fileselector_folder_only_set(Evas_Object *obj, Eina_Bool only)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2009-10-22 15:10:23 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
|
|
|
if (wd->only_folder == only) return;
|
2009-10-22 15:10:23 -07:00
|
|
|
wd->only_folder = only;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2010-03-31 13:19:55 -07:00
|
|
|
elm_fileselector_folder_only_get(const Evas_Object *obj)
|
2009-10-22 15:10:23 -07:00
|
|
|
{
|
2010-03-09 19:47:33 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
2009-10-22 15:10:23 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return EINA_FALSE;
|
2009-10-22 15:10:23 -07:00
|
|
|
return wd->only_folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_fileselector_buttons_ok_cancel_set(Evas_Object *obj, Eina_Bool only)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2009-10-22 15:10:23 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Object *box, *bt;
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-10-22 15:10:23 -07:00
|
|
|
if (only)
|
|
|
|
{
|
|
|
|
if (wd->buttons.bx) return;
|
2010-03-09 19:47:33 -08:00
|
|
|
// buttons box
|
|
|
|
box = elm_box_add(obj);
|
|
|
|
wd->buttons.bx = box;
|
|
|
|
elm_box_horizontal_set(box, 1);
|
|
|
|
elm_widget_sub_object_add(obj, box);
|
|
|
|
elm_box_pack_end(wd->vbox, box);
|
|
|
|
evas_object_show(box);
|
|
|
|
|
|
|
|
// cancel btn
|
|
|
|
bt = elm_button_add(obj);
|
|
|
|
wd->buttons.cancel = bt;
|
|
|
|
elm_button_label_set(bt, "Cancel");
|
|
|
|
elm_widget_sub_object_add(obj, bt);
|
|
|
|
elm_box_pack_end(box, bt);
|
|
|
|
evas_object_smart_callback_add(bt, "clicked", _canc, obj);
|
|
|
|
evas_object_show(bt);
|
2010-03-31 13:19:55 -07:00
|
|
|
|
2010-03-09 19:47:33 -08:00
|
|
|
// ok btn
|
|
|
|
bt = elm_button_add(obj);
|
|
|
|
wd->buttons.ok = bt;
|
|
|
|
elm_button_label_set(bt, "OK");
|
|
|
|
elm_widget_sub_object_add(obj, bt);
|
|
|
|
elm_box_pack_end(box, bt);
|
|
|
|
evas_object_smart_callback_add(bt, "clicked", _ok, obj);
|
|
|
|
evas_object_show(bt);
|
2009-10-22 15:10:23 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-09 19:47:33 -08:00
|
|
|
evas_object_del(wd->buttons.bx);
|
|
|
|
evas_object_del(wd->buttons.ok);
|
|
|
|
evas_object_del(wd->buttons.cancel);
|
2009-10-22 15:10:23 -07:00
|
|
|
wd->buttons.bx = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2010-03-31 13:19:55 -07:00
|
|
|
elm_fileselector_buttons_ok_cancel_get(const Evas_Object *obj)
|
2009-10-22 15:10:23 -07:00
|
|
|
{
|
2010-03-09 19:47:33 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
2009-10-22 15:10:23 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return EINA_FALSE;
|
2009-10-22 15:10:23 -07:00
|
|
|
return wd->buttons.bx ? EINA_TRUE : EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:08:53 -07:00
|
|
|
EAPI void
|
|
|
|
elm_fileselector_expandable_set(Evas_Object *obj, Eina_Bool expand)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2009-08-12 09:08:53 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return;
|
2009-08-12 09:08:53 -07:00
|
|
|
wd->expand = expand;
|
|
|
|
}
|
|
|
|
|
2010-03-31 13:19:55 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_fileselector_expandable_get(const Evas_Object *obj)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return EINA_FALSE;
|
|
|
|
return wd->expand;
|
|
|
|
}
|
|
|
|
|
2009-09-06 17:00:33 -07:00
|
|
|
EAPI void
|
|
|
|
elm_fileselector_path_set(Evas_Object *obj, const char *path)
|
|
|
|
{
|
|
|
|
_populate(obj, path, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI const char *
|
2010-03-23 20:06:00 -07:00
|
|
|
elm_fileselector_path_get(const Evas_Object *obj)
|
2009-09-06 17:00:33 -07:00
|
|
|
{
|
2010-03-09 19:47:33 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
2009-09-06 17:00:33 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return NULL;
|
2009-09-06 17:00:33 -07:00
|
|
|
return wd->path;
|
|
|
|
}
|
|
|
|
|
2010-03-09 19:47:33 -08:00
|
|
|
EAPI const char *
|
2010-03-23 20:06:00 -07:00
|
|
|
elm_fileselector_selected_get(const Evas_Object *obj)
|
2009-08-12 09:08:53 -07:00
|
|
|
{
|
2010-03-09 19:47:33 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
2009-08-12 09:08:53 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Elm_Genlist_Item *it;
|
2010-03-09 19:47:33 -08:00
|
|
|
if (!wd) return NULL;
|
2009-09-06 17:00:33 -07:00
|
|
|
if (wd->entry2)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
char buf[PATH_MAX];
|
2010-03-31 13:19:55 -07:00
|
|
|
|
2009-09-06 17:00:33 -07:00
|
|
|
name = elm_entry_entry_get(wd->entry2);
|
|
|
|
//TODO remove <br>
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", wd->path, name);
|
2010-03-13 13:01:26 -08:00
|
|
|
eina_stringshare_replace(&wd->selection, buf);
|
2009-09-06 17:00:33 -07:00
|
|
|
return wd->selection;
|
|
|
|
}
|
2010-03-31 13:19:55 -07:00
|
|
|
|
2009-09-06 17:00:33 -07:00
|
|
|
it = elm_genlist_selected_item_get(wd->list);
|
|
|
|
if (it) return elm_genlist_item_data_get(it);
|
2010-03-31 13:19:55 -07:00
|
|
|
|
2009-09-06 17:00:33 -07:00
|
|
|
return wd->path;
|
2009-08-12 09:08:53 -07:00
|
|
|
}
|