Ticket #3494: 3494-Use-INPUT_LAST_TEXT-for-input_dialog-instead-of-stat.patch

File 3494-Use-INPUT_LAST_TEXT-for-input_dialog-instead-of-stat.patch, 6.4 KB (added by mooffie, 9 years ago)
  • src/diffviewer/ydiff.c

    From 2f733f92abd3f33c7a4d649e5609d10edf531e80 Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Wed, 1 Jul 2015 11:12:42 +0300
    Subject: [PATCH] Use INPUT_LAST_TEXT for input_dialog() instead of static
     vars.
    
    ---
     src/diffviewer/ydiff.c | 13 +++++++------
     src/editor/editcmd.c   | 49 ++++++++++++++++++-------------------------------
     2 files changed, 25 insertions(+), 37 deletions(-)
    
    diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c
    index 8cba2ad..ceef3e5 100644
    a b dview_edit (WDiff * dview, diff_place_t ord) 
    29132913static void 
    29142914dview_goto_cmd (WDiff * dview, diff_place_t ord) 
    29152915{ 
     2916    static gboolean first_run = TRUE; 
     2917 
    29162918    /* *INDENT-OFF* */ 
    29172919    static const char *title[2] = { 
    29182920        N_("Goto line (left)"), 
    29192921        N_("Goto line (right)") 
    29202922    }; 
    29212923    /* *INDENT-ON* */ 
    2922     static char prev[256]; 
    2923     /* XXX some statics here, to be remembered between runs */ 
    29242924 
    29252925    int newline; 
    29262926    char *input; 
    29272927 
    29282928    input = 
    2929         input_dialog (_(title[ord]), _("Enter line:"), MC_HISTORY_YDIFF_GOTO_LINE, prev, 
    2930                       INPUT_COMPLETE_NONE); 
     2929        input_dialog (_(title[ord]), _("Enter line:"), MC_HISTORY_YDIFF_GOTO_LINE, 
     2930                      first_run ? NULL : INPUT_LAST_TEXT, INPUT_COMPLETE_NONE); 
    29312931    if (input != NULL) 
    29322932    { 
    29332933        const char *s = input; 
    dview_goto_cmd (WDiff * dview, diff_place_t ord) 
    29482948                } 
    29492949            } 
    29502950            dview->skip_rows = dview->search.last_accessed_num_line = (ssize_t) i; 
    2951             g_snprintf (prev, sizeof (prev), "%d", newline); 
    29522951        } 
    29532952        g_free (input); 
    29542953    } 
     2954 
     2955    first_run = FALSE; 
    29552956} 
    29562957 
    29572958/* --------------------------------------------------------------------------------------------- */ 
    dview_execute_cmd (WDiff * dview, unsigned long command) 
    32113212            find_prev_hunk (dview->a[DIFF_LEFT], dview->skip_rows); 
    32123213        break; 
    32133214    case CK_Goto: 
    3214         dview_goto_cmd (dview, TRUE); 
     3215        dview_goto_cmd (dview, DIFF_RIGHT); 
    32153216        break; 
    32163217    case CK_Edit: 
    32173218        dview_edit (dview, dview->ord); 
  • src/editor/editcmd.c

    diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c
    index ea9f49f..8572470 100644
    a b edit_paste_from_X_buf_cmd (WEdit * edit) 
    30283028void 
    30293029edit_goto_cmd (WEdit * edit) 
    30303030{ 
     3031    static gboolean first_run = TRUE; 
     3032 
    30313033    char *f; 
    3032     static long line = 0;       /* line as typed, saved as default */ 
    30333034    long l; 
    30343035    char *error; 
    3035     char s[32]; 
    30363036 
    3037     g_snprintf (s, sizeof (s), "%ld", line); 
    3038     f = input_dialog (_("Goto line"), _("Enter line:"), MC_HISTORY_EDIT_GOTO_LINE, line ? s : "", 
    3039                       INPUT_COMPLETE_NONE); 
     3037    f = input_dialog (_("Goto line"), _("Enter line:"), MC_HISTORY_EDIT_GOTO_LINE, 
     3038                      first_run ? NULL : INPUT_LAST_TEXT, INPUT_COMPLETE_NONE); 
    30403039    if (!f) 
    30413040        return; 
    30423041 
    edit_goto_cmd (WEdit * edit) 
    30533052        return; 
    30543053    } 
    30553054 
    3056     line = l; 
    30573055    if (l < 0) 
    30583056        l = edit->buffer.lines + l + 2; 
    30593057    edit_move_display (edit, l - WIDGET (edit)->lines / 2 - 1); 
    30603058    edit_move_to_line (edit, l - 1); 
    30613059    edit->force |= REDRAW_COMPLETELY; 
    30623060    g_free (f); 
     3061 
     3062    first_run = FALSE; 
    30633063} 
    30643064 
    30653065 
    edit_insert_file_cmd (WEdit * edit) 
    31403140int 
    31413141edit_sort_cmd (WEdit * edit) 
    31423142{ 
    3143     static char *old = 0; 
    31443143    char *exp, *tmp, *tmp_edit_block_name, *tmp_edit_temp_name; 
    31453144    off_t start_mark, end_mark; 
    31463145    int e; 
    edit_sort_cmd (WEdit * edit) 
    31573156 
    31583157    exp = input_dialog (_("Run sort"), 
    31593158                        _("Enter sort options (see manpage) separated by whitespace:"), 
    3160                         MC_HISTORY_EDIT_SORT, (old != NULL) ? old : "", INPUT_COMPLETE_NONE); 
     3159                        MC_HISTORY_EDIT_SORT, INPUT_LAST_TEXT, INPUT_COMPLETE_NONE); 
    31613160 
    31623161    if (!exp) 
    31633162        return 1; 
    3164     g_free (old); 
    3165     old = exp; 
    31663163    tmp_edit_block_name = mc_config_get_full_path (EDIT_BLOCK_FILE); 
    31673164    tmp_edit_temp_name = mc_config_get_full_path (EDIT_TEMP_FILE); 
    31683165    tmp = 
    edit_block_process_cmd (WEdit * edit, int macro_number) 
    32763273void 
    32773274edit_mail_dialog (WEdit * edit) 
    32783275{ 
    3279     char *tmail_to = NULL; 
    3280     char *tmail_subject = NULL; 
    3281     char *tmail_cc = NULL; 
    3282  
    3283     static char *mail_cc_last = 0; 
    3284     static char *mail_subject_last = 0; 
    3285     static char *mail_to_last = 0; 
    3286  
     3276    char *mail_to, *mail_subject, *mail_cc; 
    32873277 
    32883278    quick_widget_t quick_widgets[] = { 
    32893279        /* *INDENT-OFF* */ 
    32903280        QUICK_LABEL (N_("mail -s <subject> -c <cc> <to>"), NULL), 
    32913281        QUICK_LABELED_INPUT (N_("To"), input_label_above, 
    3292                              mail_to_last != NULL ? mail_to_last : "", "mail-dlg-input-3", 
    3293                              &tmail_to, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES), 
     3282                             INPUT_LAST_TEXT, "mail-dlg-input-3", 
     3283                             &mail_to, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES), 
    32943284        QUICK_LABELED_INPUT (N_("Subject"), input_label_above, 
    3295                               mail_subject_last != NULL ? mail_subject_last : "", "mail-dlg-input-2", 
    3296                               &tmail_subject, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE), 
     3285                              INPUT_LAST_TEXT, "mail-dlg-input-2", 
     3286                              &mail_subject, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE), 
    32973287        QUICK_LABELED_INPUT (N_("Copies to"), input_label_above, 
    3298                              mail_cc_last != NULL ? mail_cc_last  : "", "mail-dlg-input", 
    3299                              &tmail_cc, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES), 
     3288                             INPUT_LAST_TEXT, "mail-dlg-input", 
     3289                             &mail_cc, NULL, FALSE, FALSE, INPUT_COMPLETE_USERNAMES), 
    33003290        QUICK_BUTTONS_OK_CANCEL, 
    33013291        QUICK_END 
    33023292        /* *INDENT-ON* */ 
    edit_mail_dialog (WEdit * edit) 
    33103300 
    33113301    if (quick_dialog (&qdlg) != B_CANCEL) 
    33123302    { 
    3313         g_free (mail_cc_last); 
    3314         g_free (mail_subject_last); 
    3315         g_free (mail_to_last); 
    3316         mail_cc_last = tmail_cc; 
    3317         mail_subject_last = tmail_subject; 
    3318         mail_to_last = tmail_to; 
    3319         pipe_mail (&edit->buffer, mail_to_last, mail_subject_last, mail_cc_last); 
     3303        pipe_mail (&edit->buffer, mail_to, mail_subject, mail_cc); 
     3304        g_free (mail_to); 
     3305        g_free (mail_subject); 
     3306        g_free (mail_cc); 
    33203307    } 
    33213308} 
    33223309