'everything'
authorHannes Janetzek <hannes.janetzek@gmail.com>
Sun, 4 Apr 2010 14:11:35 +0000 (14:11 +0000)
committerHannes Janetzek <hannes.janetzek@gmail.com>
Sun, 4 Apr 2010 14:11:35 +0000 (14:11 +0000)
- make upadte of action selector async
- added action selector as subjects plugin for actions without object like restart, shutdown, etc

SVN revision: 47748

src/modules/everything/Evry.h
src/modules/everything/e_mod_main.h
src/modules/everything/evry.c
src/modules/everything/evry_plug_actions.c
src/modules/everything/evry_plug_aggregator.c
src/modules/everything/sources/evry_plug_border.c

index 256f9fd..cf6e13c 100644 (file)
@@ -240,13 +240,14 @@ struct _Evry_Action
   int  (*check_item) (Evry_Action *act, const Evry_Item *it);
   int  (*intercept)  (Evry_Action *act);
   void (*cleanup)    (Evry_Action *act);
+  Eina_List *(*actions)    (Evry_Action *act);
   Evas_Object *(*icon_get) (Evry_Action *act, Evas *e);
 
   /* use icon name from theme */
   const char *icon;
 
   void *data;
-  
+
   int priority;
 };
 
index 81a07ca..8955641 100644 (file)
@@ -93,8 +93,10 @@ struct _Evry_Selector
   /* provides collection of items from other plugins */
   Evry_Plugin *aggregator;
 
+  Evry_Plugin *actions;
+
   /* */
-  Eina_List   *actions;
+  Eina_List   *cur_actions;
 
   /* all plugins that belong to this selector*/
   Eina_List   *plugins;
@@ -105,6 +107,8 @@ struct _Evry_Selector
   Eina_Bool    do_thumb;
 
   Eina_Hash   *history;
+
+  Ecore_Timer *update_timer;
 };
 
 struct _Tab_View
@@ -141,7 +145,7 @@ void evry_hide(void);
 EAPI Evry_Plugin *evry_plug_aggregator_new(Evry_Selector *selector);
 EAPI void evry_plug_aggregator_free(Evry_Plugin *plugin);
 
-EAPI Evry_Plugin *evry_plug_actions_new(void);
+EAPI Evry_Plugin *evry_plug_actions_new(int type);
 EAPI void evry_plug_actions_free(Evry_Plugin *plugin);
 
 void evry_history_init(void);
@@ -157,5 +161,5 @@ void evry_browse_back(Evry_Selector *sel);
 EAPI extern Config *evry_conf;
 EAPI extern History *evry_hist;
 extern Evry_Selector **selectors;
-extern Evry_Plugin *action_selector;
+extern const char *action_selector;
 #endif
index 573c672..4418c23 100644 (file)
@@ -38,11 +38,11 @@ static void _evry_matches_update(Evry_Selector *sel, int async);
 static void _evry_plugin_action(Evry_Selector *sel, int finished);
 static void _evry_plugin_select(Evry_State *s, Evry_Plugin *p);
 static void _evry_plugin_list_insert(Evry_State *s, Evry_Plugin *p);
-static int  _evry_backspace(Evry_State *s);
-static void _evry_update(Evry_State *s, int fetch);
+static int  _evry_backspace(Evry_Selector *sel);
+static void _evry_update(Evry_Selector *sel, int fetch);
 static void _evry_update_text_label(Evry_State *s);
-static int  _evry_clear(Evry_State *s);
-static int  _evry_update_timer(void *data);
+static int  _evry_clear(Evry_Selector *sel);
+static int  _evry_cb_update_timer(void *data);
 
 static Evry_State *_evry_state_new(Evry_Selector *sel, Eina_List *plugins);
 static void _evry_state_pop(Evry_Selector *sel);
@@ -84,19 +84,18 @@ static Evry_Window *win = NULL;
 static Evry_List_Window *list = NULL;
 static Ecore_X_Window input_window = 0;
 static Eina_List   *handlers = NULL;
-static Ecore_Timer *update_timer = NULL;
 
 static Evry_Selector *selector = NULL;
 static const char *thumb_types = NULL;
 
 Evry_Selector **selectors;
-Evry_Plugin *action_selector;
+const char *action_selector;
 
 /* externally accessible functions */
 int
 evry_init(void)
 {
-   action_selector = evry_plug_actions_new();
+   action_selector = eina_stringshare_add(_("Select Action"));
    thumb_types = eina_stringshare_add("FILE");
    return 1;
 }
@@ -106,8 +105,8 @@ evry_shutdown(void)
 {
    evry_hide();
 
-   evry_plug_actions_free(action_selector);
    eina_stringshare_del(thumb_types);
+   eina_stringshare_del(action_selector);
    return 1;
 }
 
@@ -147,7 +146,8 @@ evry_show(E_Zone *zone, const char *params)
    _evry_selector_subjects_get(params);
    _evry_selector_activate(selectors[0]);
 
-   update_timer = ecore_timer_add(INITIAL_MATCH_LAG, _evry_update_timer, NULL);
+   selectors[0]->update_timer =
+     ecore_timer_add(INITIAL_MATCH_LAG, _evry_cb_update_timer, selectors[0]);
    
    if (evry_conf->views && selector->state)
      {
@@ -216,10 +216,6 @@ evry_hide(void)
 
    _evry_view_clear(selector->state);
 
-   if (update_timer)
-     ecore_timer_del(update_timer);
-   update_timer = NULL;
-
    list->visible = EINA_FALSE;
    _evry_selector_free(selectors[0]);
    _evry_selector_free(selectors[1]);
@@ -660,14 +656,15 @@ _evry_selector_new(int type)
    if (type == type_subject)
      {
        sel->history = evry_hist->subjects;
+       sel->actions = evry_plug_actions_new(type_subject);
        edje_object_part_swallow(win->o_main, "e.swallow.subject_selector", o);
      }
    else if (type == type_action)
      {
        sel->history = evry_hist->actions;
+       sel->actions = evry_plug_actions_new(type_action);
        edje_object_part_swallow(win->o_main, "e.swallow.action_selector", o);
-     }
-   
+     }   
    else if (type == type_object)
      {
        sel->history = evry_hist->subjects;
@@ -709,8 +706,14 @@ _evry_selector_free(Evry_Selector *sel)
 
    evry_plug_aggregator_free(sel->aggregator);
 
+   if (sel->actions)
+     evry_plug_actions_free(sel->actions);   
+
    if (sel->plugins) eina_list_free(sel->plugins);
 
+   if (sel->update_timer)
+     ecore_timer_del(sel->update_timer);
+   
    E_FREE(sel);
 }
 
@@ -853,6 +856,31 @@ _evry_selector_icon_set(Evry_Selector *sel)
      }
 }
 
+static int
+_evry_timer_cb_actions_get(void *data)
+{
+   Evry_Item *it = data;
+   Evry_Selector *sel = selectors[1];
+   Evry_State *s;
+
+   sel->update_timer = NULL;
+   
+   _evry_selector_actions_get(it);
+   _evry_selector_update(sel);
+
+   if (selector == sel && selector->state)
+     {
+       s = sel->state;
+       if (s->view)
+         s->view->update(s->view);
+       else
+         _evry_view_update(s, NULL); 
+     }
+
+   return 0;
+}
+
+
 static void
 _evry_selector_update(Evry_Selector *sel)
 {
@@ -905,17 +933,10 @@ _evry_selector_update(Evry_Selector *sel)
 
    if (sel == selectors[0])
      {
-       _evry_selector_actions_get(it);
-       _evry_selector_update(selectors[1]);
-
-       if (selector == selectors[1] && selector->state)
-         {
-            s = selector->state;
-            if (s->view)
-              s->view->update(s->view);
-            else
-              _evry_view_update(s, NULL); 
-         }
+       sel = selectors[1];
+       if (sel->update_timer)
+         ecore_timer_del(sel->update_timer);
+       sel->update_timer = ecore_timer_add(0.1, _evry_timer_cb_actions_get, it);
      }
 }
 
@@ -974,8 +995,8 @@ _evry_selector_actions_get(Evry_Item *it)
 
    EINA_LIST_FOREACH(sel->plugins, l, plugin)
      {
-       if ((plugin == action_selector) || (plugin == sel->aggregator) ||
-           (plugin->type_in &&  type_out && plugin->type_in == type_out))
+       if ((plugin == sel->actions) || (plugin == sel->aggregator) ||
+           (plugin->type_in && type_out && plugin->type_in == type_out))
          {
             if (plugin->begin)
               {
@@ -1175,7 +1196,7 @@ _evry_selectors_switch(void)
 {
    Evry_State *s = selector->state;
 
-   if (update_timer)
+   if (selector->update_timer)
      {
        if ((selector == selectors[0]) ||
            (selector == selectors[1]))
@@ -1184,8 +1205,8 @@ _evry_selectors_switch(void)
             _evry_selector_update(selector);
          }
 
-       ecore_timer_del(update_timer);
-       update_timer = NULL;
+       /* ecore_timer_del(update_timer);
+        * update_timer = NULL; */
      }
 
    if (selector == selectors[0])
@@ -1199,7 +1220,7 @@ _evry_selectors_switch(void)
        Evry_Action *act;
 
        if ((s->cur_item) &&
-           (s->cur_item->plugin == action_selector) &&
+           (s->cur_item->plugin == selector->actions) &&
            (act = s->cur_item->data) &&
            (act->type_in2))
          {
@@ -1272,7 +1293,7 @@ _evry_cb_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
      {
        if (!strcmp(key, "u"))
          {
-            if (!_evry_clear(s))
+            if (!_evry_clear(selector))
               evry_browse_back(selector);
          }
        else if (!strcmp(key, "1"))
@@ -1307,11 +1328,11 @@ _evry_cb_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
      _evry_selectors_switch();
    else if (!strcmp(key, "BackSpace"))
      {
-       if (!_evry_backspace(s))
+       if (!_evry_backspace(selector))
          evry_browse_back(selector);
      }
    else if (!strcmp(key, "Delete"))
-     _evry_backspace(s);
+     _evry_backspace(selector);
    else if (_evry_view_key_press(s, ev))
      goto end;
    else if ((ev->compose && !(ev->modifiers & ECORE_EVENT_MODIFIER_ALT)))
@@ -1327,15 +1348,15 @@ _evry_cb_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
                 (_evry_view_toggle(s, s->input + 1)))
               {
                  /* space at the beginning is trigger */
-                 _evry_update(s, 0);
+                 _evry_update(selector, 0);
               }
             else if (isspace(*ev->compose))
               {
                  /* do not update matches on space */
-                 _evry_update(s, 0);
+                 _evry_update(selector, 0);
               }
             else
-              _evry_update(s, 1);
+              _evry_update(selector, 1);
          }
      }
 
@@ -1346,8 +1367,9 @@ _evry_cb_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
 }
 
 static int
-_evry_backspace(Evry_State *s)
+_evry_backspace(Evry_Selector *sel)
 {
+   Evry_State *s = sel->state;
    int len, val, pos;
 
    len = strlen(s->input);
@@ -1361,7 +1383,7 @@ _evry_backspace(Evry_State *s)
             s->input[pos] = 0;
 
             if ((pos == 0) || !isspace(val))
-              _evry_update(s, 1);
+              _evry_update(sel, 1);
 
             return 1;
          }
@@ -1387,14 +1409,18 @@ _evry_update_text_label(Evry_State *s)
 }
 
 static void
-_evry_update(Evry_State *s, int fetch)
+_evry_update(Evry_Selector *sel, int fetch)
 {
+   Evry_State *s = sel->state;
+     
    _evry_update_text_label(s);
 
    if (fetch)
      {
-       if (update_timer) ecore_timer_del(update_timer);
-       update_timer = ecore_timer_add(MATCH_LAG, _evry_update_timer, s);
+       if (sel->update_timer)
+         ecore_timer_del(sel->update_timer);
+
+       sel->update_timer = ecore_timer_add(MATCH_LAG, _evry_cb_update_timer, sel);
 
        if (s->plugin && !s->plugin->trigger)
          edje_object_signal_emit(list->o_main, "e,signal,update", "e");
@@ -1402,30 +1428,35 @@ _evry_update(Evry_State *s, int fetch)
 }
 
 static int
-_evry_update_timer(void *data)
+_evry_cb_update_timer(void *data)
 {
-   _evry_matches_update(selector, 1);
-   _evry_selector_update(selector);
-   _evry_list_win_update(selector->state);
-   update_timer = NULL;
+   Evry_Selector *sel = data;
+     
+   _evry_matches_update(sel, 1);
+   _evry_selector_update(sel);
+   _evry_list_win_update(sel->state);
+   sel->update_timer = NULL;
 
    return 0;
 }
 
 static int
-_evry_clear(Evry_State *s)
+_evry_clear(Evry_Selector *sel)
 {
+   Evry_State *s = sel->state;
+   
    if ((s->plugin && s->plugin->trigger && s->input) &&
-       (!strncmp(s->plugin->trigger, s->input, strlen(s->plugin->trigger))))
+       (!strncmp(s->plugin->trigger, s->input,
+                strlen(s->plugin->trigger))))
      {
        s->input[strlen(s->plugin->trigger)] = 0;
-       _evry_update(s, 1);
+       _evry_update(sel, 1);
        return 1;
      }
    else if (s->input && s->input[0] != 0)
      {
        s->input[0] = 0;
-       _evry_update(s, 1);
+       _evry_update(sel, 1);
        if (!list->visible && evry_conf->hide_input)
          edje_object_signal_emit(list->o_main, "e,state,entry_hide", "e");
        return 1;
@@ -1445,19 +1476,17 @@ _evry_plugin_action(Evry_Selector *sel, int finished)
    if (!s_subject || !s_action)
      return;
 
-   if (update_timer)
+   if (selector->update_timer)
      {
        _evry_matches_update(selector, 0);
        _evry_selector_update(selector);
-
-       ecore_timer_del(update_timer);
-       update_timer = NULL;
      }
 
    if (!s_subject->cur_item || !s_action->cur_item)
      return;
 
-   if (s_action->cur_item->plugin == action_selector)
+   /* FIXME */
+   if (s_action->cur_item->plugin == selectors[1]->actions)
      {
        Evry_Action *act = s_action->cur_item->data;
        Evry_Item *it_object = NULL;
@@ -1703,6 +1732,10 @@ _evry_matches_update(Evry_Selector *sel, int async)
    if (s->plugin && !eina_list_data_find_list(s->cur_plugins, s->plugin))
      s->plugin = NULL;
 
+   if (sel->update_timer)
+     ecore_timer_del(sel->update_timer);
+   sel->update_timer = NULL;
+
    _evry_plugin_select(s, s->plugin);
 }
 
@@ -1775,6 +1808,7 @@ static int
 _evry_cb_selection_notify(void *data, int type, void *event)
 {
    Ecore_X_Event_Selection_Notify *ev;
+   /* FIXME Evry_Selector *sel = data; */
    Evry_State *s = selector->state;
 
    if (!s || (data != win)) return 1;
@@ -1793,7 +1827,7 @@ _evry_cb_selection_notify(void *data, int type, void *event)
              text_data = ev->data;
 
             strncat(s->input, text_data->text, (INPUTLEN - strlen(s->input)) - 1);
-            _evry_update(s, 1);
+            _evry_update(selector, 1);
           }
      }
 
index 5b96d99..8686cca 100644 (file)
@@ -8,11 +8,16 @@ static void
 _cleanup(Evry_Plugin *p)
 {
    Evry_Action *act;
-   Evry_Selector *sel = selectors[1];
+   Evry_Selector *sel;
+   
+   if (p->type == type_subject)
+     sel = selectors[0];
+   else
+     sel = selectors[1];
 
    EVRY_PLUGIN_ITEMS_FREE(p);
 
-   EINA_LIST_FREE(sel->actions, act)
+   EINA_LIST_FREE(sel->cur_actions, act)
      if (act->cleanup) act->cleanup(act);
 }
 
@@ -21,19 +26,30 @@ _begin(Evry_Plugin *p, const Evry_Item *it)
 {
    Evry_Action *act;
    Eina_List *l;
-   Evry_Selector *sel = selectors[1];
+   const char *type;   
+   Evry_Selector *sel;
+   
+   if (p->type == type_subject)
+     sel = selectors[0];
+   else
+     sel = selectors[1];
 
    _cleanup(p);
 
-   if (!it) return NULL;
-
-   const char *type = it->plugin->type_out;
-
-   if (!type) return NULL;
-
+   if (p->type == type_action)
+     {
+       if (!it) return NULL;
+       type = it->plugin->type_out;
+       if (!type) return NULL;
+     }
+   else
+     {
+       printf("begin %s\n", p->name);
+     }
+   
    EINA_LIST_FOREACH(evry_conf->actions, l, act)
      {
-       if (act->type_in1 && (act->type_in1 == type) &&
+       if (!act->type_in1 || (act->type_in1 == type) &&
            (!act->check_item || act->check_item(act, it)))
          {
             act->item1 = it;
@@ -41,12 +57,12 @@ _begin(Evry_Plugin *p, const Evry_Item *it)
             if (act->type_out && act->intercept && !(act->intercept(act)))
               continue;;
 
-            sel->actions = eina_list_append(sel->actions, act);
+            sel->cur_actions = eina_list_append(sel->cur_actions, act);
          }
      }
 
-   if (!sel->actions) return NULL;
-
+   if (!sel->cur_actions) return NULL;
+   
    return p;
 }
 
@@ -80,12 +96,17 @@ _fetch(Evry_Plugin *p, const char *input)
    Evry_Action *act;
    Eina_List *l;
    Evry_Item *it;
-   Evry_Selector *sel = selectors[1];
+   Evry_Selector *sel;
    int match = 0;
 
+   if (p->type == type_subject)
+     sel = selectors[0];
+   else
+     sel = selectors[1];
+
    EVRY_PLUGIN_ITEMS_FREE(p);
 
-   EINA_LIST_FOREACH(sel->actions, l, act)
+   EINA_LIST_FOREACH(sel->cur_actions, l, act)
      {
        if (input)
          match = evry_fuzzy_match(act->name, input);
@@ -125,11 +146,11 @@ _icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
 }
 
 Evry_Plugin *
-evry_plug_actions_new(void)
+evry_plug_actions_new(int type)
 {
    Evry_Plugin *p;
 
-   p = evry_plugin_new(NULL, "Select Action", type_action, "", "", 0, NULL, NULL,
+   p = evry_plugin_new(NULL, action_selector, type, "", "", 0, NULL, NULL,
                       _begin, _cleanup, _fetch, NULL, _icon_get, NULL, NULL);
 
    evry_plugin_register(p, 2);
index 3f65fc8..28fe4d4 100644 (file)
@@ -9,6 +9,12 @@ struct _Plugin
   Evry_Selector *selector;
 };
 
+inline static int
+_is_action(const Evry_Item *it)
+{
+   return (it->plugin->name == action_selector);
+}
+
 static int
 _cb_sort_recent(const void *data1, const void *data2)
 {
@@ -22,17 +28,15 @@ _cb_sort_recent(const void *data1, const void *data2)
    if (it2->usage && !it1->usage)
      return 1;
 
-   if ((it1->plugin == action_selector) ||
-       (it2->plugin == action_selector))
+   if (_is_action(it1) || _is_action(it2))
      {
-       if ((it1->plugin == action_selector) &&
-           (it2->plugin == action_selector))
+       if (_is_action(it1) && _is_action(it2))
          return (it1->priority - it2->priority);
-       else if (it1->plugin == action_selector)
-         return ((it1->plugin->config->priority + it1->priority)
-                 - it2->plugin->config->priority);
+       else if (_is_action(it1))
+         return ((it1->plugin->config->priority + it1->priority) -
+                 (it2->plugin->config->priority));
        else
-         return (it1->plugin->config->priority -
+         return ((it1->plugin->config->priority) -
                  (it2->plugin->config->priority + it2->priority));
      }
 
@@ -52,13 +56,11 @@ _cb_sort(const void *data1, const void *data2)
    if (it2->usage && !it1->usage)
      return 1;
 
-   if ((it1->plugin == action_selector) ||
-       (it2->plugin == action_selector))
+   if (_is_action(it1) || _is_action(it2))
      {
-       if ((it1->plugin == action_selector) &&
-           (it2->plugin == action_selector))
+       if (_is_action(it1) && _is_action(it2))
          return (it1->priority - it2->priority);
-       else if (it1->plugin == action_selector)
+       else if (_is_action(it1))
          return ((it1->plugin->config->priority + it1->priority)
                  - it2->plugin->config->priority);
        else
index 55eb721..f4d6217 100644 (file)
@@ -8,23 +8,15 @@ static Eina_Hash *border_hash = NULL;
 static int
 _cb_border_remove(void *data, int type,  void *event)
 {
-   Evry_Plugin *p = data;
-   E_Event_Border_Remove *ev;
-   Eina_List *l;
+   E_Event_Border_Remove *ev = event;
    Evry_Item *it;
-
-   ev = event;
+   Evry_Plugin *p = data;
 
    it = eina_hash_find(border_hash, &(ev->border));
 
-   printf("border del cb\n");
-
    if (!it) return 1;
 
-   printf("border del cb %s\n", it->label);
-
    eina_hash_del_by_key(border_hash, &(ev->border)); 
-
    p->items = eina_list_remove(p->items, it);
    evry_item_free(it);
    evry_plugin_async_update(p, EVRY_ASYNC_UPDATE_ADD);