Ticket #3060: 0001-Live-update-the-panels-when-editing-layout.patch

File 0001-Live-update-the-panels-when-editing-layout.patch, 9.0 KB (added by fiendish, 6 years ago)
  • src/filemanager/layout.c

    From 46d96c3a5112d2f20bd3748e8e5ff4445f429b3c Mon Sep 17 00:00:00 2001
    From: Avi Kelman <patcherton.fixesthings@gmail.com>
    Date: Sat, 24 Aug 2013 16:00:25 -0400
    Subject: [PATCH 1/3] Live update the panels when editing layout
    
     Update the panel split display while adjusting the layout dialog,
     because the user should not be expected to know what number of columns
     or rows is reasonable without being able to see the effects. Cancel
     reverts to previous settings.
    ---
     src/filemanager/layout.c | 107 +++++++++++++++++++++--------------------------
     1 file changed, 47 insertions(+), 60 deletions(-)
    
    diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c
    index 42e34b2..94d5635 100644
    a b panels_layout_t panels_layout = { 
    8080    .horizontal_equal = 1, 
    8181    .top_panel_size = 0 
    8282}; 
     83panels_layout_t old_layout; 
    8384 
    8485/* Controls the display of the rotating dash on the verbose mode */ 
    8586int nice_rotating_dash = 1; 
    static struct 
    142143 
    143144/* These variables are used to avoid updating the information unless */ 
    144145/* we need it */ 
    145 static panels_layout_t old_layout; 
    146146static int old_output_lines; 
    147147 
    148148/* Internal variables */ 
    149 panels_layout_t _panels_layout; 
    150149static int equal_split; 
    151150static int _menubar_visible; 
    152151static int _output_lines; 
    update_split (const WDialog * h) 
    227226{ 
    228227    /* Check split has to be done before testing if it changed, since 
    229228       it can change due to calling check_split() as well */ 
    230     check_split (&_panels_layout); 
    231     old_layout = _panels_layout; 
     229    check_split (&panels_layout); 
    232230 
    233     if (_panels_layout.horizontal_split) 
    234         check_options[0].widget->state = _panels_layout.horizontal_equal ? 1 : 0; 
     231    if (panels_layout.horizontal_split) 
     232        check_options[0].widget->state = panels_layout.horizontal_equal ? 1 : 0; 
    235233    else 
    236         check_options[0].widget->state = _panels_layout.vertical_equal ? 1 : 0; 
     234        check_options[0].widget->state = panels_layout.vertical_equal ? 1 : 0; 
    237235    widget_redraw (WIDGET (check_options[0].widget)); 
    238236 
    239237    tty_setcolor (check_options[0].widget->state & C_BOOL ? DISABLED_COLOR : COLOR_NORMAL); 
    240238 
    241239    widget_move (h, 6, 5); 
    242     if (_panels_layout.horizontal_split) 
    243         tty_printf ("%03d", _panels_layout.top_panel_size); 
     240    if (panels_layout.horizontal_split) 
     241        tty_printf ("%03d", panels_layout.top_panel_size); 
    244242    else 
    245         tty_printf ("%03d", _panels_layout.left_panel_size); 
     243        tty_printf ("%03d", panels_layout.left_panel_size); 
    246244 
    247245    widget_move (h, 6, 17); 
    248     if (_panels_layout.horizontal_split) 
    249         tty_printf ("%03d", height - _panels_layout.top_panel_size); 
     246    if (panels_layout.horizontal_split) 
     247        tty_printf ("%03d", height - panels_layout.top_panel_size); 
    250248    else 
    251         tty_printf ("%03d", COLS - _panels_layout.left_panel_size); 
     249        tty_printf ("%03d", COLS - panels_layout.left_panel_size); 
    252250 
    253251    widget_move (h, 6, 12); 
    254252    tty_print_char ('='); 
    b_left_right_cback (WButton * button, int action) 
    263261 
    264262    if (button == bleft_widget) 
    265263    { 
    266         if (_panels_layout.horizontal_split) 
    267             _panels_layout.top_panel_size++; 
     264        if (panels_layout.horizontal_split) 
     265            panels_layout.top_panel_size++; 
    268266        else 
    269             _panels_layout.left_panel_size++; 
     267            panels_layout.left_panel_size++; 
    270268    } 
    271269    else 
    272270    { 
    273         if (_panels_layout.horizontal_split) 
    274             _panels_layout.top_panel_size--; 
     271        if (panels_layout.horizontal_split) 
     272            panels_layout.top_panel_size--; 
    275273        else 
    276             _panels_layout.left_panel_size--; 
     274            panels_layout.left_panel_size--; 
    277275    } 
    278276 
    279277    update_split (WIDGET (button)->owner); 
     278    layout_change (); 
     279    do_refresh (); 
    280280    return 0; 
    281281} 
    282282 
    layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * 
    320320           update everything */ 
    321321        dlg_default_repaint (h); 
    322322 
    323         old_layout.horizontal_split = -1; 
    324         old_layout.left_panel_size = -1; 
    325         old_layout.top_panel_size = -1; 
    326  
    327323        old_output_lines = -1; 
    328324 
    329325        update_split (h); 
    layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * 
    355351                _output_lines = 0; 
    356352            height = LINES - _keybar_visible - (_command_prompt ? 1 : 0) - 
    357353                _menubar_visible - _output_lines - _message_visible; 
    358             minimum = MINHEIGHT * (1 + _panels_layout.horizontal_split); 
     354            minimum = MINHEIGHT * (1 + panels_layout.horizontal_split); 
    359355            if (height < minimum) 
    360356            { 
    361357                _output_lines -= minimum - height; 
    layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * 
    378374    case MSG_ACTION: 
    379375        if (sender == WIDGET (radio_widget)) 
    380376        { 
    381             if (_panels_layout.horizontal_split != radio_widget->sel) 
     377            if (panels_layout.horizontal_split != radio_widget->sel) 
    382378            { 
    383                 _panels_layout.horizontal_split = radio_widget->sel; 
     379                panels_layout.horizontal_split = radio_widget->sel; 
    384380 
    385                 if (_panels_layout.horizontal_split) 
     381                if (panels_layout.horizontal_split) 
    386382                { 
    387                     if (_panels_layout.horizontal_equal) 
    388                         _panels_layout.top_panel_size = height / 2; 
     383                    if (panels_layout.horizontal_equal) 
     384                        panels_layout.top_panel_size = height / 2; 
    389385                } 
    390386                else 
    391387                { 
    392                     if (_panels_layout.vertical_equal) 
    393                         _panels_layout.left_panel_size = COLS / 2; 
     388                    if (panels_layout.vertical_equal) 
     389                        panels_layout.left_panel_size = COLS / 2; 
    394390                } 
     391                layout_change (); 
     392                do_refresh (); 
    395393            } 
    396394 
    397395            update_split (h); 
    layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * 
    403401        { 
    404402            int eq; 
    405403 
    406             if (_panels_layout.horizontal_split) 
     404            if (panels_layout.horizontal_split) 
    407405            { 
    408                 _panels_layout.horizontal_equal = check_options[0].widget->state & C_BOOL; 
    409                 eq = _panels_layout.horizontal_equal; 
     406                panels_layout.horizontal_equal = check_options[0].widget->state & C_BOOL; 
     407                eq = panels_layout.horizontal_equal; 
    410408            } 
    411409            else 
    412410            { 
    413                 _panels_layout.vertical_equal = check_options[0].widget->state & C_BOOL; 
    414                 eq = _panels_layout.vertical_equal; 
     411                panels_layout.vertical_equal = check_options[0].widget->state & C_BOOL; 
     412                eq = panels_layout.vertical_equal; 
    415413            } 
    416414 
    417415            widget_disable (WIDGET (bleft_widget), eq); 
    418416            widget_disable (WIDGET (bright_widget), eq); 
    419417 
    420418            update_split (h); 
     419            layout_change (); 
     420            do_refresh (); 
    421421 
    422422            return MSG_HANDLED; 
    423423        } 
    init_layout (void) 
    454454    output_lines_label = _("Output lines:"); 
    455455 
    456456    /* save old params */ 
    457     _panels_layout = panels_layout; 
    458457    _menubar_visible = menubar_visible; 
    459458    _command_prompt = command_prompt; 
    460459    _keybar_visible = mc_global.keybar_visible; 
    461460    _message_visible = mc_global.message_visible; 
    462461    _xterm_title = xterm_title; 
    463462    _free_space = free_space; 
    464  
    465     old_layout.horizontal_split = -1; 
    466     old_layout.left_panel_size = -1; 
    467     old_layout.top_panel_size = -1; 
    468  
    469463    old_output_lines = -1; 
    470464    _output_lines = output_lines; 
    471465 
    void 
    642636layout_box (void) 
    643637{ 
    644638    WDialog *layout_dlg; 
    645     gboolean layout_do_change = FALSE; 
    646639 
     640    old_layout = panels_layout; 
     641    old_output_lines = output_lines; 
    647642    layout_dlg = init_layout (); 
    648643 
    649     if (dlg_run (layout_dlg) == B_ENTER) 
     644    if (dlg_run (layout_dlg) == B_CANCEL) 
     645    { 
     646        panels_layout = old_layout; 
     647        output_lines = old_output_lines; 
     648        update_split (layout_dlg); 
     649    } 
     650    else 
    650651    { 
    651652        size_t i; 
    652653 
    653654        for (i = 0; i < (size_t) LAYOUT_OPTIONS_COUNT; i++) 
    654655            if (check_options[i].widget != NULL) 
    655656                *check_options[i].variable = check_options[i].widget->state & C_BOOL; 
    656  
    657         panels_layout.horizontal_split = radio_widget->sel; 
    658         if (panels_layout.horizontal_split) 
    659         { 
    660             panels_layout.horizontal_equal = *check_options[0].variable; 
    661             panels_layout.top_panel_size = _panels_layout.top_panel_size; 
    662         } 
    663         else 
    664         { 
    665             panels_layout.vertical_equal = *check_options[0].variable; 
    666             panels_layout.left_panel_size = _panels_layout.left_panel_size; 
    667         } 
    668         output_lines = _output_lines; 
    669         layout_do_change = TRUE; 
    670657    } 
    671658 
    672659    dlg_destroy (layout_dlg); 
    673     if (layout_do_change) 
    674         layout_change (); 
     660    layout_change (); 
     661    do_refresh (); 
    675662} 
    676663 
    677664/* --------------------------------------------------------------------------------------------- */