# HG changeset patch # User ulion # Date 1197196325 0 # Node ID b1638a8b9dc692e5e2a0252b281137f521a13246 # Parent 0335de28ee01652085d73bcc861c1a95e2f8f10d Combine common code for dealing with file action and dir action. diff -r 0335de28ee01 -r b1638a8b9dc6 libmenu/menu_filesel.c --- a/libmenu/menu_filesel.c Sun Dec 09 07:50:37 2007 +0000 +++ b/libmenu/menu_filesel.c Sun Dec 09 10:32:05 2007 +0000 @@ -302,24 +302,14 @@ static char *action; static void read_cmd(menu_t* menu,int cmd) { - mp_cmd_t* c = NULL; switch(cmd) { case MENU_CMD_LEFT: mpriv->p.current = mpriv->p.menu; // Hack : we consider that the first entry is ../ case MENU_CMD_RIGHT: case MENU_CMD_OK: { // Directory - if(mpriv->p.current->d) { - if(mpriv->dir_action) { - int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; - char filename[fname_len]; - char* str; - sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); - str = replace_path(mpriv->dir_action,filename); - c = mp_input_parse_cmd(str); - if(str != mpriv->dir_action) - free(str); - } else { // Default action : open this dirctory ourself + if(mpriv->p.current->d && !mpriv->dir_action) { + // Default action : open this dirctory ourself int l = strlen(mpriv->dir); char *slash = NULL, *p = NULL; if(strcmp(mpriv->p.current->p.txt,"../") == 0) { @@ -343,22 +333,23 @@ menu->cl = 1; } free(p); - } - } else { // Files + } else { // File and directory dealt with action string. + mp_cmd_t* c; int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1; char filename[fname_len]; char *str; + char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action; sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); - str = replace_path(mpriv->file_action,filename); + str = replace_path(action, filename); c = mp_input_parse_cmd(str); - if(str != mpriv->file_action) + if (str != action) free(str); - } if(c) { mp_input_queue_cmd(c); if(mpriv->auto_close) menu->cl = 1; } + } } break; case MENU_CMD_ACTION: { int fname_len = strlen(mpriv->dir) + strlen(mpriv->p.current->p.txt) + 1;