forked from enlightenment/enlightenment
'everything' module:
some more optimizations for fuzzy matching SVN revision: 41774
This commit is contained in:
parent
69dc178b13
commit
6277b8f7f0
|
@ -461,13 +461,13 @@ evry_fuzzy_match(const char *str, const char *match)
|
|||
unsigned int pos = 0;
|
||||
unsigned int last = 0;
|
||||
unsigned char first;
|
||||
|
||||
unsigned int spaces = 0;
|
||||
|
||||
if (!match || !str) return 0;
|
||||
|
||||
for (m = match; *m != 0; m++)
|
||||
{
|
||||
mc = tolower(*m);
|
||||
|
||||
first = 0;
|
||||
|
||||
for (p = str; *p != 0 && *m != 0; p++)
|
||||
|
@ -497,6 +497,7 @@ evry_fuzzy_match(const char *str, const char *match)
|
|||
pos = last = 0;
|
||||
/* add some weight */
|
||||
cnt += pos;
|
||||
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
@ -1107,7 +1108,7 @@ _evry_selectors_switch(void)
|
|||
{
|
||||
int next_selector = 0;
|
||||
|
||||
if (s->plugin == action_selector)
|
||||
if (s->sel_item && s->sel_item->plugin == action_selector)
|
||||
{
|
||||
Evry_Action *act = s->sel_item->data[0];
|
||||
|
||||
|
@ -1306,7 +1307,7 @@ _evry_plugin_action(Evry_Selector *sel, int finished)
|
|||
|
||||
if (!s_subject->sel_item || !s_action->sel_item) return;
|
||||
|
||||
if (s_action->plugin == action_selector)
|
||||
if (s_action->sel_item->plugin == action_selector)
|
||||
{
|
||||
Evry_Action *act = s_action->sel_item->data[0];
|
||||
Evry_Item *it_object = NULL;
|
||||
|
@ -2081,7 +2082,7 @@ _evry_plug_actions_fetch(Evry_Plugin *p, const char *input)
|
|||
Eina_List *l;
|
||||
Evry_Item *it;
|
||||
Evry_Selector *sel = selectors[1];
|
||||
int fuzz = 0;
|
||||
int match = 0;
|
||||
|
||||
EINA_LIST_FREE(p->items, it)
|
||||
evry_item_free(it);
|
||||
|
@ -2089,12 +2090,12 @@ _evry_plug_actions_fetch(Evry_Plugin *p, const char *input)
|
|||
EINA_LIST_FOREACH(sel->actions, l, act)
|
||||
{
|
||||
if (input)
|
||||
fuzz = evry_fuzzy_match(act->name, input);
|
||||
match = evry_fuzzy_match(act->name, input);
|
||||
|
||||
if (!input || fuzz)
|
||||
if (!input || match)
|
||||
{
|
||||
it = evry_item_new(p, act->name, NULL);
|
||||
it->fuzzy_match = fuzz;
|
||||
it->fuzzy_match = match;
|
||||
it->data[0] = act;
|
||||
p->items = eina_list_append(p->items, it);
|
||||
}
|
||||
|
@ -2180,7 +2181,6 @@ _evry_plug_aggregator_fetch(Evry_Plugin *p, const char *input)
|
|||
Evry_Plugin *plugin;
|
||||
Evry_Item *it;
|
||||
int cnt = 0;
|
||||
int fuzzy;
|
||||
Eina_List *items = NULL;
|
||||
|
||||
EINA_LIST_FREE(p->items, it)
|
||||
|
|
|
@ -16,6 +16,7 @@ static Evry_Action *act;
|
|||
static Evry_Action *act1;
|
||||
static Evry_Action *act2;
|
||||
static Evry_Action *act3;
|
||||
static Evry_Action *act4;
|
||||
static Eina_List *exe_path = NULL;
|
||||
|
||||
|
||||
|
@ -102,7 +103,7 @@ _cleanup(Evry_Plugin *p)
|
|||
}
|
||||
|
||||
static int
|
||||
_item_add(Evry_Plugin *p, Efreet_Desktop *desktop, char *file, int prio)
|
||||
_item_add(Evry_Plugin *p, Efreet_Desktop *desktop, char *file, int match)
|
||||
{
|
||||
Evry_Item *it;
|
||||
Evry_App *app;
|
||||
|
@ -169,7 +170,7 @@ _item_add(Evry_Plugin *p, Efreet_Desktop *desktop, char *file, int prio)
|
|||
app->desktop = desktop;
|
||||
app->file = file;
|
||||
it->data[0] = app;
|
||||
it->priority = prio;
|
||||
it->fuzzy_match = match;
|
||||
|
||||
p->items = eina_list_append(p->items, it);
|
||||
|
||||
|
@ -181,34 +182,32 @@ _add_desktop_list(Evry_Plugin *p, Eina_List *apps, const char *input)
|
|||
{
|
||||
Efreet_Desktop *desktop;
|
||||
Eina_List *l;
|
||||
int fuzz;
|
||||
int m1, m2, min;
|
||||
|
||||
EINA_LIST_FOREACH(apps, l, desktop)
|
||||
{
|
||||
if (eina_list_count(p->items) > 199) continue;
|
||||
if (!desktop || !desktop->name || !desktop->exec) continue;
|
||||
if (!desktop->name || !desktop->exec) continue;
|
||||
|
||||
if (fuzz = evry_fuzzy_match(desktop->exec, input))
|
||||
_item_add(p, desktop, NULL, fuzz);
|
||||
else if (fuzz = evry_fuzzy_match(desktop->name, input))
|
||||
_item_add(p, desktop, NULL, fuzz);
|
||||
m1 = evry_fuzzy_match(desktop->exec, input);
|
||||
m2 = evry_fuzzy_match(desktop->name, input);
|
||||
|
||||
if (!m1 || (m2 && m2 < m1))
|
||||
m1 = m2;
|
||||
|
||||
if (m1) _item_add(p, desktop, NULL, m1);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
_cb_sort(const void *data1, const void *data2)
|
||||
{
|
||||
const Evry_Item *it1, *it2;
|
||||
const Evry_Item *it1 = data1;
|
||||
const Evry_Item *it2 = data2;
|
||||
Evry_App *app1, *app2;
|
||||
const char *e1, *e2;
|
||||
double t1, t2;
|
||||
|
||||
it1 = data1;
|
||||
it2 = data2;
|
||||
|
||||
if (it1->priority - it2->priority)
|
||||
return (it1->priority - it2->priority);
|
||||
|
||||
|
||||
app1 = it1->data[0];
|
||||
app2 = it2->data[0];
|
||||
|
||||
|
@ -228,6 +227,15 @@ _cb_sort(const void *data1, const void *data2)
|
|||
if ((int)(t2 - t1))
|
||||
return (int)(t2 - t1);
|
||||
|
||||
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);
|
||||
|
||||
// TODO compare exe strings?
|
||||
else return 0;
|
||||
}
|
||||
|
@ -394,6 +402,23 @@ _exec_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
|||
|
||||
if (app->file && strlen(app->file) > 0)
|
||||
return 1;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -453,6 +478,19 @@ _exec_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, c
|
|||
return _app_action(it1, it2);
|
||||
}
|
||||
|
||||
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 *p, const Evry_Item *it, const char *input __UNUSED__)
|
||||
{
|
||||
|
@ -636,6 +674,15 @@ _init(void)
|
|||
act3->icon = "everything-launch";
|
||||
evry_action_register(act3);
|
||||
|
||||
act4 = E_NEW(Evry_Action, 1);
|
||||
act4->name = "Open File...";
|
||||
act4->type_in1 = "BORDER";
|
||||
act4->type_in2 = "FILE";
|
||||
act4->action = &_exec_border_action;
|
||||
act4->check_item = &_exec_border_check_item;
|
||||
act4->icon = "everything-launch";
|
||||
evry_action_register(act4);
|
||||
|
||||
/* taken from e_exebuf.c */
|
||||
path = getenv("PATH");
|
||||
if (path)
|
||||
|
@ -676,6 +723,7 @@ _shutdown(void)
|
|||
E_FREE(act1);
|
||||
E_FREE(act2);
|
||||
E_FREE(act3);
|
||||
E_FREE(act4);
|
||||
|
||||
EINA_LIST_FREE(exe_path, str)
|
||||
free(str);
|
||||
|
|
|
@ -21,7 +21,7 @@ _item_free(Evry_Item *it)
|
|||
}
|
||||
|
||||
static void
|
||||
_item_add(Evry_Plugin *p, E_Border *bd, int fuzz, int *prio)
|
||||
_item_add(Evry_Plugin *p, E_Border *bd, int match, int *prio)
|
||||
{
|
||||
Evry_Item *it;
|
||||
|
||||
|
@ -29,7 +29,7 @@ _item_add(Evry_Plugin *p, E_Border *bd, int fuzz, int *prio)
|
|||
|
||||
/* e_object_ref(E_OBJECT(bd)); */
|
||||
it->data[0] = bd;
|
||||
it->fuzzy_match = fuzz;
|
||||
it->fuzzy_match = match;
|
||||
it->priority = *prio;
|
||||
|
||||
*prio += 1;
|
||||
|
@ -56,7 +56,8 @@ _fetch(Evry_Plugin *p, const char *input)
|
|||
E_Border *bd;
|
||||
Eina_List *l;
|
||||
int prio = 0;
|
||||
|
||||
int m1, m2;
|
||||
|
||||
_cleanup(p);
|
||||
|
||||
zone = e_util_zone_current_get(e_manager_current_get());
|
||||
|
@ -69,26 +70,24 @@ _fetch(Evry_Plugin *p, const char *input)
|
|||
_item_add(p, bd, 0, &prio);
|
||||
else
|
||||
{
|
||||
int fuzz, min;
|
||||
|
||||
min = evry_fuzzy_match(e_border_name_get(bd), input);
|
||||
m1 = evry_fuzzy_match(e_border_name_get(bd), input);
|
||||
|
||||
if (bd->client.icccm.name)
|
||||
{
|
||||
fuzz = evry_fuzzy_match(bd->client.icccm.name, input);
|
||||
if (!min || fuzz < min)
|
||||
min = fuzz;
|
||||
m2 = evry_fuzzy_match(bd->client.icccm.name, input);
|
||||
if (!m1 || (m2 && m2 < m1))
|
||||
m1 = m2;
|
||||
}
|
||||
|
||||
if (bd->desktop)
|
||||
{
|
||||
fuzz = evry_fuzzy_match(bd->desktop->name, input);
|
||||
if (!min || fuzz < min)
|
||||
min = fuzz;
|
||||
m2 = evry_fuzzy_match(bd->desktop->name, input);
|
||||
if (!m1 || (m2 && m2 < m1))
|
||||
m1 = m2;
|
||||
}
|
||||
|
||||
if (min)
|
||||
_item_add(p, bd, min, &prio);
|
||||
if (m1)
|
||||
_item_add(p, bd, m1, &prio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,17 +92,17 @@ static void
|
|||
_item_add(Evry_Plugin *p, const char *label, void (*action_cb) (E_Border *bd), const char *icon, const char *input)
|
||||
{
|
||||
Evry_Item *it;
|
||||
int fuzz = 1;
|
||||
int match = 1;
|
||||
|
||||
if (input)
|
||||
fuzz = evry_fuzzy_match(label, input);
|
||||
match = evry_fuzzy_match(label, input);
|
||||
|
||||
if (!fuzz) return;
|
||||
if (!match) return;
|
||||
|
||||
it = evry_item_new(p, label, &_item_free);
|
||||
it->data[0] = action_cb;
|
||||
it->data[1] = (void *) eina_stringshare_add(icon);
|
||||
it->fuzzy_match = fuzz;
|
||||
it->fuzzy_match = match;
|
||||
|
||||
p->items = eina_list_prepend(p->items, it);
|
||||
}
|
||||
|
|
|
@ -14,14 +14,14 @@ _cleanup(Evry_Plugin *p)
|
|||
}
|
||||
|
||||
static void
|
||||
_item_add(Evry_Plugin *p, E_Configure_It *eci, int fuzz, int prio)
|
||||
_item_add(Evry_Plugin *p, E_Configure_It *eci, int match, int prio)
|
||||
{
|
||||
Evry_Item *it;
|
||||
|
||||
it = evry_item_new(p, eci->label, NULL);
|
||||
it->data[0] = eci;
|
||||
it->priority = prio;
|
||||
it->fuzzy_match = fuzz;
|
||||
it->fuzzy_match = match;
|
||||
|
||||
p->items = eina_list_append(p->items, it);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ _fetch(Evry_Plugin *p, const char *input)
|
|||
Eina_List *l, *ll;
|
||||
E_Configure_Cat *ecat;
|
||||
E_Configure_It *eci;
|
||||
int fuzz;
|
||||
int match;
|
||||
|
||||
_cleanup(p);
|
||||
|
||||
|
@ -57,10 +57,10 @@ _fetch(Evry_Plugin *p, const char *input)
|
|||
{
|
||||
if (eci->pri >= 0)
|
||||
{
|
||||
if (fuzz = evry_fuzzy_match(eci->label, input))
|
||||
_item_add(p, eci, fuzz, 0);
|
||||
else if (fuzz = evry_fuzzy_match(ecat->label, input))
|
||||
_item_add(p, eci, fuzz, 1);
|
||||
if (match = evry_fuzzy_match(eci->label, input))
|
||||
_item_add(p, eci, match, 0);
|
||||
else if (match = evry_fuzzy_match(ecat->label, input))
|
||||
_item_add(p, eci, match, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,9 +320,9 @@ _fetch(Evry_Plugin *p, const char *input)
|
|||
{
|
||||
if (input)
|
||||
{
|
||||
int fuzz;
|
||||
if ((fuzz = evry_fuzzy_match(it->label, input)))
|
||||
it->priority = fuzz;
|
||||
int match;
|
||||
if ((match = evry_fuzzy_match(it->label, input)))
|
||||
it->priority = match;
|
||||
else
|
||||
it = NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue