'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:
parent
1fcfea9a30
commit
70af748fa7
|
@ -11,7 +11,7 @@
|
||||||
#define INPUTLEN 40
|
#define INPUTLEN 40
|
||||||
#define MATCH_LAG 0.33
|
#define MATCH_LAG 0.33
|
||||||
#define MAX_FUZZ 150
|
#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;
|
unsigned int cnt = 0;
|
||||||
/* words in match */
|
/* words in match */
|
||||||
unsigned int words = 1;
|
unsigned int m_num = 1;
|
||||||
unsigned int word = 0;
|
unsigned int m_cnt = 0;
|
||||||
unsigned int word_min[MAX_WORDS];
|
unsigned int m_min[MAX_WORDS];
|
||||||
|
|
||||||
if (!match || !str) return 0;
|
if (!match || !str) return 0;
|
||||||
|
|
||||||
|
@ -462,18 +462,18 @@ evry_fuzzy_match(const char *str, const char *match)
|
||||||
for (; (*str != 0) && isspace(*str); str++);
|
for (; (*str != 0) && isspace(*str); str++);
|
||||||
|
|
||||||
/* count words in match */
|
/* count words in match */
|
||||||
word_min[0] = MAX_FUZZ;
|
m_min[0] = MAX_FUZZ;
|
||||||
for (m = match; (*m != 0) && (*(m+1) != 0) && (words < MAX_WORDS); m++)
|
for (m = match; (*m != 0) && (*(m+1) != 0) && (m_num < MAX_WORDS); m++)
|
||||||
if (isspace(*m) && !isspace(*(m+1)))
|
if (isspace(*m) && !isspace(*(m+1)))
|
||||||
word_min[words++] = MAX_FUZZ;
|
m_min[m_num++] = MAX_FUZZ;
|
||||||
|
|
||||||
next = str;
|
next = str;
|
||||||
m = match;
|
m = match;
|
||||||
|
|
||||||
for (; (word < words) && (*next != 0);)
|
for (; (m_cnt < m_num) && (*next != 0);)
|
||||||
{
|
{
|
||||||
/* reset match */
|
/* reset match */
|
||||||
if (word == 0) m = match;
|
if (m_cnt == 0) m = match;
|
||||||
|
|
||||||
/* end of matching */
|
/* end of matching */
|
||||||
if (*m == 0) break;
|
if (*m == 0) break;
|
||||||
|
@ -489,12 +489,12 @@ evry_fuzzy_match(const char *str, const char *match)
|
||||||
/* new word of string begins */
|
/* new word of string begins */
|
||||||
if ((*p == 0) || isspace(*p))
|
if ((*p == 0) || isspace(*p))
|
||||||
{
|
{
|
||||||
if (word < words - 1)
|
if (m_cnt < m_num - 1)
|
||||||
{
|
{
|
||||||
/* test next match */
|
/* test next match */
|
||||||
for (; (*m != 0) && !isspace(*m); m++);
|
for (; (*m != 0) && !isspace(*m); m++);
|
||||||
for (; (*m != 0) && isspace(*m); m++);
|
for (; (*m != 0) && isspace(*m); m++);
|
||||||
word++;
|
m_cnt++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -503,7 +503,7 @@ evry_fuzzy_match(const char *str, const char *match)
|
||||||
for (; (*p != 0) && isspace(*p); p++);
|
for (; (*p != 0) && isspace(*p); p++);
|
||||||
cnt++;
|
cnt++;
|
||||||
next = p;
|
next = p;
|
||||||
word = 0;
|
m_cnt = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,18 +530,17 @@ evry_fuzzy_match(const char *str, const char *match)
|
||||||
if (*(++m) != 0 && !isspace(*m))
|
if (*(++m) != 0 && !isspace(*m))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
/* end of match: store min weight of match */
|
/* 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])
|
if (m_cnt < m_num - 1)
|
||||||
word_min[word] = min;
|
|
||||||
|
|
||||||
if (word < words - 1)
|
|
||||||
{
|
{
|
||||||
/* test next match */
|
/* test next match */
|
||||||
for (; (*m != 0) && isspace(*m); m++);
|
for (; (*m != 0) && isspace(*m); m++);
|
||||||
word++;
|
m_cnt++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(*p != 0)
|
else if(*p != 0)
|
||||||
|
@ -551,7 +550,7 @@ evry_fuzzy_match(const char *str, const char *match)
|
||||||
for (; (*p != 0) && isspace(*p); p++);
|
for (; (*p != 0) && isspace(*p); p++);
|
||||||
cnt++;
|
cnt++;
|
||||||
next = p;
|
next = p;
|
||||||
word = 0;
|
m_cnt = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
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;
|
sum = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sum += word_min[word];
|
sum += m_min[m_cnt];
|
||||||
}
|
}
|
||||||
/* if (sum)
|
/* if (sum)
|
||||||
* printf("min %d >> %s - %s\n", sum, match, str); */
|
* printf("min %d >> %s - %s\n", sum, match, str); */
|
||||||
|
|
|
@ -38,31 +38,28 @@ _item_add(Evry_Plugin *p, const char *directory, const char *file)
|
||||||
static void
|
static void
|
||||||
_item_fill(Evry_Item *it)
|
_item_fill(Evry_Item *it)
|
||||||
{
|
{
|
||||||
const char *mime;
|
const char *mime, *ext = NULL;
|
||||||
|
|
||||||
|
if (it->mime) return;
|
||||||
|
|
||||||
if (it->mime) return;
|
if (ecore_file_is_dir(it->uri))
|
||||||
|
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
it->mime = eina_stringshare_add("x-directory/normal");
|
it->mime = eina_stringshare_add("x-directory/normal");
|
||||||
it->browseable = EINA_TRUE;
|
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)))
|
else if ((mime = efreet_mime_type_get(it->uri)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
static Evry_View *view = NULL;
|
static Evry_View *view = NULL;
|
||||||
static Evas_Object *o_thumb[5];
|
static Evas_Object *o_thumb[5];
|
||||||
static Evas_Object *o_main = NULL;
|
static Evas_Object *o_main = NULL;
|
||||||
|
static Eina_List *items = NULL;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_check_item(const Evry_Item *it)
|
_check_item(const Evry_Item *it)
|
||||||
|
@ -15,7 +15,7 @@ _check_item(const Evry_Item *it)
|
||||||
|
|
||||||
if (!it->uri || !it->mime) return 0;
|
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 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -84,64 +84,44 @@ _show_item(const Evry_Item *it, int dir)
|
||||||
static int
|
static int
|
||||||
_cb_key_down(Evry_View *v, const Ecore_Event_Key *ev)
|
_cb_key_down(Evry_View *v, const Ecore_Event_Key *ev)
|
||||||
{
|
{
|
||||||
Eina_List *l, *ll, *cur_items;
|
Eina_List *l;
|
||||||
Evry_Item *found = NULL, *it, *cur_item;
|
Evry_Item *it = NULL, *cur_item;
|
||||||
|
|
||||||
cur_items = view->state->plugin->items;
|
|
||||||
cur_item = view->state->sel_item;
|
cur_item = view->state->sel_item;
|
||||||
|
|
||||||
if (!strcmp(ev->key, "Down"))
|
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)
|
if (l && l->next)
|
||||||
|
it = l->next->data;
|
||||||
|
else
|
||||||
|
it = items->data;
|
||||||
|
|
||||||
|
if (it && (it != cur_item))
|
||||||
{
|
{
|
||||||
EINA_LIST_FOREACH(l->next, ll, it)
|
_show_item(it, 1);
|
||||||
{
|
evry_item_select(view->state, 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);
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (!strcmp(ev->key, "Up"))
|
else if (!strcmp(ev->key, "Up"))
|
||||||
{
|
{
|
||||||
EINA_LIST_FOREACH(cur_items, ll, it)
|
if (!items) return 1;
|
||||||
{
|
|
||||||
if (it == cur_item)
|
l = eina_list_data_find_list(items, cur_item);
|
||||||
break;
|
|
||||||
|
|
||||||
if (_check_item(it))
|
if (l && l->prev)
|
||||||
found = it;
|
it = l->prev->data;
|
||||||
}
|
else
|
||||||
if (!found && ll)
|
it = eina_list_last(items)->data;
|
||||||
|
|
||||||
|
if (it && (it != cur_item))
|
||||||
{
|
{
|
||||||
EINA_LIST_FOREACH(ll->next, l, it)
|
_show_item(it, -1);
|
||||||
{
|
evry_item_select(view->state, it);
|
||||||
if (_check_item(it))
|
|
||||||
found = it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found && (found != cur_item))
|
|
||||||
{
|
|
||||||
_show_item(found, -1);
|
|
||||||
evry_item_select(view->state, found);
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -149,9 +129,6 @@ _cb_key_down(Evry_View *v, const Ecore_Event_Key *ev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_clear(Evry_View *v, const Evry_State *s)
|
_clear(Evry_View *v, const Evry_State *s)
|
||||||
{
|
{
|
||||||
|
@ -181,17 +158,19 @@ _find_first(const Evry_State *s)
|
||||||
if (_check_item(s->sel_item))
|
if (_check_item(s->sel_item))
|
||||||
return s->sel_item;
|
return s->sel_item;
|
||||||
|
|
||||||
|
eina_list_free(items);
|
||||||
|
items = NULL;
|
||||||
|
|
||||||
EINA_LIST_FOREACH(s->plugin->items, l, it)
|
EINA_LIST_FOREACH(s->plugin->items, l, it)
|
||||||
{
|
{
|
||||||
if (!_check_item(it)) continue;
|
if (!_check_item(it)) continue;
|
||||||
found = it;
|
if (!found) found = it;
|
||||||
break;
|
items = eina_list_append(items, it);
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_update(Evry_View *v, const Evry_State *s)
|
_update(Evry_View *v, const Evry_State *s)
|
||||||
{
|
{
|
||||||
|
@ -208,7 +187,6 @@ _update(Evry_View *v, const Evry_State *s)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Evas_Object *
|
static Evas_Object *
|
||||||
_begin(Evry_View *v, const Evry_State *s, const Evas_Object *swallow)
|
_begin(Evry_View *v, const Evry_State *s, const Evas_Object *swallow)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue