Ticket #2733: 2733-file-edit-history.patch

File 2733-file-edit-history.patch, 7.2 KB (added by filipsef, 8 years ago)

updated patch working with master on 05-13-2016

  • lib/keybind.c

    diff --git a/lib/keybind.c b/lib/keybind.c
    index 89fa9a0..2c7510a 100644
    a b static name_keymap_t command_names[] = { 
    231231    {"SortBySize", CK_SortBySize}, 
    232232    {"SortByMTime", CK_SortByMTime}, 
    233233    {"CdParentSmart", CK_CdParentSmart}, 
     234    {"FileEditHistory", CK_FileEditHistory}, 
    234235 
    235236    /* dialog */ 
    236237    {"Ok", CK_Ok}, 
  • lib/keybind.h

    diff --git a/lib/keybind.h b/lib/keybind.h
    index a88efbc..19e539b 100644
    a b enum 
    205205    CK_SortByMTime, 
    206206    CK_ScrollLeft, 
    207207    CK_ScrollRight, 
     208    CK_FileEditHistory, 
    208209 
    209210    /* dialog */ 
    210211    CK_Ok = 300L, 
  • lib/widget/history.c

    diff --git a/lib/widget/history.c b/lib/widget/history.c
    index 67aff69..768c203 100644
    a b int num_history_items_recorded = 60; 
    5757 
    5858/*** file scope macro definitions ****************************************************************/ 
    5959 
     60#define B_VIEW          (B_USER + 1) 
     61#define B_EDIT          (B_USER + 2) 
     62 
    6063/*** file scope type declarations ****************************************************************/ 
    6164 
    6265typedef struct 
    history_dlg_reposition (WDialog * dlg_head) 
    114117 
    115118/* --------------------------------------------------------------------------------------------- */ 
    116119 
     120static inline cb_ret_t 
     121history_handle_key (WDialog * h, int key) 
     122{ 
     123    switch (key) 
     124    { 
     125    case KEY_F (3): 
     126        h->ret_value = B_VIEW; 
     127        dlg_stop (h); 
     128        return MSG_HANDLED; 
     129 
     130    case KEY_F (4): 
     131        h->ret_value = B_EDIT; 
     132        dlg_stop (h); 
     133        return MSG_HANDLED; 
     134    default: 
     135        return MSG_NOT_HANDLED; 
     136    } 
     137} 
     138 
     139/* --------------------------------------------------------------------------------------------- */ 
     140 
    117141static cb_ret_t 
    118142history_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) 
    119143{ 
    history_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v 
    122146    case MSG_RESIZE: 
    123147        return history_dlg_reposition (DIALOG (w)); 
    124148 
     149    case MSG_UNHANDLED_KEY: 
     150         return history_handle_key (DIALOG (w), parm); 
     151 
    125152    default: 
    126153        return dlg_default_callback (w, sender, msg, parm, data); 
    127154    } 
    history_save (mc_config_t * cfg, const char *name, GList * h) 
    285312/* --------------------------------------------------------------------------------------------- */ 
    286313 
    287314char * 
    288 history_show (GList ** history, Widget * widget, int current) 
     315history_show (GList ** history, Widget * widget, int current, int *param) 
    289316{ 
    290317    GList *z, *hlist = NULL, *hi; 
    291318    size_t maxlen, count = 0; 
    history_show (GList ** history, Widget * widget, int current) 
    293320    WDialog *query_dlg; 
    294321    WListbox *query_list; 
    295322    history_dlg_data hist_data; 
     323    int dlg_ret; 
    296324 
    297325    if (*history == NULL) 
    298326        return NULL; 
    history_show (GList ** history, Widget * widget, int current) 
    356384            listbox_select_entry (query_list, current); 
    357385    } 
    358386 
    359     if (dlg_run (query_dlg) != B_CANCEL) 
     387    dlg_ret = dlg_run (query_dlg); 
     388    if (dlg_ret != B_CANCEL) 
    360389    { 
    361390        char *q; 
    362391 
     392        if (param != NULL) 
     393        { 
     394            switch (dlg_ret) 
     395            { 
     396            case B_EDIT: 
     397                *param = CK_Edit; 
     398                break; 
     399            case B_VIEW: 
     400                *param = CK_View; 
     401                break; 
     402            default: 
     403                *param = CK_CdChild; 
     404            } 
     405        } 
     406 
    363407        listbox_get_current (query_list, &q, NULL); 
    364408        r = g_strdup (q); 
    365409    } 
  • lib/widget/history.h

    diff --git a/lib/widget/history.h b/lib/widget/history.h
    index 101ffd4..48038de 100644
    a b GList *history_load (mc_config_t * cfg, const char *name); 
    2828void history_save (mc_config_t * cfg, const char *name, GList * h); 
    2929/* for repositioning of history dialog we should pass widget to this 
    3030 * function, as position of history dialog depends on widget's position */ 
    31 char *history_show (GList ** history, Widget * widget, int current); 
     31char *history_show (GList ** history, Widget * widget, int current, int *action); 
    3232 
    3333/*** inline functions ****************************************************************************/ 
    3434 
  • lib/widget/input.c

    diff --git a/lib/widget/input.c b/lib/widget/input.c
    index d0dc1cb..df11de5 100644
    a b do_show_hist (WInput * in) 
    178178    len = get_history_length (in->history.list); 
    179179 
    180180    r = history_show (&in->history.list, WIDGET (in), 
    181                       g_list_position (in->history.list, in->history.list)); 
     181                      g_list_position (in->history.list, in->history.list), NULL); 
    182182    if (r != NULL) 
    183183    { 
    184184        input_assign_text (in, r); 
  • src/filemanager/panel.c

    diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c
    index 30d2706..54be0c0 100644
    a b directory_history_list (WPanel * panel) 
    33443344 
    33453345    pos = g_list_position (panel->dir_history_current, panel->dir_history); 
    33463346 
    3347     s = history_show (&panel->dir_history, WIDGET (panel), pos); 
     3347    s = history_show (&panel->dir_history, WIDGET (panel), pos, NULL); 
    33483348    if (s != NULL) 
    33493349    { 
    33503350        vfs_path_t *s_vpath; 
    directory_history_list (WPanel * panel) 
    33813381    } 
    33823382} 
    33833383 
     3384static void 
     3385file_edit_history_list (WPanel * panel) 
     3386{ 
     3387 
     3388    char *fn; 
     3389    FILE *f; 
     3390    char buf[MC_MAXPATHLEN + 100]; 
     3391    GList *file_list = NULL; 
     3392    char *s; 
     3393    int action; 
     3394 
     3395    /* open file with positions */ 
     3396    fn =  mc_config_get_full_path (MC_FILEPOS_FILE); 
     3397    f = fopen (fn, "r"); 
     3398    g_free (fn); 
     3399    if (f == NULL) 
     3400        return; 
     3401 
     3402    while (fgets (buf, sizeof (buf), f) != NULL) 
     3403    { 
     3404        s = strrchr(buf, ' '); 
     3405        if (s) 
     3406        { 
     3407            *s = 0; 
     3408        } 
     3409        s = g_strdup (buf); 
     3410 
     3411       file_list = g_list_prepend (file_list, s); 
     3412       file_list = g_list_first(file_list); 
     3413    } 
     3414    fclose(f); 
     3415 
     3416    file_list = g_list_last(file_list); 
     3417 
     3418    s = history_show (&file_list, WIDGET(panel), 0, &action); 
     3419 
     3420    if (s != NULL) 
     3421    { 
     3422        vfs_path_t *vpath; 
     3423 
     3424        switch (action) 
     3425        { 
     3426        case CK_Edit: 
     3427            vpath = vfs_path_from_str (s); 
     3428            edit_file_at_line (vpath, use_internal_edit, 0); 
     3429            break; 
     3430        case CK_View: 
     3431            vpath = vfs_path_from_str (s); 
     3432            view_file (vpath, TRUE, use_internal_view); 
     3433            break; 
     3434        default: 
     3435            { 
     3436            char *dirname = g_path_get_dirname(s); 
     3437            vpath = vfs_path_from_str (dirname); 
     3438            g_free (dirname); 
     3439 
     3440            do_cd (vpath, cd_exact); 
     3441            try_to_select (panel, basename(s)); 
     3442            } 
     3443        } 
     3444        vfs_path_free(vpath); 
     3445        g_free (s); 
     3446    } 
     3447 
     3448    file_list = g_list_first (file_list); 
     3449    g_list_foreach (file_list, (GFunc) g_free, NULL); 
     3450    g_list_free (file_list); 
     3451} 
     3452 
    33843453/* --------------------------------------------------------------------------------------------- */ 
    33853454 
    33863455static cb_ret_t 
    panel_execute_cmd (WPanel * panel, long command) 
    34583527    case CK_CdParent: 
    34593528        goto_parent_dir (panel); 
    34603529        break; 
     3530    case CK_FileEditHistory: 
     3531        file_edit_history_list (panel); 
     3532        break; 
    34613533    case CK_History: 
    34623534        directory_history_list (panel); 
    34633535        break;