'everything' module:

- no more glob matches
- dir browse now checks for mime magic, hope that slows down no too much
- preview: cleanups
- nicer var names in fuzzy match


SVN revision: 41852
This commit is contained in:
Hannes Janetzek 2009-08-18 00:47:09 +00:00
parent 1fcfea9a30
commit 70af748fa7
3 changed files with 70 additions and 96 deletions

View File

@ -11,7 +11,7 @@
#define INPUTLEN 40
#define MATCH_LAG 0.33
#define MAX_FUZZ 150
#define MAX_WORDS 64
#define MAX_WORDS 5
@ -451,9 +451,9 @@ evry_fuzzy_match(const char *str, const char *match)
unsigned int cnt = 0;
/* words in match */
unsigned int words = 1;
unsigned int word = 0;
unsigned int word_min[MAX_WORDS];
unsigned int m_num = 1;
unsigned int m_cnt = 0;
unsigned int m_min[MAX_WORDS];
if (!match || !str) return 0;
@ -462,18 +462,18 @@ evry_fuzzy_match(const char *str, const char *match)
for (; (*str != 0) && isspace(*str); str++);
/* count words in match */
word_min[0] = MAX_FUZZ;
for (m = match; (*m != 0) && (*(m+1) != 0) && (words < MAX_WORDS); m++)
m_min[0] = MAX_FUZZ;
for (m = match; (*m != 0) && (*(m+1) != 0) && (m_num < MAX_WORDS); m++)
if (isspace(*m) && !isspace(*(m+1)))
word_min[words++] = MAX_FUZZ;
m_min[m_num++] = MAX_FUZZ;
next = str;
m = match;
for (; (word < words) && (*next != 0);)
for (; (m_cnt < m_num) && (*next != 0);)
{
/* reset match */
if (word == 0) m = match;
if (m_cnt == 0) m = match;
/* end of matching */
if (*m == 0) break;
@ -489,12 +489,12 @@ evry_fuzzy_match(const char *str, const char *match)
/* new word of string begins */
if ((*p == 0) || isspace(*p))
{
if (word < words - 1)
if (m_cnt < m_num - 1)
{
/* test next match */
for (; (*m != 0) && !isspace(*m); m++);
for (; (*m != 0) && isspace(*m); m++);
word++;
m_cnt++;
break;
}
else
@ -503,7 +503,7 @@ evry_fuzzy_match(const char *str, const char *match)
for (; (*p != 0) && isspace(*p); p++);
cnt++;
next = p;
word = 0;
m_cnt = 0;
break;
}
}
@ -530,18 +530,17 @@ evry_fuzzy_match(const char *str, const char *match)
if (*(++m) != 0 && !isspace(*m))
continue;
/* end of match: store min weight of match */
min += (cnt - word) > 0 ? (cnt - word) : 0;
min += (cnt - m_cnt) > 0 ? (cnt - m_cnt) : 0;
if (min < m_min[m_cnt])
m_min[m_cnt] = min;
if (min < word_min[word])
word_min[word] = min;
if (word < words - 1)
if (m_cnt < m_num - 1)
{
/* test next match */
for (; (*m != 0) && isspace(*m); m++);
word++;
m_cnt++;
break;
}
else if(*p != 0)
@ -551,7 +550,7 @@ evry_fuzzy_match(const char *str, const char *match)
for (; (*p != 0) && isspace(*p); p++);
cnt++;
next = p;
word = 0;
m_cnt = 0;
break;
}
else
@ -562,14 +561,14 @@ evry_fuzzy_match(const char *str, const char *match)
}
}
for (word = 0; word < words; word++)
for (m_cnt = 0; m_cnt < m_num; m_cnt++)
{
if (word_min[word] >= MAX_FUZZ)
if (m_min[m_cnt] >= MAX_FUZZ)
{
sum = 0;
break;
}
sum += word_min[word];
sum += m_min[m_cnt];
}
/* if (sum)
* printf("min %d >> %s - %s\n", sum, match, str); */

View File

@ -38,31 +38,28 @@ _item_add(Evry_Plugin *p, const char *directory, const char *file)
static void
_item_fill(Evry_Item *it)
{
const char *mime;
const char *mime, *ext = NULL;
if (it->mime) return;
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(it->uri);
if (!desktop) return;
it->label = eina_stringshare_add(desktop->name);
efreet_desktop_free(desktop);
}
mime = efreet_mime_globs_type_get(it->uri);
if (mime)
{
it->mime = eina_stringshare_add(mime);
}
else if (ecore_file_is_dir(it->uri))
if (ecore_file_is_dir(it->uri))
{
it->mime = eina_stringshare_add("x-directory/normal");
it->browseable = EINA_TRUE;
it->priority = 1;
}
else if ((ext = strrchr(it->label, '.')))
{
if (!strcmp(ext, ".desktop") || !strcmp(ext, ".directory"))
{
Efreet_Desktop *desktop;
desktop = efreet_desktop_new(it->uri);
if (!desktop) return;
it->label = eina_stringshare_add(desktop->name);
it->mime = eina_stringshare_add("None");
efreet_desktop_free(desktop);
return;
}
}
else if ((mime = efreet_mime_type_get(it->uri)))
{

View File

@ -4,7 +4,7 @@
static Evry_View *view = NULL;
static Evas_Object *o_thumb[5];
static Evas_Object *o_main = NULL;
static Eina_List *items = NULL;
static int
_check_item(const Evry_Item *it)
@ -15,7 +15,7 @@ _check_item(const Evry_Item *it)
if (!it->uri || !it->mime) return 0;
if (e_util_glob_case_match(it->mime, "*image/*"))
if (!strncmp(it->mime, "image/", 6))
return 1;
return 0;
@ -84,64 +84,44 @@ _show_item(const Evry_Item *it, int dir)
static int
_cb_key_down(Evry_View *v, const Ecore_Event_Key *ev)
{
Eina_List *l, *ll, *cur_items;
Evry_Item *found = NULL, *it, *cur_item;
Eina_List *l;
Evry_Item *it = NULL, *cur_item;
cur_items = view->state->plugin->items;
cur_item = view->state->sel_item;
if (!strcmp(ev->key, "Down"))
{
l = eina_list_data_find_list(cur_items, cur_item);
if (!items) return 1;
l = eina_list_data_find_list(items, cur_item);
if (l && l->next)
it = l->next->data;
else
it = items->data;
if (it && (it != cur_item))
{
EINA_LIST_FOREACH(l->next, ll, it)
{
if (!_check_item(it)) continue;
found = it;
break;
}
}
if (!found)
{
EINA_LIST_FOREACH(cur_items, ll, it)
{
if (!_check_item(it)) continue;
found = it;
break;
}
}
if (found && (found != cur_item))
{
_show_item(found, 1);
evry_item_select(view->state, found);
_show_item(it, 1);
evry_item_select(view->state, it);
}
return 1;
}
else if (!strcmp(ev->key, "Up"))
{
EINA_LIST_FOREACH(cur_items, ll, it)
{
if (it == cur_item)
break;
if (!items) return 1;
l = eina_list_data_find_list(items, cur_item);
if (_check_item(it))
found = it;
}
if (!found && ll)
if (l && l->prev)
it = l->prev->data;
else
it = eina_list_last(items)->data;
if (it && (it != cur_item))
{
EINA_LIST_FOREACH(ll->next, l, it)
{
if (_check_item(it))
found = it;
}
}
if (found && (found != cur_item))
{
_show_item(found, -1);
evry_item_select(view->state, found);
_show_item(it, -1);
evry_item_select(view->state, it);
}
return 1;
}
@ -149,9 +129,6 @@ _cb_key_down(Evry_View *v, const Ecore_Event_Key *ev)
return 0;
}
static void
_clear(Evry_View *v, const Evry_State *s)
{
@ -181,17 +158,19 @@ _find_first(const Evry_State *s)
if (_check_item(s->sel_item))
return s->sel_item;
eina_list_free(items);
items = NULL;
EINA_LIST_FOREACH(s->plugin->items, l, it)
{
if (!_check_item(it)) continue;
found = it;
break;
if (!found) found = it;
items = eina_list_append(items, it);
}
return found;
}
static int
_update(Evry_View *v, const Evry_State *s)
{
@ -208,7 +187,6 @@ _update(Evry_View *v, const Evry_State *s)
return 1;
}
static Evas_Object *
_begin(Evry_View *v, const Evry_State *s, const Evas_Object *swallow)
{