'everything' apps: use own history for sorting apps

SVN revision: 47873
This commit is contained in:
Hannes Janetzek 2010-04-09 14:41:37 +00:00
parent 68dbfe61e6
commit 83c17e9f4c
3 changed files with 53 additions and 48 deletions

View File

@ -153,7 +153,7 @@ void evry_history_free(void);
EAPI void evry_history_load(void); EAPI void evry_history_load(void);
EAPI void evry_history_unload(void); EAPI void evry_history_unload(void);
EAPI void evry_history_add(Eina_Hash *hist, Evry_State *s, const char *ctxt); EAPI void evry_history_add(Eina_Hash *hist, Evry_State *s, const char *ctxt);
int evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, const char *ctxt); EAPI int evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, const char *ctxt);
EAPI int evry_browse_item(Evry_Selector *sel); EAPI int evry_browse_item(Evry_Selector *sel);
void evry_browse_back(Evry_Selector *sel); void evry_browse_back(Evry_Selector *sel);

View File

@ -256,7 +256,7 @@ evry_history_add(Eina_Hash *hist, Evry_State *s, const char *ctxt)
} }
} }
int EAPI int
evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, const char *ctxt) evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, const char *ctxt)
{ {
History_Entry *he; History_Entry *he;

View File

@ -49,7 +49,6 @@ static int _scan_idler(void *data);
static void _hash_free(void *data) static void _hash_free(void *data)
{ {
ITEM_APP(app, data); ITEM_APP(app, data);
evry_item_free(EVRY_ITEM(app)); evry_item_free(EVRY_ITEM(app));
} }
@ -64,7 +63,7 @@ _begin_open_with(Evry_Plugin *plugin, const Evry_Item *item)
if (!item) return 0; if (!item) return 0;
ITEM_FILE(file, item); ITEM_FILE(file, item);
Efreet_Desktop *desktop; Efreet_Desktop *d, *d2;
if (!file->path) return NULL; if (!file->path) return NULL;
@ -85,18 +84,26 @@ _begin_open_with(Evry_Plugin *plugin, const Evry_Item *item)
Eina_List *tmp; Eina_List *tmp;
tmp = efreet_util_desktop_mime_list("text/plain"); tmp = efreet_util_desktop_mime_list("text/plain");
EINA_LIST_FREE(tmp, desktop) EINA_LIST_FREE(tmp, d)
{ {
if (!eina_list_data_find_list(p->apps_mime, desktop)) if (!eina_list_data_find_list(p->apps_mime, d))
p->apps_mime = eina_list_append(p->apps_mime, desktop); p->apps_mime = eina_list_append(p->apps_mime, d);
else else
efreet_desktop_free(desktop); efreet_desktop_free(d);
} }
} }
desktop = e_exehist_mime_desktop_get(mime); d = e_exehist_mime_desktop_get(mime);
if (desktop) if (d)
p->apps_mime = eina_list_prepend(p->apps_mime, desktop); {
if (d2 = eina_list_data_find(p->apps_mime, d))
{
p->apps_mime = eina_list_remove(p->apps_mime, d2);
efreet_desktop_free(d2);
}
p->apps_mime = eina_list_prepend(p->apps_mime, d);
}
p->added = eina_hash_string_small_new(_hash_free); p->added = eina_hash_string_small_new(_hash_free);
@ -357,41 +364,27 @@ _cb_sort(const void *data1, const void *data2)
{ {
const Evry_Item *it1 = data1; const Evry_Item *it1 = data1;
const Evry_Item *it2 = data2; const Evry_Item *it2 = data2;
const char *e1, *e2;
double t1, t2;
ITEM_APP(app1, it1); if (it1->usage && it2->usage)
ITEM_APP(app2, it2); return (it1->usage > it2->usage ? -1 : 1);
if (it1->usage && !it2->usage)
if (app1->desktop) return -1;
e1 = app1->desktop->exec; if (it2->usage && !it1->usage)
else return 1;
e1 = app1->file;
if (app2->desktop)
e2 = app2->desktop->exec;
else
e2 = app2->file;
t1 = e_exehist_newest_run_get(e1);
t2 = e_exehist_newest_run_get(e2);
if (it1->fuzzy_match || it2->fuzzy_match)
{
if (it1->fuzzy_match && !it2->fuzzy_match) if (it1->fuzzy_match && !it2->fuzzy_match)
return -1; return -1;
if (!it1->fuzzy_match && it2->fuzzy_match) if (!it1->fuzzy_match && it2->fuzzy_match)
return 1; return 1;
t1 = t1 / (double)it1->fuzzy_match;
t2 = t2 / (double)it2->fuzzy_match;
if ((int)(t2 - t1))
return (int)(t2 - t1);
if (it1->fuzzy_match - it2->fuzzy_match) if (it1->fuzzy_match - it2->fuzzy_match)
return (it1->fuzzy_match - it2->fuzzy_match); return (it1->fuzzy_match - it2->fuzzy_match);
}
else return 0; return 0;
} }
static Eina_Bool static Eina_Bool
@ -421,8 +414,12 @@ _hist_items_add_cb(const Eina_Hash *hash, const void *key, void *data, void *fda
} }
if (app && app->desktop) if (app && app->desktop)
{
p->apps_hist = eina_list_append(p->apps_hist, app->desktop); p->apps_hist = eina_list_append(p->apps_hist, app->desktop);
} }
if (app) break;
}
return EINA_TRUE; return EINA_TRUE;
} }
@ -511,12 +508,20 @@ _fetch(Evry_Plugin *plugin, const char *input)
if (!plugin->items) return 0; if (!plugin->items) return 0;
if (plugin->type == type_action)
{
EINA_LIST_FOREACH(plugin->items, l, it)
evry_history_item_usage_set(evry_hist->actions, it, input, NULL);
}
else
{
EINA_LIST_FOREACH(plugin->items, l, it)
evry_history_item_usage_set(evry_hist->subjects, it, input, NULL);
}
if (plugin->type != type_action || input) if (plugin->type != type_action || input)
EVRY_PLUGIN_ITEMS_SORT(plugin, _cb_sort); EVRY_PLUGIN_ITEMS_SORT(plugin, _cb_sort);
EINA_LIST_FOREACH(plugin->items, l, it)
it->priority = prio++;
return 1; return 1;
} }