Ticket #4065: vc_chain_menu2.patch

File vc_chain_menu2.patch, 5.0 KB (added by akorop, 4 years ago)
  • lib/mcconfig.h

    diff a/lib/mcconfig.h b/lib/mcconfig.h
    a b const char *mc_config_get_cache_path (void); 
    9999const char *mc_config_get_home_dir (void); 
    100100const char *mc_config_get_path (void); 
    101101char *mc_config_get_full_path (const char *config_name); 
     102char *mc_file_get_full_path (const char *file_name); 
    102103vfs_path_t *mc_config_get_full_vpath (const char *config_name); 
    103104 
    104105gboolean mc_config_migrate_from_old_place (GError ** mcerror, char **msg); 
  • lib/mcconfig/paths.c

    diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c
    index 916bff9..4aa1e89 100644
    a b mc_config_get_full_path (const char *config_name) 
    528528 
    529529/* --------------------------------------------------------------------------------------------- */ 
    530530/** 
     531 * Get full path to existing file by short name. 
     532 * 
     533 * @param file_name file short name 
     534 * @return full path to file (NULL if not found) 
     535 */ 
     536 
     537char * 
     538mc_file_get_full_path (const char *file_name) 
     539{ 
     540    size_t rule_index; 
     541    char* full_path; 
     542 
     543    if (file_name == NULL) 
     544        return NULL; 
     545 
     546    if (!xdg_vars_initialized) 
     547        mc_config_init_config_paths (NULL); 
     548 
     549    for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++) 
     550    { 
     551        full_path = g_build_filename (*mc_config_files_reference[rule_index].new_basedir, 
     552                                     file_name, NULL); 
     553        if (exist_file(full_path)) 
     554            return full_path; 
     555        g_free(full_path); 
     556    } 
     557    return NULL; 
     558} 
     559 
     560/* --------------------------------------------------------------------------------------------- */ 
     561/** 
    531562 * Get full path to config file by short name. 
    532563 * 
    533564 * @param config_name short name 
  • src/usermenu.c

    diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c
    index bafb1a7..afde214 100644
    a b  
    420420/* --------------------------------------------------------------------------------------------- */ 
    421421/** FIXME: recode this routine on version 3.0, it could be cleaner */ 
    422422 
    423 static void 
     423static char* 
    424424execute_menu_command (const WEdit * edit_widget, const char *commands, gboolean show_prompt) 
    425425{ 
    426426    FILE *cmd_file; 
     
    432432    int col; 
    433433    vfs_path_t *file_name_vpath; 
    434434    gboolean run_view = FALSE; 
     435    const char* text_start; 
     436    char* new_menu; 
    435437 
    436438    /* Skip menu entry title line */ 
    437439    commands = strchr (commands, '\n'); 
    438440    if (commands == NULL) 
    439         return; 
     441        return(NULL); 
     442 
     443    /* chain menu? */ 
     444    text_start = commands+1; 
     445    while (*text_start == ' ' || *text_start == '\t') ++text_start; 
     446    if (*text_start == '>') 
     447    { 
     448        char*  line_end;  
     449 
     450        ++text_start; 
     451        while (*text_start == ' ' || *text_start == '\t') ++text_start; 
     452        line_end = strchr (text_start, '\n'); 
     453        if  (!line_end) return(NULL); 
     454        new_menu = g_strndup(text_start, line_end - text_start); 
     455        return(new_menu); 
     456     } 
    440457 
    441458    cmd_file_fd = mc_mkstemps (&file_name_vpath, "mcusr", SCRIPT_SUFFIX); 
    442459 
     
    445462        message (D_ERROR, MSG_ERROR, _("Cannot create temporary command file\n%s"), 
    446463                 unix_error_string (errno)); 
    447464        vfs_path_free (file_name_vpath); 
    448         return; 
     465        return(NULL); 
    449466    } 
    450467    cmd_file = fdopen (cmd_file_fd, "w"); 
    451468    fputs ("#! /bin/sh\n", cmd_file); 
     
    481498                    fclose (cmd_file); 
    482499                    mc_unlink (file_name_vpath); 
    483500                    vfs_path_free (file_name_vpath); 
    484                     return; 
     501                    return(NULL); 
    485502                } 
    486503                if (do_quote) 
    487504                { 
     
    568585    } 
    569586    mc_unlink (file_name_vpath); 
    570587    vfs_path_free (file_name_vpath); 
     588    return(NULL); 
    571589} 
    572590 
    573591/* --------------------------------------------------------------------------------------------- */ 
     
    934952        menu = g_strdup (menu_file); 
    935953    else 
    936954        menu = g_strdup (edit_widget != NULL ? EDIT_LOCAL_MENU : MC_LOCAL_MENU); 
     955 
     956do /* process menu file */ 
     957{ 
     958    res = FALSE; 
    937959    if (!exist_file (menu) || !menu_file_own (menu)) 
    938960    { 
    939961        if (menu_file != NULL) 
     
    9821004        MC_PTR_FREE (menu); 
    9831005        return FALSE; 
    9841006    } 
     1007    g_free (menu); 
     1008    menu = NULL; 
    9851009 
    9861010    max_cols = 0; 
    9871011    selected = 0; 
     
    11101134        } 
    11111135        if (selected >= 0) 
    11121136        { 
    1113             execute_menu_command (edit_widget, entries[selected], interactive); 
     1137            menu = execute_menu_command (edit_widget, entries[selected], interactive); 
    11141138            res = TRUE; 
    11151139        } 
    11161140 
     
    11181142    } 
    11191143 
    11201144    easy_patterns = old_patterns; 
    1121     MC_PTR_FREE (menu); 
    11221145    g_free (entries); 
    11231146    g_free (data); 
     1147    if (menu) /* possible chain menu */ 
     1148    { 
     1149        char* temp = mc_file_get_full_path (menu); 
     1150        g_free (menu); 
     1151        menu = temp; 
     1152        if (!exist_file (menu)) 
     1153        { 
     1154            g_free(menu); 
     1155            menu = NULL; 
     1156        } 
     1157    } 
     1158} 
     1159while (menu); 
     1160    do_refresh (); 
    11241161    return res; 
    11251162} 
    11261163