2009-08-21 15:42:06 -07:00
|
|
|
#include "e_mod_main.h"
|
|
|
|
|
|
|
|
/* action selector plugin: provides list of actions registered for
|
|
|
|
candidate types provided by current plugin */
|
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
typedef struct _Plugin Plugin;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
struct _Plugin
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-26 11:21:09 -07:00
|
|
|
Evry_Plugin base;
|
|
|
|
Evry_Selector *selector;
|
|
|
|
Eina_List *actions;
|
2010-04-27 20:22:40 -07:00
|
|
|
Eina_Bool parent;
|
|
|
|
Evry_Action *action;
|
2010-04-26 11:21:09 -07:00
|
|
|
};
|
2010-04-23 17:54:12 -07:00
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
static Evry_Plugin *_base_plug = NULL;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
static void
|
2010-04-27 20:22:40 -07:00
|
|
|
_finish(Evry_Plugin *plugin)
|
2010-04-26 11:21:09 -07:00
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_PLUGIN(p, plugin);
|
2010-04-26 11:21:09 -07:00
|
|
|
Evry_Action *act;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
if (p->parent)
|
|
|
|
{
|
|
|
|
EINA_LIST_FREE(p->actions, act);
|
|
|
|
E_FREE(p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EINA_LIST_FREE(p->actions, act);
|
|
|
|
}
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Evry_Plugin *
|
2010-04-26 11:21:09 -07:00
|
|
|
_begin(Evry_Plugin *plugin, const Evry_Item *it)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_PLUGIN(p, plugin);
|
2009-08-21 15:42:06 -07:00
|
|
|
Evry_Action *act;
|
|
|
|
Eina_List *l;
|
2010-04-28 09:39:50 -07:00
|
|
|
Evry_Type type;
|
2010-04-27 20:22:40 -07:00
|
|
|
|
|
|
|
if (!it || !it->type) return NULL;
|
|
|
|
|
|
|
|
type = it->type;
|
|
|
|
|
|
|
|
if (it->browseable)
|
2010-04-04 07:11:35 -07:00
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
EINA_LIST_FOREACH(evry_conf->actions, l, act)
|
|
|
|
{
|
|
|
|
if (act == EVRY_ACTN(it))
|
|
|
|
{
|
|
|
|
p = E_NEW(Plugin, 1);
|
|
|
|
p->base = *plugin;
|
|
|
|
p->base.items = NULL;
|
|
|
|
p->actions = act->fetch(act);
|
|
|
|
p->parent = EINA_TRUE;
|
|
|
|
p->action = act;
|
|
|
|
return EVRY_PLUGIN(p);
|
|
|
|
}
|
|
|
|
}
|
2010-04-04 07:11:35 -07:00
|
|
|
}
|
2010-04-23 17:54:12 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
EINA_LIST_FOREACH(evry_conf->actions, l, act)
|
|
|
|
{
|
2010-04-28 05:58:24 -07:00
|
|
|
if ((!act->it1.type) ||
|
|
|
|
((act->it1.type == type) &&
|
2010-04-27 20:22:40 -07:00
|
|
|
(!act->check_item || act->check_item(act, it))))
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-26 11:21:09 -07:00
|
|
|
act->base.plugin = plugin;
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
if (!eina_list_data_find_list(p->actions, act))
|
|
|
|
{
|
|
|
|
p->actions = eina_list_append(p->actions, act);
|
|
|
|
}
|
|
|
|
continue;
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
2010-04-26 11:21:09 -07:00
|
|
|
p->actions = eina_list_remove(p->actions, act);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
if (!p->actions) return NULL;
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
return plugin;
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_cb_sort(const void *data1, const void *data2)
|
|
|
|
{
|
|
|
|
const Evry_Item *it1 = data1;
|
|
|
|
const Evry_Item *it2 = data2;
|
|
|
|
|
|
|
|
if (it1->fuzzy_match || it2->fuzzy_match)
|
|
|
|
{
|
|
|
|
if (it1->fuzzy_match && !it2->fuzzy_match)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!it1->fuzzy_match && it2->fuzzy_match)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (it1->fuzzy_match - it2->fuzzy_match)
|
|
|
|
return (it1->fuzzy_match - it2->fuzzy_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it1->priority - it2->priority)
|
|
|
|
return (it1->priority - it2->priority);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-04-26 11:21:09 -07:00
|
|
|
_fetch(Evry_Plugin *plugin, const char *input)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_PLUGIN(p, plugin);
|
2009-08-21 15:42:06 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Evry_Item *it;
|
2010-04-26 11:21:09 -07:00
|
|
|
int match;
|
2010-04-04 07:11:35 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
EINA_LIST_FOREACH(p->actions, l, it)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-26 11:21:09 -07:00
|
|
|
match = evry_fuzzy_match(it->label, input);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
|
|
|
if (!input || match)
|
|
|
|
{
|
|
|
|
it->fuzzy_match = match;
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, it);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
if (!plugin->items) return 0;
|
2010-04-23 17:54:12 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2009-08-22 21:22:46 -07:00
|
|
|
return 1;
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Evry_Plugin *
|
2010-04-26 11:21:09 -07:00
|
|
|
evry_plug_actions_new(Evry_Selector *sel, int type)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-26 11:21:09 -07:00
|
|
|
Evry_Plugin *plugin;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-28 09:39:50 -07:00
|
|
|
plugin = EVRY_PLUGIN_NEW(Plugin, N_("Actions"), NULL, 0, _begin, _finish, _fetch, NULL);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_PLUGIN(p, plugin);
|
2010-04-26 11:21:09 -07:00
|
|
|
p->selector = sel;
|
2010-04-27 20:22:40 -07:00
|
|
|
|
|
|
|
evry_plugin_register(plugin, type, 2);
|
2010-04-26 11:21:09 -07:00
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
int evry_plug_actions_init()
|
|
|
|
{
|
2010-04-28 09:39:50 -07:00
|
|
|
_base_plug = evry_plugin_new(NULL, _("Actions"), NULL, NULL,
|
|
|
|
EVRY_TYPE_ACTION, NULL, NULL, NULL, NULL);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void evry_plug_actions_shutdown()
|
|
|
|
{
|
2010-04-28 04:28:45 -07:00
|
|
|
Evry_Action *a;
|
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
evry_plugin_free(_base_plug);
|
2010-04-28 04:28:45 -07:00
|
|
|
|
|
|
|
EINA_LIST_FREE(evry_conf->actions, a)
|
|
|
|
evry_action_free(a);
|
2010-04-27 20:22:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
EAPI void
|
|
|
|
evry_action_register(Evry_Action *act, int priority)
|
|
|
|
{
|
|
|
|
EVRY_ITEM(act)->priority = priority;
|
|
|
|
|
|
|
|
evry_conf->actions = eina_list_append(evry_conf->actions, act);
|
|
|
|
/* TODO sorting, initialization, etc */
|
|
|
|
}
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
EAPI void
|
|
|
|
evry_action_unregister(Evry_Action *act)
|
|
|
|
{
|
|
|
|
evry_conf->actions = eina_list_remove(evry_conf->actions, act);
|
2010-04-27 20:22:40 -07:00
|
|
|
/* finish */
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
static void
|
|
|
|
_action_free_cb(Evry_Item *it)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_ACTION(act, it);
|
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
if (act->name) eina_stringshare_del(act->name);
|
|
|
|
|
|
|
|
E_FREE(act);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Evry_Action *
|
|
|
|
evry_action_new(const char *name, const char *label,
|
2010-04-28 09:39:50 -07:00
|
|
|
Evry_Type type_in1, Evry_Type type_in2,
|
2010-04-26 11:21:09 -07:00
|
|
|
const char *icon,
|
|
|
|
int (*action) (Evry_Action *act),
|
|
|
|
int (*check_item) (Evry_Action *act, const Evry_Item *it))
|
|
|
|
{
|
2010-04-28 09:39:50 -07:00
|
|
|
Evry_Action *act = EVRY_ITEM_NEW(Evry_Action, _base_plug, label, NULL, _action_free_cb);
|
2010-04-26 11:21:09 -07:00
|
|
|
act->base.icon = icon;
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
act->name = eina_stringshare_add(name);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-04-28 09:39:50 -07:00
|
|
|
act->it1.type = type_in1;
|
|
|
|
act->it2.type = type_in2;
|
2010-04-26 11:21:09 -07:00
|
|
|
|
|
|
|
act->action = action;
|
|
|
|
act->check_item = check_item;
|
|
|
|
|
|
|
|
return act;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
evry_action_free(Evry_Action *act)
|
|
|
|
{
|
|
|
|
evry_action_unregister(act);
|
|
|
|
|
|
|
|
evry_item_free(EVRY_ITEM(act));
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|