forked from enlightenment/enlightenment
'everything' module:
- fix segv in calc - added triggers to plugins. '=' for calc, to be configurable soon - added optional realize-cb for plugins to delay list generation until shown SVN revision: 41290
This commit is contained in:
parent
81cd7f0c74
commit
b454b231d2
|
@ -39,6 +39,7 @@ e_modapi_init(E_Module *m)
|
|||
#define T Plugin_Config
|
||||
#define D conf_item_edd
|
||||
E_CONFIG_VAL(D, T, name, STR);
|
||||
E_CONFIG_VAL(D, T, trigger, STR);
|
||||
E_CONFIG_VAL(D, T, min_query, INT);
|
||||
E_CONFIG_VAL(D, T, loaded, INT);
|
||||
E_CONFIG_VAL(D, T, enabled, INT);
|
||||
|
|
|
@ -50,7 +50,7 @@ struct _Config
|
|||
struct _Plugin_Config
|
||||
{
|
||||
const char *name;
|
||||
|
||||
|
||||
int loaded;
|
||||
int enabled;
|
||||
|
||||
|
@ -58,6 +58,8 @@ struct _Plugin_Config
|
|||
int min_query;
|
||||
|
||||
int priority;
|
||||
|
||||
const char *trigger;
|
||||
};
|
||||
|
||||
|
||||
|
@ -86,6 +88,8 @@ struct _Evry_Plugin
|
|||
const char *type_in;
|
||||
const char *type_out;
|
||||
|
||||
const char *trigger;
|
||||
|
||||
/* sync/async ?*/
|
||||
Eina_Bool async_query;
|
||||
|
||||
|
@ -110,6 +114,9 @@ struct _Evry_Plugin
|
|||
/* provide more information for a candidate */
|
||||
/* int (*candidate_info) (Evas *evas, Evry_Item *item); */
|
||||
|
||||
/* optional */
|
||||
void (*realize_items) (Evry_Plugin *p, Evas *e);
|
||||
|
||||
Eina_List *items;
|
||||
|
||||
Evas_Object *(*config_page) (void);
|
||||
|
|
|
@ -136,6 +136,9 @@ evry_plugin_register(Evry_Plugin *plugin)
|
|||
evry_conf->plugins_conf = eina_list_append(evry_conf->plugins_conf, pc);
|
||||
}
|
||||
|
||||
if (plugin->trigger && !pc->trigger)
|
||||
pc->trigger = eina_stringshare_add(plugin->trigger);
|
||||
|
||||
plugin->config = pc;
|
||||
|
||||
evry_conf->plugins = eina_list_sort(evry_conf->plugins,
|
||||
|
@ -354,6 +357,8 @@ evry_plugin_async_update(Evry_Plugin *p, int action)
|
|||
_evry_list_clear();
|
||||
_evry_show_items(s->cur_plugins->data);
|
||||
}
|
||||
else if (s->cur_plugin)
|
||||
_evry_tab_scroll_to(s->cur_plugin);
|
||||
}
|
||||
else if ((action == EVRY_ASYNC_UPDATE_CLEAR) && (s->cur_plugin == p))
|
||||
{
|
||||
|
@ -891,9 +896,13 @@ _evry_show_items(Evry_Plugin *p)
|
|||
else
|
||||
edje_object_signal_emit(p->tab, "e,state,selected", "e");
|
||||
|
||||
/* XXX move this to push/pop as plugin could be the same for
|
||||
different states!*/
|
||||
if (s->cur_plugin != p)
|
||||
s->sel_item = NULL;
|
||||
|
||||
if (p->realize_items) p->realize_items(p, popup->evas);
|
||||
|
||||
s->cur_plugin = p;
|
||||
s->cur_items = p->items;
|
||||
|
||||
|
@ -928,7 +937,8 @@ _evry_show_items(Evry_Plugin *p)
|
|||
_evry_cb_item_mouse_out, it);
|
||||
evas_object_show(o);
|
||||
|
||||
p->icon_get(p, it, popup->evas);
|
||||
if (!it->o_icon) p->icon_get(p, it, popup->evas);
|
||||
|
||||
if (edje_object_part_exists(o, "e.swallow.icons") && it->o_icon)
|
||||
{
|
||||
edje_object_part_swallow(o, "e.swallow.icons", it->o_icon);
|
||||
|
@ -971,23 +981,31 @@ _evry_matches_update(Evry_Plugin *cur_plugin)
|
|||
|
||||
_evry_list_clear();
|
||||
eina_list_free(s->cur_plugins);
|
||||
|
||||
s->cur_plugins = NULL;
|
||||
s->sel_item = NULL;
|
||||
|
||||
EINA_LIST_FOREACH(s->plugins, l, p)
|
||||
{
|
||||
/* input matches trigger? */
|
||||
if (p->trigger)
|
||||
{
|
||||
const char *trigger = p->trigger;
|
||||
|
||||
if ((strlen(s->input) < strlen(trigger)) ||
|
||||
(strncmp(s->input, trigger, strlen(trigger))))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen(s->input) == 0)
|
||||
items = !p->need_query ? p->fetch(p, NULL) : 0;
|
||||
else
|
||||
items = p->fetch(p, s->input);
|
||||
|
||||
if (!s->initial || (items && eina_list_count(p->items) > 0))
|
||||
{
|
||||
s->cur_plugins = eina_list_append(s->cur_plugins, p);
|
||||
}
|
||||
s->cur_plugins = eina_list_append(s->cur_plugins, p);
|
||||
}
|
||||
|
||||
/* remove tabs for not active plugins */
|
||||
EINA_LIST_FOREACH(evry_conf->plugins, l, p)
|
||||
{
|
||||
if (!p->config->enabled) continue;
|
||||
|
@ -998,7 +1016,7 @@ _evry_matches_update(Evry_Plugin *cur_plugin)
|
|||
p->tab = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* show/update tabs of active plugins */
|
||||
EINA_LIST_FOREACH(s->cur_plugins, l, p)
|
||||
_evry_plugin_selector_show(p);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ evry_plug_calc_init(void)
|
|||
p->name = "Calculator";
|
||||
p->type_in = "NONE";
|
||||
p->type_out = "NONE";
|
||||
p->trigger = "=";
|
||||
p->need_query = 0;
|
||||
p->async_query = 1;
|
||||
p->begin = &_begin;
|
||||
|
@ -101,7 +102,7 @@ static int
|
|||
_send_input(const char *input)
|
||||
{
|
||||
char buf[1024];
|
||||
snprintf(buf, 1024, "%s\n", input);
|
||||
snprintf(buf, 1024, "%s\n", input + (strlen(p->trigger)));
|
||||
|
||||
return ecore_exe_send(exe, buf, strlen(buf));
|
||||
}
|
||||
|
@ -121,6 +122,8 @@ _action(Evry_Plugin *p, Evry_Item *it, const char *input)
|
|||
/* remove duplicates */
|
||||
if (p->items->next)
|
||||
{
|
||||
it = p->items->data;
|
||||
|
||||
EINA_LIST_FOREACH(p->items->next, l, it2)
|
||||
{
|
||||
if (!strcmp(it->label, it2->label))
|
||||
|
@ -143,9 +146,9 @@ _action(Evry_Plugin *p, Evry_Item *it, const char *input)
|
|||
|
||||
evry_plugin_async_update(p, EVRY_ASYNC_UPDATE_ADD);
|
||||
|
||||
return EVRY_ACTION_CONTINUE;
|
||||
/* return EVRY_ACTION_CONTINUE; */
|
||||
}
|
||||
else
|
||||
/* else */
|
||||
{
|
||||
/* XXX on which windows must the selection be set? */
|
||||
ecore_x_selection_primary_set(e_manager_current_get()->win,
|
||||
|
@ -153,11 +156,11 @@ _action(Evry_Plugin *p, Evry_Item *it, const char *input)
|
|||
ecore_x_selection_clipboard_set(e_manager_current_get()->win,
|
||||
it->label, strlen(it->label));
|
||||
|
||||
if (p->items->data == it)
|
||||
{
|
||||
Evry_Item *it2 = p->items->data;
|
||||
_item_add(p, (char *) it2->label, 1);
|
||||
}
|
||||
/* if (p->items->data == it)
|
||||
* {
|
||||
* Evry_Item *it2 = p->items->data;
|
||||
* _item_add(p, (char *) it2->label, 1);
|
||||
* } */
|
||||
}
|
||||
|
||||
return EVRY_ACTION_FINISHED;
|
||||
|
|
|
@ -16,7 +16,9 @@ static void _cleanup(Evry_Plugin *p);
|
|||
static int _cb_sort(const void *data1, const void *data2);
|
||||
static void _item_icon_get(Evry_Plugin *p, Evry_Item *it, Evas *e);
|
||||
static void _list_free(Evry_Plugin *p);
|
||||
static Evry_Item *_item_fill(Evry_Plugin *p, const char *directory, const char *file);
|
||||
static void _item_fill(Evry_Item *it, Evas *evas);
|
||||
static Evry_Item *_item_add(const char *directory, const char *file);
|
||||
static void _realize(Evry_Plugin *p, Evas *e);
|
||||
|
||||
static Evry_Plugin *p;
|
||||
static Eina_List *stack = NULL;
|
||||
|
@ -33,6 +35,7 @@ evry_plug_dir_browse_init(void)
|
|||
p->fetch = &_fetch;
|
||||
p->action = &_action;
|
||||
p->cleanup = &_cleanup;
|
||||
p->realize_items = &_realize;
|
||||
p->icon_get = &_item_icon_get;
|
||||
|
||||
evry_plugin_register(p);
|
||||
|
@ -154,78 +157,98 @@ _fetch(Evry_Plugin *p, const char *input)
|
|||
{
|
||||
if (e_util_glob_case_match(file, match1))
|
||||
{
|
||||
it = _item_fill(p, s->directory, file);
|
||||
it = _item_add(s->directory, file);
|
||||
it->priority += 1;
|
||||
}
|
||||
else if (e_util_glob_case_match(file, match2))
|
||||
{
|
||||
it = _item_fill(p, s->directory, file);
|
||||
it = _item_add(s->directory, file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
it = _item_fill(p, s->directory, file);
|
||||
it = _item_add(s->directory, file);
|
||||
}
|
||||
|
||||
|
||||
if (it)
|
||||
p->items = eina_list_append(p->items, it);
|
||||
|
||||
free(file);
|
||||
}
|
||||
|
||||
if (p->items) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Evry_Item *
|
||||
_item_add(const char *directory, const char *file)
|
||||
{
|
||||
Evry_Item *it = NULL;
|
||||
char buf[4096];
|
||||
|
||||
it = E_NEW(Evry_Item, 1);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", directory, file);
|
||||
it->uri = eina_stringshare_add(buf);
|
||||
it->label = eina_stringshare_add(file);
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
static void
|
||||
_realize(Evry_Plugin *p, Evas *e)
|
||||
{
|
||||
Eina_List *l;
|
||||
Evry_Item *it;
|
||||
State *s = stack->data;
|
||||
|
||||
EINA_LIST_FOREACH(p->items, l, it)
|
||||
_item_fill(it, e);
|
||||
|
||||
|
||||
if (eina_list_count(p->items) > 0)
|
||||
{
|
||||
p->items = eina_list_sort(p->items, eina_list_count(p->items),
|
||||
_cb_sort);
|
||||
s->items = p->items;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* based on directory-watcher from drawer module */
|
||||
static Evry_Item *
|
||||
_item_fill(Evry_Plugin *p, const char *directory, const char *file)
|
||||
static void
|
||||
_item_fill(Evry_Item *it, Evas *e)
|
||||
{
|
||||
Evry_Item *it = NULL;
|
||||
char buf[4096];
|
||||
const char *mime, *file_path;
|
||||
const char *mime;
|
||||
|
||||
it = E_NEW(Evry_Item, 1);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", directory, file);
|
||||
|
||||
if ((e_util_glob_case_match(file, "*.desktop")) ||
|
||||
(e_util_glob_case_match(file, "*.directory")))
|
||||
if (it->mime) return;
|
||||
|
||||
if ((e_util_glob_case_match(it->label, "*.desktop")) ||
|
||||
(e_util_glob_case_match(it->label, "*.directory")))
|
||||
{
|
||||
Efreet_Desktop *desktop;
|
||||
|
||||
desktop = efreet_desktop_new(buf);
|
||||
if (!desktop) return NULL;
|
||||
desktop = efreet_desktop_new(it->uri);
|
||||
if (!desktop) return;
|
||||
it->label = eina_stringshare_add(desktop->name);
|
||||
efreet_desktop_free(desktop);
|
||||
}
|
||||
else
|
||||
it->label = eina_stringshare_add(file);
|
||||
|
||||
file_path = eina_stringshare_add(buf);
|
||||
|
||||
it->uri = file_path;
|
||||
|
||||
mime = efreet_mime_globs_type_get(file_path);
|
||||
mime = efreet_mime_globs_type_get(it->uri);
|
||||
if (mime)
|
||||
{
|
||||
it->mime = eina_stringshare_add(mime);
|
||||
it->priority = 0;
|
||||
}
|
||||
else if (ecore_file_is_dir(file_path))
|
||||
else if (ecore_file_is_dir(it->uri))
|
||||
{
|
||||
it->mime = eina_stringshare_add("Folder");
|
||||
it->priority = 1;
|
||||
it->o_icon = edje_object_add(e);
|
||||
e_theme_edje_object_set(it->o_icon, "base/theme/fileman", "e/icons/folder");
|
||||
}
|
||||
else if ((mime = efreet_mime_type_get(file_path)))
|
||||
else if ((mime = efreet_mime_type_get(it->uri)))
|
||||
{
|
||||
it->mime = eina_stringshare_add(mime);
|
||||
it->priority = 0;
|
||||
|
@ -236,7 +259,18 @@ _item_fill(Evry_Plugin *p, const char *directory, const char *file)
|
|||
it->priority = 0;
|
||||
}
|
||||
|
||||
return it;
|
||||
if (strcmp(it->mime, "Folder"))
|
||||
{
|
||||
char *item_path = efreet_mime_type_icon_get(it->mime, e_config->icon_theme, 32);
|
||||
|
||||
if (item_path)
|
||||
it->o_icon = e_util_icon_add(item_path, e);
|
||||
else
|
||||
{
|
||||
it->o_icon = edje_object_add(e);
|
||||
e_theme_edje_object_set(it->o_icon, "base/theme/fileman", "e/icons/fileman/file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue