static int _evry_cb_plugin_sort(const void *data1, const void *data2);
static int _evry_plug_act_select_init(void);
-static int _evry_plug_act_select_actions_set(void);
+static int _evry_plug_act_select_begin(Evry_Plugin *p, Evry_Item *it);
static int _evry_plug_act_select_fetch(Evry_Plugin *p, const char *input);
static int _evry_plug_act_select_action(Evry_Plugin *p, Evry_Item *item, const char *input);
static void _evry_plug_act_select_cleanup(Evry_Plugin *p);
{
if (!p->config->enabled) continue;
- if (strstr(p->type_in, cur_type))
+ if (strstr(p->type_in, cur_type) || p == action_selector)
{
/* printf("%s- in:%s out:%s\n", p->name, p->type_in, p->type_out); */
}
}
- if (s && !s->cur_action)
- {
- if (_evry_plug_act_select_actions_set())
- {
- list = eina_list_append(list, action_selector);
- }
- }
-
if (!list) return 0;
- /* list = eina_list_sort(list, eina_list_count(list), _evry_cb_plugin_sort); */
-
_evry_list_clear();
s = E_NEW(Evry_State, 1);
{
s->request_type = cur_state->request_type;
s->cur_action = cur_state->cur_action;
+ s->cur_actions = cur_state->cur_actions;
s->initial = 0;
}
else
if (s->cur_plugin == action_selector)
{
/* set cur_action and start plugins for second parameter (if required)*/
- if (s->sel_item) _evry_plug_act_select_action(s->cur_plugin, s->sel_item, s->input);
-
- finished = 0;
+ if (s->sel_item)
+ finished = _evry_plug_act_select_action(s->cur_plugin, s->sel_item, s->input);
}
else if (s->cur_action)
{
if (s->sel_item && (!strcmp(s->cur_plugin->type_out, s->request_type)))
{
s->cur_action->thing2 = s->sel_item;
- s->cur_action->action();
+ s->cur_action->action(s->cur_action);
}
}
else if (s->cur_plugin && (s->sel_item || s->input))
/* remove tabs for not active plugins */
EINA_LIST_FOREACH(evry_conf->plugins, l, p)
{
- if (!p->config->enabled) continue;
-
if (p->tab && !eina_list_data_find(s->cur_plugins, p))
{
evas_object_del(p->tab);
p->tab = NULL;
}
}
+
/* show/update tabs of active plugins */
EINA_LIST_FOREACH(s->cur_plugins, l, p)
_evry_plugin_selector_show(p);
{
scroll_align_to = (double)i / (double)(n - 1);
if (evry_conf->scroll_animate)
- {
+ {
if (!scroll_timer)
scroll_timer = ecore_timer_add(0.01, _evry_scroll_timer, NULL);
if (!scroll_animator)
p->tab = o;
}
+
+/* action selector plugin: provides list of actions registered for
+ candidate types provided by current plugin */
static int
_evry_plug_act_select_init(void)
{
+ Plugin_Config *pc;
Evry_Plugin *p = E_NEW(Evry_Plugin, 1);
p->name = "Select Action";
p->type_in = "ANY";
p->type_out = "NONE";
+ p->begin = &_evry_plug_act_select_begin;
p->cleanup = &_evry_plug_act_select_cleanup;
p->fetch = &_evry_plug_act_select_fetch;
p->action = &_evry_plug_act_select_action;
p->icon_get = &_evry_plug_act_select_item_icon_get;
+
+ pc = E_NEW(Plugin_Config, 1);
+ pc->name = eina_stringshare_add(p->name);
+ pc->enabled = 1;
+ pc->priority = 100;
+ p->config = pc;
+
+ evry_conf->plugins = eina_list_append(evry_conf->plugins, p);
action_selector = p;
}
static int
-_evry_plug_act_select_actions_set(void)
+_evry_plug_act_select_begin(Evry_Plugin *p, Evry_Item *it)
{
Evry_Action *act;
Eina_List *l;
Evry_State *s = cur_state;
- Evry_Plugin *p = action_selector;
_evry_plug_act_select_cleanup(p);
+ if (!s || !s->cur_plugin || s->cur_action) return 0;
+
const char *type = s->cur_plugin->type_out;
EINA_LIST_FOREACH(actions, l, act)
{
- if (strstr(act->type_in1, type))
+ if ((strstr(act->type_in1, type)) &&
+ (!act->check_item || act->check_item(act, s->sel_item)))
{
act->thing1 = s->sel_item;
s->cur_actions = eina_list_append(s->cur_actions, act);
{
Evry_Action *act;
Eina_List *l;
-
+ Evry_State *s = cur_state;
+
if (p->items) return 1;
- EINA_LIST_FOREACH(actions, l, act)
+ EINA_LIST_FOREACH(s->cur_actions, l, act)
{
Evry_Item *it;
{
Evry_Action *act = it->data[0];
cur_state->cur_action = act;
-
- cur_state->request_type = act->type_in2;
-
- return _evry_push_state();
+ if (strcmp(act->type_in2, "NONE"))
+ {
+ /* XXX hackish - param for push? */
+ cur_state->request_type = act->type_in2;
+ _evry_push_state();
+
+ return 0;
+ }
+ else
+ {
+ act->action(act);
+ return 1;
+ }
}
static void
{
Evry_Item *it;
+ if (!cur_state) return;
+
EINA_LIST_FREE(p->items, it)
{
eina_stringshare_del(it->label);
cur_state->cur_actions = NULL;
p->items = NULL;
-
- if (p->tab)
- {
- evas_object_del(p->tab);
- p->tab = NULL;
- }
}
static void
static void _item_add(Evry_Plugin *p, Efreet_Desktop *desktop, char *file, int prio);
static int _cb_sort(const void *data1, const void *data2);
static void _item_icon_get(Evry_Plugin *p, Evry_Item *it, Evas *e);
-static int _exec_action(void);
+static int _exec_app_action(Evry_Action *act);
+static int _edit_app_action(Evry_Action *act);
+static int _edit_app_check_item(Evry_Action *act, Evry_Item *it);
+static int _new_app_action(Evry_Action *act);
static Evry_Plugin *p1;
static Evry_Plugin *p2;
static Evry_Action *act;
+static Evry_Action *act2;
+static Evry_Action *act3;
static Inst *inst;
act->type_in1 = "APPLICATION";
act->type_in2 = "FILE";
act->type_out = "NONE";
- act->action = &_exec_action;
+ act->action = &_exec_app_action;
evry_action_register(act);
+ act2 = E_NEW(Evry_Action, 1);
+ act2->name = "Edit Application Entry";
+ act2->type_in1 = "APPLICATION";
+ act2->type_in2 = "NONE";
+ act2->type_out = "NONE";
+ act2->action = &_edit_app_action;
+ act2->check_item = &_edit_app_check_item;
+ evry_action_register(act2);
+
+ act3 = E_NEW(Evry_Action, 1);
+ act3->name = "New Application Entry";
+ act3->type_in1 = "APPLICATION";
+ act3->type_in2 = "NONE";
+ act3->type_out = "NONE";
+ act3->action = &_new_app_action;
+ evry_action_register(act3);
+
inst = NULL;
return 1;
evry_plugin_unregister(p1);
evry_plugin_unregister(p2);
evry_action_unregister(act);
+ evry_action_unregister(act2);
+ evry_action_unregister(act3);
return 1;
}
if (desktop)
{
- if (inst->candidate)
+ if (inst && inst->candidate)
files = eina_list_append(files, inst->candidate->uri);
zone = e_util_zone_current_get(e_manager_current_get());
e_exec(zone, desktop, NULL, files, "everything");
- if (inst->candidate && inst->candidate->mime)
+ if (inst && inst->candidate && inst->candidate->mime)
e_exehist_mime_desktop_add(inst->candidate->mime, desktop);
if (!it)
char *file;
char match1[4096];
char match2[4096];
-
+ Evry_Item *it;
+ Evry_App *app;
+
_list_free(p);
- if (inst->apps)
+ if (inst && inst->apps)
{
if (!input)
{
inst->added = NULL;
}
- if (p->items)
+ it = E_NEW(Evry_Item, 1);
+ app = E_NEW(Evry_App, 1);
+ app->file = eina_stringshare_add(input);
+ app->desktop = NULL;
+ it->data[0] = app;
+ it->priority = 100;
+ it->label = eina_stringshare_add("Run Command");
+ p->items = eina_list_append(p->items, it);
+
+ if (p->items)
{
- /* if (input) */
p->items = eina_list_sort(p->items, eina_list_count(p->items), _cb_sort);
return 1;
}
}
static int
-_exec_action()
+_exec_app_action(Evry_Action *act)
{
if (act->thing1 && act->thing2)
{
- inst = E_NEW(Inst, 1);
- inst->candidate = act->thing2;
+ E_Zone *zone;
+ Evry_App *app = NULL;
+ Efreet_Desktop *desktop = NULL;
+ Eina_List *files = NULL;
- _action(NULL, act->thing1, NULL);
+ app = act->thing1->data[0];
- E_FREE(inst);
- inst = NULL;
+ if (app->desktop)
+ desktop = app->desktop;
+ else
+ {
+ desktop = efreet_desktop_empty_new("");
+ if (strchr(app->file, '%'))
+ desktop->exec = strdup(app->file);
+ else
+ {
+ int len = strlen(app->file) + 4;
+ desktop->exec = malloc(len);
+ if (desktop->exec)
+ snprintf(desktop->exec, len, "%s %%U", app->file);
+ }
+ }
+
+ if (desktop)
+ {
+ files = eina_list_append(files, act->thing2->uri);
+
+ zone = e_util_zone_current_get(e_manager_current_get());
+
+ e_exec(zone, desktop, NULL, files, "everything");
+
+ if (act->thing2->mime)
+ e_exehist_mime_desktop_add(act->thing2->mime, desktop);
+
+ if (!app->desktop)
+ efreet_desktop_free(desktop);
+
+ eina_list_free(files);
+
+ return EVRY_ACTION_FINISHED;
+ }
+
+ return EVRY_ACTION_CONTINUE;
+ }
+
+ return 0;
+}
+
+static int
+_edit_app_check_item(Evry_Action *act, Evry_Item *it)
+{
+ Evry_App *app = it->data[0];
+ if (app->desktop)
+ return 1;
+
+ return 0;
+}
+
+static int
+_edit_app_action(Evry_Action *act)
+{
+ if (act->thing1)
+ {
+ Evry_Item *it = act->thing1;
+ Evry_App *app = it->data[0];
+
+ Efreet_Desktop *desktop;
+
+ if (app->desktop)
+ desktop = app->desktop;
+ else
+ {
+ char buf[128];
+ snprintf(buf, 128, "%s/.local/share/applications/%s.desktop", e_user_homedir_get(), app->file);
+
+ desktop = efreet_desktop_empty_new(eina_stringshare_add(buf));
+ /* XXX check if this is freed */
+ desktop->exec = strdup(app->file);
+ }
+
+ e_desktop_edit(e_container_current_get(e_manager_current_get()), desktop);
+
return 1;
}
+
+ return 0;
+}
+
+static int
+_new_app_action(Evry_Action *act)
+{
+ if (act->thing1)
+ {
+ Evry_Item *it = act->thing1;
+ Evry_App *app = it->data[0];
+ char *name;
+ char buf[4096];
+ char *end;
+ Efreet_Desktop *desktop;
+ int i;
+
+ if (app->desktop)
+ name = strdup(app->desktop->name);
+ else
+ /* TODO replace '/' and remove other special characters */
+ name = strdup(app->file);
+
+ if ((end = strchr(name, ' ')))
+ name[end - name] = '\0';
+
+ for (i = 0; i < 10; i++)
+ {
+ snprintf(buf, 4096, "%s/.local/share/applications/%s-%d.desktop", e_user_homedir_get(), name, i);
+ if (ecore_file_exists(buf))
+ {
+ buf[0] = '\0';
+ continue;
+ }
+ else break;
+ }
+
+ free(name);
+
+ if (strlen(buf) == 0)
+ return 0;
+
+ if (!app->desktop)
+ {
+ desktop = efreet_desktop_empty_new(buf);
+ desktop->exec = strdup(app->file);
+ }
+ else
+ {
+ efreet_desktop_save_as(app->desktop, buf);
+ /*XXX hackish - desktop is removed on save_as..*/
+ efreet_desktop_new(app->desktop->orig_path);
+
+ desktop = efreet_desktop_new(buf);
+ }
+
+ e_desktop_edit(e_container_current_get(e_manager_current_get()), desktop);
+
+ return 1;
+ }
+
return 0;
}
+
+