'everything' module:

- added intercept and cleanup functions for Evry_Action. 
  intercept is run before subject item is passed to object plugin
  so that it can convert the output type of subject to the input type 
  of object plugin. used for BORDER -> APPLICATION (if border has a 
  reference to a .desktop file)


SVN revision: 41921
This commit is contained in:
Hannes Janetzek 2009-08-22 01:15:21 +00:00
parent a9589df2e7
commit 71943a92da
12 changed files with 126 additions and 102 deletions

View File

@ -58,7 +58,7 @@ struct _Evry_Item
Evas_Object *o_icon;
Evas_Object *o_bg;
int ref;
void (*cb_free) (Evry_Item *item);
void (*free) (Evry_Item *item);
};
struct _Evry_Plugin
@ -94,7 +94,7 @@ struct _Evry_Plugin
/* int (*candidate_info) (Evas *evas, Evry_Item *item); */
/* optional: default action for this plugins items */
int (*action) (Evry_Plugin *p, const Evry_Item *item, const char *input);
int (*action) (Evry_Plugin *p, const Evry_Item *item);
Evas_Object *(*config_page) (Evry_Plugin *p);
void (*config_apply) (Evry_Plugin *p);
@ -138,10 +138,10 @@ struct _Evry_View
Evas_Object *o_bar;
Evry_View *(*create) (Evry_View *view, const Evry_State *s, const Evas_Object *swallow);
void (*destroy) (Evry_View *view);
int (*cb_key_down) (Evry_View *view, const Ecore_Event_Key *ev);
int (*update) (Evry_View *view);
void (*clear) (Evry_View *view);
void (*destroy) (Evry_View *view);
int (*cb_key_down) (Evry_View *view, const Ecore_Event_Key *ev);
int (*update) (Evry_View *view);
void (*clear) (Evry_View *view);
int priority;
};
@ -153,21 +153,19 @@ struct _Evry_Action
const char *type_in1;
const char *type_in2;
const char *type_out;
const Evry_Item *item1;
const Evry_Item *item2;
int (*action) (Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input);
int (*check_item) (Evry_Action *act, const Evry_Item *it);
int (*action) (Evry_Action *act);
int (*check_item) (Evry_Action *act, const Evry_Item *it);
int (*intercept) (Evry_Action *act);
void (*cleanup) (Evry_Action *act);
Evas_Object *(*icon_get) (Evry_Action *act, Evas *e);
/* use icon name from theme */
const char *icon;
Eina_Bool is_default;
/* only for internal use by plugin */
void *private;
/* not to be set by plugin! */
Evas_Object *o_icon;
};
@ -209,7 +207,7 @@ EAPI Evry_Plugin *evry_plugin_new(Evry_Plugin *base, const char *name, int type,
Evry_Plugin *(*begin) (Evry_Plugin *p, const Evry_Item *item),
void (*cleanup) (Evry_Plugin *p),
int (*fetch) (Evry_Plugin *p, const char *input),
int (*action) (Evry_Plugin *p, const Evry_Item *item, const char *input),
int (*action) (Evry_Plugin *p, const Evry_Item *item),
Evas_Object *(*icon_get) (Evry_Plugin *p, const Evry_Item *it, Evas *e),
Evas_Object *(*config_page) (Evry_Plugin *p),
void (*config_apply) (Evry_Plugin *p));
@ -217,10 +215,13 @@ EAPI Evry_Plugin *evry_plugin_new(Evry_Plugin *base, const char *name, int type,
EAPI void evry_plugin_free(Evry_Plugin *p, int free_pointer);
EAPI Evry_Action *evry_action_new(const char *name, const char *type_in1, const char *type_in2, const char *type_out,
EAPI Evry_Action *evry_action_new(const char *name, const char *type_in1,
const char *type_in2, const char *type_out,
const char *icon,
int (*action) (Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input),
int (*check_item) (Evry_Action *act, const Evry_Item *it),
int (*action) (Evry_Action *act),
int (*check_item) (Evry_Action *act, const Evry_Item *it),
void (*cleanup) (Evry_Action *act),
int (*intercept) (Evry_Action *act),
Evas_Object *(*icon_get) (Evry_Action *act, Evas *e));
EAPI void evry_action_free(Evry_Action *act);

View File

@ -274,7 +274,7 @@ evry_plugin_new(Evry_Plugin *base, const char *name, int type,
Evry_Plugin *(*begin) (Evry_Plugin *p, const Evry_Item *item),
void (*cleanup) (Evry_Plugin *p),
int (*fetch) (Evry_Plugin *p, const char *input),
int (*action) (Evry_Plugin *p, const Evry_Item *item, const char *input),
int (*action) (Evry_Plugin *p, const Evry_Item *item),
Evas_Object *(*icon_get) (Evry_Plugin *p, const Evry_Item *it, Evas *e),
Evas_Object *(*config_page) (Evry_Plugin *p),
void (*config_apply) (Evry_Plugin *p))
@ -331,9 +331,12 @@ evry_plugin_free(Evry_Plugin *p, int free_pointer)
Evry_Action *
evry_action_new(const char *name, const char *type_in1, const char *type_in2, const char *type_out, const char *icon,
int (*action) (Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input),
evry_action_new(const char *name, const char *type_in1, const char *type_in2,
const char *type_out, const char *icon,
int (*action) (Evry_Action *act),
int (*check_item) (Evry_Action *act, const Evry_Item *it),
void (*cleanup) (Evry_Action *act),
int (*intercept) (Evry_Action *act),
Evas_Object *(*icon_get) (Evry_Action *act, Evas *e))
{
Evry_Action *act = E_NEW(Evry_Action, 1);
@ -343,6 +346,8 @@ evry_action_new(const char *name, const char *type_in1, const char *type_in2, co
act->type_out = (type_out ? eina_stringshare_add(type_out) : NULL);
act->action = action;
act->check_item = check_item;
act->intercept = intercept;
act->cleanup = cleanup;
act->icon = (icon ? eina_stringshare_add(icon) : NULL);
return act;

View File

@ -246,7 +246,7 @@ evry_item_new(Evry_Plugin *p, const char *label, void (*cb_free) (Evry_Item *ite
it->plugin = p;
if (label) it->label = eina_stringshare_add(label);
if (cb_free) it->cb_free = cb_free;
if (free) it->free = cb_free;
it->ref = 1;
@ -269,7 +269,7 @@ evry_item_free(Evry_Item *it)
* it->label);
* item_cnt--; */
if (it->cb_free) it->cb_free(it);
if (it->free) it->free(it);
if (it->label) eina_stringshare_del(it->label);
if (it->uri) eina_stringshare_del(it->uri);
@ -569,7 +569,8 @@ _evry_list_win_new(E_Zone *zone)
evas_event_freeze(popup->evas);
evas_event_feed_mouse_in(popup->evas, ecore_x_current_time_get(), NULL);
evas_event_feed_mouse_move(popup->evas, -1000000, -1000000, ecore_x_current_time_get(), NULL);
evas_event_feed_mouse_move(popup->evas, -1000000, -1000000,
ecore_x_current_time_get(), NULL);
o = edje_object_add(popup->evas);
list_win->o_main = o;
e_theme_edje_object_set(o, "base/theme/everything",
@ -1380,25 +1381,24 @@ _evry_plugin_action(Evry_Selector *sel, int finished)
it_object = selector->state->sel_item;
if (act->type_in2 && !it_object) return;
act->action(act, s_subject->sel_item, it_object, NULL);
act->item2 = it_object;
act->action(act);
}
else
{
Evry_Item *it = s_action->sel_item;
s_action->plugin->action(s_action->plugin, it,
selector->state->input);
s_action->plugin->action(s_action->plugin, it);
}
/* let subject and object plugin know that an action was performed */
if (s_subject->plugin->action)
s_subject->plugin->action(s_subject->plugin,
s_subject->sel_item,
s_subject->input);
s_subject->plugin->action(s_subject->plugin, s_subject->sel_item);
if (s_object && s_object->plugin->action)
s_object->plugin->action(s_object->plugin,
s_object->sel_item,
s_object->input);
s_object->plugin->action(s_object->plugin, s_object->sel_item);
if (finished)
evry_hide();
}

View File

@ -37,6 +37,7 @@ _begin(Evry_Plugin *p, const Evry_Item *it)
if (act->type_in1 && (act->type_in1 == type) &&
(!act->check_item || act->check_item(act, it)))
{
act->item1 = it;
sel->actions = eina_list_append(sel->actions, act);
}
}

View File

@ -108,10 +108,10 @@ _fetch(Evry_Plugin *plugin, const char *input)
}
static int
_action(Evry_Plugin *plugin, const Evry_Item *it, const char *input)
_action(Evry_Plugin *plugin, const Evry_Item *it)
{
if (it->plugin && it->plugin->action)
return it->plugin->action(it->plugin, it, input);
return it->plugin->action(it->plugin, it);
return 0;
}

View File

@ -383,23 +383,6 @@ _exec_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
return 0;
}
static int
_exec_border_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
{
E_Border *bd = it->data[0];
E_OBJECT_CHECK_RETURN(bd, 0);
E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, 0);
if ((bd->desktop && bd->desktop->exec) &&
((strstr(bd->desktop->exec, "%u")) ||
(strstr(bd->desktop->exec, "%U")) ||
(strstr(bd->desktop->exec, "%f")) ||
(strstr(bd->desktop->exec, "%F"))))
return 1;
return 0;
}
static int
_app_action(const Evry_Item *it_app, const Evry_Item *it_file)
{
@ -482,26 +465,13 @@ _app_action(const Evry_Item *it_app, const Evry_Item *it_file)
}
static int
_exec_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input)
_exec_app_action(Evry_Action *act)
{
return _app_action(it1, it2);
return _app_action(act->item1, act->item2);
}
static int
_exec_border_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input)
{
Evry_Item *it = E_NEW(Evry_Item, 1);
Evry_App *app = E_NEW(Evry_App, 1);
E_Border *bd = it1->data[0];
app->desktop = bd->desktop;
it->data[0] = app;
return _app_action(it, it2);
}
static int
_open_with_action(Evry_Plugin *plugin, const Evry_Item *it, const char *input __UNUSED__)
_open_with_action(Evry_Plugin *plugin, const Evry_Item *it)
{
Plugin *p = (Plugin*) plugin;
@ -521,16 +491,13 @@ _edit_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
return 0;
}
static int
_edit_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input)
_edit_app_action(Evry_Action *act)
{
Evry_App *app;
Efreet_Desktop *desktop;
if (!it1) return 0;
app = it1->data[0];
app = act->item1->data[0];
if (app->desktop)
desktop = app->desktop;
else
@ -548,7 +515,6 @@ _edit_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, c
return 1;
}
static int
_new_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
{
@ -562,9 +528,8 @@ _new_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
return 0;
}
static int
_new_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input)
_new_app_action(Evry_Action *act)
{
Evry_App *app;
char *name;
@ -573,9 +538,7 @@ _new_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, co
Efreet_Desktop *desktop;
int i;
if (!it1) return 0;
app = it1->data[0];
app = act->item1->data[0];
if (app->desktop)
name = strdup(app->desktop->name);
@ -621,6 +584,54 @@ _new_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, co
return 1;
}
static int
_exec_border_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
{
E_Border *bd = it->data[0];
E_OBJECT_CHECK_RETURN(bd, 0);
E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, 0);
if ((bd->desktop && bd->desktop->exec) &&
((strstr(bd->desktop->exec, "%u")) ||
(strstr(bd->desktop->exec, "%U")) ||
(strstr(bd->desktop->exec, "%f")) ||
(strstr(bd->desktop->exec, "%F"))))
return 1;
return 0;
}
static int
_exec_border_action(Evry_Action *act)
{
return _app_action(act->item1, act->item2);
}
static int
_exec_border_intercept(Evry_Action *act)
{
Evry_Item *it = E_NEW(Evry_Item, 1);
Evry_App *app = E_NEW(Evry_App, 1);
E_Border *bd = act->item1->data[0];
app->desktop = bd->desktop;
it->data[0] = app;
act->item1 = it;
}
static void
_exec_border_cleanup(Evry_Action *act)
{
Evry_Item *it = (Evry_Item*) act->item1;
Evry_App *app = it->data[0];
E_FREE(app);
E_FREE(it);
}
static Eina_Bool
_init(void)
{
@ -640,23 +651,28 @@ _init(void)
act = evry_action_new("Launch", "APPLICATION", NULL, NULL,
"everything-launch",
_exec_app_action, _exec_app_check_item, NULL);
_exec_app_action, _exec_app_check_item,
NULL, NULL,NULL);
act1 = evry_action_new("Open File...", "APPLICATION", "FILE", "APPLICATION",
"document-open",
_exec_app_action, _exec_app_check_item, NULL);
_exec_app_action, _exec_app_check_item,
NULL, NULL, NULL);
act2 = evry_action_new("Edit Application Entry", "APPLICATION", NULL, NULL,
"everything-launch",
_edit_app_action, _edit_app_check_item, NULL);
_edit_app_action, _edit_app_check_item,
NULL, NULL, NULL);
act3 = evry_action_new("New Application Entry", "APPLICATION", NULL, NULL,
"everything-launch",
_new_app_action, _new_app_check_item, NULL);
_new_app_action, _new_app_check_item,
NULL, NULL, NULL);
act4 = evry_action_new("Open File...", "BORDER", "FILE", NULL,
act4 = evry_action_new("Open File...", "BORDER", "FILE", "APPLICATION",
"everything-launch",
_exec_border_action, _exec_border_check_item, NULL);
_exec_border_action, _exec_border_check_item,
_exec_border_cleanup, _exec_border_intercept, NULL);
evry_action_register(act);
evry_action_register(act1);

View File

@ -190,7 +190,7 @@ _fetch(Evry_Plugin *p, const char *input)
}
static int
_action(Evry_Plugin *p __UNUSED__, const Evry_Item *item, const char *input __UNUSED__)
_action(Evry_Plugin *p __UNUSED__, const Evry_Item *item)
{
void (*border_action) (E_Border *bd);
border_action = item->data[0];

View File

@ -94,7 +94,7 @@ _cleanup(Evry_Plugin *p)
}
static int
_action(Evry_Plugin *p, const Evry_Item *it, const char *input __UNUSED__)
_action(Evry_Plugin *p, const Evry_Item *it)
{
Eina_List *l;
Evry_Item *it2;

View File

@ -5,8 +5,10 @@ static Evry_Action *act;
static Ecore_X_Window clipboard_win = 0;
static int
_action(Evry_Action *act __UNUSED__, const Evry_Item *it, const Evry_Item *it2 __UNUSED__, const char *input __UNUSED__)
_action(Evry_Action *act)
{
const Evry_Item *it = act->item1;
ecore_x_selection_primary_set(clipboard_win, it->label, strlen(it->label));
ecore_x_selection_clipboard_set(clipboard_win, it->label, strlen(it->label));
@ -26,7 +28,7 @@ _init(void)
if (!win) return EINA_FALSE;
act = evry_action_new("Copy to Clipboard", "TEXT", NULL, NULL, "edit-copy",
_action, _check_item, NULL);
_action, _check_item, NULL, NULL, NULL);
evry_action_register(act);

View File

@ -92,7 +92,7 @@ _item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
}
static int
_action(Evry_Action *act, const Evry_Item *it, const Evry_Item *it2 __UNUSED__, const char *input __UNUSED__)
_action(Evry_Action *act)
{
E_Configure_It *eci, *eci2;
E_Container *con;
@ -101,7 +101,7 @@ _action(Evry_Action *act, const Evry_Item *it, const Evry_Item *it2 __UNUSED__,
char buf[1024];
int found = 0;
eci = it->data[0];
eci = act->item1->data[0];
con = e_container_current_get(e_manager_current_get());
EINA_LIST_FOREACH(e_configure_registry, l, ecat)
@ -134,7 +134,7 @@ _init(void)
NULL, _cleanup, _fetch, NULL, _item_icon_get, NULL, NULL);
act = evry_action_new("Show Dialog", "E_SETTINGS", NULL, NULL, "preferences-advanced",
_action, NULL, NULL);
_action, NULL, NULL, NULL, NULL);
evry_plugin_register(p, 10);
evry_action_register(act);

View File

@ -334,8 +334,7 @@ _open_folder_check(Evry_Action *act __UNUSED__, const Evry_Item *it)
}
static int
_open_folder_action(Evry_Action *act __UNUSED__, const Evry_Item *it,
const Evry_Item *it2 __UNUSED__, const char *input __UNUSED__)
_open_folder_action(Evry_Action *act)
{
E_Action *action = e_action_find("fileman");
char *path;
@ -345,16 +344,16 @@ _open_folder_action(Evry_Action *act __UNUSED__, const Evry_Item *it,
m = e_manager_list();
if (!it->browseable)
if (!act->item1->browseable)
{
path = ecore_file_dir_get(it->uri);
path = ecore_file_dir_get(act->item1->uri);
if (!path) return 0;
action->func.go(E_OBJECT(m->data), path);
free(path);
}
else
{
action->func.go(E_OBJECT(m->data), it->uri);
action->func.go(E_OBJECT(m->data), act->item1->uri);
}
return 1;
@ -376,7 +375,7 @@ _init(void)
evry_plugin_register(p2, 1);
act = evry_action_new("Open Folder (EFM)", "FILE", NULL, NULL, "folder-open",
_open_folder_action, _open_folder_check, NULL);
_open_folder_action, _open_folder_check, NULL, NULL, NULL);
evry_action_register(act);

View File

@ -29,8 +29,8 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it)
p->active = 0;
/* is application */
if (it->plugin->type_out == plugin->type_in)
/* is APPLICATION ? */
if (it && it->plugin->type_out == plugin->type_in)
{
Eina_List *l;
const char *mime;