everything' module:

- automatically create e-actions for subject plugins so that 
  can be triggered directly
  -> see bindings category: everything
- optimze fuuzy match
- plug border: handle border remove events


SVN revision: 41865
This commit is contained in:
Hannes Janetzek 2009-08-19 00:27:41 +00:00
parent 1c93b96400
commit ca72f2e9a5
7 changed files with 168 additions and 75 deletions

View File

@ -12,13 +12,13 @@
#define CONFIG_VERSION 1
/* actual module specifics */
static void _e_mod_action_exebuf_cb(E_Object *obj, const char *params);
static int _e_mod_run_defer_cb(void *data);
static void _e_mod_run_cb(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_mod_menu_add(void *data, E_Menu *m);
static void _e_mod_action_exebuf_cb(E_Object *obj, const char *params);
static int _e_mod_run_defer_cb(void *data);
static void _e_mod_run_cb(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_mod_menu_add(void *data, E_Menu *m);
/* static E_Module *conf_module = NULL; */
static E_Int_Menu_Augmentation *maug = NULL;
static E_Action *act = NULL;
static Eina_Array *plugins = NULL;
static E_Config_DD *conf_edd = NULL;
@ -123,15 +123,18 @@ e_modapi_init(E_Module *m)
if (act)
{
act->func.go = _e_mod_action_exebuf_cb;
e_action_predef_name_set(_("Launch"), _("Run Everything Dialog"), "everything",
NULL, NULL, 0);
evry_conf->action_show = act;
}
e_action_predef_name_set(_("Everything"), _("Show Everything Dialog"),
"everything", NULL, NULL, 0);
maug = e_int_menus_menu_augmentation_add("main/1", _e_mod_menu_add, NULL, NULL, NULL);
e_configure_registry_category_add("extensions", 80, _("Extensions"), NULL, "preferences-extensions");
e_configure_registry_item_add("extensions/run_everything", 40, _("Run Everything"), NULL, "system-run", evry_config_dialog);
e_configure_registry_category_add("extensions", 80, _("Extensions"),
NULL, "preferences-extensions");
e_configure_registry_item_add("extensions/run_everything", 40, _("Run Everything"),
NULL, "system-run", evry_config_dialog);
evry_init();
@ -145,6 +148,8 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
{
E_Config_Dialog *cfd;
evry_shutdown();
/* remove module-supplied menu additions */
if (maug)
{
@ -152,13 +157,12 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
maug = NULL;
}
/* remove module-supplied action */
if (evry_conf->action_show)
if (act)
{
e_action_predef_name_del(_("Launch"), _("Run Everything Dialog"));
e_action_predef_name_del(_("Everything"), _("Show Everything Dialog"));
e_action_del("everything");
}
evry_shutdown();
/* conf_module = NULL; */
eina_list_free(evry_conf->plugins);
eina_list_free(evry_conf->actions);
@ -172,7 +176,9 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
eina_module_shutdown();
while ((cfd = e_config_dialog_get("E", "_config_everything_dialog"))) e_object_del(E_OBJECT(cfd));
while ((cfd = e_config_dialog_get("E", "_config_everything_dialog")))
e_object_del(E_OBJECT(cfd));
e_configure_registry_item_del("extensions/run_everything");
e_configure_registry_category_del("extensions");
@ -195,7 +201,7 @@ e_modapi_save(E_Module *m __UNUSED__)
/* action callback */
static void
_e_mod_action_exebuf_cb(E_Object *obj, const char *params __UNUSED__)
_e_mod_action_exebuf_cb(E_Object *obj, const char *params)
{
E_Zone *zone = NULL;
@ -212,7 +218,7 @@ _e_mod_action_exebuf_cb(E_Object *obj, const char *params __UNUSED__)
}
if (!zone) zone = e_util_zone_current_get(e_manager_current_get());
if (zone) evry_show(zone);
if (zone) evry_show(zone, params);
}
/* menu item callback(s) */
@ -222,7 +228,7 @@ _e_mod_run_defer_cb(void *data)
E_Zone *zone;
zone = data;
if (zone) evry_show(zone);
if (zone) evry_show(zone, NULL);
return 0;
}
@ -283,7 +289,7 @@ evry_plugin_new(const char *name, int type,
p->browse = browse;
p->config_page = config_page;
p->config_apply = config_apply;
return p;
}
@ -344,17 +350,17 @@ evry_action_free(Evry_Action *act)
}
void
evry_plugin_register(Evry_Plugin *plugin, int priority)
evry_plugin_register(Evry_Plugin *p, int priority)
{
Eina_List *l;
Plugin_Config *pc;
Eina_Bool found = 0;
evry_conf->plugins = eina_list_append(evry_conf->plugins, plugin);
evry_conf->plugins = eina_list_append(evry_conf->plugins, p);
EINA_LIST_FOREACH(evry_conf->plugins_conf, l, pc)
{
if (pc->name && plugin->name && !strcmp(pc->name, plugin->name))
if (pc->name && p->name && !strcmp(pc->name, p->name))
{
found = 1;
break;
@ -364,7 +370,7 @@ evry_plugin_register(Evry_Plugin *plugin, int priority)
if (!found)
{
pc = E_NEW(Plugin_Config, 1);
pc->name = eina_stringshare_add(plugin->name);
pc->name = eina_stringshare_add(p->name);
pc->enabled = 1;
pc->priority = priority ? priority : 100;;
@ -374,19 +380,35 @@ evry_plugin_register(Evry_Plugin *plugin, int priority)
/* if (plugin->trigger && !pc->trigger)
* pc->trigger = eina_stringshare_add(plugin->trigger); */
plugin->config = pc;
p->config = pc;
evry_conf->plugins = eina_list_sort(evry_conf->plugins,
eina_list_count(evry_conf->plugins),
_evry_cb_plugin_sort);
if (p->type == type_subject)
{
char buf[256];
snprintf(buf, sizeof(buf), "Show %s Plugin", p->name);
e_action_predef_name_set(_("Everything"), buf,
"everything", p->name, NULL, 1);
}
/* TODO sorting, initialization, etc */
}
void
evry_plugin_unregister(Evry_Plugin *plugin)
evry_plugin_unregister(Evry_Plugin *p)
{
evry_conf->plugins = eina_list_remove(evry_conf->plugins, plugin);
evry_conf->plugins = eina_list_remove(evry_conf->plugins, p);
if (p->type == type_subject)
{
char buf[256];
snprintf(buf, sizeof(buf), "Show %s Plugin", p->name);
e_action_predef_name_del(_("Everything"), buf);
}
/* cleanup */
}

View File

@ -33,7 +33,6 @@ struct _Config
Eina_List *views;
Eina_Hash *history;
E_Action *action_show;
};
EAPI extern E_Module_Api e_modapi;
@ -45,7 +44,7 @@ EAPI E_Config_Dialog *evry_config_dialog(E_Container *con, const char *params);
int evry_init(void);
int evry_shutdown(void);
int evry_show(E_Zone *zone);
int evry_show(E_Zone *zone, const char *params);
void evry_hide(void);
extern Config *evry_conf;

View File

@ -48,6 +48,8 @@ struct _Evry_Window
Eina_Bool request_selection;
/* E_Popup *input_win; */
Eina_Bool plugin_dedicated;
};
struct _Evry_List_Window
@ -88,7 +90,7 @@ static void _evry_selector_free(Evry_Selector *sel);
static void _evry_selector_activate(Evry_Selector *sel);
static void _evry_selector_update(Evry_Selector *sel);
static void _evry_selector_icon_set(Evry_Selector *sel);
static int _evry_selector_subjects_get(void);
static int _evry_selector_subjects_get(const char *plugin_name);
static int _evry_selector_actions_get(Evry_Item *it);
static int _evry_selector_objects_get(const char *type);
@ -156,7 +158,7 @@ evry_shutdown(void)
}
int
evry_show(E_Zone *zone)
evry_show(E_Zone *zone, const char *params)
{
if (win) return 0;
@ -183,11 +185,14 @@ evry_show(E_Zone *zone)
selectors[1] = _evry_selector_new(type_action);
selectors[2] = _evry_selector_new(type_object);
_evry_selector_subjects_get();
_evry_selector_activate(selectors[0]);
if (params)
win->plugin_dedicated = EINA_TRUE;
mime_hash = eina_hash_stringshared_new(NULL);
_evry_selector_subjects_get(params);
_evry_selector_activate(selectors[0]);
_evry_selector_update(selector);
e_popup_layer_set(list->popup, 255);
@ -376,7 +381,13 @@ evry_plugin_async_update(Evry_Plugin *p, int action)
agg = selector->aggregator;
/* received data from a plugin of the current selector ? */
if (!s || !eina_list_data_find(s->plugins, p)) return;
if (!s || !eina_list_data_find(s->plugins, p))
{
if (p->type == type_action)
return;
}
if (action == EVRY_ASYNC_UPDATE_ADD)
{
@ -507,31 +518,43 @@ evry_fuzzy_match(const char *str, const char *match)
/* current char matches? */
if (tolower(*p) != tolower(*m))
{
offset++;
continue;
if (!first)
offset += 1;
else
offset += 3;
if (offset < 10)
continue;
}
/* first offset of match in word */
if (!first)
if (min < MAX_FUZZ && offset < 10)
{
offset *= 2;
/* first offset of match in word */
if (!first)
{
first = 1;
last = offset;
}
min += offset + (offset - last) * 5;
last = offset;
first = 1;
/* try next char of match */
if (*(++m) != 0 && !isspace(*m))
continue;
/* end of match: store min weight of match */
min += (cnt - m_cnt) > 0 ? (cnt - m_cnt) : 0;
if (min < m_min[m_cnt])
m_min[m_cnt] = min;
}
min += offset + (offset - last) * 10;
last = offset;
/* try next char of match */
if (*(++m) != 0 && !isspace(*m))
continue;
/* end of match: store min weight of match */
min += (cnt - m_cnt) > 0 ? (cnt - m_cnt) : 0;
if (min < m_min[m_cnt])
m_min[m_cnt] = min;
else
{
/* go to next match */
for (; (*m != 0) && !isspace(*m); m++);
}
if (m_cnt < m_num - 1)
{
/* test next match */
@ -957,7 +980,7 @@ _evry_list_win_update(Evry_State *s)
}
static int
_evry_selector_subjects_get(void)
_evry_selector_subjects_get(const char *plugin_name)
{
Eina_List *l, *plugins = NULL;
Evry_Plugin *p;
@ -965,6 +988,9 @@ _evry_selector_subjects_get(void)
EINA_LIST_FOREACH(sel->plugins, l, p)
{
if (plugin_name && strcmp(plugin_name, p->name))
continue;
if (p->begin)
{
if (p->begin(p, NULL))
@ -1598,7 +1624,7 @@ _evry_matches_update(Evry_Selector *sel)
(!strncmp(s->input, p->trigger, strlen(p->trigger))))
{
s->cur_plugins = eina_list_append(s->cur_plugins, p);
p->fetch(p, s->input);
p->fetch(p, s->input + strlen(p->trigger));
break;
}
}
@ -1608,10 +1634,12 @@ _evry_matches_update(Evry_Selector *sel)
{
EINA_LIST_FOREACH(s->plugins, l, p)
{
if (p->trigger) continue;
if (!win->plugin_dedicated && p->trigger) continue;
if (p == sel->aggregator) continue;
if (p->fetch(p, input) || sel->states->next)
if (p->fetch(p, input) ||
(sel->states->next) ||
(win->plugin_dedicated))
s->cur_plugins = eina_list_append(s->cur_plugins, p);
}
@ -2278,7 +2306,7 @@ Evas_Object *
evry_icon_mime_get(const char *mime, Evas *e)
{
char *file;
const char *icon = "";
const char *icon;
if (!(icon = eina_hash_find(mime_hash, mime)))
{
@ -2287,11 +2315,11 @@ evry_icon_mime_get(const char *mime, Evas *e)
{
icon = eina_stringshare_add(file);
free (file);
eina_hash_add(mime_hash, mime, icon);
}
eina_hash_add(mime_hash, mime, icon);
}
if (icon && icon[0])
if (icon)
return e_util_icon_add(icon, e);
else
return evry_icon_theme_get("none", e);

View File

@ -672,10 +672,9 @@ _init(void)
act3 = evry_action_new("New Application Entry", "APPLICATION", NULL, "everything-launch",
_new_app_action, _new_app_check_item, NULL);
act4 = evry_action_new("Open File...", "BORDER", NULL, "everything-launch",
act4 = evry_action_new("Open File...", "BORDER", "FILE", "everything-launch",
_exec_border_action, _exec_border_check_item, NULL);
evry_action_register(act);
evry_action_register(act1);
evry_action_register(act2);

View File

@ -181,8 +181,13 @@ _cb_data(void *data, int type __UNUSED__, void *event)
word = _space_skip(word_end + 1);
}
evry_plugin_async_update(plugin, EVRY_ASYNC_UPDATE_ADD);
if (plugin->items)
{
evry_list_win_show();
}
evry_plugin_async_update(plugin, EVRY_ASYNC_UPDATE_ADD);
return 1;
}
@ -221,12 +226,10 @@ _fetch(Evry_Plugin *plugin, const char *input)
const char *s;
int len;
len = sizeof(TRIGGER) - 1;
if (strncmp(input, TRIGGER, len) != 0)
return 0;
input += len;
if (!input) return 0;
if (!p->handler.data && !_begin(plugin, NULL)) return 0;
len = sizeof(LANG_MODIFIER) - 1;
if (strncmp(input, LANG_MODIFIER, len) == 0)
{
@ -337,7 +340,6 @@ _init(void)
p->base.type_out = eina_stringshare_add("TEXT");
p->base.icon = "accessories-dictionary";
p->base.trigger = TRIGGER;
p->base.begin = _begin;
p->base.fetch = _fetch;
p->base.cleanup = _cleanup;

View File

@ -2,8 +2,41 @@
#include "e_mod_main.h"
static Evry_Plugin *p;
static Eina_List *handlers = NULL;
/* XXX handle border remove events */
static int
_cb_border_remove(void *data, int type, void *event)
{
E_Event_Border_Remove *ev;
Eina_List *l;
Evry_Item *it;
ev = event;
EINA_LIST_FOREACH(p->items, l, it)
{
if (it->data[0] == ev->border)
{
p->items = eina_list_remove(p->items, it);
evry_item_free(it);
evry_plugin_async_update(p, EVRY_ASYNC_UPDATE_ADD);
break;
}
}
return 1;
}
static int
_begin(Evry_Plugin *p, const Evry_Item *it)
{
handlers = eina_list_append
(handlers, ecore_event_handler_add
(E_EVENT_BORDER_REMOVE, _cb_border_remove, NULL));
return 1;
}
static void
_cleanup(Evry_Plugin *p)
@ -12,6 +45,12 @@ _cleanup(Evry_Plugin *p)
EINA_LIST_FREE(p->items, it)
evry_item_free(it);
while (handlers)
{
ecore_event_handler_del(handlers->data);
handlers = eina_list_remove_list(handlers, handlers);
}
}
static void
@ -181,7 +220,7 @@ static Eina_Bool
_init(void)
{
p = evry_plugin_new("Windows", type_subject, NULL, "BORDER", 0, NULL, NULL,
NULL, _cleanup, _fetch, NULL, NULL, _item_icon_get, NULL, NULL);
_begin, _cleanup, _fetch, NULL, NULL, _item_icon_get, NULL, NULL);
evry_plugin_register(p, 2);

View File

@ -121,10 +121,14 @@ _fetch(Evry_Plugin *p, const char *input)
{
char buf[1024];
if (!strncmp(input, "=scale=", 7))
snprintf(buf, 1024, "%s\n", input + (strlen(p->trigger)));
if (!input) return 0;
if (!data_handler && !_begin(p, NULL)) return 0;
if (!strncmp(input, "scale=", 6))
snprintf(buf, 1024, "%s\n", input);
else
snprintf(buf, 1024, "scale=3;%s\n", input + (strlen(p->trigger)));
snprintf(buf, 1024, "scale=3;%s\n", input);
ecore_exe_send(exe, buf, strlen(buf));
@ -192,7 +196,7 @@ static Eina_Bool
_init(void)
{
p1 = evry_plugin_new("Calculator", type_subject, NULL, "TEXT", 1, "accessories-calculator", "=",
_begin, _cleanup, _fetch, _action, NULL, NULL, NULL, NULL);
NULL, _cleanup, _fetch, _action, NULL, NULL, NULL, NULL);
evry_plugin_register(p1, 0);