Enlightenment CVS committal Author : lordchaos Project : e17 Module : proto
Dir : e17/proto/entropy/src/plugins Modified Files: action_simple.c etk_list_viewer.c Log Message: * Multi-mime-actions part 2: Actions are now hooked up (try right click a file->open with..->()). Note that this temporarily breaks the mime dialogs =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/entropy/src/plugins/action_simple.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -3 -r1.9 -r1.10 --- action_simple.c 31 Jan 2006 07:17:48 -0000 1.9 +++ action_simple.c 18 Mar 2006 08:04:11 -0000 1.10 @@ -2,7 +2,7 @@ #include "entropy_gui.h" #include "entropy_config.h" #include <unistd.h> - +#include <limits.h> @@ -20,14 +20,77 @@ } +/*FIXME - this is vomit. In serious need of optimization*/ +char* entropy_action_simple_str_replace(entropy_generic_file* file, char* exe, char* args) +{ + /*A function to replace %p (path), %pf (path+filename), and %u (uri), with their + * real equivalents*/ + int i=0; + char* str = calloc(1,sizeof(char)*PATH_MAX); + char* currStr = exe; + + while (currStr) { + i=0; + while (i < strlen(currStr)) { + int ud = 0; + + if ( i +3 <= strlen(currStr) && !strncmp(currStr+i, "\%pf", 3)) { + printf("Subbing path and filename\n"); + + strcat(str, file->path); + strcat(str, "/"); + strcat(str, file->filename); + ud = 1; + i+=3; + } + + if ( i +2 <= strlen(currStr) && !strncmp(currStr+i, "\%p", 2)) { + printf("Subbing path only\n"); + + strcat(str, file->path); + ud = 1; + i+=2; + } + + if ( i +2 <= strlen(currStr) && !strncmp(currStr+i, "\%u", 2)) { + printf("Subbing uri\n"); + + char* uri = entropy_core_generic_file_uri_create(file, 0); + strcat(str, uri); + ud = 1; + i+=2; + free(uri); + } + + if (!ud) { + strncat(str, currStr+i, 1); + i += 1; + } + + ud = 0; + + } + + + if (currStr == exe) { + currStr = args; + strcat(str, " "); + } else + currStr = NULL; + } + + return str; +} + + void gui_event_callback (entropy_notify_event * eevent, void *requestor, void *obj, entropy_gui_component_instance * comp) { - char fullname[1024]; + char *fullname; entropy_gui_event *gui_event; entropy_core *core = ((entropy_gui_component_instance *) requestor)->core; - entropy_mime_action *app; + Entropy_Config_Mime_Binding_Action *app; char *uri; char *pos; @@ -91,34 +154,10 @@ /*First get the app associated with this mime type */ app = - entropy_core_mime_hint_get (((entropy_generic_file *) obj)->mime_type); + entropy_core_mime_hint_get (((entropy_generic_file *) obj)->mime_type, eevent->key); if (app) { - /*First do a replace */ - if ((pos = strstr (app->executable, "\%u"))) { - bzero (fullname, 1024); - uri = entropy_core_generic_file_uri_create (file, 0); - - printf ("Action '%s' contains a URI replace reference\n", - app->executable); - - /*This is some evil shit - TODO make a proper strreplace function */ - strncat (fullname, app->executable, pos - app->executable); - strcat (fullname, uri); - pos += 2; - strcat (fullname, pos); - - - printf ("'%s'\n", fullname); - - free (uri); - } - else { - sprintf (fullname, "%s \"%s/%s\"", app->executable, - ((entropy_generic_file *) obj)->path, - ((entropy_generic_file *) obj)->filename); - } - - + fullname = entropy_action_simple_str_replace((entropy_generic_file*)obj, app->executable, app->args); + printf("'%s'\n", fullname); //printf ("Hit action callback\n"); =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/entropy/src/plugins/etk_list_viewer.c,v retrieving revision 1.45 retrieving revision 1.46 diff -u -3 -r1.45 -r1.46 --- etk_list_viewer.c 16 Mar 2006 12:22:01 -0000 1.45 +++ etk_list_viewer.c 18 Mar 2006 08:04:11 -0000 1.46 @@ -136,6 +136,37 @@ } static void +_open_with_item_cb(Etk_Object *obj, void *data) +{ + int i; + entropy_gui_event* gui_event; + entropy_gui_component_instance* instance; + entropy_etk_file_list_viewer* viewer; + Etk_Tree_Row* row; + gui_file* file; + + + i = (int)etk_object_data_get(obj, "INDEX"); + instance = data; + if (instance) viewer = instance->data; + + if (instance && viewer) { + row = etk_tree_selected_row_get(ETK_TREE(viewer->tree)); + file = ecore_hash_get(row_hash, row); + + + if (file) { + gui_event = entropy_malloc (sizeof (entropy_gui_event)); + gui_event->event_type = + entropy_core_gui_event_get (ENTROPY_GUI_EVENT_ACTION_FILE); + gui_event->data = file->file; + gui_event->key = i; + entropy_core_layout_notify_event (instance, gui_event, ENTROPY_EVENT_GLOBAL); + } + } +} + +static void _entropy_etk_list_viewer_menu_popup_cb(Etk_Object *object, void *data) { entropy_gui_component_instance* instance; @@ -156,10 +187,17 @@ if (file && strlen(file->file->mime_type)) { binding = entropy_config_mime_binding_for_type_get(file->file->mime_type); + + if (ETK_MENU_ITEM(viewer->open_with_menuitem)->submenu) { + etk_menu_item_submenu_set(ETK_MENU_ITEM(viewer->open_with_menuitem), NULL); + etk_object_destroy(ETK_OBJECT(viewer->open_with_menu)); + viewer->open_with_menu = NULL; + } + if (binding) { - - //etk_object_destroy(ETK_OBJECT(viewer->open_with_menu)); + Etk_Widget* w; + int i=0; viewer->open_with_menu = etk_menu_new(); etk_menu_item_submenu_set(ETK_MENU_ITEM(viewer->open_with_menuitem), ETK_MENU(viewer->open_with_menu)); @@ -167,17 +205,24 @@ for (l = binding->actions; l; ) { action = l->data; - _entropy_etk_menu_item_new(ETK_MENU_ITEM_NORMAL, _(action->app_description), + w = _entropy_etk_menu_item_new(ETK_MENU_ITEM_NORMAL, _(action->app_description), ETK_STOCK_EDIT_COPY, ETK_MENU_SHELL(viewer->open_with_menu),NULL); + etk_object_data_set(ETK_OBJECT(w), "INDEX", (int*)i); + + etk_signal_connect("activated", ETK_OBJECT(w), ETK_CALLBACK(_open_with_item_cb), instance); l = l->next; + i++; } + + } + + } - printf("Menu activated!\n"); } ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs